Skip to content

Commit 342c6e0

Browse files
committed
Whatnot:
* updated alloc_persist to use critical sections * changed extension shutdown to two-phase * updated dependencies * PR support (don't remember if there was any really)
1 parent 2e8fb4e commit 342c6e0

14 files changed

+59
-43
lines changed

Zend/configure.in

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,11 @@ if test -d /usr/pkg/include -a -d /usr/pkg/lib ; then
7070
LDFLAGS="$LDFLAGS -L/usr/pkg/lib"
7171
fi
7272

73-
AC_CHECK_LIB(nsl, gethostname, [
74-
LIBS="-lnsl $LIBS"
75-
AC_DEFINE(HAVE_LIBNSL) ], [])
76-
7773
AC_CHECK_LIB(c, socket, [:], [
7874
AC_CHECK_LIB(socket, socket, [
7975
LIBS="-lsocket $LIBS"
8076
AC_DEFINE(HAVE_LIBSOCKET) ], []) ])
8177

82-
AC_CHECK_LIB(c, gethostbyaddr, [:], [
83-
AC_CHECK_LIB(nsl, gethostbyaddr, [
84-
LIBS="-lnsl $LIBS"
85-
AC_DEFINE(HAVE_LIBNSL) ], []) ])
86-
8778
AC_CHECK_LIB(c, dlopen, [
8879
# fake it
8980
AC_DEFINE(HAVE_LIBDL) ], [
@@ -96,24 +87,6 @@ dnl as well as res_search resides in libsocket
9687
AC_CHECK_LIB(c, sin, [:], [
9788
AC_CHECK_LIB(m, sin) ])
9889

99-
dnl The res_search may be in libsocket as well, and if it is
100-
dnl make sure to check for dn_skipname in libresolv, or if res_search
101-
dnl is in neither of these libs, still check for dn_skipname in libresolv
102-
AC_CHECK_LIB(socket, res_search, [
103-
AC_CHECK_LIB(resolv, dn_skipname)
104-
AC_CHECK_LIB(resolv, __dn_skipname)
105-
LIBS="$LIBS -lsocket"
106-
AC_DEFINE(HAVE_LIBSOCKET)
107-
], [
108-
AC_CHECK_LIB(resolv, res_search, [
109-
LIBS="$LIBS -lresolv"
110-
AC_DEFINE(HAVE_LIBRESOLV)
111-
], [
112-
AC_CHECK_LIB(resolv, dn_skipname)
113-
AC_CHECK_LIB(resolv, __dn_skipname)
114-
])
115-
])
116-
11790
dnl Checks for header files.
11891
AC_HEADER_STDC
11992

Zend/zend-scanner.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ zend_op_array *compile_filename(zval *filename CLS_DC)
243243
}
244244
file_handle.filename = filename->value.str.val;
245245
file_handle.type = ZEND_HANDLE_FILENAME;
246-
retval = compile_files(0 CLS_CC, 1, &file_handle);
246+
retval = zend_compile_files(0 CLS_CC, 1, &file_handle);
247247
if (filename==&tmp) {
248248
zval_dtor(&tmp);
249249
}

Zend/zend.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ static void register_standard_class()
154154
standard_class.handle_function_call = NULL;
155155
standard_class.handle_property_get = NULL;
156156
standard_class.handle_property_set = NULL;
157+
standard_class.refcount = (int *) malloc(sizeof(int));
158+
*standard_class.refcount = 1;
157159
zend_hash_add(CG(class_table), "stdClass", sizeof("stdClass"), &standard_class, sizeof(zend_class_entry), NULL);
158160
}
159161

@@ -206,7 +208,7 @@ void zend_shutdown()
206208
free(CG(function_table));
207209
zend_hash_destroy(CG(class_table));
208210
free(CG(class_table));
209-
zend_llist_destroy(&zend_extensions);
211+
zend_shutdown_extensions();
210212
free(zend_version_info);
211213
zend_shutdown_constants();
212214
}

Zend/zend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ typedef struct {
8585
char *fname;
8686
void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
8787
unsigned char *func_arg_types;
88-
} function_entry;
88+
} zend_function_entry;
8989

9090

