Shimmed ZVAL_PSTRING* API for PHP 5, fixed return for hash output

This commit is contained in:
Justin Boswell
2021-06-21 12:00:54 -07:00
parent e0123d4653
commit ad550a42a8
2 changed files with 6 additions and 7 deletions
+1 -5
View File
@@ -39,12 +39,8 @@ PHP_FUNCTION(aws_crt_hash_digest) {
length = truncate_to;
}
uint8_t *output = aws_crt_hash_digest(hash, truncate_to);
size_t len = strlen((const char *)output) + 1;
char arr[len]; // Make sure there's enough space
strcpy(arr, (char *) output);
printf(arr);
zval *php_output = NULL;
ZVAL_STRINGL(php_output, (const char *)output, length);
ZVAL_PSTRINGL(php_output, (const char *)output, length);
aws_mem_release(aws_crt_default_allocator(), output);
// copy false, destroy false?
RETURN_ZVAL(php_output, false, false);
+5 -2
View File
@@ -48,8 +48,8 @@ ZEND_EXTERN_MODULE_GLOBALS(awscrt)
#if AWS_PHP_AT_LEAST_7
/* PHP 7 takes a zval*, PHP5 takes a zval** */
# define AWS_PHP_STREAM_FROM_ZVAL(s, z) php_stream_from_zval(s, z)
#else /* PHP 5.5-5.6, 7.0-7.1 */
/* PHP 7.2+ always duplicate string return values */
#else /* PHP 5.5-5.6 */
/* PHP 7.2+ always duplicates string return values */
# undef RETURN_STRING
# define RETURN_STRING(s) \
{ \
@@ -63,6 +63,9 @@ ZEND_EXTERN_MODULE_GLOBALS(awscrt)
return; \
}
# define AWS_PHP_STREAM_FROM_ZVAL(s, z) php_stream_from_zval(s, &z)
/* PHP 5.x doesn't have zend_string, so we need to shim the char* -> string zval API */
#define ZVAL_PSTRING(z, s) ZVAL_STRING(z, s)
#define ZVAL_PSTRINGL(z, s) ZVAL_STRINGL(z, s)
#endif /* PHP 5.x */
#include "api.h"