]> granicus.if.org Git - php/commitdiff
Make number printing functions less generic
authorNikita Popov <nikic@php.net>
Fri, 19 Sep 2014 21:22:26 +0000 (23:22 +0200)
committerNikita Popov <nikic@php.net>
Fri, 19 Sep 2014 21:39:07 +0000 (23:39 +0200)
Now that zend_ulong is 64bit on 64bit platforms, it should be
sufficient to always use it, rather than supporting multiple
types.

API changes:
 * _zend_print_unsigned_to_buf and _zend_print_signed_to_buf
   no longer exist.
 * smart_str(ing)_print_long and smart_str(ing)_print_unsigned
   no longer exist.
 * Instead of all these, zend_print_ulong_to_buf and
   zend_print_long_to_buf should be used.
 * smart_str_append_generic_ex no longer exists.
 * smart_str(ing)_append_off_t(_ex) no longer exists, use
   smart_str(ing)_append_long(_ex) instead.

Zend/zend_operators.c
Zend/zend_operators.h
ext/standard/php_smart_str.h
ext/standard/php_smart_string.h
ext/standard/var.c
sapi/cli/php_cli_server.c
sapi/thttpd/thttpd.c

index a63b1757e2cf810fec7953f4de9d8d494e5f0784..8047aa601990137c4c0b6c3738f6d870d2bebc12 100644 (file)
@@ -2520,8 +2520,7 @@ ZEND_API void zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_DC) /* {{{ */
 ZEND_API zend_string *zend_long_to_str(zend_long num) /* {{{ */
 {
        char buf[MAX_LENGTH_OF_LONG + 1];
-       char *res;
-       _zend_print_signed_to_buf(buf + sizeof(buf) - 1, num, zend_ulong, res);
+       char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1, num);
        return zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
 }
 /* }}} */
index ece77936ebf34e91afa57546b7a32c13be0bd7cf..ddec16217467ba90e10dc7dd8d22e8d6b50bcf10 100644 (file)
@@ -894,27 +894,26 @@ static zend_always_inline void fast_is_not_identical_function(zval *result, zval
                return SUCCESS;                                                                           \
        }
 
-/* input: buf points to the END of the buffer */
-#define _zend_print_unsigned_to_buf(buf, num, vartype, result) do {    \
-       char *__p = (buf);                                                 \
-       vartype __num = (num);                                             \
-       *__p = '\0';                                                       \
-       do {                                                               \
-               *--__p = (char) (__num % 10) + '0';                            \
-               __num /= 10;                                                   \
-       } while (__num > 0);                                               \
-       result = __p;                                                      \
-} while (0)
+/* buf points to the END of the buffer */
+static zend_always_inline char *zend_print_ulong_to_buf(char *buf, zend_ulong num) {
+       *buf = '\0';
+       do {
+               *--buf = (char) (num % 10) + '0';
+               num /= 10;
+       } while (num > 0);
+       return buf;
+}
 
 /* buf points to the END of the buffer */
-#define _zend_print_signed_to_buf(buf, num, vartype, result) do {               \
-       if (num < 0) {                                                              \
-           _zend_print_unsigned_to_buf((buf), (~((vartype)(num)) + 1), vartype, (result)); \
-           *--(result) = '-';                                                      \
-       } else {                                                                    \
-           _zend_print_unsigned_to_buf((buf), (num), vartype, (result));           \
-       }                                                                           \
-} while (0)
+static zend_always_inline char *zend_print_long_to_buf(char *buf, zend_long num) {
+       if (num < 0) {
+           char *result = zend_print_ulong_to_buf(buf, ~((zend_ulong) num) + 1);
+           *--result = '-';
+               return result;
+       } else {
+           return zend_print_ulong_to_buf(buf, num);
+       }
+}
 
 ZEND_API zend_string *zend_long_to_str(zend_long num);
 
index 25d6fe2db4aa60090d1554e7015d451544a7dbda..1c8c41837030bf7bbc016cc3841be8da2ac322c0 100644 (file)
@@ -50,8 +50,6 @@
        smart_str_setl((dest), (src), strlen(src));
 #define smart_str_append_long(dest, val) \
        smart_str_append_long_ex((dest), (val), 0)
-#define smart_str_append_off_t(dest, val) \
-       smart_str_append_off_t_ex((dest), (val), 0)
 #define smart_str_append_unsigned(dest, val) \
        smart_str_append_unsigned_ex((dest), (val), 0)
 
@@ -106,37 +104,21 @@ static zend_always_inline void smart_str_append_ex(smart_str *dest, const smart_
        }
 }
 
-static zend_always_inline void smart_str_setl(smart_str *dest, const char *src, size_t len) {
-       smart_str_free(dest);
-       smart_str_appendl(dest, src, len);
-}
-static inline char *smart_str_print_long(char *buf, zend_long num) {
-       char *r; 
-       _zend_print_signed_to_buf(buf, num, zend_long, r); 
-       return r;
+static zend_always_inline void smart_str_append_long_ex(smart_str *dest, zend_long num, zend_bool persistent) {
+       char buf[32];
+       char *result = zend_print_long_to_buf(buf + sizeof(buf) - 1, num);
+       smart_str_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent);
 }
 
-static inline char *smart_str_print_unsigned(char *buf, zend_long num) {
-       char *r; 
-       _zend_print_unsigned_to_buf(buf, num, zend_ulong, r); 
-       return r;
+static zend_always_inline void smart_str_append_unsigned_ex(smart_str *dest, zend_ulong num, zend_bool persistent) {
+       char buf[32];
+       char *result = zend_print_ulong_to_buf(buf + sizeof(buf) - 1, num);
+       smart_str_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent);
 }
 
-#define smart_str_append_generic_ex(dest, num, type, vartype, func) do {       \
-       char __b[32];                                                                                                                   \
-       char *__t;                                                                                                                              \
-       _zend_print##func##_to_buf (__b + sizeof(__b) - 1, (num), vartype, __t);        \
-       smart_str_appendl_ex((dest), __t, __b + sizeof(__b) - 1 - __t, (type)); \
-} while (0)
-       
-#define smart_str_append_unsigned_ex(dest, num, type) \
-       smart_str_append_generic_ex((dest), (num), (type), zend_ulong, _unsigned)
-
-#define smart_str_append_long_ex(dest, num, type) \
-       smart_str_append_generic_ex((dest), (num), (type), zend_ulong, _signed)
-
-#define smart_str_append_off_t_ex(dest, num, type) \
-       smart_str_append_generic_ex((dest), (num), (type), zend_off_t, _signed)
+static zend_always_inline void smart_str_setl(smart_str *dest, const char *src, size_t len) {
+       smart_str_free(dest);
+       smart_str_appendl(dest, src, len);
+}
 
 #endif
index 36647aa27a71ef1ee30b2f1a237514f5fa73af2f..e052574a34674b1d572abd0129bb27026a0af9c0 100644 (file)
@@ -89,8 +89,6 @@
        smart_string_append_ex((dest), (src), 0)
 #define smart_string_append_long(dest, val) \
        smart_string_append_long_ex((dest), (val), 0)
-#define smart_string_append_off_t(dest, val) \
-       smart_string_append_off_t_ex((dest), (val), 0)
 #define smart_string_append_unsigned(dest, val) \
        smart_string_append_unsigned_ex((dest), (val), 0)
 
        __dest->len = __nl;                                                                                             \
 } while (0)
 
-static inline char *smart_string_print_long(char *buf, zend_long num) {
-       char *r; 
-       _zend_print_signed_to_buf(buf, num, zend_long, r);
-       return r;
-}
-
-static inline char *smart_string_print_unsigned(char *buf, zend_long num) {
-       char *r; 
-       _zend_print_unsigned_to_buf(buf, num, zend_ulong, r);
-       return r;
-}
-
 #define smart_string_append_generic_ex(dest, num, type, vartype, func) do {    \
        char __b[32];                                                                                                                   \
-       char *__t;                                                                                                                              \
-       _zend_print##func##_to_buf(__b + sizeof(__b) - 1, (num), vartype, __t); \
+       char *__t = zend_print##func##_to_buf(__b + sizeof(__b) - 1, (num));    \
        smart_string_appendl_ex((dest), __t, __b + sizeof(__b) - 1 - __t, (type));      \
 } while (0)
        
 #define smart_string_append_unsigned_ex(dest, num, type) \
-       smart_string_append_generic_ex((dest), (num), (type), zend_ulong, _unsigned)
+       smart_string_append_generic_ex((dest), (num), (type), zend_ulong, _ulong)
 
 #define smart_string_append_long_ex(dest, num, type) \
