svn: /pecl/hidef/trunk/ hidef.c php_hidef.h tests/hidef_016.phpt
| From: | Gopal Vijayaraghavan | Date: | Thu, 08 Dec 2011 21:31:51 +0000 |
| Subject: | svn: /pecl/hidef/trunk/ hidef.c php_hidef.h tests/hidef_016.phpt | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-17340@lists.php.net to get a copy of this message | ||
gopalv Thu, 08 Dec 2011 21:31:51 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=320699
Log:
work-around the memory allocator weirdness and avoid using PERSISTENT constants for dynamic defines
Changed paths:
U pecl/hidef/trunk/hidef.c
U pecl/hidef/trunk/php_hidef.h
U pecl/hidef/trunk/tests/hidef_016.phpt
Modified: pecl/hidef/trunk/hidef.c
===================================================================
--- pecl/hidef/trunk/hidef.c 2011-12-08 21:25:44 UTC (rev 320698)
+++ pecl/hidef/trunk/hidef.c 2011-12-08 21:31:51 UTC (rev 320699)
@@ -71,6 +71,7 @@
{
hidef_globals->ini_path = NULL;
hidef_globals->data_path = NULL;
+ hidef_globals->per_request_ini = NULL;
}
/* }}} */
@@ -134,7 +135,7 @@
hidef_functions,
PHP_MINIT(hidef),
PHP_MSHUTDOWN(hidef),
- NULL,
+ PHP_RINIT(hidef),
PHP_RSHUTDOWN(hidef),
PHP_MINFO(hidef),
#if ZEND_MODULE_API_NO >= 20010901
@@ -169,12 +170,14 @@
/* {{{ hidef_define_constant */
static int hidef_define_constant(char *key, zval *v, hidef_parser_ctxt* ctxt TSRMLS_DC)
{
- zval value = *v;
+ zval value;
zend_constant c;
c.flags = ctxt->flags;
c.module_number = ctxt->module_number;
+ /* this is free'd by zend_register_constant, if the addition fails */
+ value = *v;
zval_copy_ctor(&value);
switch(ctxt->type)
@@ -204,28 +207,31 @@
/* TODO: check conversion results */
c.value = value;
- if(ctxt->type == IS_STRING)
+ if(ctxt->flags & CONST_PERSISTENT && Z_TYPE(value) == IS_STRING)
{
- /* TODO: this leaks memory */
- c.value.value.str.val = zend_strndup(Z_STRVAL_P(&c.value), Z_STRLEN_P(&c.value));
+ /* we do this because the zval_copy_ctor might gives us addresses that would be cleaned up after
MINIT() */
+ Z_STRVAL_P(&c.value) = zend_strndup(Z_STRVAL_P(&c.value), Z_STRLEN_P(&c.value));
}
-
c.name_len = strlen(key)+1;
c.name = zend_strndup(key, c.name_len-1);
if(zend_register_constant(&c TSRMLS_CC) == FAILURE)
{
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Constant '%s' redefined in %s line
%d\n", key, ctxt->filename, INI_SCNG(lineno) - 1);
- zval_dtor(&value);
+ if(ctxt->flags & CONST_PERSISTENT)
+ {
+ zval_dtor(&value);
+ }
return 0;
}
if(ctxt->flags & CONST_PERSISTENT)
{
zend_hash_add(hidef_constants_table, c.name, c.name_len, &c.value, sizeof(c.value), NULL);
+ zval_dtor(&value);
}
+
- zval_dtor(&value);
return 1;
}
/* }}} */
@@ -488,9 +494,21 @@
static PHP_INI_MH(OnUpdate_request_ini) /* {{{ */
{
hidef_parser_ctxt ctxt = {0,};
- ctxt.flags = CONST_CS | CONST_PERSISTENT;
+ ctxt.flags = CONST_CS;
ctxt.module_number = PHP_USER_CONSTANT;
+ if(stage == ZEND_INI_STAGE_STARTUP || stage == ZEND_INI_STAGE_ACTIVATE)
+ {
+ HIDEF_G(per_request_ini) = new_value;
+ /* read this later in RINIT */
+ return SUCCESS;
+ }
+
+ if(stage != ZEND_INI_STAGE_RUNTIME)
+ {
+ return FAILURE;
+ }
+
if(new_value != NULL)
{
if(!hidef_parse_ini(new_value, &ctxt TSRMLS_CC))
@@ -661,6 +679,24 @@
}
/* }}} */
+/* {{{ PHP_RINIT_FUNCTION(hidef) */
+PHP_RINIT_FUNCTION(hidef)
+{
+ hidef_parser_ctxt ctxt = {0,};
+ ctxt.flags = CONST_CS;
+ ctxt.module_number = PHP_USER_CONSTANT;
+ if(HIDEF_G(per_request_ini))
+ {
+ if(!hidef_parse_ini(HIDEF_G(per_request_ini), &ctxt TSRMLS_CC))
+ {
+ zend_error(E_WARNING, "hidef cannot read %s", HIDEF_G(per_request_ini));
+ /* this shouldn't be cause to fail, right? */
+ }
+ }
+ return SUCCESS;
+}
+/* }}} */
+
/* {{{ PHP_RSHUTDOWN_FUNCTION(hidef) */
PHP_RSHUTDOWN_FUNCTION(hidef)
{
Modified: pecl/hidef/trunk/php_hidef.h
===================================================================
--- pecl/hidef/trunk/php_hidef.h 2011-12-08 21:25:44 UTC (rev 320698)
+++ pecl/hidef/trunk/php_hidef.h 2011-12-08 21:31:51 UTC (rev 320699)
@@ -86,6 +86,7 @@
#endif
PHP_MINIT_FUNCTION(hidef);
+PHP_RINIT_FUNCTION(hidef);
PHP_MSHUTDOWN_FUNCTION(hidef);
PHP_RSHUTDOWN_FUNCTION(hidef);
PHP_MINFO_FUNCTION(hidef);
@@ -102,6 +103,7 @@
#else
pid_t p_pid; /* process-id of parent process */
#endif
+ char* per_request_ini; /* per request ini (load at RINIT) */
ZEND_END_MODULE_GLOBALS(hidef)
/* }}} */
Modified: pecl/hidef/trunk/tests/hidef_016.phpt
===================================================================
--- pecl/hidef/trunk/tests/hidef_016.phpt 2011-12-08 21:25:44 UTC (rev 320698)
+++ pecl/hidef/trunk/tests/hidef_016.phpt 2011-12-08 21:31:51 UTC (rev 320699)
@@ -3,8 +3,9 @@
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
-hidef.data_path=.
-hidef.per_request_ini=tests/hidef-test.ini
+hidef.data_path=none
+hidef.ini_path=.
+hidef.per_request_ini=tests/hidef_test.ini
--FILE--
<?php
echo "XYZ=".XYZ."\n";