summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Zmievski <andrei@php.net>1999-12-11 22:42:01 +0000
committerAndrei Zmievski <andrei@php.net>1999-12-11 22:42:01 +0000
commitdbaf6c5c653d932745e7c2592415cccd29ade73b (patch)
tree6c8530e741853b11d3935936d648412b70ca9e86
parent0c779c51c9ee0362106c04cdccb91a3bac478e70 (diff)
downloadphp-git-dbaf6c5c653d932745e7c2592415cccd29ade73b.tar.gz
Added array globals in preparation for multisort() changes.
-rw-r--r--ext/standard/array.c24
-rw-r--r--ext/standard/php_array.h24
2 files changed, 46 insertions, 2 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index b0eddb0f81..9c61e31dc3 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -38,6 +38,12 @@
#include "php_array.h"
#include "basic_functions.h"
+#ifdef ZTS
+int array_globals_id;
+#else
+php_array_globals array_globals;
+#endif
+
#define EXTR_OVERWRITE 0
#define EXTR_SKIP 1
#define EXTR_PREFIX_SAME 2
@@ -96,7 +102,7 @@ zend_module_entry array_module_entry = {
"Array Functions", /* extension name */
array_functions, /* function list */
PHP_MINIT(array), /* process startup */
- NULL, /* process shutdown */
+ PHP_MSHUTDOWN(array), /* process shutdown */
NULL, /* request startup */
NULL, /* request shutdown */
NULL, /* extension info */
@@ -107,6 +113,10 @@ PHP_MINIT_FUNCTION(array)
{
ELS_FETCH();
+#ifdef ZTS
+ array_globals_id = ts_allocate_id(sizeof(php_array_globals), NULL, NULL);
+#endif
+
REGISTER_LONG_CONSTANT("EXTR_OVERWRITE", EXTR_OVERWRITE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("EXTR_SKIP", EXTR_SKIP, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("EXTR_PREFIX_SAME", EXTR_PREFIX_SAME, CONST_CS | CONST_PERSISTENT);
@@ -115,6 +125,15 @@ PHP_MINIT_FUNCTION(array)
return SUCCESS;
}
+PHP_MSHUTDOWN_FUNCTION(array)
+{
+#ifdef ZTS
+ ts_free_id(array_globals_id);
+#endif
+
+ return SUCCESS;
+}
+
static int array_key_compare(const void *a, const void *b)
{
Bucket *f;
@@ -1941,6 +1960,7 @@ int multisort_compare(const void *a, const void *b)
int r;
int result = 0;
zval temp;
+ ARRAYLS_FETCH();
r = 0;
do {
@@ -1962,6 +1982,7 @@ PHP_FUNCTION(multisort)
int argc;
int array_size;
int i, k;
+ ARRAYLS_FETCH();
/* Get the argument count and check it */
argc = ARG_COUNT(ht);
@@ -2012,6 +2033,7 @@ PHP_FUNCTION(multisort)
/* Do the actual sort */
qsort(indirect, array_size, sizeof(Bucket **), multisort_compare);
+ /* Restructure the arrays based on sorted indirect */
HANDLE_BLOCK_INTERRUPTIONS();
for (i = 0; i < argc; i++) {
hash = (*args[i])->value.ht;
diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h
index 46ec921fc8..2fee1a3589 100644
--- a/ext/standard/php_array.h
+++ b/ext/standard/php_array.h
@@ -36,7 +36,7 @@ extern zend_module_entry array_module_entry;
#define array_module_ptr &array_module_entry
PHP_MINIT_FUNCTION(array);
-PHP_RINIT_FUNCTION(array);
+PHP_MSHUTDOWN_FUNCTION(array);
PHP_FUNCTION(ksort);
PHP_FUNCTION(krsort);
@@ -80,5 +80,27 @@ PHP_FUNCTION(array_flip);
HashTable* _phpi_splice(HashTable *, int, int, zval ***, int, HashTable **);
int multisort_compare(const void *a, const void *b);
+typedef struct {
+ int *multisort_flags;
+} php_array_globals;
+
+#ifdef ZTS
+#define ARRAYLS_D php_array_globals *array_globals
+#define ARRAYLS_DC , ARRAYLS_D
+#define ARRAYLS_C array_globals
+#define ARRAYLS_CC , ARRAYLS_C
+#define ARRAYG(v) (array_globals->v)
+#define ARRAYLS_FETCH() php_array_globals *array_globals = ts_resource(array_globals_id)
+extern int array_globals_id;
+#else
+#define ARRAYLS_D
+#define ARRAYLS_DC
+#define ARRAYLS_C
+#define ARRAYLS_CC
+#define ARRAYG(v) (array_globals.v)
+#define ARRAYLS_FETCH()
+extern php_array_globals array_globals;
+#endif
+
#define phpext_array_ptr array_module_ptr
#endif /* _PHP_ARRAY_H */