Skip to content
Snippets Groups Projects
Commit ede8d1a5 authored by Don's avatar Don
Browse files

renamed conflicting Drupal functions defined in the extension. added drupal_extension_enable()

parent ada870be
No related branches found
No related tags found
No related merge requests found
......@@ -14,14 +14,19 @@ ZEND_DECLARE_MODULE_GLOBALS(drupal_extension)
/* True global resources - no need for thread safety here */
static int le_drupal_extension;
/* {{{ arginfo_drupal_static */
ZEND_BEGIN_ARG_INFO_EX(arginfo_check_plain, 0, 0, 1)
/* {{{ arginfo_check_plain_ext */
ZEND_BEGIN_ARG_INFO(arginfo_drupal_extension_enable__void, 0)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ arginfo_check_plain_ext */
ZEND_BEGIN_ARG_INFO_EX(arginfo_check_plain_ext, 0, 0, 1)
ZEND_ARG_INFO(0, text)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ arginfo_drupal_static */
ZEND_BEGIN_ARG_INFO_EX(arginfo_drupal_static, 0, 1, 1)
/* {{{ arginfo_drupal_static_ext */
ZEND_BEGIN_ARG_INFO_EX(arginfo_drupal_static_ext, 0, 1, 1)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, default)
ZEND_ARG_INFO(0, reset)
......@@ -33,8 +38,9 @@ ZEND_END_ARG_INFO()
* Every user visible function must have an entry in drupal_extension_functions[].
*/
zend_function_entry drupal_extension_functions[] = {
PHP_FE(check_plain, arginfo_check_plain)
PHP_FE(drupal_static, arginfo_drupal_static)
PHP_FE(check_plain_ext, arginfo_check_plain_ext)
PHP_FE(drupal_static_ext, arginfo_drupal_static_ext)
PHP_FE(drupal_extension_enable, arginfo_drupal_extension_enable__void)
{NULL, NULL, NULL} /* Must be the last line in drupal_extension_functions[] */
};
/* }}} */
......@@ -68,11 +74,11 @@ ZEND_GET_MODULE(drupal_extension)
static void php_drupal_extension_init_globals(zend_drupal_extension_globals *drupal_extension_globals)
{
// ALlocate memory and initialize hash tables for each page request.
ALLOC_HASHTABLE(drupal_extension_globals->drupal_static_zdata);
ALLOC_HASHTABLE(drupal_extension_globals->drupal_static_zdefault);
ALLOC_HASHTABLE(drupal_extension_globals->drupal_static_ext_zdata);
ALLOC_HASHTABLE(drupal_extension_globals->drupal_static_ext_zdefault);
zend_hash_init(drupal_extension_globals->drupal_static_zdata, 0, NULL, NULL, 0);
zend_hash_init(drupal_extension_globals->drupal_static_zdefault, 0, NULL, NULL, 0);
zend_hash_init(drupal_extension_globals->drupal_static_ext_zdata, 0, NULL, NULL, 0);
zend_hash_init(drupal_extension_globals->drupal_static_ext_zdefault, 0, NULL, NULL, 0);
}
/* }}} */
......@@ -107,11 +113,18 @@ PHP_RINIT_FUNCTION(drupal_extension)
*/
PHP_RSHUTDOWN_FUNCTION(drupal_extension)
{
zend_hash_destroy(DRUPAL_EXTENSION_G(drupal_static_zdata));
zend_hash_destroy(DRUPAL_EXTENSION_G(drupal_static_zdefault));
FREE_HASHTABLE(DRUPAL_EXTENSION_G(drupal_static_zdata));
FREE_HASHTABLE(DRUPAL_EXTENSION_G(drupal_static_zdefault));
// Apparently function_table is persistent across requests so we have to remove our
// changes or else we'll bork subsequent requests.
// TODO: Add a global flag to track whether these functions were ever overriden.
zend_hash_del(EG(function_table), "check_plain", sizeof("check_plain"));
zend_hash_del(EG(function_table), "drupal_static", sizeof("drupal_static"));
zend_hash_destroy(DRUPAL_EXTENSION_G(drupal_static_ext_zdata));
zend_hash_destroy(DRUPAL_EXTENSION_G(drupal_static_ext_zdefault));
FREE_HASHTABLE(DRUPAL_EXTENSION_G(drupal_static_ext_zdata));
FREE_HASHTABLE(DRUPAL_EXTENSION_G(drupal_static_ext_zdefault));
return SUCCESS;
}
......@@ -131,9 +144,33 @@ PHP_MINFO_FUNCTION(drupal_extension)
}
/* }}} */
/* {{{ proto string check_plain(string text)
Experimental implementation of Drupal check_plain(). */
PHP_FUNCTION(check_plain)
/* {{{ proto bool drupal_extension_enable()
*/
PHP_FUNCTION(drupal_extension_enable)
{
zend_function *check_plain_ext_func = NULL;
zend_function *drupal_static_ext_func = NULL;
if (zend_hash_exists(EG(function_table), "check_plain", sizeof("check_plain"))
&& zend_hash_exists(EG(function_table), "drupal_static", sizeof("drupal_static"))) {
zend_hash_find(EG(function_table), "check_plain_ext", sizeof("check_plain_ext"), (void **)&check_plain_ext_func);
zend_hash_find(EG(function_table), "drupal_static_ext", sizeof("drupal_static_ext"), (void **)&drupal_static_ext_func);
zend_hash_update(EG(function_table), "check_plain", sizeof("check_plain"), check_plain_ext_func, sizeof(zend_function), NULL);
zend_hash_update(EG(function_table), "drupal_static", sizeof("drupal_static"), drupal_static_ext_func, sizeof(zend_function), NULL);
RETURN_TRUE;
}
RETURN_FALSE;
}
/* {{{ proto string check_plain_ext(string text)
Experimental implementation of Drupal check_plain_ext(). */
PHP_FUNCTION(check_plain_ext)
{
char *str;
int str_len;
......@@ -149,9 +186,9 @@ PHP_FUNCTION(check_plain)
}
/* }}} */
/* {{{ proto string drupal_static(string arg)
Experimental implementation of drupal_static */
PHP_FUNCTION(drupal_static)
/* {{{ proto string drupal_static_ext(string arg)
Experimental implementation of drupal_static_ext */
PHP_FUNCTION(drupal_static_ext)
{
zval *name = NULL;
zval **drawer = NULL;
......@@ -159,8 +196,8 @@ PHP_FUNCTION(drupal_static)
zval *new_drawer = NULL;
zval *zdeft = NULL;
zend_bool reset = 0;
HashTable *zdata = DRUPAL_EXTENSION_G(drupal_static_zdata);
HashTable *zdefault = DRUPAL_EXTENSION_G(drupal_static_zdefault);
HashTable *zdata = DRUPAL_EXTENSION_G(drupal_static_ext_zdata);
HashTable *zdefault = DRUPAL_EXTENSION_G(drupal_static_ext_zdefault);
char *key = NULL;
int key_len = 0;
int arg_len; // Currently only used for zend_parse_parameters().
......@@ -177,7 +214,6 @@ PHP_FUNCTION(drupal_static)
zend_hash_clean(zdata);
zend_hash_copy(zdata, zdefault, NULL, NULL, sizeof(zval *));
return;
} else if (Z_TYPE_P(name) != IS_STRING) {
// name holds the key and must be a string if not NULL. We have to bail out here to prevent segfaults and other horrors.
convert_to_string(name);
......
......@@ -21,12 +21,13 @@ PHP_RINIT_FUNCTION(drupal_extension);
PHP_RSHUTDOWN_FUNCTION(drupal_extension);
PHP_MINFO_FUNCTION(drupal_extension);
PHP_FUNCTION(check_plain);
PHP_FUNCTION(drupal_static);
PHP_FUNCTION(check_plain_ext);
PHP_FUNCTION(drupal_static_ext);
PHP_FUNCTION(drupal_extension_enable);
ZEND_BEGIN_MODULE_GLOBALS(drupal_extension)
HashTable *drupal_static_zdata;
HashTable *drupal_static_zdefault;
HashTable *drupal_static_ext_zdata;
HashTable *drupal_static_ext_zdefault;
ZEND_END_MODULE_GLOBALS(drupal_extension)
#ifdef ZTS
......
--TEST--
Check for drupal_extension presence
--SKIPIF--
<?php
// $Id$
if (!extension_loaded("drupal_extension")) print "skip";
?>
<?php if (!extension_loaded("drupal_extension")) print "skip"; ?>
--FILE--
<?php
// $Id$
echo "drupal_extension extension is available";
/*
you can add regression tests for your extension here
......
--TEST--
Check basic functionality of check_plain().
Check basic functionality of check_plain_ext().
--SKIPIF--
<?php if (!extension_loaded("drupal_extension")) print "skip"; ?>
--FILE--
<?php
// $Id$
if (!extension_loaded("drupal_extension")) print "skip";
?>
--FILE--
<?php
function check_plain() {}
function drupal_static() {}
drupal_extension_enable();
echo check_plain('test & <toto>');
?>
--EXPECT--
......
......@@ -6,6 +6,11 @@ Test basic drupal_static() functionnality
<?php
// $Id$
function check_plain() {}
function drupal_static() {}
drupal_extension_enable();
$ret = &drupal_static("test", array());
if (is_array($ret) && empty($ret)) {
echo "Initial array value is preserved.\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment