mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-18 18:13:09 +00:00
Shimmed ZVAL_PSTRING* API for PHP 5, fixed return for hash output
This commit is contained in:
+1
-5
@@ -39,12 +39,8 @@ PHP_FUNCTION(aws_crt_hash_digest) {
|
|||||||
length = truncate_to;
|
length = truncate_to;
|
||||||
}
|
}
|
||||||
uint8_t *output = aws_crt_hash_digest(hash, 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 *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);
|
aws_mem_release(aws_crt_default_allocator(), output);
|
||||||
// copy false, destroy false?
|
// copy false, destroy false?
|
||||||
RETURN_ZVAL(php_output, false, false);
|
RETURN_ZVAL(php_output, false, false);
|
||||||
|
|||||||
+5
-2
@@ -48,8 +48,8 @@ ZEND_EXTERN_MODULE_GLOBALS(awscrt)
|
|||||||
#if AWS_PHP_AT_LEAST_7
|
#if AWS_PHP_AT_LEAST_7
|
||||||
/* PHP 7 takes a zval*, PHP5 takes a zval** */
|
/* PHP 7 takes a zval*, PHP5 takes a zval** */
|
||||||
# define AWS_PHP_STREAM_FROM_ZVAL(s, z) php_stream_from_zval(s, z)
|
# define AWS_PHP_STREAM_FROM_ZVAL(s, z) php_stream_from_zval(s, z)
|
||||||
#else /* PHP 5.5-5.6, 7.0-7.1 */
|
#else /* PHP 5.5-5.6 */
|
||||||
/* PHP 7.2+ always duplicate string return values */
|
/* PHP 7.2+ always duplicates string return values */
|
||||||
# undef RETURN_STRING
|
# undef RETURN_STRING
|
||||||
# define RETURN_STRING(s) \
|
# define RETURN_STRING(s) \
|
||||||
{ \
|
{ \
|
||||||
@@ -63,6 +63,9 @@ ZEND_EXTERN_MODULE_GLOBALS(awscrt)
|
|||||||
return; \
|
return; \
|
||||||
}
|
}
|
||||||
# define AWS_PHP_STREAM_FROM_ZVAL(s, z) php_stream_from_zval(s, &z)
|
# 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 */
|
#endif /* PHP 5.x */
|
||||||
|
|
||||||
#include "api.h"
|
#include "api.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user