cvs: php4 /ext/sablot php_sablot.h sablot.c
| From: | Sterling Hughes | Date: | Mon, 11 Dec 2000 14:15:09 +0000 |
| Subject: | cvs: php4 /ext/sablot php_sablot.h sablot.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-3069@lists.php.net to get a copy of this message | ||
sterling Mon Dec 11 06:15:09 2000 EDT
Modified files:
/php4/ext/sablot sablot.c php_sablot.h
Log:
Fix a crash related to the simple sablotron api. (thies)
make sablotron work with zts.
fix a leak or two,
Index: php4/ext/sablot/sablot.c
diff -u php4/ext/sablot/sablot.c:1.24 php4/ext/sablot/sablot.c:1.25
--- php4/ext/sablot/sablot.c:1.24 Sun Dec 10 02:57:46 2000
+++ php4/ext/sablot/sablot.c Mon Dec 11 06:15:08 2000
@@ -31,8 +31,7 @@
#include "ext/standard/php_output.h"
#include "php_sablot.h"
-static int le_sablot;
-static SablotHandle processor;
+static int le_sablot;
/* Functions related to PHP's list handling */
static void _php_sablot_free_processor(zend_rsrc_list_entry *rsrc);
@@ -68,37 +67,37 @@
/* ERROR Macros */
-#define SABLOT_FREE_ERROR_HANDLE(__handle) \
- if ((__handle).errors) { \
+#define SABLOT_FREE_ERROR_HANDLE(__handle) \
+ if ((__handle).errors) { \
(__handle).errors = (__handle).errors_start.next; \
- while ((__handle).errors) { \
- S_FREE((__handle).errors->key); \
- S_FREE((__handle).errors->value); \
- (__handle).errors = (__handle).errors->next; \
- } \
- S_FREE((__handle).errors); \
+ while ((__handle).errors) { \
+ S_FREE((__handle).errors->key); \
+ S_FREE((__handle).errors->value); \
+ (__handle).errors = (__handle).errors->next; \
+ } \
+ S_FREE((__handle).errors); \
}
/* Sablotron Basic Api macro's */
-#define SABLOT_BASIC_CREATE_PROCESSOR() \
- if (processor == NULL) { \
- int ret = 0; \
- \
- ret = SablotCreateProcessor(&processor); \
- if (ret) { \
- SABLOTG(last_errno) = ret; \
- return; \
- } \
- \
- ret = SablotRegHandler(processor, HLR_MESSAGE, (void *)&mh, (void *)NULL); \
- if (ret) { \
- SABLOTG(last_errno) = ret; \
- return; \
- } \
+#define SABLOT_BASIC_CREATE_PROCESSOR() \
+ if (SABLOTG(processor) == NULL) { \
+ int ret = 0; \
+ \
+ ret = SablotCreateProcessor(&SABLOTG(processor)); \
+ if (ret) { \
+ SABLOTG(last_errno) = (int) ret; \
+ return; \
+ } \
+ \
+ ret = SablotRegHandler(SABLOTG(processor), HLR_MESSAGE, (void *)&mh, (void *)NULL); \
+ if (ret) { \
+ SABLOTG(last_errno) = (int) ret; \
+ return; \
+ } \
}
-#define SABLOT_BASIC_HANDLE processor
+#define SABLOT_BASIC_HANDLE SABLOTG(processor)
/**
* SAX Handler structure, this defines the different functions to be
@@ -161,9 +160,9 @@
"sablot",
sablot_functions,
PHP_MINIT(sablot),
- PHP_MSHUTDOWN(sablot),
+ PHP_MSHUTDOWN(sablot),
NULL,
- NULL,
+ PHP_RSHUTDOWN(sablot),
PHP_MINFO(sablot),
STANDARD_MODULE_PROPERTIES
};
@@ -172,26 +171,48 @@
ZEND_GET_MODULE(sablot)
#endif
+static void php_sablot_init_globals(SABLOTLS_D)
+{
+ SABLOTG(processor) = NULL;
+ SABLOTG(errors) = NULL;
+ SABLOTG(errorHandler) = NULL;
+}
+
/* MINIT and MINFO Functions */
PHP_MINIT_FUNCTION(sablot)
{
+#ifdef ZTS
+ sablot_globals_id = ts_allocate_id(sizeof(php_sablot_globals),
(ts_allocate_ctor)php_sablot_init_globals, NULL);
+#else
+ php_sablot_init_globals(SABLOTLS_C);
+#endif
+
le_sablot = zend_register_list_destructors_ex(_php_sablot_free_processor, NULL, "Sablotron
XSLT", module_number);
- processor = NULL;
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(sablot)
{
- if (processor) {
- SablotUnregHandler(processor, HLR_MESSAGE, NULL, NULL);
- SablotDestroyProcessor(processor);
+ SABLOTLS_FETCH();
+ if (SABLOTG(processor)) {
+ SablotUnregHandler(SABLOTG(processor), HLR_MESSAGE, NULL, NULL);
+ SablotDestroyProcessor(SABLOTG(processor));
}
return SUCCESS;
}
+PHP_RSHUTDOWN_FUNCTION(sablot)
+{
+ SABLOTLS_FETCH();
+
+ SABLOT_FREE_ERROR_HANDLE(SABLOTG_HANDLE);
+
+ return SUCCESS;
+}
+
PHP_MINFO_FUNCTION(sablot)
{
php_info_print_table_start();
@@ -785,7 +806,6 @@
RETURN_FALSE;
}
-
if (!strcasecmp("document", string_key)) {
_php_sablot_handler_pair(handle,
&handle->startDocHandler,
&handle->endDocHandler,
@@ -1173,11 +1193,12 @@
int isAdvanced = 0,
argc = 0,
+ i,
idx,
len;
SABLOTLS_FETCH();
-
+
if (userData == NULL) {
SABLOT_FREE_ERROR_HANDLE(SABLOTG_HANDLE);
@@ -1271,6 +1292,10 @@
zval_dtor(retval);
efree(retval);
+
+ for (i = 1; i < argc; i++) {
+ zval_del_ref(&argv[i]);
+ }
} else {
if (level == MH_LEVEL_CRITICAL ||
level == MH_LEVEL_ERROR ||
@@ -1280,7 +1305,6 @@
}
return(0);
-
}
/* }}} */
Index: php4/ext/sablot/php_sablot.h
diff -u php4/ext/sablot/php_sablot.h:1.9 php4/ext/sablot/php_sablot.h:1.10
--- php4/ext/sablot/php_sablot.h:1.9 Fri Dec 8 01:29:09 2000
+++ php4/ext/sablot/php_sablot.h Mon Dec 11 06:15:09 2000
@@ -37,6 +37,9 @@
PHP_MINFO_FUNCTION(sablot);
PHP_MSHUTDOWN_FUNCTION(sablot);
+/* Request functions */
+PHP_RSHUTDOWN_FUNCTION(sablot);
+
/* Output transformation functions */
PHP_FUNCTION(xslt_output_begintransform);
PHP_FUNCTION(xslt_output_endtransform);
@@ -65,6 +68,7 @@
char *value;
struct _php_sablot_error *next;
};
+
typedef struct _php_sablot_error php_sablot_error;
@@ -102,6 +106,7 @@
php_sablot_error errors_start;
char *output_transform_file; /* For output transformations */
int last_errno; /* Global last_errno, if no handle is found */
+ SablotHandle processor;
} php_sablot_globals;
@@ -109,10 +114,18 @@
#define SABLOTG(v) (sablot_globals->v)
#define SABLOTLS_FETCH() php_sablot_globals *sablot_globals = ts_resource(sablot_globals_id)
#define SABLOTG_HANDLE (*sablot_globals)
+#define SABLOTLS_C sablot_globals
+#define SABLOTLS_CC , SABLOTLS_C
+#define SABLOTLS_D php_sablot_globals *sablot_globals
+#define SABLOTLS_DC , SABLOTLS_D
#else
#define SABLOTG(v) (sablot_globals.v)
#define SABLOTG_HANDLE sablot_globals
#define SABLOTLS_FETCH()
+#define SABLOTLS_C
+#define SABLOTLS_CC
+#define SABLOTLS_D
+#define SABLOTLS_DC
#endif
#else
@@ -126,4 +139,4 @@
* tab-width: 4
* c-basic-offset: 4
* End:
- */
\ No newline at end of file
+ */