From adf46e4378ab3d629c8d76ccebfe9b1f2c8fafed Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 4 Oct 2006 12:40:04 +0000 Subject: [PATCH] Fix #1569587 for PHP. Don't use sizeof() except with string literals. Change some "//" comments to "/* */" for portability. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9404 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/CHANGES.current | 10 +++++++--- SWIG/Lib/php4/const.i | 20 +++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/SWIG/CHANGES.current b/SWIG/CHANGES.current index b304b55d5..6a83b1e8d 100644 --- a/SWIG/CHANGES.current +++ b/SWIG/CHANGES.current @@ -1,6 +1,13 @@ Version 1.3.30 (in progress) ============================ +10/04/2006: olly + [php] Fix #1569587 for PHP. Don't use sizeof() except with string + literals. Change some "//" comments to "/* */" for portability. + +10/04/2006: mgossage + [Lua] Partial Fix #1569587. The type is now correct, but the name is still not correct. + 10/03/2006: wsfulton [Ruby] Fix #1527885 - Overloaded director virtual methods sometimes produced uncompileable code when used with the director:except feature. @@ -9,9 +16,6 @@ Version 1.3.30 (in progress) Directors: Directors are output in the order in which they are declared in the C++ class rather than in some pseudo-random order. -10/04/2006: mgossage - [Lua] Partial Fix #1569587. The type is now correct, but the name is still not correct. - 10/03/2006: mmatus Fix #1486281 and #1471039. diff --git a/SWIG/Lib/php4/const.i b/SWIG/Lib/php4/const.i index 2b933e8ae..1ecd45e7f 100644 --- a/SWIG/Lib/php4/const.i +++ b/SWIG/Lib/php4/const.i @@ -17,35 +17,37 @@ signed char, bool, enum SWIGTYPE - "REGISTER_LONG_CONSTANT( \"$symname\", $value, CONST_CS | CONST_PERSISTENT);"; + "REGISTER_LONG_CONSTANT(\"$symname\", $value, CONST_CS | CONST_PERSISTENT);"; %typemap(consttab) float, double "REGISTER_DOUBLE_CONSTANT(\"$symname\", $value, CONST_CS | CONST_PERSISTENT);"; -%typemap(consttab) char - "REGISTER_STRING_CONSTANT(\"$symname\", \"$value\", CONST_CS | CONST_PERSISTENT );"; +%typemap(consttab) char { + char swig_char = $value; + REGISTER_STRINGL_CONSTANT("$symname", &swig_char, 1, CONST_CS | CONST_PERSISTENT); +} %typemap(consttab) char *, const char *, char [], const char [] - "REGISTER_STRINGL_CONSTANT(\"$symname\", \"$value\", sizeof(\"$value\") - 1, CONST_CS | CONST_PERSISTENT);"; + "REGISTER_STRINGL_CONSTANT(\"$symname\", $value, strlen($value), CONST_CS | CONST_PERSISTENT);"; %typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { - // This actually registers it as a global variable and constant. I don't like it, but I can't figure out - // the zend_constant code... + /* This actually registers it as a global variable and constant. I don't + * like it, but I can't figure out the zend_constant code... */ zval *z_var; MAKE_STD_ZVAL(z_var); SWIG_SetPointerZval(z_var, (void*)$value, $1_descriptor, 0); - //zend_hash_add(&EG(symbol_table), "$1", strlen("$1")+1, (void *)&z_var,sizeof(zval *), NULL); + /* zend_hash_add(&EG(symbol_table), "$1", sizeof("$1"), (void *)&z_var,sizeof(zval *), NULL); */ zend_constant c; c.value = *z_var; zval_copy_ctor(&c.value); - size_t len = strlen("$1"); - c.name = zend_strndup( "$1", len ); + size_t len = sizeof("$1") - 1; + c.name = zend_strndup("$1", len); c.name_len = len+1; c.flags = CONST_CS | CONST_PERSISTENT; c.module_number = module_number;