9191
typedef struct {
@@ -107,6 +107,7 @@ struct _zend_class_entry {
107107
char *name;
108108
uint name_length;
109109
struct _zend_class_entry *parent;
110+
int *refcount;
110111

111112
HashTable function_table;
112113
HashTable default_properties;

Zend/zend_API.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ ZEND_API int _register_list_destructors(void (*list_destructor)(void *), void (*
592592

593593

594594
/* registers all functions in *library_functions in the function hash */
595-
int register_functions(function_entry *functions)
595+
int register_functions(zend_function_entry *functions)
596596
{
597-
function_entry *ptr = functions;
597+
zend_function_entry *ptr = functions;
598598
zend_internal_function internal_function;
599599
int count=0,unload=0;
600600
CLS_FETCH();
@@ -633,9 +633,9 @@ int register_functions(function_entry *functions)
633633
/* count=-1 means erase all functions, otherwise,
634634
* erase the first count functions
635635
*/
636-
void unregister_functions(function_entry *functions,int count)
636+
void unregister_functions(zend_function_entry *functions,int count)
637637
{
638-
function_entry *ptr = functions;
638+
zend_function_entry *ptr = functions;
639639
int i=0;
640640
CLS_FETCH();
641641

@@ -753,6 +753,8 @@ zend_class_entry *register_internal_class(zend_class_entry *class_entry)
753753

754754
class_entry->type = ZEND_INTERNAL_CLASS;
755755
class_entry->parent = NULL;
756+
class_entry->refcount = (int *) malloc(sizeof(int));
757+
*class_entry->refcount = 1;
756758
zend_hash_init(&class_entry->default_properties, 0, NULL, PVAL_PTR_DTOR, 1);
757759
zend_hash_init(&class_entry->function_table, 0, NULL, (void (*)(void *)) destroy_zend_function, 1);
758760

Zend/zend_API.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
#include "zend_list.h"
2222

2323

24+
#define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)
25+
#define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(zend_if_##name)
26+
27+
#define ZEND_NAMED_FE(runtime_name, name, arg_types) { #runtime_name, name, arg_types },
28+
#define ZEND_FE(name, arg_types) ZEND_NAMED_FE(name, zend_if_##name, arg_types)
29+
30+
2431
int zend_next_free_module(void);
2532

2633
int getParameters(int ht, int param_count,...);
@@ -32,8 +39,8 @@ int getThis(zval **this);
3239

3340

3441
int ParameterPassedByReference(int ht, uint n);
35-
int register_functions(function_entry *functions);
36-
void unregister_functions(function_entry *functions, int count);
42+
int register_functions(zend_function_entry *functions);
43+
void unregister_functions(zend_function_entry *functions, int count);
3744
int register_module(zend_module_entry *module_entry);
3845
zend_class_entry *register_internal_class(zend_class_entry *class_entry);
3946

Zend/zend_alloc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,16 @@ ZEND_API void _persist_alloc(void *ptr)
494494
_mem_block_check(ptr, 1, filename, lineno);
495495
#endif
496496

497+
HANDLE_BLOCK_INTERRUPTIONS();
498+
497499
/* remove the block from the non persistent list */
498500
REMOVE_POINTER_FROM_LIST(p);
499501

500502
p->persistent = 1;
501503

502504
/* add the block to the persistent list */
503505
ADD_POINTER_TO_LIST(p);
506+
HANDLE_UNBLOCK_INTERRUPTIONS();
504507
}
505508

506509

Zend/zend_compile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,8 @@ void do_begin_class_declaration(znode *class_name, znode *parent_class_name CLS_
11071107
CG(class_entry).type = ZEND_USER_CLASS;
11081108
CG(class_entry).name = class_name->u.constant.value.str.val;
11091109
CG(class_entry).name_length = class_name->u.constant.value.str.len;
1110+
CG(class_entry).refcount = (int *) emalloc(sizeof(int));
1111+
*CG(class_entry).refcount = 1;
11101112

11111113
zend_str_tolower(CG(class_entry).name, CG(class_entry).name_length);
11121114

Zend/zend_extensions.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,26 @@ int zend_load_extension(char *path)
100100
#endif
101101
}
102102

103-
104-
void zend_extension_dtor(zend_extension *extension)
103+
static void zend_extension_shutdown(zend_extension *extension)
105104
{
106105
#if ZEND_EXTENSIONS_SUPPORT
107106
if (extension->shutdown) {
108107
extension->shutdown(extension);
109108
}
109+
#endif
110+
}
111+
112+
113+
void zend_shutdown_extensions()
114+
{
115+
zend_llist_apply(&zend_extensions, (void (*)(void *)) zend_extension_shutdown);
116+
zend_llist_destroy(&zend_extensions);
117+
}
118+
119+
120+
void zend_extension_dtor(zend_extension *extension)
121+
{
122+
#if ZEND_EXTENSIONS_SUPPORT
110123
DL_UNLOAD(extension->handle);
111124
#endif
112125
}

Zend/zend_extensions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ void zend_extension_dtor(zend_extension *extension);
8686
int zend_load_extension(char *path);
8787
int zend_load_extensions(char **extension_paths);
8888
void zend_append_version_info(zend_extension *extension);
89+
void zend_shutdown_extensions();
8990

9091
#endif /* _ZEND_EXTENSIONS_H */

Zend/zend_globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ struct _zend_executor_globals {
187187

188188
zend_ptr_stack argument_stack;
189189

190+
void *reserved[4];
190191
#if SUPPORT_INTERACTIVE
191192
int interactive;
192193
#endif

Zend/zend_llist.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,26 @@ ZEND_API void zend_llist_del_element(zend_llist *l, void *element)
7272

7373
ZEND_API void zend_llist_destroy(zend_llist *l)
7474
{
75-
zend_llist_element *current=l->head, *next;
75+
zend_llist_element *current, *next;
7676

77-
while (current) {
78-
next = current->next;
79-
if (l->dtor) {
77+
if (l->dtor) {
78+
current = l->head;
79+
80+
while (current) {
8081
l->dtor(current->data);
82+
current = current->next;
8183
}
84+
}
85+
86+
current = l->head;
87+
while (current) {
88+
next = current->next;
8289
pefree(current, l->persistent);
8390
current = next;
8491
}
8592
}
8693

94+
8795
ZEND_API void zend_llist_remove_tail(zend_llist *l)
8896
{
8997
zend_llist_element *old_tail;

Zend/zend_modules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
typedef struct {
3030
char *name;
31-
function_entry *functions;
31+
zend_function_entry *functions;
3232
int (*module_startup_func)(INIT_FUNC_ARGS);
3333
int (*module_shutdown_func)(SHUTDOWN_FUNC_ARGS);
3434
int (*request_startup_func)(INIT_FUNC_ARGS);

Zend/zend_opcode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ ZEND_API void destroy_zend_function(zend_function *function)
111111

112112
ZEND_API void destroy_zend_class(zend_class_entry *ce)
113113
{
114+
if (--(*ce->refcount)>0) {
115+
return;
116+
}
114117
switch (ce->type) {
115118
case ZEND_USER_CLASS:
116119
efree(ce->name);

0 commit comments

Comments
 (0)