Skip to content

Commit

Permalink
Fix compat
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Weinand <[email protected]>
  • Loading branch information
bwoebi committed Jan 26, 2024
1 parent b5f0b92 commit a1dd509
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion ext/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdbool.h>
#include <php.h>
#include <Zend/zend_closures.h>
#include <Zend/zend_smart_str.h>

#include "ext/standard/base64.h"

Expand Down Expand Up @@ -110,7 +111,6 @@ static zend_always_inline zend_string *zend_string_init_interned(const char *str

typedef void zend_type;

#include <Zend/zend_smart_str.h>
static inline void smart_str_append_printf(smart_str *dest, const char *format, ...) {
va_list arg;
va_start(arg, format);
Expand Down Expand Up @@ -324,6 +324,22 @@ static zend_always_inline zend_result add_next_index_object(zval *arg, zend_obje
return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
}

static zend_always_inline void smart_str_appendl(smart_str *dest, const char *src, size_t length) {
size_t new_len = smart_str_alloc(dest, len, false);
memcpy(ZSTR_VAL(dest->s) + ZSTR_LEN(dest->s), str, len);
ZSTR_LEN(dest->s) = new_len;
}

static inline void smart_str_append_double(smart_str *str, double num, int precision, bool zero_fraction) {
char buf[ZEND_DOUBLE_MAX_LENGTH];
/* Model snprintf precision behavior. */
zend_gcvt(num, precision ? precision : 1, '.', 'E', buf);
smart_str_appends(str, buf);
if (zero_fraction && zend_finite(num) && !strchr(buf, '.')) {
smart_str_appendl(str, ".0", 2);
}
}

#endif

#if PHP_VERSION_ID < 80200
Expand Down

0 comments on commit a1dd509

Please sign in to comment.