diff options
author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:36:21 -0400 |
---|---|---|
committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:36:21 -0400 |
commit | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (patch) | |
tree | b38e2e5c6974b9a15f103e5cf884cba9fff90ef4 /ext/libxml | |
parent | a88a88d0986a4a32288c102cdbfebd78d7e91d99 (diff) | |
download | php-d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76.tar.gz |
Imported Upstream version 5.2.0upstream/5.2.0
Diffstat (limited to 'ext/libxml')
-rw-r--r-- | ext/libxml/libxml.c | 94 | ||||
-rw-r--r-- | ext/libxml/php_libxml.h | 21 | ||||
-rw-r--r-- | ext/libxml/php_libxml2.def | 1 | ||||
-rw-r--r-- | ext/libxml/tests/001.phpt | 31 | ||||
-rw-r--r-- | ext/libxml/tests/002.phpt | 87 | ||||
-rw-r--r-- | ext/libxml/tests/003.phpt | 28 | ||||
-rw-r--r-- | ext/libxml/tests/004.phpt | 57 | ||||
-rw-r--r-- | ext/libxml/tests/test.xml | 8 |
8 files changed, 290 insertions, 37 deletions
diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index d974f1272..2ad1896b7 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: libxml.c,v 1.32.2.7 2006/01/01 12:50:08 sniper Exp $ */ +/* $Id: libxml.c,v 1.32.2.7.2.8 2006/09/06 21:44:45 edink Exp $ */ #define IS_EXT_MODULE @@ -60,20 +60,14 @@ typedef struct _php_libxml_func_handler { static HashTable php_libxml_exports; -#ifdef ZTS -int libxml_globals_id; -#else -PHP_LIBXML_API php_libxml_globals libxml_globals; -#endif +ZEND_DECLARE_MODULE_GLOBALS(libxml) +static PHP_GINIT_FUNCTION(libxml); zend_class_entry *libxmlerror_class_entry; /* {{{ dynamically loadable module stuff */ #ifdef COMPILE_DL_LIBXML ZEND_GET_MODULE(libxml) -# ifdef PHP_WIN32 -# include "zend_arg_defs.c" -# endif #endif /* COMPILE_DL_LIBXML */ /* }}} */ @@ -86,13 +80,38 @@ PHP_MINFO_FUNCTION(libxml); /* }}} */ +/* {{{ arginfo */ +static +ZEND_BEGIN_ARG_INFO(arginfo_libxml_set_streams_context, 0) + ZEND_ARG_INFO(0, context) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO(arginfo_libxml_use_internal_errors, 0) + ZEND_ARG_INFO(0, use_errors) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO(arginfo_libxml_get_last_error, 0) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO(arginfo_libxml_get_errors, 0) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO(arginfo_libxml_clear_errors, 0) +ZEND_END_ARG_INFO() + +/* }}} */ + /* {{{ extension definition structures */ zend_function_entry libxml_functions[] = { - PHP_FE(libxml_set_streams_context, NULL) - PHP_FE(libxml_use_internal_errors, NULL) - PHP_FE(libxml_get_last_error, NULL) - PHP_FE(libxml_clear_errors, NULL) - PHP_FE(libxml_get_errors, NULL) + PHP_FE(libxml_set_streams_context, arginfo_libxml_set_streams_context) + PHP_FE(libxml_use_internal_errors, arginfo_libxml_use_internal_errors) + PHP_FE(libxml_get_last_error, arginfo_libxml_get_last_error) + PHP_FE(libxml_clear_errors, arginfo_libxml_clear_errors) + PHP_FE(libxml_get_errors, arginfo_libxml_get_errors) {NULL, NULL, NULL} }; @@ -106,7 +125,11 @@ zend_module_entry libxml_module_entry = { PHP_RSHUTDOWN(libxml), /* per-request shutdown function */ PHP_MINFO(libxml), /* information function */ NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES + PHP_MODULE_GLOBALS(libxml), /* globals descriptor */ + PHP_GINIT(libxml), /* globals ctor */ + NULL, /* globals dtor */ + NULL, /* post deactivate */ + STANDARD_MODULE_PROPERTIES_EX }; /* }}} */ @@ -237,14 +260,12 @@ static void php_libxml_node_free_list(xmlNodePtr node TSRMLS_DC) /* }}} */ /* {{{ startup, shutdown and info functions */ -#ifdef ZTS -static void php_libxml_init_globals(php_libxml_globals *libxml_globals_p TSRMLS_DC) +static PHP_GINIT_FUNCTION(libxml) { - LIBXML(stream_context) = NULL; - LIBXML(error_buffer).c = NULL; - LIBXML(error_list) = NULL; + libxml_globals->stream_context = NULL; + libxml_globals->error_buffer.c = NULL; + libxml_globals->error_list = NULL; } -#endif /* Channel libxml file io layer through the PHP streams subsystem. * This allows use of ftps:// and https:// urls */ @@ -575,14 +596,6 @@ PHP_MINIT_FUNCTION(libxml) php_libxml_initialize(); -#ifdef ZTS - ts_allocate_id(&libxml_globals_id, sizeof(php_libxml_globals), (ts_allocate_ctor) php_libxml_init_globals, NULL); -#else - LIBXML(stream_context) = NULL; - LIBXML(error_buffer).c = NULL; - LIBXML(error_list) = NULL; -#endif - REGISTER_LONG_CONSTANT("LIBXML_VERSION", LIBXML_VERSION, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("LIBXML_DOTTED_VERSION", LIBXML_DOTTED_VERSION, CONST_CS | CONST_PERSISTENT); @@ -644,6 +657,10 @@ PHP_RSHUTDOWN_FUNCTION(libxml) xmlParserInputBufferCreateFilenameDefault(NULL); xmlOutputBufferCreateFilenameDefault(NULL); + if (LIBXML(stream_context)) { + zval_ptr_dtor(&LIBXML(stream_context)); + LIBXML(stream_context) = NULL; + } smart_str_free(&LIBXML(error_buffer)); if (LIBXML(error_list)) { zend_llist_destroy(LIBXML(error_list)); @@ -683,12 +700,12 @@ PHP_FUNCTION(libxml_set_streams_context) } /* }}} */ -/* {{{ proto void libxml_use_internal_errors(boolean use_errors) +/* {{{ proto void libxml_use_internal_errors([boolean use_errors]) Disable libxml errors and allow user to fetch error information as needed */ PHP_FUNCTION(libxml_use_internal_errors) { xmlStructuredErrorFunc current_handler; - int use_errors=0, retval; + zend_bool use_errors=0, retval; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &use_errors) == FAILURE) { return; @@ -942,11 +959,15 @@ int php_libxml_decrement_doc_ref(php_libxml_node_object *object TSRMLS_DC) { xmlFreeDoc((xmlDoc *) object->document->ptr); } if (object->document->doc_props != NULL) { + if (object->document->doc_props->classmap) { + zend_hash_destroy(object->document->doc_props->classmap); + FREE_HASHTABLE(object->document->doc_props->classmap); + } efree(object->document->doc_props); } efree(object->document); + object->document = NULL; } - object->document = NULL; } return ret_refcount; @@ -1004,12 +1025,21 @@ void php_libxml_node_decrement_resource(php_libxml_node_object *object TSRMLS_DC obj_node->_private = NULL; } } + } + if (object != NULL && object->document != NULL) { /* Safe to call as if the resource were freed then doc pointer is NULL */ php_libxml_decrement_doc_ref(object TSRMLS_CC); } } /* }}} */ +#ifdef PHP_WIN32 +PHP_LIBXML_API BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + return xmlDllMain(hinstDLL, fdwReason, lpvReserved); +} +#endif + #endif /* diff --git a/ext/libxml/php_libxml.h b/ext/libxml/php_libxml.h index 65a7ef186..2a1e54bb8 100644 --- a/ext/libxml/php_libxml.h +++ b/ext/libxml/php_libxml.h @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_libxml.h,v 1.15.2.2 2006/01/01 12:50:08 sniper Exp $ */ +/* $Id: php_libxml.h,v 1.15.2.2.2.2 2006/06/15 18:33:07 dmitry Exp $ */ #ifndef PHP_LIBXML_H #define PHP_LIBXML_H @@ -37,16 +37,27 @@ extern zend_module_entry libxml_module_entry; #define LIBXML_SAVE_NOEMPTYTAG 1<<2 -typedef struct { +ZEND_BEGIN_MODULE_GLOBALS(libxml) zval *stream_context; smart_str error_buffer; zend_llist *error_list; -} php_libxml_globals; +ZEND_END_MODULE_GLOBALS(libxml) + +typedef struct _libxml_doc_props { + int formatoutput; + int validateonparse; + int resolveexternals; + int preservewhitespace; + int substituteentities; + int stricterror; + int recover; + HashTable *classmap; +} libxml_doc_props; typedef struct _php_libxml_ref_obj { void *ptr; int refcount; - void *doc_props; + libxml_doc_props *doc_props; } php_libxml_ref_obj; typedef struct _php_libxml_node_ptr { @@ -92,7 +103,7 @@ PHP_LIBXML_API void php_libxml_initialize(); PHP_LIBXML_API void php_libxml_shutdown(); #ifdef ZTS -#define LIBXML(v) TSRMG(libxml_globals_id, php_libxml_globals *, v) +#define LIBXML(v) TSRMG(libxml_globals_id, zend_libxml_globals *, v) #else #define LIBXML(v) (libxml_globals.v) #endif diff --git a/ext/libxml/php_libxml2.def b/ext/libxml/php_libxml2.def index f1998c320..ef21f5e64 100644 --- a/ext/libxml/php_libxml2.def +++ b/ext/libxml/php_libxml2.def @@ -1391,6 +1391,7 @@ xmlXPathCompile xmlXPathCompiledEval
xmlXPathConcatFunction
xmlXPathContainsFunction
+xmlXPathContextSetCache
xmlXPathConvertBoolean
xmlXPathConvertNumber
xmlXPathConvertString
diff --git a/ext/libxml/tests/001.phpt b/ext/libxml/tests/001.phpt new file mode 100644 index 000000000..6f68cb4a8 --- /dev/null +++ b/ext/libxml/tests/001.phpt @@ -0,0 +1,31 @@ +--TEST-- +libxml_use_internal_errors() +--SKIPIF-- +<?php if (!extension_loaded('libxml')) die('skip'); ?> +--FILE-- +<?php + +var_dump(libxml_use_internal_errors(false)); +var_dump(libxml_use_internal_errors(true)); +var_dump(libxml_use_internal_errors()); +var_dump(libxml_use_internal_errors(new stdclass)); + +var_dump(libxml_get_errors()); +var_dump(libxml_get_last_error()); + +var_dump(libxml_clear_errors()); + +echo "Done\n"; +?> +--EXPECTF-- +bool(false) +bool(false) +bool(true) + +Warning: libxml_use_internal_errors() expects parameter 1 to be boolean, object given in %s001.php on line 6 +NULL +array(0) { +} +bool(false) +NULL +Done diff --git a/ext/libxml/tests/002.phpt b/ext/libxml/tests/002.phpt new file mode 100644 index 000000000..f803d7ab1 --- /dev/null +++ b/ext/libxml/tests/002.phpt @@ -0,0 +1,87 @@ +--TEST-- +libxml_get_errors() +--SKIPIF-- +<?php if (!extension_loaded('simplexml')) die('skip'); ?> +--FILE-- +<?php + +var_dump(libxml_use_internal_errors(true)); + +$xmlstr = <<< XML +<?xml version='1.0' standalone='yes'?> + <movies> + <movie> + <titles>PHP: Behind the Parser</title> + </movie> + </movies> +XML; + +$doc = simplexml_load_string($xmlstr); +$xml = explode("\n", $xmlstr); + +if (!$doc) { + $errors = libxml_get_errors(); + + foreach ($errors as $error) { + echo display_xml_error($error, $xml); + } + + var_dump(libxml_get_last_error()); +} + + +function display_xml_error($error, $xml) +{ + $return = $xml[$error->line - 1] . "\n"; + $return .= str_repeat('-', $error->column) . "^\n"; + + switch ($error->level) { + case LIBXML_ERR_WARNING: + $return .= "Warning $error->code: "; + break; + case LIBXML_ERR_ERROR: + $return .= "Error $error->code: "; + break; + case LIBXML_ERR_FATAL: + $return .= "Fatal Error $error->code: "; + break; + } + + $return .= trim($error->message) . "\n Line: $error->line" . "\n Column: $error->column"; + + if ($error->file) { + $return .= "\n File: $error->file"; + } + + return "$return\n\n--------------------------------------------\n\n"; +} + + +echo "Done\n"; +?> +--EXPECTF-- +bool(false) + <titles>PHP: Behind the Parser</title> +%s +Fatal Error 76: Opening and ending tag mismatch: titles line 4 and title + Line: 4 + Column: %d + +-------------------------------------------- + +object(LibXMLError)#%d (6) { + ["level"]=> + int(3) + ["code"]=> + int(76) + ["column"]=> + int(%d) + ["message"]=> + string(57) "Opening and ending tag mismatch: titles line 4 and title +" + ["file"]=> + string(0) "" + ["line"]=> + int(4) +} +Done diff --git a/ext/libxml/tests/003.phpt b/ext/libxml/tests/003.phpt new file mode 100644 index 000000000..dcf6c0bb6 --- /dev/null +++ b/ext/libxml/tests/003.phpt @@ -0,0 +1,28 @@ +--TEST-- +libxml_use_internal_errors() memory leaks +--SKIPIF-- +<?php if (!extension_loaded('simplexml')) die('skip'); ?> +--FILE-- +<?php +var_dump(libxml_use_internal_errors(true)); + +$xmlstr = <<< XML +<?xml version='1.0' standalone='yes'?> + <movies> + <movie> + <titles>PHP: Behind the Parser</title> + </movie> + </movies> +XML; + +simplexml_load_string($xmlstr); + +// test memleaks here +var_dump(libxml_use_internal_errors(false)); + +echo "Done\n"; +?> +--EXPECTF-- +bool(false) +bool(true) +Done diff --git a/ext/libxml/tests/004.phpt b/ext/libxml/tests/004.phpt new file mode 100644 index 000000000..f347aed61 --- /dev/null +++ b/ext/libxml/tests/004.phpt @@ -0,0 +1,57 @@ +--TEST-- +libxml_set_streams_context() +--SKIPIF-- +<?php if (!extension_loaded('dom')) die('skip'); ?> +--FILE-- +<?php + +$ctxs = array( + NULL, + 'bogus', + 123, + new stdclass, + array('a'), + stream_context_create(), + stream_context_create(array('file')), + stream_context_create(array('file' => array('some_opt' => 'aaa'))) +); + + +foreach ($ctxs as $ctx) { + var_dump(libxml_set_streams_context($ctx)); + $dom = new DOMDocument(); + var_dump($dom->load(dirname(__FILE__).'/test.xml')); +} + +echo "Done\n"; + +?> +--EXPECTF-- +Warning: options should have the form ["wrappername"]["optionname"] = $value in %s004.php on line 10 +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL + +Warning: DOMDocument::load(): supplied argument is not a valid Stream-Context resource in %s004.php on line 18 +bool(true) +NULL +bool(true) +NULL +bool(true) +NULL +bool(true) +Done diff --git a/ext/libxml/tests/test.xml b/ext/libxml/tests/test.xml new file mode 100644 index 000000000..fc1d32890 --- /dev/null +++ b/ext/libxml/tests/test.xml @@ -0,0 +1,8 @@ +<library> + <book> + <title>PHP made simple</title> + </book> + <book> + <title>learn PHP easily</title> + </book> +</library> |