1 /* 2 +----------------------------------------------------------------------+ 3 | Compatibility macros for different PHP versions | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 2016 The PHP Group | 6 +----------------------------------------------------------------------+ 7 | This source file is subject to version 3.01 of the PHP license, | 8 | that is bundled with this package in the file LICENSE, and is | 9 | available through the world-wide-web at the following url: | 10 | http://www.php.net/license/3_01.txt. | 11 | If you did not receive a copy of the PHP license and are unable to | 12 | obtain it through the world-wide-web, please send a note to | 13 | license@php.net so we can mail you a copy immediately. | 14 +----------------------------------------------------------------------+ 15 | Author: Adam Harvey <aharvey@php.net> | 16 +----------------------------------------------------------------------+ 17 */ 18 19 #ifndef _COMPAT_ZEND_API_H 20 #define _COMPAT_ZEND_API_H 21 22 #ifdef PHP_7 23 /*============================================================================*/ 24 25 #else 26 /*== PHP 5 ===================================================================*/ 27 28 /* 29 * Many string-related macros used to take duplicate parameters, which 30 * specified whether the string should be duplicated or not. In practice, 31 * almost all code used 1, so PHP 7 always duplicates. 32 * 33 * This header redefines the relevant macros to match PHP 7. 34 */ 35 36 #undef ZVAL_STRING 37 #define ZVAL_STRING(z, s) do { \ 38 const char *__s = (s); \ 39 zval *__z = (z); \ 40 Z_STRLEN_P(__z) = strlen(__s); \ 41 Z_STRVAL_P(__z) = estrndup(__s, Z_STRLEN_P(__z)); \ 42 Z_TYPE_P(__z) = IS_STRING; \ 43 } while (0) 44 45 #undef ZVAL_STRINGL 46 #define ZVAL_STRINGL(z, s, l) do { \ 47 const char *__s = (s); \ 48 int __l = (l); \ 49 zval *__z = (z); \ 50 Z_STRLEN_P(__z) = __l; \ 51 Z_STRVAL_P(__z) = estrndup(__s, __l); \ 52 Z_TYPE_P(__z) = IS_STRING; \ 53 } while (0) 54 55 #undef RETVAL_STRING 56 #define RETVAL_STRING(s) ZVAL_STRING(return_value, (s)) 57 58 #undef RETVAL_STRINGL 59 #define RETVAL_STRINGL(s, l) ZVAL_STRINGL(return_value, (s), (l)) 60 61 #undef RETURN_STRING 62 #define RETURN_STRING(s) { RETVAL_STRING(s); return; } 63 64 #undef RETURN_STRINGL 65 #define RETURN_STRINGL(s, l) { RETVAL_STRINGL(s, l); return; } 66 67 #undef add_assoc_string 68 #define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key)+1, __str, 1) 69 70 #undef add_assoc_stringl 71 #define add_assoc_stringl(__arg, __key, __str, __len) add_assoc_stringl_ex(__arg, __key, strlen(__key)+1, __str, __len, 1) 72 73 #endif /* PHP_7 */ 74 /*============================================================================*/ 75 76 #endif /* _COMPAT_ZEND_API_H */ 77