From 07670ff8712dd39240b2050fd8014bf7aa8769c5 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sun, 19 Oct 2014 21:20:43 +0200 Subject: [PATCH] Fix TSRMLS_* and a few warnings --- phpdbg.c | 9 +++++---- phpdbg.h | 23 ++++++++++++----------- phpdbg_io.c | 47 +++++++++++++++-------------------------------- phpdbg_io.h | 28 ++++++++-------------------- phpdbg_utils.c | 42 ++++++++++++++++++++---------------------- phpdbg_utils.h | 3 ++- 6 files changed, 62 insertions(+), 90 deletions(-) diff --git a/phpdbg.c b/phpdbg.c index 72582ceeac..71def1dd52 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -28,6 +28,7 @@ #include "phpdbg_list.h" #include "phpdbg_utils.h" #include "phpdbg_set.h" +#include "phpdbg_io.h" #include "zend_alloc.h" /* {{{ remote console headers */ @@ -793,7 +794,7 @@ static void phpdbg_remote_close(int socket, FILE *stream) { } /* don't inline this, want to debug it easily, will inline when done */ -static int phpdbg_remote_init(const char* address, unsigned short port, int server, int *socket, FILE **stream) { +static int phpdbg_remote_init(const char* address, unsigned short port, int server, int *socket, FILE **stream TSRMLS_DC) { phpdbg_remote_close(*socket, *stream); if (server < 0) { @@ -1255,8 +1256,8 @@ phpdbg_main: /* setup remote server if necessary */ if (!cleaning && listen > 0) { - server = phpdbg_open_socket(address, listen); - if (-1 > server || phpdbg_remote_init(address, listen, server, &socket, &stream) == FAILURE) { + server = phpdbg_open_socket(address, listen TSRMLS_CC); + if (-1 > server || phpdbg_remote_init(address, listen, server, &socket, &stream TSRMLS_CC) == FAILURE) { exit(0); } @@ -1462,7 +1463,7 @@ phpdbg_interact: if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { /* renegociate connections */ - phpdbg_remote_init(address, listen, server, &socket, &stream); + phpdbg_remote_init(address, listen, server, &socket, &stream TSRMLS_CC); /* set streams */ if (stream) { diff --git a/phpdbg.h b/phpdbg.h index fc9944111e..2cb73ff43f 100644 --- a/phpdbg.h +++ b/phpdbg.h @@ -40,20 +40,20 @@ #include "zend_ini_scanner.h" #include "zend_stream.h" #ifndef _WIN32 -# include "zend_signal.h" +# include "zend_signal.h" #endif #include "SAPI.h" #include #include #if defined(_WIN32) && !defined(__MINGW32__) -# include -# include "config.w32.h" -# undef strcasecmp -# undef strncasecmp -# define strcasecmp _stricmp -# define strncasecmp _strnicmp +# include +# include "config.w32.h" +# undef strcasecmp +# undef strncasecmp +# define strcasecmp _stricmp +# define strncasecmp _strnicmp #else -# include "php_config.h" +# include "php_config.h" #endif #ifndef O_BINARY # define O_BINARY 0 @@ -65,11 +65,11 @@ #endif #ifdef HAVE_LIBREADLINE -# include -# include +# include +# include #endif #ifdef HAVE_LIBEDIT -# include +# include #endif /* {{{ remote console headers */ @@ -78,6 +78,7 @@ # include # include # include +# include #endif /* }}} */ /* {{{ strings */ diff --git a/phpdbg_io.c b/phpdbg_io.c index 437e3ec3af..79fd55957d 100644 --- a/phpdbg_io.c +++ b/phpdbg_io.c @@ -51,14 +51,11 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); -PHPDBG_API int -phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo) -{/*{{{*/ +PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo TSRMLS_DC) { int got_now, i = len, j; char *p = ptr; #ifndef PHP_WIN32 struct pollfd pfd; - TSRMLS_FETCH(); if (tmo < 0) goto recv_once; pfd.fd = sock; @@ -70,7 +67,6 @@ phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo) #else struct fd_set readfds; struct timeval ttmo; - TSRMLS_FETCH(); if (tmo < 0) goto recv_once; FD_ZERO(&readfds); @@ -105,11 +101,9 @@ recv_once: } return p - ptr; -}/*}}}*/ +} -PHPDBG_API int -phpdbg_send_bytes(int sock, char *ptr, int len) -{/*{{{*/ +PHPDBG_API int phpdbg_send_bytes(int sock, const char *ptr, int len) { int sent, i = len; char *p = ptr; /* XXX poll/select needed here? */ @@ -123,36 +117,30 @@ phpdbg_send_bytes(int sock, char *ptr, int len) } return len; -}/*}}}*/ +} -PHPDBG_API int -phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_CC) -{/*{{{*/ +PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_DC) { if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { - return phpdbg_consume_bytes(sock, ptr, len, tmo); + return phpdbg_consume_bytes(sock, ptr, len, tmo TSRMLS_CC); } return read(sock, ptr, len); -}/*}}}*/ +} -PHPDBG_API int -phpdbg_mixed_write(int sock, char *ptr, int len TSRMLS_CC) -{/*{{{*/ +PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len TSRMLS_DC) { if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { return phpdbg_send_bytes(sock, ptr, len); } return write(sock, ptr, len); -}/*}}}*/ +} -PHPDBG_API int -phpdbg_open_socket(const char *interface, short port) /* {{{ */ -{ +PHPDBG_API int phpdbg_open_socket(const char *interface, short port TSRMLS_DC) { struct addrinfo res; - int fd = phpdbg_create_listenable_socket(interface, port, &res); + int fd = phpdbg_create_listenable_socket(interface, port, &res TSRMLS_CC); if (fd == -1) { return -1; @@ -166,19 +154,16 @@ phpdbg_open_socket(const char *interface, short port) /* {{{ */ listen(fd, 5); return fd; -} /* }}} */ +} -PHPDBG_API int -phpdbg_create_listenable_socket(const char *addr, int port, struct addrinfo *addr_res) -{/*{{{*/ +PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, int port, struct addrinfo *addr_res TSRMLS_DC) { int sock = -1, rc; int reuse = 1; struct in6_addr serveraddr; struct addrinfo hints, *res = NULL; char port_buf[8]; int8_t any_addr = *addr == '*'; - TSRMLS_FETCH(); do { memset(&hints, 0, sizeof hints); @@ -263,11 +248,9 @@ phpdbg_create_listenable_socket(const char *addr, int port, struct addrinfo *add *addr_res = *res; return sock; -}/*}}}*/ +} -PHPDBG_API void -phpdbg_close_socket(int sock) -{ +PHPDBG_API void phpdbg_close_socket(int sock) { if (socket >= 0) { #ifdef _WIN32 closesocket(sock); diff --git a/phpdbg_io.h b/phpdbg_io.h index 1edfe73662..4d1b74044b 100644 --- a/phpdbg_io.h +++ b/phpdbg_io.h @@ -21,26 +21,14 @@ #include "phpdbg.h" -PHPDBG_API int -phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo); - -PHPDBG_API int -phpdbg_send_bytes(int sock, char *ptr, int len); - -PHPDBG_API int -phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_CC); - -PHPDBG_API int -phpdbg_mixed_write(int sock, char *ptr, int len TSRMLS_CC); - -PHPDBG_API int -phpdbg_create_listenable_socket(const char *addr, int port, struct addrinfo *res); - -PHPDBG_API int -phpdbg_open_socket(const char *interface, short port); - -PHPDBG_API void -phpdbg_close_socket(int sock); +PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo TSRMLS_DC); +PHPDBG_API int phpdbg_send_bytes(int sock, const char *ptr, int len); +PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_DC); +PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len TSRMLS_DC); + +PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, int port, struct addrinfo *res TSRMLS_DC); +PHPDBG_API int phpdbg_open_socket(const char *interface, short port TSRMLS_DC); +PHPDBG_API void phpdbg_close_socket(int sock); #endif /* PHPDBG_IO_H */ diff --git a/phpdbg_utils.c b/phpdbg_utils.c index 4a45642a4d..0768726e6e 100644 --- a/phpdbg_utils.c +++ b/phpdbg_utils.c @@ -1129,7 +1129,7 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m const char *severity; if ((PHPDBG_G(flags) & PHPDBG_WRITE_XML) && PHPDBG_G(in_script_xml) && PHPDBG_G(in_script_xml) != type) { - phpdbg_mixed_write(fd, ZEND_STRL("")); + phpdbg_mixed_write(fd, ZEND_STRL("") TSRMLS_CC); PHPDBG_G(in_script_xml) = 0; } @@ -1140,9 +1140,9 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m severity = "error"; if (!PHPDBG_G(last_was_newline)) { if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { - phpdbg_mixed_write(fd, ZEND_STRL("\n" "")); + phpdbg_mixed_write(fd, ZEND_STRL("\n" "") TSRMLS_CC); } else { - phpdbg_mixed_write(fd, ZEND_STRL("\n")); + phpdbg_mixed_write(fd, ZEND_STRL("\n") TSRMLS_CC); } PHPDBG_G(last_was_newline) = 1; } @@ -1157,9 +1157,9 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m severity = "notice"; if (!PHPDBG_G(last_was_newline)) { if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) { - phpdbg_mixed_write(fd, ZEND_STRL("\n" "")); + phpdbg_mixed_write(fd, ZEND_STRL("\n" "") TSRMLS_CC); } else { - phpdbg_mixed_write(fd, ZEND_STRL("\n")); + phpdbg_mixed_write(fd, ZEND_STRL("\n") TSRMLS_CC); } PHPDBG_G(last_was_newline) = 1; } @@ -1201,16 +1201,16 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m if (PHPDBG_G(in_script_xml) != type) { char *stream_buf; int stream_buflen = spprintf(&stream_buf, 0, "", type == P_STDERR ? "stderr" : "stdout"); - phpdbg_mixed_write(fd, stream_buf, stream_buflen); + phpdbg_mixed_write(fd, stream_buf, stream_buflen TSRMLS_CC); efree(stream_buf); PHPDBG_G(in_script_xml) = type; } buf = php_escape_html_entities((unsigned char *) msg, msglen, (size_t *) &buflen, 0, ENT_NOQUOTES, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8") TSRMLS_CC); phpdbg_encode_ctrl_chars(&buf, &buflen); - phpdbg_mixed_write(fd, buf, buflen); + phpdbg_mixed_write(fd, buf, buflen TSRMLS_CC); efree(buf); } else { - phpdbg_mixed_write(fd, msg, msglen); + phpdbg_mixed_write(fd, msg, msglen TSRMLS_CC); } return msglen; } @@ -1239,8 +1239,6 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m xml = xmlbuf; } if (msgout) { -// unsigned char *tmp = msgout; -// buf = php_escape_html_entities(tmp, msgoutlen, (size_t *) &buflen, 0, ENT_COMPAT, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8") TSRMLS_CC); buflen = phpdbg_encode_xml(&buf, msgout, msgoutlen, '"', """); xmloutlen = spprintf(&xmlout, 0, "<%s severity=\"%s\" %.*s msgout=\"%.*s\" />", tag, severity, xmllen, xml, buflen, buf); @@ -1250,10 +1248,10 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m } phpdbg_encode_ctrl_chars(&xmlout, &xmloutlen); - phpdbg_mixed_write(fd, xmlout, xmloutlen); + phpdbg_mixed_write(fd, xmlout, xmloutlen TSRMLS_CC); efree(xmlout); } else if (msgout) { - phpdbg_mixed_write(fd, msgout, msgoutlen); + phpdbg_mixed_write(fd, msgout, msgoutlen TSRMLS_CC); } if (PHPDBG_G(req_id) && (PHPDBG_G(flags) & PHPDBG_WRITE_XML)) { @@ -1381,11 +1379,11 @@ PHPDBG_API int phpdbg_xml_internal(int fd TSRMLS_DC, const char *fmt, ...) { phpdbg_encode_ctrl_chars(&buffer, &buflen); if (PHPDBG_G(in_script_xml)) { - phpdbg_mixed_write(fd, ZEND_STRL("")); + phpdbg_mixed_write(fd, ZEND_STRL("") TSRMLS_CC); PHPDBG_G(in_script_xml) = 0; } - len = phpdbg_mixed_write(fd, buffer, buflen); + len = phpdbg_mixed_write(fd, buffer, buflen TSRMLS_CC); efree(buffer); } @@ -1402,7 +1400,7 @@ PHPDBG_API int phpdbg_log_internal(int fd TSRMLS_DC, const char *fmt, ...) { buflen = vspprintf(&buffer, 0, fmt, args); va_end(args); - len = phpdbg_mixed_write(fd, buffer, buflen); + len = phpdbg_mixed_write(fd, buffer, buflen TSRMLS_CC); efree(buffer); return len; @@ -1426,22 +1424,22 @@ PHPDBG_API int phpdbg_out_internal(int fd TSRMLS_DC, const char *fmt, ...) { phpdbg_encode_ctrl_chars(&msg, &msglen); if (PHPDBG_G(in_script_xml)) { - phpdbg_mixed_write(fd, ZEND_STRL("")); + phpdbg_mixed_write(fd, ZEND_STRL("") TSRMLS_CC); PHPDBG_G(in_script_xml) = 0; } - phpdbg_mixed_write(fd, ZEND_STRL("")); - len = phpdbg_mixed_write(fd, msg, msglen); - phpdbg_mixed_write(fd, ZEND_STRL("")); + phpdbg_mixed_write(fd, ZEND_STRL("") TSRMLS_CC); + len = phpdbg_mixed_write(fd, msg, msglen TSRMLS_CC); + phpdbg_mixed_write(fd, ZEND_STRL("") TSRMLS_CC); } else { - len = phpdbg_mixed_write(fd, buffer, buflen); + len = phpdbg_mixed_write(fd, buffer, buflen TSRMLS_CC); } return len; } -PHPDBG_API int phpdbg_rlog(int fd, const char *fmt, ...) { /* {{{ */ +PHPDBG_API int phpdbg_rlog_internal(int fd TSRMLS_DC, const char *fmt, ...) { /* {{{ */ int rc = 0; va_list args; @@ -1463,7 +1461,7 @@ PHPDBG_API int phpdbg_rlog(int fd, const char *fmt, ...) { /* {{{ */ rc = vspprintf(&outbuf, 0, format, args); if (outbuf) { - rc = phpdbg_mixed_write(fd, outbuf, rc); + rc = phpdbg_mixed_write(fd, outbuf, rc TSRMLS_CC); efree(outbuf); } diff --git a/phpdbg_utils.h b/phpdbg_utils.h index 0a677b40c6..cee39c4879 100644 --- a/phpdbg_utils.h +++ b/phpdbg_utils.h @@ -56,7 +56,8 @@ PHPDBG_API int phpdbg_xml_internal(int fd TSRMLS_DC, const char *fmt, ...); PHPDBG_API int phpdbg_log_internal(int fd TSRMLS_DC, const char *fmt, ...); PHPDBG_API int phpdbg_out_internal(int fd TSRMLS_DC, const char *fmt, ...); -PHPDBG_API int phpdbg_rlog(int fd, const char *fmt, ...); +PHPDBG_API int phpdbg_rlog_internal(int fd TSRMLS_DC, const char *fmt, ...); +#define phpdbg_rlog(fd, fmt, ...) phpdbg_rlog_internal(fd TSRMLS_CC, fmt, ##__VA_ARGS__) #define phpdbg_error(tag, xmlfmt, strfmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__) #define phpdbg_notice(tag, xmlfmt, strfmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__) -- 2.40.0