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 ); > } > } > } > -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php