11/*
2- * $PostgreSQL: pgsql/contrib/xml2/xpath.c,v 1.27 2010/02/28 21:31:57 tgl Exp $
2+ * $PostgreSQL: pgsql/contrib/xml2/xpath.c,v 1.28 2010/03/01 05:16:35 tgl Exp $
33 *
44 * Parser interface for DOM-based parser (libxml) rather than
55 * stream-based SAX-type parser
@@ -145,12 +145,8 @@ xml_is_well_formed(PG_FUNCTION_ARGS)
145145
146146doctree = xmlParseMemory ((char * )VARDATA (t ),docsize );
147147if (doctree == NULL )
148- {
149- xmlCleanupParser ();
150148PG_RETURN_BOOL (false);/* i.e. not well-formed */
151- }
152149xmlFreeDoc (doctree );
153- xmlCleanupParser ();
154150PG_RETURN_BOOL (true);
155151}
156152
@@ -297,7 +293,6 @@ xpath_nodeset(PG_FUNCTION_ARGS)
297293xpres = pgxml_result_to_text (pgxml_xpath (PG_GETARG_TEXT_P (0 ),xpath ),
298294toptag ,septag ,NULL );
299295
300- /* xmlCleanupParser(); done by result_to_text routine */
301296pfree (xpath );
302297
303298if (xpres == NULL )
@@ -332,7 +327,6 @@ xpath_list(PG_FUNCTION_ARGS)
332327xpres = pgxml_result_to_text (pgxml_xpath (PG_GETARG_TEXT_P (0 ),xpath ),
333328NULL ,NULL ,plainsep );
334329
335- /* xmlCleanupParser(); done by result_to_text routine */
336330pfree (xpath );
337331
338332if (xpres == NULL )
@@ -371,7 +365,6 @@ xpath_string(PG_FUNCTION_ARGS)
371365xpres = pgxml_result_to_text (pgxml_xpath (PG_GETARG_TEXT_P (0 ),xpath ),
372366NULL ,NULL ,NULL );
373367
374- xmlCleanupParser ();
375368pfree (xpath );
376369
377370if (xpres == NULL )
@@ -403,13 +396,10 @@ xpath_number(PG_FUNCTION_ARGS)
403396pfree (xpath );
404397
405398if (res == NULL )
406- {
407- xmlCleanupParser ();
408399PG_RETURN_NULL ();
409- }
410400
411401fRes = xmlXPathCastToNumber (res );
412- xmlCleanupParser ();
402+
413403if (xmlXPathIsNaN (fRes ))
414404PG_RETURN_NULL ();
415405
@@ -440,13 +430,10 @@ xpath_bool(PG_FUNCTION_ARGS)
440430pfree (xpath );
441431
442432if (res == NULL )
443- {
444- xmlCleanupParser ();
445433PG_RETURN_BOOL (false);
446- }
447434
448435bRes = xmlXPathCastToBoolean (res );
449- xmlCleanupParser ();
436+
450437PG_RETURN_BOOL (bRes );
451438}
452439
@@ -469,9 +456,7 @@ pgxml_xpath(text *document, xmlChar *xpath)
469456
470457doctree = xmlParseMemory ((char * )VARDATA (document ),docsize );
471458if (doctree == NULL )
472- {/* not well-formed */
473- return NULL ;
474- }
459+ return NULL ;/* not well-formed */
475460
476461ctxt = xmlXPathNewContext (doctree );
477462ctxt -> node = xmlDocGetRootElement (doctree );
@@ -480,7 +465,6 @@ pgxml_xpath(text *document, xmlChar *xpath)
480465comppath = xmlXPathCompile (xpath );
481466if (comppath == NULL )
482467{
483- xmlCleanupParser ();
484468xmlFreeDoc (doctree );
485469elog_error ("XPath Syntax Error" , true);
486470}
@@ -492,7 +476,6 @@ pgxml_xpath(text *document, xmlChar *xpath)
492476if (res == NULL )
493477{
494478xmlXPathFreeContext (ctxt );
495- /* xmlCleanupParser(); */
496479xmlFreeDoc (doctree );
497480
498481return NULL ;
@@ -511,10 +494,8 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
511494text * xpres ;
512495
513496if (res == NULL )
514- {
515- xmlCleanupParser ();
516497return NULL ;
517- }
498+
518499switch (res -> type )
519500{
520501case XPATH_NODESET :
@@ -536,9 +517,6 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
536517xpres = cstring_to_text ((char * )xpresstr );
537518
538519/* Free various storage */
539- xmlCleanupParser ();
540- /* xmlFreeDoc(doctree); -- will die at end of tuple anyway */
541-
542520xmlFree (xpresstr );
543521
544522elog_error ("XPath error" , false);
@@ -779,7 +757,6 @@ xpath_table(PG_FUNCTION_ARGS)
779757comppath = xmlXPathCompile (xpaths [j ]);
780758if (comppath == NULL )
781759{
782- xmlCleanupParser ();
783760xmlFreeDoc (doctree );
784761elog_error ("XPath Syntax Error" , true);
785762}
@@ -844,8 +821,6 @@ xpath_table(PG_FUNCTION_ARGS)
844821pfree (xmldoc );
845822}
846823
847- xmlCleanupParser ();
848-
849824tuplestore_donestoring (tupstore );
850825
851826SPI_finish ();