Re: Global HashTables & access violations
| From: | Brian 'Bex' Huff | Date: | Tue, 22 Oct 2002 19:10:44 +0000 |
| Subject: | Re: Global HashTables & access violations | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-89931@lists.php.net to get a copy of this message | ||
thanks for the response... I was using the macros before, but gave them up in my pursuit of this access violation. Via process of elimination, I have tracked down the offending code. Believe it or not, its "zend_parse_parameters"
This code:
char* name;
if (zend_parse_parameters(1 TSRMLS_CC, "s", &name) == FAILURE)
return;
causes the access violation AFTER my code is completed... however, if I instead do this:
char* name;
int arg_len;
if (zend_parse_parameters(1 TSRMLS_CC, "s", &name, &arg_len) == FAILURE)
return;
It seems to work fine... passing that last pointer seems to make all the difference... really really wierd. Its not a problem when the parameter Im passing is an array, or if Im passing multiple parameters... it only seems to be problematic when the function is a single string value.
again... wierd...
--
Brian 'Bex' Huff
bex@stellent.com
Phone: 952-903-2023
Fax: 952-829-5424
Tony Leake wrote:
> On Mon, 2002-10-21 at 20:19, Brian 'Bex' Huff wrote:
>
>
>>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.
>>
>
> Hi Brian,
>
> I can't help with your specific problems but there are a couple of
> shortcuts you can use in your module.
>
> You can get the string length of your arguments as they are passes in,
> see below.
>
> Also there are macros for returning values which I believe are the
> preferred way of doing things. I have made the change in your code below
> to show how to get the string length passed in.
>
> you have 2 functions for returning strings :
> RETURN_STRING(char *s, int dup)
> and
> RETURN_STRINGL(char *s, int l, int dup) if you know the length of the
> string.
> int dup, should be 1 unless you estrdup or emalloc the string.
>
> these 2 functions seem to have aliases RETVAL_STRING and RETVAL_STRINGL
> I'm not sure which version is preferred.
>
> see for further info
> http://zend.com/apidoc/zend.returning.php
>
>
> HTH
> Tony
>
>
>
>>PHP_FUNCTION(idc_env)
>>{
>> HashTable *env = IDC_G(server_environment);
>> zval **value = NULL;
>> char *valueStr = NULL;
>> int argc = ZEND_NUM_ARGS();
>> char *name = NULL;
>
> /* NEW LINE, and line below modified */
> long name_length;
>
>> if (zend_parse_parameters(argc TSRMLS_CC, "s", &name, &name_length) ==
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);
>
>
> /* previous 3 lines can be replaced with */
> RETURN_STRINGL(valueStr, Z_STRLEN_PP(value), 1 );
>
>> }
>> }
>>}
>>
>
>
>
>