Skip to content

Commit

Permalink
Export zend_s(tr)pprintf
Browse files Browse the repository at this point in the history
It's annoying that in Zend you have to use zend_strpprintf instead
of strpprintf, while in PHP you have to use strpprintf instead of
zend_strpprintf.

Make zend_s(tr)pprintf always available and keep s(tr)pprintf as
macro aliases.
  • Loading branch information
nikic committed Jan 1, 2017
1 parent 38f72ce commit c7742e2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 57 deletions.
24 changes: 24 additions & 0 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@ static uint32_t zend_version_info_length;
#define ZEND_CORE_VERSION_INFO "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2016 Zend Technologies\n"
#define PRINT_ZVAL_INDENT 4

ZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */
{
va_list arg;
size_t len;

va_start(arg, format);
len = zend_vspprintf(message, max_len, format, arg);
va_end(arg);
return len;
}
/* }}} */

ZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */
{
va_list arg;
zend_string *str;

va_start(arg, format);
str = zend_vstrpprintf(max_len, format, arg);
va_end(arg);
return str;
}
/* }}} */

static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent);

static void print_hash(smart_str *buf, HashTable *ht, int indent, zend_bool is_object) /* {{{ */
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ void zend_set_utility_values(zend_utility_values *utility_values);

ZEND_API ZEND_COLD void _zend_bailout(char *filename, uint32_t lineno);

ZEND_API size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4);
ZEND_API zend_string *zend_strpprintf(size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);

ZEND_API char *get_zend_version(void);
ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy);
ZEND_API size_t zend_print_zval(zval *expr, int indent);
Expand Down
24 changes: 0 additions & 24 deletions Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,30 +651,6 @@ ZEND_METHOD(exception, getPrevious)
ZVAL_COPY(return_value, GET_PROPERTY_SILENT(getThis(), ZEND_STR_PREVIOUS));
} /* }}} */

size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */
{
va_list arg;
size_t len;

va_start(arg, format);
len = zend_vspprintf(message, max_len, format, arg);
va_end(arg);
return len;
}
/* }}} */

zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */
{
va_list arg;
zend_string *str;

va_start(arg, format);
str = zend_vstrpprintf(max_len, format, arg);
va_end(arg);
return str;
}
/* }}} */

/* {{{ proto string Exception|Error::__toString()
Obtain the string representation of the Exception object */
ZEND_METHOD(exception, __toString)
Expand Down
4 changes: 0 additions & 4 deletions Zend/zend_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ extern ZEND_API void (*zend_throw_exception_hook)(zval *ex);
/* show an exception using zend_error(severity,...), severity should be E_ERROR */
ZEND_API ZEND_COLD void zend_exception_error(zend_object *exception, int severity);

/* do not export, in php it's available thru spprintf directly */
size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4);
zend_string *zend_strpprintf(size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);

#include "zend_globals.h"

static zend_always_inline void zend_rethrow_exception(zend_execute_data *execute_data)
Expand Down
24 changes: 0 additions & 24 deletions main/spprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,18 +857,6 @@ PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list
}
/* }}} */

PHPAPI size_t spprintf(char **pbuf, size_t max_len, const char *format, ...) /* {{{ */
{
size_t cc;
va_list ap;

va_start(ap, format);
cc = vspprintf(pbuf, max_len, format, ap);
va_end(ap);
return (cc);
}
/* }}} */

PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */
{
smart_str buf = {0};
Expand All @@ -888,18 +876,6 @@ PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap)
}
/* }}} */

PHPAPI zend_string *strpprintf(size_t max_len, const char *format, ...) /* {{{ */
{
va_list ap;
zend_string *str;

va_start(ap, format);
str = vstrpprintf(max_len, format, ap);
va_end(ap);
return str;
}
/* }}} */

/*
* Local variables:
* tab-width: 4
Expand Down
8 changes: 3 additions & 5 deletions main/spprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ There is also snprintf: See difference explained in snprintf.h
#include "snprintf.h"

BEGIN_EXTERN_C()
PHPAPI size_t spprintf( char **pbuf, size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);

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 zend_string *strpprintf(size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
END_EXTERN_C()

#define spprintf zend_spprintf
#define strpprintf zend_strpprintf

#endif /* SNPRINTF_H */

/*
Expand Down

0 comments on commit c7742e2

Please sign in to comment.