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

Rolling back previous changes for now.

parent d8a06d61
Branches
Tags
No related merge requests found
drupal_extension
\ No newline at end of file
drupal_extension
......@@ -14,14 +14,14 @@ ZEND_DECLARE_MODULE_GLOBALS(drupal_extension)
/* True global resources - no need for thread safety here */
static int le_drupal_extension;
/* {{{ arginfo_drupal_static_ext */
ZEND_BEGIN_ARG_INFO_EX(arginfo_check_plain_ext, 0, 0, 1)
/* {{{ arginfo_drupal_static */
ZEND_BEGIN_ARG_INFO_EX(arginfo_check_plain, 0, 0, 1)
ZEND_ARG_INFO(0, text)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ arginfo_drupal_static_ext */
ZEND_BEGIN_ARG_INFO_EX(arginfo_drupal_static_ext, 0, 1, 1)
/* {{{ arginfo_drupal_static */
ZEND_BEGIN_ARG_INFO_EX(arginfo_drupal_static, 0, 1, 1)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, default)
ZEND_ARG_INFO(0, reset)
......@@ -33,9 +33,8 @@ 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_ext, arginfo_check_plain_ext)
PHP_FE(drupal_static_ext, arginfo_drupal_static_ext)
PHP_FE(drupal_ext_activate, NULL)
PHP_FE(check_plain, arginfo_check_plain)
PHP_FE(drupal_static, arginfo_drupal_static)
{NULL, NULL, NULL} /* Must be the last line in drupal_extension_functions[] */
};
/* }}} */
......@@ -69,11 +68,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_ext_zdata);
ALLOC_HASHTABLE(drupal_extension_globals->drupal_static_ext_zdefault);
ALLOC_HASHTABLE(drupal_extension_globals->drupal_static_zdata);
ALLOC_HASHTABLE(drupal_extension_globals->drupal_static_zdefault);
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);
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);
}
/* }}} */
......@@ -108,11 +107,11 @@ PHP_RINIT_FUNCTION(drupal_extension)
*/
PHP_RSHUTDOWN_FUNCTION(drupal_extension)
{
zend_hash_destroy(DRUPAL_EXTENSION_G(drupal_static_ext_zdata));
zend_hash_destroy(DRUPAL_EXTENSION_G(drupal_static_ext_zdefault));
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_ext_zdata));
FREE_HASHTABLE(DRUPAL_EXTENSION_G(drupal_static_ext_zdefault));
FREE_HASHTABLE(DRUPAL_EXTENSION_G(drupal_static_zdata));
FREE_HASHTABLE(DRUPAL_EXTENSION_G(drupal_static_zdefault));
return SUCCESS;
}
......@@ -132,30 +131,9 @@ PHP_MINFO_FUNCTION(drupal_extension)
}
/* }}} */
/* {{{ proto bool drupal_ext_activate()
*/
PHP_FUNCTION(drupal_ext_activate)
{
zend_function *check_plain_ext_ptr = NULL;
zend_function *drupal_static_ext_ptr = NULL;
if (zend_hash_find(EG(function_table), "check_plain_ext", sizeof("check_plain"), (void **)&check_plain_ext_ptr) != FAILURE
&& zend_hash_find(EG(function_table), "drupal_static_ext", sizeof("drupal_static_ext"), (void **)&drupal_static_ext_ptr) != FAILURE) {
zend_hash_update(EG(function_table), "check_plain", sizeof("check_plain"), check_plain_ext_ptr, sizeof(zend_function), NULL);
zend_hash_update(EG(function_table), "drupal_static", sizeof("drupal_static"), drupal_static_ext_ptr, 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)
/* {{{ proto string check_plain(string text)
Experimental implementation of Drupal check_plain(). */
PHP_FUNCTION(check_plain)
{
char *str;
int str_len;
......@@ -171,9 +149,9 @@ PHP_FUNCTION(check_plain_ext)
}
/* }}} */
/* {{{ proto string drupal_static_ext(string arg)
Experimental implementation of drupal_static_ext */
PHP_FUNCTION(drupal_static_ext)
/* {{{ proto string drupal_static(string arg)
Experimental implementation of drupal_static */
PHP_FUNCTION(drupal_static)
{
zval *name = NULL;
zval **drawer = NULL;
......@@ -181,8 +159,8 @@ PHP_FUNCTION(drupal_static_ext)
zval *new_drawer = NULL;
zval *zdeft = NULL;
zend_bool reset = 0;
HashTable *zdata = DRUPAL_EXTENSION_G(drupal_static_ext_zdata);
HashTable *zdefault = DRUPAL_EXTENSION_G(drupal_static_ext_zdefault);
HashTable *zdata = DRUPAL_EXTENSION_G(drupal_static_zdata);
HashTable *zdefault = DRUPAL_EXTENSION_G(drupal_static_zdefault);
char *key = NULL;
int key_len = 0;
int arg_len; // Currently only used for zend_parse_parameters().
......@@ -199,6 +177,7 @@ PHP_FUNCTION(drupal_static_ext)
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,13 +21,12 @@ PHP_RINIT_FUNCTION(drupal_extension);
PHP_RSHUTDOWN_FUNCTION(drupal_extension);
PHP_MINFO_FUNCTION(drupal_extension);
PHP_FUNCTION(check_plain_ext);
PHP_FUNCTION(drupal_static_ext);
PHP_FUNCTION(drupal_ext_activate);
PHP_FUNCTION(check_plain);
PHP_FUNCTION(drupal_static);
ZEND_BEGIN_MODULE_GLOBALS(drupal_extension)
HashTable *drupal_static_ext_zdata;
HashTable *drupal_static_ext_zdefault;
HashTable *drupal_static_zdata;
HashTable *drupal_static_zdefault;
ZEND_END_MODULE_GLOBALS(drupal_extension)
#ifdef ZTS
......
--TEST--
Check for drupal_extension presence
--SKIPIF--
<?php if (!extension_loaded("drupal_extension")) print "skip"; ?>
--FILE--
<?php
// $Id$
if (!extension_loaded("drupal_extension")) print "skip";
?>
--FILE--
<?php
echo "drupal_extension extension is available";
/*
you can add regression tests for your extension here
......
--TEST--
Check basic functionality of check_plain_ext().
Check basic functionality of check_plain().
--SKIPIF--
<?php if (!extension_loaded("drupal_extension")) print "skip"; ?>
--FILE--
<?php
// $Id$
echo check_plain_ext('test & <toto>');
if (!extension_loaded("drupal_extension")) print "skip";
?>
--FILE--
<?php
echo check_plain('test & <toto>');
?>
--EXPECT--
test &amp; &lt;toto&gt;
--TEST--
Test basic drupal_static_ext() functionnality
Test basic drupal_static() functionnality
--SKIPIF--
<?php if (!extension_loaded("drupal_extension")) print "skip"; ?>
--FILE--
<?php
// $Id$
$ret = &drupal_static_ext("test", array());
$ret = &drupal_static("test", array());
if (is_array($ret) && empty($ret)) {
echo "Initial array value is preserved.\n";
}
$ret['test_value'] = 'toto';
$ret2 = &drupal_static_ext("test", array());
$ret2 = &drupal_static("test", array());
if (isset($ret2['test_value']) && $ret2['test_value'] == 'toto') {
echo "Stored array value is preserved.\n";
}
$ret = &drupal_static_ext('test', NULL, TRUE);
$ret = &drupal_static('test', NULL, TRUE);
if (is_array($ret) && empty($ret)) {
echo "Reset key with array value successful.\n";
}
$ret = &drupal_static_ext('test_scalar', 'default');
$ret = &drupal_static('test_scalar', 'default');
if (is_scalar($ret) && $ret == 'default') {
echo "Initial scalar value is preserved.\n";
}
$ret = 'default_changed';
$ret2 = &drupal_static_ext('test_scalar');
$ret2 = &drupal_static('test_scalar');
if (is_scalar($ret2) && $ret2 == 'default_changed') {
echo "Stored scalar value is preserved.\n";
}
$ret = &drupal_static_ext('test_scalar', NULL, TRUE);
$ret = &drupal_static('test_scalar', NULL, TRUE);
if (is_scalar($ret) && $ret == 'default') {
echo "Reset key with scalar value successful.\n";
}
$ret = &drupal_static_ext('test2', NULL);
$ret = &drupal_static('test2', NULL);
$ret['foo_key'] = 'foo_value';
$ret = &drupal_static_ext('test2');
$ret = &drupal_static('test2');
if (is_array($ret) && isset($ret['foo_key']) && $ret['foo_key'] == 'foo_value') {
echo "Passed test with NULL as default.\n";
}
......@@ -58,23 +58,23 @@ if (!$failed) {
}
function loop_stability_test($key) {
$ret = &drupal_static_ext($key, array());
$ret = &drupal_static($key, array());
if (!is_array($ret) || !empty($ret)) {
return FALSE;
}
$ret["$key $key"] = $key;
$ret2 = &drupal_static_ext($key);
$ret2 = &drupal_static($key);
if (!isset($ret2["$key $key"]) || $ret2["$key $key"] != $key) {
return FALSE;
}
$ret = &drupal_static_ext($key, NULL, TRUE);
$ret = &drupal_static($key, NULL, TRUE);
if (!is_array($ret) || !empty($ret)) {
return FALSE;
}
$ret = &drupal_static_ext($key, NULL);
$ret = &drupal_static($key, NULL);
if (!is_array($ret) || !empty($ret)) {
return FALSE;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment