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);
}
/* }}} */
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);
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)
}
}
-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
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, \
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;
}
}
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);
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);
}
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);
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");
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] = '/';
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));
}