summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2016-12-18 17:53:27 +0100
committerNikita Popov <nikic@php.net>2017-01-01 21:28:20 +0100
commit5fc9aa9a9509727a55ec5badae9df1a9617be6a1 (patch)
tree1ffcd5cf9baee362c5556d4e5bf99e973cb255fe /main
parentc7742e280a4edcc8b216d7b798c805c9a439d663 (diff)
downloadphp-git-5fc9aa9a9509727a55ec5badae9df1a9617be6a1.tar.gz
Make printf_to_smart_str(ing) the primitive printf operation
vs(tr)pprintf is now implemented in Zend on top of printf_to_smart_str(int), which is provided as a utility function. This allows us to efficiently printf to the end of a smart string.
Diffstat (limited to 'main')
-rw-r--r--main/main.c4
-rw-r--r--main/spprintf.c45
-rw-r--r--main/spprintf.h23
3 files changed, 12 insertions, 60 deletions
diff --git a/main/main.c b/main/main.c
index 361b356d44..afa4313570 100644
--- a/main/main.c
+++ b/main/main.c
@@ -2114,8 +2114,8 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
zuf.ticks_function = php_run_ticks;
zuf.on_timeout = php_on_timeout;
zuf.stream_open_function = php_stream_open_for_zend;
- zuf.vspprintf_function = vspprintf;
- zuf.vstrpprintf_function = vstrpprintf;
+ zuf.printf_to_smart_string_function = php_printf_to_smart_string;
+ zuf.printf_to_smart_str_function = php_printf_to_smart_str;
zuf.getenv_function = sapi_getenv;
zuf.resolve_path_function = php_resolve_path_for_zend;
zend_startup(&zuf, NULL);
diff --git a/main/spprintf.c b/main/spprintf.c
index 8f141c9978..0e0784663c 100644
--- a/main/spprintf.c
+++ b/main/spprintf.c
@@ -827,52 +827,15 @@ skip_output:
}
/* }}} */
-/*
- * This is the general purpose conversion function.
- */
-PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */
+PHPAPI void php_printf_to_smart_string(smart_string *buf, const char *format, va_list ap) /* {{{ */
{
- smart_string buf = {0};
-
- /* since there are places where (v)spprintf called without checking for null,
- a bit of defensive coding here */
- if(!pbuf) {
- return 0;
- }
- xbuf_format_converter(&buf, 1, format, ap);
-
- if (max_len && buf.len > max_len) {
- buf.len = max_len;
- }
-
- smart_string_0(&buf);
-
- if (buf.c) {
- *pbuf = buf.c;
- return buf.len;
- } else {
- *pbuf = estrndup("", 0);
- return 0;
- }
+ xbuf_format_converter(buf, 1, format, ap);
}
/* }}} */
-PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */
+PHPAPI void php_printf_to_smart_str(smart_str *buf, const char *format, va_list ap) /* {{{ */
{
- smart_str buf = {0};
-
- xbuf_format_converter(&buf, 0, format, ap);
-
- if (!buf.s) {
- return ZSTR_EMPTY_ALLOC();
- }
-
- if (max_len && ZSTR_LEN(buf.s) > max_len) {
- ZSTR_LEN(buf.s) = max_len;
- }
-
- smart_str_0(&buf);
- return buf.s;
+ xbuf_format_converter(buf, 0, format, ap);
}
/* }}} */
diff --git a/main/spprintf.h b/main/spprintf.h
index db684c2be8..d69bffa05b 100644
--- a/main/spprintf.h
+++ b/main/spprintf.h
@@ -16,33 +16,22 @@
+----------------------------------------------------------------------+
*/
-/* $Id$ */
-
-/*
-
-The pbuf parameter of all spprintf version receives a pointer to the allocated
-buffer. This buffer must be freed manually after usage using efree() function.
-The buffer will always be terminated by a zero character. When pbuf is NULL
-the function can be used to calculate the required size of the buffer but for
-that purpose snprintf is faster. When both pbuf and the return value are 0
-than you are out of memory.
-
-There is also snprintf: See difference explained in snprintf.h
-
-*/
-
#ifndef SPPRINTF_H
#define SPPRINTF_H
#include "snprintf.h"
+#include "zend_smart_str_public.h"
+#include "zend_smart_string_public.h"
BEGIN_EXTERN_C()
-PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0);
-PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 2, 0);
+PHPAPI void php_printf_to_smart_string(smart_string *buf, const char *format, va_list ap);
+PHPAPI void php_printf_to_smart_str(smart_str *buf, const char *format, va_list ap);
END_EXTERN_C()
#define spprintf zend_spprintf
#define strpprintf zend_strpprintf
+#define vspprintf zend_vspprintf
+#define vstrpprintf zend_vstrpprintf
#endif /* SNPRINTF_H */