cvs: /php4/ext/standard array.c basic_functions.c basic_functions.h fsock.c string.c

From: Date: Wed, 01 Dec 1999 17:22:24 +0000
Subject: cvs: /php4/ext/standard array.c basic_functions.c basic_functions.h fsock.c string.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-7187@lists.php.net to get a copy of this message
sas Wed Dec 1 12:22:24 1999 EDT Modified files: /php4/ext/standard array.c basic_functions.c basic_functions.h fsock.c string.c Log: Make array.c thread-safe Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.10 php4/ext/standard/array.c:1.11 --- php4/ext/standard/array.c:1.10 Sun Nov 21 12:13:39 1999 +++ php4/ext/standard/array.c Wed Dec 1 12:21:52 1999 @@ -36,13 +36,13 @@ #include "zend_globals.h" #include "php_globals.h" #include "php_array.h" +#include "basic_functions.h" #define EXTR_OVERWRITE 0 #define EXTR_SKIP 1 #define EXTR_PREFIX_SAME 2 #define EXTR_PREFIX_ALL 3 -static zval **user_compare_func_name; static unsigned char all_args_force_ref[] = { 1, BYREF_FORCE_REST }; function_entry array_functions[] = { @@ -97,7 +97,7 @@ array_functions, /* function list */ PHP_MINIT(array), /* process startup */ NULL, /* process shutdown */ - PHP_RINIT(array), /* request startup */ + NULL, /* request startup */ NULL, /* request shutdown */ NULL, /* extension info */ STANDARD_MODULE_PROPERTIES @@ -115,12 +115,6 @@ return SUCCESS; } -PHP_RINIT_FUNCTION(array) -{ - user_compare_func_name=NULL; - return SUCCESS; -} - static int array_key_compare(const void *a, const void *b) { Bucket *f; @@ -372,6 +366,7 @@ pval **args[2]; pval retval; CLS_FETCH(); + BLS_FETCH(); f = *((Bucket **) a); s = *((Bucket **) b); @@ -379,7 +374,7 @@ args[0] = (pval **) f->pData; args[1] = (pval **) s->pData; - if (call_user_function_ex(CG(function_table), NULL, *user_compare_func_name, &retval, 2, args, 0)==SUCCESS) { + if (call_user_function_ex(CG(function_table), NULL, *BG(user_compare_func_name), &retval, 2, args, 0)==SUCCESS) { convert_to_long(&retval); return retval.value.lval; } else { @@ -393,24 +388,25 @@ pval **array; pval **old_compare_func; HashTable *target_hash; + BLS_FETCH(); - old_compare_func = user_compare_func_name; - if (ARG_COUNT(ht) != 2 || getParametersEx(2, &array, &user_compare_func_name) == FAILURE) { - user_compare_func_name = old_compare_func; + old_compare_func = BG(user_compare_func_name); + if (ARG_COUNT(ht) != 2 || getParametersEx(2, &array, &BG(user_compare_func_name)) == FAILURE) { + BG(user_compare_func_name) = old_compare_func; WRONG_PARAM_COUNT; } target_hash = HASH_OF(*array); if (!target_hash) { php_error(E_WARNING, "Wrong datatype in usort() call"); - user_compare_func_name = old_compare_func; + BG(user_compare_func_name) = old_compare_func; return; } - convert_to_string_ex(user_compare_func_name); + convert_to_string_ex(BG(user_compare_func_name)); if (zend_hash_sort(target_hash, qsort, array_user_compare, 1) == FAILURE) { - user_compare_func_name = old_compare_func; + BG(user_compare_func_name) = old_compare_func; return; } - user_compare_func_name = old_compare_func; + BG(user_compare_func_name) = old_compare_func; RETURN_TRUE; } @@ -419,24 +415,25 @@ pval **array; pval **old_compare_func; HashTable *target_hash; + BLS_FETCH(); - old_compare_func = user_compare_func_name; - if (ARG_COUNT(ht) != 2 || getParametersEx(2, &array, &user_compare_func_name) == FAILURE) { - user_compare_func_name = old_compare_func; + old_compare_func = BG(user_compare_func_name); + if (ARG_COUNT(ht) != 2 || getParametersEx(2, &array, &BG(user_compare_func_name)) == FAILURE) { + BG(user_compare_func_name) = old_compare_func; WRONG_PARAM_COUNT; } target_hash = HASH_OF(*array); if (!target_hash) { php_error(E_WARNING, "Wrong datatype in uasort() call"); - user_compare_func_name = old_compare_func; + BG(user_compare_func_name) = old_compare_func; return; } - convert_to_string_ex(user_compare_func_name); + convert_to_string_ex(BG(user_compare_func_name)); if (zend_hash_sort(target_hash, qsort, array_user_compare, 0) == FAILURE) { - user_compare_func_name = old_compare_func; + BG(user_compare_func_name) = old_compare_func; return; } - user_compare_func_name = old_compare_func; + BG(user_compare_func_name) = old_compare_func; RETURN_TRUE; } @@ -450,6 +447,7 @@ pval retval; int status; CLS_FETCH(); + BLS_FETCH(); args[0] = &key1; args[1] = &key2; @@ -476,7 +474,7 @@ key2.type = IS_LONG; } - status = call_user_function(CG(function_table), NULL, *user_compare_func_name, &retval, 2, args); + status = call_user_function(CG(function_table), NULL, *BG(user_compare_func_name), &retval, 2, args); zval_dtor(&key1); zval_dtor(&key2); @@ -495,24 +493,25 @@ pval **array; pval **old_compare_func; HashTable *target_hash; + BLS_FETCH(); - old_compare_func = user_compare_func_name; - if (ARG_COUNT(ht) != 2 || getParametersEx(2, &array, &user_compare_func_name) == FAILURE) { - user_compare_func_name = old_compare_func; + old_compare_func = BG(user_compare_func_name); + if (ARG_COUNT(ht) != 2 || getParametersEx(2, &array, &BG(user_compare_func_name)) == FAILURE) { + BG(user_compare_func_name) = old_compare_func; WRONG_PARAM_COUNT; } target_hash = HASH_OF(*array); if (!target_hash) { php_error(E_WARNING, "Wrong datatype in uksort() call"); - user_compare_func_name = old_compare_func; + BG(user_compare_func_name) = old_compare_func; return; } - convert_to_string_ex(user_compare_func_name); + convert_to_string_ex(BG(user_compare_func_name)); if (zend_hash_sort(target_hash, qsort, array_user_key_compare, 0) == FAILURE) { - user_compare_func_name = old_compare_func; + BG(user_compare_func_name) = old_compare_func; return; } - user_compare_func_name = old_compare_func; + BG(user_compare_func_name) = old_compare_func; RETURN_TRUE; } @@ -770,8 +769,6 @@ } } -static zval **php_array_walk_func_name; - static int php_array_walk(HashTable *target_hash, zval **userdata) { zval **args[3], /* Arguments to userland function */ @@ -780,6 +777,7 @@ char *string_key; ulong num_key; CLS_FETCH(); + BLS_FETCH(); /* Allocate space for key */ MAKE_STD_ZVAL(key); @@ -801,7 +799,7 @@ } /* Call the userland function */ - call_user_function_ex(CG(function_table), NULL, *php_array_walk_func_name, + call_user_function_ex(CG(function_table), NULL, *BG(array_walk_func_name), &retval, userdata ? 3 : 2, args, 0); /* Clean up the key */ @@ -823,23 +821,24 @@ **userdata = NULL, **old_walk_func_name; HashTable *target_hash; + BLS_FETCH(); argc = ARG_COUNT(ht); - old_walk_func_name = php_array_walk_func_name; + old_walk_func_name = BG(array_walk_func_name); if (argc < 2 || argc > 3 || - getParametersEx(argc, &array, &php_array_walk_func_name, &userdata) == FAILURE) { - php_array_walk_func_name = old_walk_func_name; + getParametersEx(argc, &array, &BG(array_walk_func_name), &userdata) == FAILURE) { + BG(array_walk_func_name) = old_walk_func_name; WRONG_PARAM_COUNT; } target_hash = HASH_OF(*array); if (!target_hash) { php_error(E_WARNING, "Wrong datatype in array_walk() call"); - php_array_walk_func_name = old_walk_func_name; + BG(array_walk_func_name) = old_walk_func_name; return; } - convert_to_string_ex(php_array_walk_func_name); + convert_to_string_ex(BG(array_walk_func_name)); php_array_walk(target_hash, userdata); - php_array_walk_func_name = old_walk_func_name; + BG(array_walk_func_name) = old_walk_func_name; RETURN_TRUE; } Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.129 php4/ext/standard/basic_functions.c:1.130 --- php4/ext/standard/basic_functions.c:1.129 Tue Nov 30 15:18:10 1999 +++ php4/ext/standard/basic_functions.c Wed Dec 1 12:21:52 1999 @@ -394,6 +394,8 @@ BG(strtok_string) = NULL; BG(locale_string) = NULL; + BG(user_compare_func_name) = NULL; + BG(array_walk_func_name) = NULL; #ifdef HAVE_PUTENV if (zend_hash_init(&BG(putenv_ht), 1, NULL, (int (*)(void *)) _php3_putenv_destructor, 0) == FAILURE) { return FAILURE; Index: php4/ext/standard/basic_functions.h diff -u php4/ext/standard/basic_functions.h:1.31 php4/ext/standard/basic_functions.h:1.32 --- php4/ext/standard/basic_functions.h:1.31 Sat Nov 27 19:31:02 1999 +++ php4/ext/standard/basic_functions.h Wed Dec 1 12:21:52 1999 @@ -29,7 +29,7 @@ */ -/* $Id: basic_functions.h,v 1.31 1999/11/28 00:31:02 sas Exp $ */ +/* $Id: basic_functions.h,v 1.32 1999/12/01 17:21:52 sas Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H @@ -111,6 +111,8 @@ char *strtok_pos1; char *strtok_pos2; char str_ebuf[40]; + zval **array_walk_func_name; + zval **user_compare_func_name; } php_basic_globals; #ifdef ZTS @@ -120,6 +122,7 @@ #define BLS_CC , BLS_C #define BG(v) (basic_globals->v) #define BLS_FETCH() php_basic_globals *basic_globals = ts_resource(basic_globals_id) +extern int basic_globals_id; #else #define BLS_D #define BLS_DC @@ -127,6 +130,7 @@ #define BLS_CC #define BG(v) (basic_globals.v) #define BLS_FETCH() +extern php_basic_globals basic_globals; #endif #if HAVE_PUTENV Index: php4/ext/standard/fsock.c diff -u php4/ext/standard/fsock.c:1.27 php4/ext/standard/fsock.c:1.28 --- php4/ext/standard/fsock.c:1.27 Wed Dec 1 12:07:25 1999 +++ php4/ext/standard/fsock.c Wed Dec 1 12:21:52 1999 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.27 1999/12/01 17:07:25 sas Exp $ */ +/* $Id: fsock.c,v 1.28 1999/12/01 17:21:52 sas Exp $ */ /* Synced with php3 revision 1.121 1999-06-18 [ssb] */ /* Synced with php3 revision 1.133 1999-07-21 [sas] */ @@ -149,9 +149,9 @@ int _php3_is_persistent_sock(int sock) { char *key; - PLS_FETCH(); + FLS_FETCH(); - if (zend_hash_find(&PG(ht_fsock_socks), (char *) &sock, sizeof(sock), + if (zend_hash_find(&FG(ht_fsock_socks), (char *) &sock, sizeof(sock), (void **) &key) == SUCCESS) { return 1; } @@ -245,7 +245,7 @@ unsigned short portno; unsigned long conv; char *key = NULL; - PLS_FETCH(); + FLS_FETCH(); if (arg_count > 5 || arg_count < 2 || getParametersArray(ht,arg_count,args)==FAILURE) { FREE_SOCK; @@ -282,7 +282,7 @@ key = emalloc(args[0]->value.str.len + 10); sprintf(key, "%s:%d", args[0]->value.str.val, portno); - if (persistent && zend_hash_find(&PG(ht_fsock_keys), key, strlen(key) + 1, + if (persistent && zend_hash_find(&FG(ht_fsock_keys), key, strlen(key) + 1, (void *) &sockp) == SUCCESS) { FREE_SOCK; *sock = *sockp; @@ -358,9 +358,9 @@ *sock=socketd; if (persistent) { - zend_hash_update(&PG(ht_fsock_keys), key, strlen(key) + 1, + zend_hash_update(&FG(ht_fsock_keys), key, strlen(key) + 1, sock, sizeof(*sock), NULL); - zend_hash_update(&PG(ht_fsock_socks), (char *) sock, sizeof(*sock), + zend_hash_update(&FG(ht_fsock_socks), (char *) sock, sizeof(*sock), key, strlen(key) + 1, NULL); } if(key) efree(key); Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.60 php4/ext/standard/string.c:1.61 --- php4/ext/standard/string.c:1.60 Sat Nov 27 19:31:02 1999 +++ php4/ext/standard/string.c Wed Dec 1 12:21:52 1999 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.60 1999/11/28 00:31:02 sas Exp $ */ +/* $Id: string.c,v 1.61 1999/12/01 17:21:52 sas Exp $ */ /* Synced with php3 revision 1.193 1999-06-16 [ssb] */ @@ -32,12 +32,6 @@ #endif #include "zend_execute.h" #include "php_globals.h" - -#ifdef ZTS -extern int basic_globals_id; -#else -extern php_basic_globals basic_globals; -#endif /* this is read-only, so it's ok */ static char hexconvtab[] = "0123456789abcdef";

« previous php.version4 (#7187) next »