-       smart_string_append_generic_ex((dest), (num), (type), zend_ulong, _signed)
-
-#define smart_string_append_off_t_ex(dest, num, type) \
-       smart_string_append_generic_ex((dest), (num), (type), zend_off_t, _signed)
+       smart_string_append_generic_ex((dest), (num), (type), zend_ulong, _long)
 
 #define smart_string_append_ex(dest, src, what) \
        smart_string_appendl_ex((dest), ((smart_string *)(src))->c, \
index 9d2de3031fd0cdb881e8b5c770f35afe05713527..532e53a110fb09645a58b61e26078198ae3294f9 100644 (file)
@@ -611,17 +611,17 @@ static inline int php_add_var_hash(HashTable *var_hash, zval *var_ptr, zval *var
                var = Z_REFVAL_P(var);
        }
        if ((Z_TYPE_P(var) == IS_OBJECT) && Z_OBJ_HT_P(var)->get_class_entry) {
-               p = smart_str_print_long(id + sizeof(id) - 1,
+               p = zend_print_long_to_buf(id + sizeof(id) - 1,
                                (zend_long) Z_OBJ_P(var));
                *(--p) = 'O';
                len = id + sizeof(id) - 1 - p;
        } else if (var_ptr != var) {
-               p = smart_str_print_long(id + sizeof(id) - 1,
+               p = zend_print_long_to_buf(id + sizeof(id) - 1,
                                (zend_long) Z_REF_P(var_ptr));
                *(--p) = 'R';
                len = id + sizeof(id) - 1 - p;
        } else {
-               p = smart_str_print_long(id + sizeof(id) - 1, (zend_long) var);
+               p = zend_print_long_to_buf(id + sizeof(id) - 1, (zend_long) var);
                len = id + sizeof(id) - 1 - p;
        }
 
index 2d2e399ec87f236748b28985ea9f5064447425ed..b2defe0841eed7128d6a36abd06834c1b87eb254 100644 (file)
@@ -380,11 +380,11 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int
        }
        smart_str_appendl_ex(buffer, "HTTP", 4, persistent);
        smart_str_appendc_ex(buffer, '/', persistent);
-       smart_str_append_generic_ex(buffer, protocol_version / 100, persistent, int, _unsigned);
+       smart_str_append_long_ex(buffer, protocol_version / 100, persistent);
        smart_str_appendc_ex(buffer, '.', persistent);
-       smart_str_append_generic_ex(buffer, protocol_version % 100, persistent, int, _unsigned);
+       smart_str_append_long_ex(buffer, protocol_version % 100, persistent);
        smart_str_appendc_ex(buffer, ' ', persistent);
-       smart_str_append_generic_ex(buffer, response_code, persistent, int, _unsigned);
+       smart_str_append_long_ex(buffer, response_code, persistent);
        smart_str_appendc_ex(buffer, ' ', persistent);
        smart_str_appends_ex(buffer, get_status_string(response_code), persistent);
        smart_str_appendl_ex(buffer, "\r\n", 2, persistent);
@@ -1902,7 +1902,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server
                append_essential_headers(&buffer, client, 1);
                smart_str_appends_ex(&buffer, "Content-Type: text/html; charset=UTF-8\r\n", 1);
                smart_str_appends_ex(&buffer, "Content-Length: ", 1);
-               smart_str_append_generic_ex(&buffer, php_cli_server_buffer_size(&client->content_sender.buffer), 1, size_t, _unsigned);
+               smart_str_append_unsigned_ex(&buffer, php_cli_server_buffer_size(&client->content_sender.buffer), 1);
                smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
                smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
 
@@ -1993,7 +1993,7 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
                }
                smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
                smart_str_appends_ex(&buffer, "Content-Length: ", 1);
-               smart_str_append_generic_ex(&buffer, client->request.sb.st_size, 1, size_t, _unsigned);
+               smart_str_append_unsigned_ex(&buffer, client->request.sb.st_size, 1);
                smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
                smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
                chunk = php_cli_server_chunk_heap_new(buffer.s, buffer.s->val, buffer.s->len);
index 529ac2f48b660f0c8426ae5546cca5f4a80c7bf4..1671a5b65b77a55a89f583c35d9aea2d78b44cc9 100644 (file)
@@ -181,7 +181,7 @@ static int sapi_thttpd_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
        
        if (!SG(sapi_headers).http_status_line) {
                ADD_VEC_S("HTTP/1.1 ");
-               p = smart_str_print_long(buf+sizeof(buf)-1, 
+               p = zend_print_long_to_buf(buf+sizeof(buf)-1, 
                                SG(sapi_headers).http_response_code);
                ADD_VEC(p, strlen(p));
                ADD_VEC_S(" HTTP\r\n");
@@ -293,7 +293,7 @@ static void sapi_thttpd_register_variables(zval *track_vars_array TSRMLS_DC)
        ADD_STRING_EX("REMOTE_HOST", p);
 
        ADD_STRING_EX("SERVER_PORT",
-                       smart_str_print_long(buf + sizeof(buf) - 1,
+                       zend_print_long_to_buf(buf + sizeof(buf) - 1,
                                TG(hc)->hs->port));
 
        buf[0] = '/';
@@ -323,7 +323,7 @@ static void sapi_thttpd_register_variables(zval *track_vars_array TSRMLS_DC)
 
        if (TG(hc)->contentlength != -1) {
                ADD_STRING_EX("CONTENT_LENGTH",
-                               smart_str_print_long(buf + sizeof(buf) - 1, 
+                               zend_print_long_to_buf(buf + sizeof(buf) - 1, 
                                        TG(hc)->contentlength));
        }