Skip to content

Commit

Permalink
Move va_copy compatibility code into zend_portability.h
Browse files Browse the repository at this point in the history
Previously this was defined in zend.c and php.h and also handled
in another way in soap.c.
  • Loading branch information
nikic committed Jun 25, 2017
1 parent 6dd2eaf commit 205807f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 40 deletions.
13 changes: 0 additions & 13 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1230,22 +1230,9 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list a
break;
default:
/* Handle the error in user space */
/* va_copy() is __va_copy() in old gcc versions.
* According to the autoconf manual, using
* memcpy(&dst, &src, sizeof(va_list))
* gives maximum portability. */
#ifndef va_copy
# ifdef __va_copy
# define va_copy(dest, src) __va_copy((dest), (src))
# else
# define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
# endif
#endif
va_copy(usr_copy, args);
ZVAL_STR(&params[1], zend_vstrpprintf(0, format, usr_copy));
#ifdef va_copy
va_end(usr_copy);
#endif

ZVAL_LONG(&params[0], type);

Expand Down
12 changes: 12 additions & 0 deletions Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,18 @@ static zend_always_inline double _zend_get_nan(void) /* {{{ */
#define ZEND_VALID_SOCKET(sock) ((sock) >= 0)
#endif

/* va_copy() is __va_copy() in old gcc versions.
* According to the autoconf manual, using
* memcpy(&dst, &src, sizeof(va_list))
* gives maximum portability. */
#ifndef va_copy
# ifdef __va_copy
# define va_copy(dest, src) __va_copy((dest), (src))
# else
# define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
# endif
#endif

#endif /* ZEND_PORTABILITY_H */

/*
Expand Down
21 changes: 2 additions & 19 deletions ext/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,13 @@ ZEND_DECLARE_MODULE_GLOBALS(soap)

static void (*old_error_handler)(int, const char *, const uint32_t, const char*, va_list);

#ifdef va_copy
#define call_old_error_handler(error_num, error_filename, error_lineno, format, args) \
{ \
va_list copy; \
va_copy(copy, args); \
old_error_handler(error_num, error_filename, error_lineno, format, copy); \
va_end(copy); \
}
#else
#define call_old_error_handler(error_num, error_filename, error_lineno, format, args) \
{ \
old_error_handler(error_num, error_filename, error_lineno, format, args); \
}
#endif

#define PHP_SOAP_SERVER_CLASSNAME "SoapServer"
#define PHP_SOAP_CLIENT_CLASSNAME "SoapClient"
Expand Down Expand Up @@ -2163,19 +2156,14 @@ static void soap_error_handler(int error_num, const char *error_filename, const
char* code = SOAP_GLOBAL(error_code);
char buffer[1024];
size_t buffer_len;
#ifdef va_copy
va_list argcopy;
#endif
zend_object **old_objects;
int old = PG(display_errors);

#ifdef va_copy
va_copy(argcopy, args);
buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, argcopy);
va_end(argcopy);
#else
buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, args);
#endif

buffer[sizeof(buffer)-1]=0;
if (buffer_len > sizeof(buffer) - 1 || buffer_len == (size_t)-1) {
buffer_len = sizeof(buffer) - 1;
Expand Down Expand Up @@ -2216,9 +2204,7 @@ static void soap_error_handler(int error_num, const char *error_filename, const
int old = PG(display_errors);
int fault = 0;
zval fault_obj;
#ifdef va_copy
va_list argcopy;
#endif

if (error_num == E_USER_ERROR ||
error_num == E_COMPILE_ERROR ||
Expand Down Expand Up @@ -2246,13 +2232,10 @@ static void soap_error_handler(int error_num, const char *error_filename, const
size_t buffer_len;
zval outbuflen;

#ifdef va_copy
va_copy(argcopy, args);
buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, argcopy);
va_end(argcopy);
#else
buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, args);
#endif

buffer[sizeof(buffer)-1]=0;
if (buffer_len > sizeof(buffer) - 1 || buffer_len == (size_t)-1) {
buffer_len = sizeof(buffer) - 1;
Expand Down
8 changes: 0 additions & 8 deletions main/php.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,6 @@ typedef unsigned int socklen_t;
# endif
#endif

#ifndef va_copy
# ifdef __va_copy
# define va_copy(ap1, ap2) __va_copy((ap1), (ap2))
# else
# define va_copy(ap1, ap2) memcpy((&ap1), (&ap2), sizeof(va_list))
# endif
#endif

#include "php_stdint.h"

#include "zend_hash.h"
Expand Down

0 comments on commit 205807f

Please sign in to comment.