php 4.2.3 and 4.2.2
windows 2000
command line debugging

I posted this a week ago, no replies yet...

Ive written an extension to PHP that (among other things) uses a global HashTable object for a mini cache. I fill it, and then have a simple PHP function to pull a string out of the cache, and return it. However, I keep getting wierd internal access violations whenever I try to use it.

In the sample code below, if I do this in test.php:

$zendTest = idc_env("zendTest");
echo "zendTest: $zendTest\n";

And execute it, the value "this is a zend test" will be output to the screen, as well as everything after. My code executes fine... but at the very very last second I get an access violation when "zend_execute_scripts" tries to calculate "if(!retval)", because suddenly "retval" cannot be evaluated any more. Whaaa?

Anyway, here's the relevant snippets of my C code:

=======================

PHP_RINIT_FUNCTION(idc)
{
zval* val;
char* key = "zendTest";
MAKE_STD_ZVAL(val);
ZVAL_STRING(val, "this is a zend test", 1);

// move to PHP_MINIT_FUNCTION after all bugs are out
ALLOC_HASHTABLE(IDC_G(server_environment));
zend_hash_init(IDC_G(server_environment), 0, NULL, ZVAL_PTR_DTOR, 0);

// run a test
zend_hash_update(IDC_G(server_environment), key, strlen(key)+1,
(void *)&val, sizeof(zval *), NULL);

return SUCCESS;
}

PHP_RSHUTDOWN_FUNCTION(idc)
{
// move to PHP_MSHUTDOWN_FUNCTION once all bugs are out
zend_hash_destroy(IDC_G(server_environment));
FREE_HASHTABLE(IDC_G(server_environment));

return SUCCESS;
}

PHP_FUNCTION(idc_env)
{
HashTable *env = IDC_G(server_environment);
zval **value = NULL;
char *valueStr = NULL;
int argc = ZEND_NUM_ARGS();
char *name = NULL;

if (zend_parse_parameters(argc TSRMLS_CC, "s", &name) == FAILURE)
return;

if (zend_hash_find(env, name, strlen(name) + 1,
(void **) &value) == SUCCESS)
{
if ((*value)->type == IS_STRING)
{
valueStr = Z_STRVAL_PP(value);
return_value->type = IS_STRING;
return_value->value.str.len = Z_STRLEN_PP(value);
return_value->value.str.val = estrdup(valueStr);
}
}
}

=======================

Im assuming that Im not initializing (or destroying) something properly, but my code seems to be fairly correct, based on the other PHP extensions. In addition, if I move the code in RSTARTUP and RSHUTDOWN to MSTARTUP and MSHUTDOWN, I get a bunch of memory leaks that dont make any sense... the leaks are worse in php 4.2.3 than in 4.2.2. I have no clue why that would be.

Any hints on the "right" way to use a HashTable or Zend object in C for a global PHP mini-cache would be greatly appreciated...

--

Brian 'Bex' Huff
[EMAIL PROTECTED]
Phone: 952-903-2023
Fax: 952-829-5424


**All Electronic Mail sent from the Stellent, Inc Electronic Communication Network is scanned by Antigen 7.0.**

--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to