From ffcea7064a37e03ed8c0497a23580936bf0ebd3d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 2 Apr 2015 18:40:41 +0200 Subject: [PATCH 1/2] fix PHP 7 compatibility --- libsodium.c | 224 +++++++++++++++++++++++++++++--------------------------- package.xml | 1 - php_libsodium.h | 12 +++ run-tests.php | 25 ++++--- 4 files changed, 143 insertions(+), 119 deletions(-) diff --git a/libsodium.c b/libsodium.c index 7480404..6da5245 100644 --- a/libsodium.c +++ b/libsodium.c @@ -274,7 +274,7 @@ PHP_MINFO_FUNCTION(libsodium) PHP_METHOD(Sodium, sodium_version_string) { - RETURN_STRING(sodium_version_string(), 1); + _RETURN_STRING(sodium_version_string()); } PHP_METHOD(Sodium, sodium_library_version_major) @@ -291,12 +291,18 @@ PHP_METHOD(Sodium, sodium_memzero) { zval *zv; char *buf; - int len; + strsize_t len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &zv) == FAILURE || - Z_TYPE_P(zv) != IS_STRING) { - zend_error(E_ERROR, "sodium_memzero: a PHP string is required"); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zv) == FAILURE) { + return; + } +#if PHP_MAJOR_VERSION >= 7 + if (Z_TYPE_P(zv) == IS_REFERENCE) { + ZVAL_DEREF(zv); + } +#endif + if (Z_TYPE_P(zv) != IS_STRING) { + zend_error(E_ERROR, "sodium_memzero: a PHP string is required") ; } buf = Z_STRVAL(*zv); len = Z_STRLEN(*zv); @@ -310,8 +316,8 @@ PHP_METHOD(Sodium, sodium_memcmp) { char *buf1; char *buf2; - int len1; - int len2; + strsize_t len1; + strsize_t len2; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &buf1, &len1, @@ -330,7 +336,7 @@ PHP_METHOD(Sodium, sodium_memcmp) PHP_METHOD(Sodium, randombytes_buf) { char *buf; - long len; + zend_long len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &len) == FAILURE || @@ -341,7 +347,7 @@ PHP_METHOD(Sodium, randombytes_buf) randombytes_buf(buf, (size_t) len); buf[len] = 0U; - RETURN_STRINGL(buf, (int) len, 0); + _RETURN_STRINGL(buf, (int) len); } PHP_METHOD(Sodium, randombytes_random16) @@ -351,7 +357,7 @@ PHP_METHOD(Sodium, randombytes_random16) PHP_METHOD(Sodium, randombytes_uniform) { - long upper_bound; + zend_long upper_bound; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &upper_bound) == FAILURE || @@ -366,8 +372,8 @@ PHP_METHOD(Sodium, crypto_shorthash) unsigned char *hash; unsigned char *key; unsigned char *msg; - int key_len; - int msg_len; + strsize_t key_len; + strsize_t msg_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &msg, &msg_len, @@ -386,7 +392,7 @@ PHP_METHOD(Sodium, crypto_shorthash) } hash[crypto_shorthash_BYTES] = 0U; - RETURN_STRINGL((char *) hash, crypto_shorthash_BYTES, 0); + _RETURN_STRINGL((char *) hash, crypto_shorthash_BYTES); } PHP_METHOD(Sodium, crypto_secretbox) @@ -395,9 +401,9 @@ PHP_METHOD(Sodium, crypto_secretbox) unsigned char *key; unsigned char *msg; unsigned char *nonce; - int key_len; - int msg_len; - int nonce_len; + strsize_t key_len; + strsize_t msg_len; + strsize_t nonce_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &msg, &msg_len, @@ -427,7 +433,7 @@ PHP_METHOD(Sodium, crypto_secretbox) } ciphertext[msg_len + crypto_secretbox_MACBYTES] = 0U; - RETURN_STRINGL((char *) ciphertext, msg_len + crypto_secretbox_MACBYTES, 0); + _RETURN_STRINGL((char *) ciphertext, msg_len + crypto_secretbox_MACBYTES); } PHP_METHOD(Sodium, crypto_secretbox_open) @@ -436,9 +442,9 @@ PHP_METHOD(Sodium, crypto_secretbox_open) unsigned char *ciphertext; unsigned char *msg; unsigned char *nonce; - int key_len; - int ciphertext_len; - int nonce_len; + strsize_t key_len; + strsize_t ciphertext_len; + strsize_t nonce_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &ciphertext, &ciphertext_len, @@ -469,8 +475,8 @@ PHP_METHOD(Sodium, crypto_secretbox_open) RETURN_FALSE; } else { msg[ciphertext_len - crypto_secretbox_MACBYTES] = 0U; - RETURN_STRINGL((char *) msg, - ciphertext_len - crypto_secretbox_MACBYTES, 0); + _RETURN_STRINGL((char *) msg, + ciphertext_len - crypto_secretbox_MACBYTES); } } @@ -479,9 +485,9 @@ PHP_METHOD(Sodium, crypto_generichash) unsigned char *hash; unsigned char *key = NULL; unsigned char *msg; - long hash_len = crypto_generichash_BYTES; - int key_len = 0; - int msg_len; + zend_long hash_len = crypto_generichash_BYTES; + strsize_t key_len = 0; + strsize_t msg_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sl", &msg, &msg_len, @@ -507,7 +513,7 @@ PHP_METHOD(Sodium, crypto_generichash) } hash[hash_len] = 0U; - RETURN_STRINGL((char *) hash, (int) hash_len, 0); + _RETURN_STRINGL((char *) hash, (int) hash_len); } PHP_METHOD(Sodium, crypto_box_keypair) @@ -524,7 +530,7 @@ PHP_METHOD(Sodium, crypto_box_keypair) } keypair[keypair_len] = 0U; - RETURN_STRINGL((char *) keypair, (int) keypair_len, 0); + _RETURN_STRINGL((char *) keypair, (int) keypair_len); } PHP_METHOD(Sodium, crypto_box_keypair_from_secretkey_and_publickey) @@ -533,8 +539,8 @@ PHP_METHOD(Sodium, crypto_box_keypair_from_secretkey_and_publickey) char *publickey; char *secretkey; size_t keypair_len; - int publickey_len; - int secretkey_len; + strsize_t publickey_len; + strsize_t secretkey_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &secretkey, &secretkey_len, @@ -558,14 +564,14 @@ PHP_METHOD(Sodium, crypto_box_keypair_from_secretkey_and_publickey) crypto_box_PUBLICKEYBYTES); keypair[keypair_len] = 0U; - RETURN_STRINGL(keypair, (int) keypair_len, 0); + _RETURN_STRINGL(keypair, (int) keypair_len); } PHP_METHOD(Sodium, crypto_box_secretkey) { unsigned char *keypair; char *secretkey; - int keypair_len; + strsize_t keypair_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &keypair, &keypair_len) == FAILURE) { @@ -581,14 +587,14 @@ PHP_METHOD(Sodium, crypto_box_secretkey) memcpy(secretkey, keypair, crypto_box_SECRETKEYBYTES); secretkey[crypto_box_SECRETKEYBYTES] = 0U; - RETURN_STRINGL((char *) secretkey, crypto_box_SECRETKEYBYTES, 0); + _RETURN_STRINGL((char *) secretkey, crypto_box_SECRETKEYBYTES); } PHP_METHOD(Sodium, crypto_box_publickey) { unsigned char *keypair; char *publickey; - int keypair_len; + strsize_t keypair_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &keypair, &keypair_len) == FAILURE) { @@ -605,14 +611,14 @@ PHP_METHOD(Sodium, crypto_box_publickey) crypto_box_PUBLICKEYBYTES); publickey[crypto_box_PUBLICKEYBYTES] = 0U; - RETURN_STRINGL((char *) publickey, crypto_box_PUBLICKEYBYTES, 0); + _RETURN_STRINGL((char *) publickey, crypto_box_PUBLICKEYBYTES); } PHP_METHOD(Sodium, crypto_box_publickey_from_secretkey) { unsigned char *publickey; unsigned char *secretkey; - int secretkey_len; + strsize_t secretkey_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &secretkey, &secretkey_len) == FAILURE) { @@ -631,7 +637,7 @@ PHP_METHOD(Sodium, crypto_box_publickey_from_secretkey) crypto_scalarmult_base(publickey, secretkey); publickey[crypto_box_PUBLICKEYBYTES] = 0U; - RETURN_STRINGL((char *) publickey, crypto_box_PUBLICKEYBYTES, 0); + _RETURN_STRINGL((char *) publickey, crypto_box_PUBLICKEYBYTES); } PHP_METHOD(Sodium, crypto_box) @@ -642,9 +648,9 @@ PHP_METHOD(Sodium, crypto_box) unsigned char *nonce; unsigned char *publickey; unsigned char *secretkey; - int keypair_len; - int msg_len; - int nonce_len; + strsize_t keypair_len; + strsize_t msg_len; + strsize_t nonce_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &msg, &msg_len, @@ -675,7 +681,7 @@ PHP_METHOD(Sodium, crypto_box) } ciphertext[msg_len + crypto_box_MACBYTES] = 0U; - RETURN_STRINGL((char *) ciphertext, msg_len + crypto_box_MACBYTES, 0); + _RETURN_STRINGL((char *) ciphertext, msg_len + crypto_box_MACBYTES); } PHP_METHOD(Sodium, crypto_box_open) @@ -686,9 +692,9 @@ PHP_METHOD(Sodium, crypto_box_open) unsigned char *nonce; unsigned char *publickey; unsigned char *secretkey; - int ciphertext_len; - int keypair_len; - int nonce_len; + strsize_t ciphertext_len; + strsize_t keypair_len; + strsize_t nonce_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &ciphertext, &ciphertext_len, @@ -721,8 +727,8 @@ PHP_METHOD(Sodium, crypto_box_open) RETURN_FALSE; } else { msg[ciphertext_len - crypto_box_MACBYTES] = 0U; - RETURN_STRINGL((char *) msg, - ciphertext_len - crypto_box_MACBYTES, 0); + _RETURN_STRINGL((char *) msg, + ciphertext_len - crypto_box_MACBYTES); } } @@ -740,7 +746,7 @@ PHP_METHOD(Sodium, crypto_sign_keypair) } keypair[keypair_len] = 0U; - RETURN_STRINGL((char *) keypair, keypair_len, 0); + _RETURN_STRINGL((char *) keypair, keypair_len); } PHP_METHOD(Sodium, crypto_sign_seed_keypair) @@ -748,7 +754,7 @@ PHP_METHOD(Sodium, crypto_sign_seed_keypair) unsigned char *keypair; unsigned char *seed; size_t keypair_len; - int seed_len; + strsize_t seed_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &seed, &seed_len) == FAILURE) { @@ -768,7 +774,7 @@ PHP_METHOD(Sodium, crypto_sign_seed_keypair) } keypair[keypair_len] = 0U; - RETURN_STRINGL((char *) keypair, keypair_len, 0); + _RETURN_STRINGL((char *) keypair, keypair_len); } PHP_METHOD(Sodium, crypto_sign_keypair_from_secretkey_and_publickey) @@ -777,8 +783,8 @@ PHP_METHOD(Sodium, crypto_sign_keypair_from_secretkey_and_publickey) char *publickey; char *secretkey; size_t keypair_len; - int publickey_len; - int secretkey_len; + strsize_t publickey_len; + strsize_t secretkey_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &secretkey, &secretkey_len, @@ -802,14 +808,14 @@ PHP_METHOD(Sodium, crypto_sign_keypair_from_secretkey_and_publickey) crypto_sign_PUBLICKEYBYTES); keypair[keypair_len] = 0U; - RETURN_STRINGL(keypair, keypair_len, 0); + _RETURN_STRINGL(keypair, keypair_len); } PHP_METHOD(Sodium, crypto_sign_secretkey) { unsigned char *keypair; char *secretkey; - int keypair_len; + strsize_t keypair_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &keypair, &keypair_len) == FAILURE) { @@ -825,14 +831,14 @@ PHP_METHOD(Sodium, crypto_sign_secretkey) memcpy(secretkey, keypair, crypto_sign_SECRETKEYBYTES); secretkey[crypto_sign_SECRETKEYBYTES] = 0U; - RETURN_STRINGL((char *) secretkey, crypto_sign_SECRETKEYBYTES, 0); + _RETURN_STRINGL((char *) secretkey, crypto_sign_SECRETKEYBYTES); } PHP_METHOD(Sodium, crypto_sign_publickey) { unsigned char *keypair; char *publickey; - int keypair_len; + strsize_t keypair_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &keypair, &keypair_len) == FAILURE) { @@ -849,7 +855,7 @@ PHP_METHOD(Sodium, crypto_sign_publickey) crypto_sign_PUBLICKEYBYTES); publickey[crypto_sign_PUBLICKEYBYTES] = 0U; - RETURN_STRINGL((char *) publickey, crypto_sign_PUBLICKEYBYTES, 0); + _RETURN_STRINGL((char *) publickey, crypto_sign_PUBLICKEYBYTES); } PHP_METHOD(Sodium, crypto_sign) @@ -858,9 +864,9 @@ PHP_METHOD(Sodium, crypto_sign) unsigned char *msg_signed; unsigned char *secretkey; unsigned long long msg_signed_real_len; - int msg_len; - int msg_signed_len; - int secretkey_len; + strsize_t msg_len; + strsize_t msg_signed_len; + strsize_t secretkey_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &msg, &msg_len, @@ -889,7 +895,7 @@ PHP_METHOD(Sodium, crypto_sign) } msg_signed[msg_signed_real_len] = 0U; - RETURN_STRINGL((char *) msg_signed, (int) msg_signed_real_len, 0); + _RETURN_STRINGL((char *) msg_signed, (int) msg_signed_real_len); } PHP_METHOD(Sodium, crypto_sign_open) @@ -898,9 +904,9 @@ PHP_METHOD(Sodium, crypto_sign_open) unsigned char *msg_signed; unsigned char *publickey; unsigned long long msg_real_len; - int msg_len; - int msg_signed_len; - int publickey_len; + strsize_t msg_len; + strsize_t msg_signed_len; + strsize_t publickey_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &msg_signed, &msg_signed_len, @@ -930,7 +936,7 @@ PHP_METHOD(Sodium, crypto_sign_open) } msg[msg_real_len] = 0U; - RETURN_STRINGL((char *) msg, (int) msg_real_len, 0); + _RETURN_STRINGL((char *) msg, (int) msg_real_len); } PHP_METHOD(Sodium, crypto_sign_detached) @@ -939,8 +945,8 @@ PHP_METHOD(Sodium, crypto_sign_detached) unsigned char *signature; unsigned char *secretkey; unsigned long long signature_real_len; - int msg_len; - int secretkey_len; + strsize_t msg_len; + strsize_t secretkey_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &msg, &msg_len, @@ -964,7 +970,7 @@ PHP_METHOD(Sodium, crypto_sign_detached) } signature[signature_real_len] = 0U; - RETURN_STRINGL((char *) signature, (int) signature_real_len, 0); + _RETURN_STRINGL((char *) signature, (int) signature_real_len); } PHP_METHOD(Sodium, crypto_sign_verify_detached) @@ -972,9 +978,9 @@ PHP_METHOD(Sodium, crypto_sign_verify_detached) unsigned char *msg; unsigned char *publickey; unsigned char *signature; - int msg_len; - int publickey_len; - int signature_len; + strsize_t msg_len; + strsize_t publickey_len; + strsize_t signature_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &signature, &signature_len, @@ -1005,9 +1011,9 @@ PHP_METHOD(Sodium, crypto_stream) unsigned char *ciphertext; unsigned char *key; unsigned char *nonce; - long ciphertext_len; - int key_len; - int nonce_len; + zend_long ciphertext_len; + strsize_t key_len; + strsize_t nonce_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss", &ciphertext_len, @@ -1032,7 +1038,7 @@ PHP_METHOD(Sodium, crypto_stream) } ciphertext[ciphertext_len] = 0U; - RETURN_STRINGL((char *) ciphertext, ciphertext_len, 0); + _RETURN_STRINGL((char *) ciphertext, ciphertext_len); } PHP_METHOD(Sodium, crypto_stream_xor) @@ -1041,9 +1047,9 @@ PHP_METHOD(Sodium, crypto_stream_xor) unsigned char *key; unsigned char *msg; unsigned char *nonce; - int key_len; - int msg_len; - int nonce_len; + strsize_t key_len; + strsize_t msg_len; + strsize_t nonce_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &msg, &msg_len, @@ -1065,7 +1071,7 @@ PHP_METHOD(Sodium, crypto_stream_xor) } ciphertext[msg_len] = 0U; - RETURN_STRINGL((char *) ciphertext, msg_len, 0); + _RETURN_STRINGL((char *) ciphertext, msg_len); } PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256) @@ -1073,11 +1079,11 @@ PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256) unsigned char *hash; unsigned char *salt; char *passwd; - long hash_len; - long memlimit; - long opslimit; - int passwd_len; - int salt_len; + zend_long hash_len; + zend_long memlimit; + zend_long opslimit; + strsize_t passwd_len; + strsize_t salt_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lssll", &hash_len, @@ -1113,16 +1119,16 @@ PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256) } hash[hash_len] = 0U; - RETURN_STRINGL((char *) hash, hash_len, 0); + _RETURN_STRINGL((char *) hash, hash_len); } PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256_str) { char *hash_str; char *passwd; - long memlimit; - long opslimit; - int passwd_len; + zend_long memlimit; + zend_long opslimit; + strsize_t passwd_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &passwd, &passwd_len, @@ -1152,16 +1158,16 @@ PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256_str) } hash_str[crypto_pwhash_scryptsalsa208sha256_STRBYTES] = 0U; - RETURN_STRINGL((char *) hash_str, - crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1, 0); + _RETURN_STRINGL((char *) hash_str, + crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1); } PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256_str_verify) { char *hash_str; char *passwd; - int hash_str_len; - int passwd_len; + strsize_t hash_str_len; + strsize_t passwd_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &hash_str, &hash_str_len, @@ -1191,11 +1197,11 @@ PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_encrypt) unsigned char *npub; unsigned char *secretkey; unsigned long long ciphertext_real_len; - int ad_len; - int ciphertext_len; - int msg_len; - int npub_len; - int secretkey_len; + strsize_t ad_len; + strsize_t ciphertext_len; + strsize_t msg_len; + strsize_t npub_len; + strsize_t secretkey_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &msg, &msg_len, @@ -1234,7 +1240,7 @@ PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_encrypt) } ciphertext[ciphertext_real_len] = 0U; - RETURN_STRINGL((char *) ciphertext, (int) ciphertext_real_len, 0); + _RETURN_STRINGL((char *) ciphertext, (int) ciphertext_real_len); } PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_decrypt) @@ -1245,11 +1251,11 @@ PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_decrypt) unsigned char *npub; unsigned char *secretkey; unsigned long long msg_real_len; - int ad_len; - int ciphertext_len; - int msg_len; - int npub_len; - int secretkey_len; + strsize_t ad_len; + strsize_t ciphertext_len; + strsize_t msg_len; + strsize_t npub_len; + strsize_t secretkey_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &ciphertext, &ciphertext_len, @@ -1288,15 +1294,15 @@ PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_decrypt) } msg[msg_real_len] = 0U; - RETURN_STRINGL((char *) msg, (int) msg_real_len, 0); + _RETURN_STRINGL((char *) msg, (int) msg_real_len); } PHP_METHOD(Sodium, sodium_bin2hex) { unsigned char *bin; char *hex; - int bin_len; - int hex_len; + strsize_t bin_len; + strsize_t hex_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &bin, &bin_len) == FAILURE) { @@ -1309,7 +1315,7 @@ PHP_METHOD(Sodium, sodium_bin2hex) hex = safe_emalloc((size_t) hex_len + 1U, 1U, 0U); sodium_bin2hex(hex, hex_len + 1U, bin, bin_len); - RETURN_STRINGL(hex, hex_len, 0); + _RETURN_STRINGL(hex, hex_len); } PHP_METHOD(Sodium, sodium_hex2bin) @@ -1319,8 +1325,8 @@ PHP_METHOD(Sodium, sodium_hex2bin) char *ignore = NULL; size_t bin_real_len; size_t bin_len; - int hex_len; - int ignore_len = 0; + strsize_t hex_len; + strsize_t ignore_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &hex, &hex_len, @@ -1336,5 +1342,5 @@ PHP_METHOD(Sodium, sodium_hex2bin) } bin[bin_real_len] = 0U; - RETURN_STRINGL((char *) bin, (int) bin_real_len, 0); + _RETURN_STRINGL((char *) bin, (int) bin_real_len); } diff --git a/php_libsodium.h b/php_libsodium.h index 4038dfd..ae4f9b6 100644 --- a/php_libsodium.h +++ b/php_libsodium.h @@ -69,6 +69,18 @@ PHP_METHOD(Sodium, sodium_version_string); #define LIBSODIUM_G(v) (libsodium_globals.v) #endif +#if PHP_MAJOR_VERSION < 7 +typedef long zend_long; +typedef int strsize_t; +#define _RETURN_STRING(a) RETURN_STRING(a,1) +#define _RETURN_STRINGL(a,l) RETURN_STRINGL(a,l,0) +#else +typedef size_t strsize_t; +#define TSRMLS_CC +#define _RETURN_STRING(a) RETURN_STRING(a) +#define _RETURN_STRINGL(a,l) { RETVAL_STRINGL(a, l); efree(a); return; } +#endif + #endif /* PHP_LIBSODIUM_H */ /*