summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-04-11 15:06:01 +0400
committerDmitry Stogov <dmitry@zend.com>2014-04-11 15:06:01 +0400
commit33c731d94f236aacd16cc1383f13d985e429b773 (patch)
tree8e2bd35d3b532d3904a0e90bb5e3f8a3fd61f338
parentb6af031e523717f3f26e094fc5f8d68f45b11e35 (diff)
parenta2a2481dd109f3648d204538bcd9196d66005416 (diff)
downloadphp-git-33c731d94f236aacd16cc1383f13d985e429b773.tar.gz
Merge branch 'refactoring2' of github.com:zendtech/php into refactoring2
-rw-r--r--ext/libxml/libxml.c156
-rw-r--r--ext/libxml/php_libxml.h7
-rw-r--r--ext/mbstring/mbstring.c1
-rw-r--r--main/php_streams.h4
4 files changed, 80 insertions, 88 deletions
diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c
index 2e6e00b106..10768942ae 100644
--- a/ext/libxml/libxml.c
+++ b/ext/libxml/libxml.c
@@ -267,22 +267,24 @@ static void php_libxml_node_free_list(xmlNodePtr node TSRMLS_DC)
/* {{{ startup, shutdown and info functions */
static PHP_GINIT_FUNCTION(libxml)
{
- libxml_globals->stream_context = NULL;
- libxml_globals->error_buffer.c = NULL;
+ ZVAL_UNDEF(&libxml_globals->stream_context);
+ libxml_globals->error_buffer.s = NULL;
libxml_globals->error_list = NULL;
+ ZVAL_UNDEF(&libxml_globals->entity_loader.object);
libxml_globals->entity_loader.fci.size = 0;
libxml_globals->entity_loader_disabled = 0;
}
-static void _php_libxml_destroy_fci(zend_fcall_info *fci)
+static void _php_libxml_destroy_fci(zend_fcall_info *fci, zval *object)
{
if (fci->size > 0) {
zval_ptr_dtor(&fci->function_name);
- if (fci->object_ptr != NULL) {
- zval_ptr_dtor(&fci->object_ptr);
- }
fci->size = 0;
}
+ if (!ZVAL_IS_UNDEF(object)) {
+ zval_ptr_dtor(object);
+ ZVAL_UNDEF(object);
+ }
}
/* Channel libxml file io layer through the PHP streams subsystem.
@@ -334,7 +336,7 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
}
}
- context = php_stream_context_from_zval(LIBXML(stream_context), 0);
+ context = php_stream_context_from_zval(&LIBXML(stream_context), 0);
ret_val = php_stream_open_wrapper_ex(path_to_open, (char *)mode, REPORT_ERRORS, NULL, context);
if (isescaped) {
@@ -534,17 +536,17 @@ static void php_libxml_internal_error_handler(int error_type, void *ctx, const c
if (output == 1) {
if (LIBXML(error_list)) {
- _php_list_set_error_structure(NULL, LIBXML(error_buffer).c);
+ _php_list_set_error_structure(NULL, LIBXML(error_buffer).s->val);
} else {
switch (error_type) {
case PHP_LIBXML_CTX_ERROR:
- php_libxml_ctx_error_level(E_WARNING, ctx, LIBXML(error_buffer).c TSRMLS_CC);
+ php_libxml_ctx_error_level(E_WARNING, ctx, LIBXML(error_buffer).s->val TSRMLS_CC);
break;
case PHP_LIBXML_CTX_WARNING:
- php_libxml_ctx_error_level(E_NOTICE, ctx, LIBXML(error_buffer).c TSRMLS_CC);
+ php_libxml_ctx_error_level(E_NOTICE, ctx, LIBXML(error_buffer).s->val TSRMLS_CC);
break;
default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", LIBXML(error_buffer).c);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", LIBXML(error_buffer).s->val);
}
}
smart_str_free(&LIBXML(error_buffer));
@@ -556,12 +558,9 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
{
xmlParserInputPtr ret = NULL;
const char *resource = NULL;
- zval *public = NULL,
- *system = NULL,
- *ctxzv = NULL,
- **params[] = {&public, &system, &ctxzv},
- *retval_ptr = NULL;
- int retval;
+ zval *ctxzv, retval;
+ zval params[3];
+ int status;
zend_fcall_info *fci;
TSRMLS_FETCH();
@@ -572,22 +571,24 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
return _php_libxml_default_entity_loader(URL, ID, context);
}
- ALLOC_INIT_ZVAL(public);
if (ID != NULL) {
- ZVAL_STRING(public, ID, 1);
+ ZVAL_STRING(&params[0], ID);
+ } else {
+ ZVAL_UNDEF(&params[0]);
}
- ALLOC_INIT_ZVAL(system);
if (URL != NULL) {
- ZVAL_STRING(system, URL, 1);
+ ZVAL_STRING(&params[1], URL);
+ } else {
+ ZVAL_UNDEF(&params[1]);
}
- MAKE_STD_ZVAL(ctxzv);
+ ctxzv = &params[2];
array_init_size(ctxzv, 4);
#define ADD_NULL_OR_STRING_KEY(memb) \
if (context->memb == NULL) { \
- add_assoc_null_ex(ctxzv, #memb, sizeof(#memb)); \
+ add_assoc_null_ex(ctxzv, #memb, sizeof(#memb) - 1); \
} else { \
- add_assoc_string_ex(ctxzv, #memb, sizeof(#memb), \
+ add_assoc_string_ex(ctxzv, #memb, sizeof(#memb - 1), \
(char *)context->memb, 1); \
}
@@ -598,34 +599,35 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
#undef ADD_NULL_OR_STRING_KEY
- fci->retval_ptr_ptr = &retval_ptr;
- fci->params = params;
- fci->param_count = sizeof(params)/sizeof(*params);
+ fci->retval = &retval;
+ fci->params = params;
+ fci->param_count = sizeof(params)/sizeof(*params);
fci->no_separation = 1;
- retval = zend_call_function(fci, &LIBXML(entity_loader).fcc TSRMLS_CC);
- if (retval != SUCCESS || fci->retval_ptr_ptr == NULL) {
+ status = zend_call_function(fci, &LIBXML(entity_loader).fcc TSRMLS_CC);
+ if (status != SUCCESS || ZVAL_IS_UNDEF(&retval)) {
php_libxml_ctx_error(context,
"Call to user entity loader callback '%s' has failed",
- fci->function_name);
+ Z_STRVAL(fci->function_name));
} else {
+ /*
retval_ptr = *fci->retval_ptr_ptr;
if (retval_ptr == NULL) {
php_libxml_ctx_error(context,
"Call to user entity loader callback '%s' has failed; "
"probably it has thrown an exception",
fci->function_name);
- } else if (Z_TYPE_P(retval_ptr) == IS_STRING) {
+ } else */ if (Z_TYPE(retval) == IS_STRING) {
is_string:
- resource = Z_STRVAL_P(retval_ptr);
- } else if (Z_TYPE_P(retval_ptr) == IS_RESOURCE) {
+ resource = Z_STRVAL(retval);
+ } else if (Z_TYPE(retval) == IS_RESOURCE) {
php_stream *stream;
- php_stream_from_zval_no_verify(stream, &retval_ptr);
+ php_stream_from_zval_no_verify(stream, &retval);
if (stream == NULL) {
php_libxml_ctx_error(context,
"The user entity loader callback '%s' has returned a "
"resource, but it is not a stream",
- fci->function_name);
+ Z_STRVAL(fci->function_name));
} else {
/* TODO: allow storing the encoding in the stream context? */
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
@@ -635,7 +637,7 @@ is_string:
"input buffer");
} else {
/* make stream not being closed when the zval is freed */
- zend_list_addref(stream->rsrc_id);
+ ++GC_REFCOUNT(stream->res);
pib->context = stream;
pib->readcallback = php_libxml_streams_IO_read;
pib->closecallback = php_libxml_streams_IO_close;
@@ -646,10 +648,10 @@ is_string:
}
}
}
- } else if (Z_TYPE_P(retval_ptr) != IS_NULL) {
+ } else if (Z_TYPE(retval) != IS_NULL) {
/* retval not string nor resource nor null; convert to string */
- SEPARATE_ZVAL(&retval_ptr);
- convert_to_string(retval_ptr);
+ SEPARATE_ZVAL(&retval);
+ convert_to_string(&retval);
goto is_string;
} /* else is null; don't try anything */
}
@@ -667,12 +669,10 @@ is_string:
}
}
- zval_ptr_dtor(&public);
- zval_ptr_dtor(&system);
- zval_ptr_dtor(&ctxzv);
- if (retval_ptr != NULL) {
- zval_ptr_dtor(&retval_ptr);
- }
+ zval_ptr_dtor(&params[0]);
+ zval_ptr_dtor(&params[1]);
+ zval_ptr_dtor(&params[2]);
+ zval_ptr_dtor(&retval);
return ret;
}
@@ -758,14 +758,10 @@ PHP_LIBXML_API void php_libxml_shutdown(void)
}
}
-PHP_LIBXML_API zval *php_libxml_switch_context(zval *context TSRMLS_DC)
+PHP_LIBXML_API void php_libxml_switch_context(zval *context, zval *oldcontext TSRMLS_DC)
{
- zval *oldcontext;
-
- oldcontext = LIBXML(stream_context);
- LIBXML(stream_context) = context;
- return oldcontext;
-
+ ZVAL_COPY_VALUE(oldcontext, &LIBXML(stream_context));
+ ZVAL_COPY_VALUE(&LIBXML(stream_context), context);
}
static PHP_MINIT_FUNCTION(libxml)
@@ -888,11 +884,8 @@ static int php_libxml_post_deactivate()
}
xmlSetStructuredErrorFunc(NULL, NULL);
- if (LIBXML(stream_context)) {
- /* the steam_context resource will be released by resource list destructor */
- efree(LIBXML(stream_context));
- LIBXML(stream_context) = NULL;
- }
+ /* the steam_context resource will be released by resource list destructor */
+ ZVAL_UNDEF(&LIBXML(stream_context));
smart_str_free(&LIBXML(error_buffer));
if (LIBXML(error_list)) {
zend_llist_destroy(LIBXML(error_list));
@@ -901,7 +894,7 @@ static int php_libxml_post_deactivate()
}
xmlResetLastError();
- _php_libxml_destroy_fci(&LIBXML(entity_loader).fci);
+ _php_libxml_destroy_fci(&LIBXML(entity_loader).fci, &LIBXML(entity_loader).object);
return SUCCESS;
}
@@ -927,12 +920,11 @@ static PHP_FUNCTION(libxml_set_streams_context)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg) == FAILURE) {
return;
}
- if (LIBXML(stream_context)) {
+ if (!ZVAL_IS_UNDEF(&LIBXML(stream_context))) {
zval_ptr_dtor(&LIBXML(stream_context));
- LIBXML(stream_context) = NULL;
+ ZVAL_UNDEF(&LIBXML(stream_context));
}
- Z_ADDREF_P(arg);
- LIBXML(stream_context) = arg;
+ ZVAL_COPY(&LIBXML(stream_context), arg);
}
/* }}} */
@@ -1022,25 +1014,24 @@ static PHP_FUNCTION(libxml_get_errors)
error = zend_llist_get_first(LIBXML(error_list));
while (error != NULL) {
- zval *z_error;
- MAKE_STD_ZVAL(z_error);
+ zval z_error;
- object_init_ex(z_error, libxmlerror_class_entry);
- add_property_long(z_error, "level", error->level);
- add_property_long(z_error, "code", error->code);
- add_property_long(z_error, "column", error->int2);
+ object_init_ex(&z_error, libxmlerror_class_entry);
+ add_property_long(&z_error, "level", error->level);
+ add_property_long(&z_error, "code", error->code);
+ add_property_long(&z_error, "column", error->int2);
if (error->message) {
- add_property_string(z_error, "message", error->message, 1);
+ add_property_string(&z_error, "message", error->message, 1);
} else {
- add_property_stringl(z_error, "message", "", 0, 1);
+ add_property_stringl(&z_error, "message", "", 0, 1);
}
if (error->file) {
- add_property_string(z_error, "file", error->file, 1);
+ add_property_string(&z_error, "file", error->file, 1);
} else {
- add_property_stringl(z_error, "file", "", 0, 1);
+ add_property_stringl(&z_error, "file", "", 0, 1);
}
- add_property_long(z_error, "line", error->line);
- add_next_index_zval(return_value, z_error);
+ add_property_long(&z_error, "line", error->line);
+ add_next_index_zval(return_value, &z_error);
error = zend_llist_get_next(LIBXML(error_list));
}
@@ -1092,13 +1083,14 @@ static PHP_FUNCTION(libxml_set_external_entity_loader)
return;
}
- _php_libxml_destroy_fci(&LIBXML(entity_loader).fci);
+ _php_libxml_destroy_fci(&LIBXML(entity_loader).fci, &LIBXML(entity_loader).object);
if (fci.size > 0) { /* argument not null */
LIBXML(entity_loader).fci = fci;
- Z_ADDREF_P(fci.function_name);
- if (fci.object_ptr != NULL) {
- Z_ADDREF_P(fci.object_ptr);
+ Z_ADDREF(fci.function_name);
+ if (fci.object != NULL) {
+ ZVAL_OBJ(&LIBXML(entity_loader).object, fci.object);
+ Z_ADDREF(LIBXML(entity_loader).object);
}
LIBXML(entity_loader).fcc = fcc;
}
@@ -1134,7 +1126,7 @@ int php_libxml_xmlCheckUTF8(const unsigned char *s)
return 1;
}
-int php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function)
+zval *php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function)
{
php_libxml_func_handler export_hnd;
@@ -1142,7 +1134,7 @@ int php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node expo
php_libxml_initialize();
export_hnd.export_func = export_function;
- return zend_hash_add(&php_libxml_exports, ce->name, ce->name_length + 1, &export_hnd, sizeof(export_hnd), NULL);
+ return zend_hash_add_mem(&php_libxml_exports, ce->name, &export_hnd, sizeof(export_hnd));
}
PHP_LIBXML_API xmlNodePtr php_libxml_import_node(zval *object TSRMLS_DC)
@@ -1151,12 +1143,12 @@ PHP_LIBXML_API xmlNodePtr php_libxml_import_node(zval *object TSRMLS_DC)
xmlNodePtr node = NULL;
php_libxml_func_handler *export_hnd;
- if (object->type == IS_OBJECT) {
+ if (Z_TYPE_P(object) == IS_OBJECT) {
ce = Z_OBJCE_P(object);
while (ce->parent != NULL) {
ce = ce->parent;
}
- if (zend_hash_find(&php_libxml_exports, ce->name, ce->name_length + 1, (void **) &export_hnd) == SUCCESS) {
+ if ((export_hnd = zend_hash_find_ptr(&php_libxml_exports, ce->name)) == SUCCESS) {
node = export_hnd->export_func(object TSRMLS_CC);
}
}
diff --git a/ext/libxml/php_libxml.h b/ext/libxml/php_libxml.h
index 901e321aac..64c6bd7874 100644
--- a/ext/libxml/php_libxml.h
+++ b/ext/libxml/php_libxml.h
@@ -40,10 +40,11 @@ extern zend_module_entry libxml_module_entry;
#define LIBXML_SAVE_NOEMPTYTAG 1<<2
ZEND_BEGIN_MODULE_GLOBALS(libxml)
- zval *stream_context;
+ zval stream_context;
smart_str error_buffer;
zend_llist *error_list;
struct _php_libxml_entity_resolver {
+ zval object;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
} entity_loader;
@@ -87,7 +88,7 @@ PHP_LIBXML_API int php_libxml_decrement_node_ptr(php_libxml_node_object *object
PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp TSRMLS_DC);
PHP_LIBXML_API int php_libxml_decrement_doc_ref(php_libxml_node_object *object TSRMLS_DC);
PHP_LIBXML_API xmlNodePtr php_libxml_import_node(zval *object TSRMLS_DC);
-PHP_LIBXML_API int php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function);
+PHP_LIBXML_API zval *php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function);
/* When an explicit freeing of node and children is required */
PHP_LIBXML_API void php_libxml_node_free_resource(xmlNodePtr node TSRMLS_DC);
/* When object dtor is called as node may still be referenced */
@@ -96,7 +97,7 @@ PHP_LIBXML_API void php_libxml_error_handler(void *ctx, const char *msg, ...);
PHP_LIBXML_API void php_libxml_ctx_warning(void *ctx, const char *msg, ...);
PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...);
PHP_LIBXML_API int php_libxml_xmlCheckUTF8(const unsigned char *s);
-PHP_LIBXML_API zval *php_libxml_switch_context(zval *context TSRMLS_DC);
+PHP_LIBXML_API void php_libxml_switch_context(zval *context, zval *oldcontext TSRMLS_DC);
PHP_LIBXML_API void php_libxml_issue_error(int level, const char *msg TSRMLS_DC);
PHP_LIBXML_API zend_bool php_libxml_disable_entity_loader(zend_bool disable TSRMLS_DC);
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 7cf0eef249..340d631dc8 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -56,7 +56,6 @@
#include "ext/standard/php_string.h"
#include "ext/standard/php_mail.h"
#include "ext/standard/exec.h"
-#include "ext/standard/php_smart_str.h"
#include "ext/standard/url.h"
#include "main/php_output.h"
#include "ext/standard/info.h"
diff --git a/main/php_streams.h b/main/php_streams.h
index 7e9b6a6c26..a0550a2356 100644
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -255,8 +255,8 @@ END_EXTERN_C()
# define php_stream_to_zval(stream, zval) { ZVAL_RES(zval, (stream)->res); }
#endif
-#define php_stream_from_zval(xstr, ppzval) ZEND_FETCH_RESOURCE2((xstr), php_stream *, (ppzval), -1, "stream", php_file_le_stream(), php_file_le_pstream())
-#define php_stream_from_zval_no_verify(xstr, ppzval) (xstr) = (php_stream*)zend_fetch_resource((ppzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream())
+#define php_stream_from_zval(xstr, pzval) ZEND_FETCH_RESOURCE2((xstr), php_stream *, (pzval), -1, "stream", php_file_le_stream(), php_file_le_pstream())
+#define php_stream_from_zval_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource((pzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream())
BEGIN_EXTERN_C()
PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclosed);