From 96a19593b223bdc8dbfa9aeb5e31c4a66102745b Mon Sep 17 00:00:00 2001 From: Andi Gutmans Date: Mon, 20 Sep 1999 16:56:02 +0000 Subject: [PATCH] - Internal functions which are basic language functions should be in Zend and not in PHP. I.e. strlen(), each(), error_reporting(), count(), get_class_name(). --- ext/standard/basic_functions.c | 82 ---------------------------------- ext/standard/basic_functions.h | 2 - ext/standard/php3_string.h | 3 -- ext/standard/string.c | 43 ------------------ main/php.h | 1 - tests/testarray | 1 - 6 files changed, 132 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index e75f0f4ff4..14e877f761 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -100,7 +100,6 @@ function_entry basic_functions[] = { PHP_FE(reset, first_arg_force_ref) PHP_FE(current, first_arg_force_ref) PHP_FE(key, first_arg_force_ref) - PHP_FE(each, first_arg_force_ref) PHP_FALIAS(pos, current, first_arg_force_ref) PHP_FE(time, NULL) @@ -137,11 +136,8 @@ function_entry basic_functions[] = { PHP_FE(phpversion, NULL) PHP_FE(phpcredits, NULL) - PHP_FE(strlen, NULL) - PHP_FE(strcmp, NULL) PHP_FE(strspn, NULL) PHP_FE(strcspn, NULL) - PHP_FE(strcasecmp, NULL) PHP_FE(strtok, NULL) PHP_FE(strtoupper, NULL) PHP_FE(strtolower, NULL) @@ -217,8 +213,6 @@ function_entry basic_functions[] = { PHP_FE(getmxrr, second_and_third_args_force_ref) #endif - PHP_FE(error_reporting, NULL) - PHP_FE(getmyuid, NULL) PHP_FE(getmypid, NULL) PHP_FE(getmyinode, NULL) @@ -557,30 +551,6 @@ PHP_FUNCTION(putenv) #endif -PHP_FUNCTION(error_reporting) -{ - pval *arg; - int old_error_reporting; - ELS_FETCH(); - - old_error_reporting = EG(error_reporting); - switch (ARG_COUNT(ht)) { - case 0: - break; - case 1: - if (getParameters(ht,1,&arg) == FAILURE) { - RETURN_FALSE; - } - convert_to_long(arg); - EG(error_reporting)=arg->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - - RETVAL_LONG(old_error_reporting); -} PHP_FUNCTION(toggle_short_open_tag) { @@ -1098,58 +1068,6 @@ PHP_FUNCTION(next) pval_copy_constructor(return_value); } - -PHP_FUNCTION(each) -{ - pval *array,*entry,**entry_ptr, *tmp; - char *string_key; - ulong num_key; - pval **inserted_pointer; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(array); - if (!target_hash) { - php_error(E_WARNING,"Variable passed to each() is not an array or object"); - return; - } - if (zend_hash_get_current_data(target_hash, (void **) &entry_ptr)==FAILURE) { - RETURN_FALSE; - } - array_init(return_value); - entry = *entry_ptr; - - /* add value elements */ - if (entry->EA.is_ref) { - tmp = (pval *)emalloc(sizeof(pval)); - *tmp = *entry; - pval_copy_constructor(tmp); - tmp->EA.is_ref=0; - tmp->EA.locks = 0; - tmp->refcount=0; - entry=tmp; - } - zend_hash_index_update(return_value->value.ht, 1, &entry, sizeof(pval *), NULL); - entry->refcount++; - zend_hash_update_ptr(return_value->value.ht, "value", sizeof("value"), entry, sizeof(pval *), NULL); - entry->refcount++; - - /* add the key elements */ - switch (zend_hash_get_current_key(target_hash, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - add_get_index_string(return_value,0,string_key,(void **) &inserted_pointer,0); - break; - case HASH_KEY_IS_LONG: - add_get_index_long(return_value,0,num_key, (void **) &inserted_pointer); - break; - } - zend_hash_update(return_value->value.ht, "key", sizeof("key"), inserted_pointer, sizeof(pval *), NULL); - (*inserted_pointer)->refcount++; - zend_hash_move_forward(target_hash); -} - PHP_FUNCTION(reset) { diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index d33a5559c8..967f45b2d3 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -64,7 +64,6 @@ PHP_FUNCTION(flush); PHP_FUNCTION(end); PHP_FUNCTION(prev); PHP_FUNCTION(next); -PHP_FUNCTION(each); PHP_FUNCTION(reset); PHP_FUNCTION(current); PHP_FUNCTION(key); @@ -76,7 +75,6 @@ PHP_FUNCTION(max); /* system functions */ PHP_FUNCTION(getenv); PHP_FUNCTION(putenv); -PHP_FUNCTION(error_reporting); PHP_FUNCTION(get_current_user); PHP_FUNCTION(set_time_limit); diff --git a/ext/standard/php3_string.h b/ext/standard/php3_string.h index 7d8bda4903..725364af6b 100644 --- a/ext/standard/php3_string.h +++ b/ext/standard/php3_string.h @@ -40,11 +40,8 @@ extern char *strtok_string; #endif -PHP_FUNCTION(strlen); -PHP_FUNCTION(strcmp); PHP_FUNCTION(strspn); PHP_FUNCTION(strcspn); -PHP_FUNCTION(strcasecmp); PHP_FUNCTION(str_replace); PHP_FUNCTION(chop); PHP_FUNCTION(trim); diff --git a/ext/standard/string.c b/ext/standard/string.c index 066ccf4a00..3058239b59 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -78,49 +78,6 @@ PHP_FUNCTION(bin2hex) RETURN_STRINGL(new, newlen, 0); } -/* {{{ proto int strlen(string str) - Get string length */ -PHP_FUNCTION(strlen) -{ - pval **str; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - RETVAL_LONG((*str)->value.str.len); -} -/* }}} */ - -/* {{{ proto int strcmp(string str1, string str2) - Binary safe string comparison */ -PHP_FUNCTION(strcmp) -{ - pval *s1,*s2; - - if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &s1, &s2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(s1); - convert_to_string(s2); - RETURN_LONG(php3_binary_strcmp(s1,s2)); -} -/* }}} */ - -/* {{{ proto int strcasecmp(string str1, string str2) - Binary safe case-insensitive string comparison */ -PHP_FUNCTION(strcasecmp) -{ - pval *s1,*s2; - - if (ARG_COUNT(ht)!=2 || getParameters(ht, 2, &s1, &s2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(s1); - convert_to_string(s2); - RETURN_LONG(zend_binary_strcasecmp(s1, s2)); -} -/* }}} */ /* {{{ proto int strspn(string str, string mask) Find length of initial segment consisting entirely of characters found in mask */ diff --git a/main/php.h b/main/php.h index 2207dbce8d..4f635a21e8 100644 --- a/main/php.h +++ b/main/php.h @@ -249,7 +249,6 @@ extern int ap_vsnprintf(char *, size_t, const char *, va_list); #define STR_FREE(ptr) if (ptr && ptr!=empty_string && ptr!=undefined_variable_string) { efree(ptr); } #define COPY_STRING(yy) (yy).value.str.val = (char *) estrndup((yy).value.str.val,(yy).value.str.len) #define STR_PRINT(str) ((str)?(str):"") -#define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL))) #ifndef MAXPATHLEN #define MAXPATHLEN 256 /* Should be safe for any weird systems that do not define it */ diff --git a/tests/testarray b/tests/testarray index 27a2f9bc4d..056bd2966b 100644 --- a/tests/testarray +++ b/tests/testarray @@ -1,4 +1,3 @@ - This is a small test...