]> granicus.if.org Git - php/commitdiff
use common doc with ref counting rather than copy
authorRob Richards <rrichards@php.net>
Sat, 5 Jul 2003 23:43:10 +0000 (23:43 +0000)
committerRob Richards <rrichards@php.net>
Sat, 5 Jul 2003 23:43:10 +0000 (23:43 +0000)
ext/xsl/php_xsl.c
ext/xsl/xsltprocessor.c

index 30db612f945fc483032aa08c76c2a9ee703e0ffe..3b18a7946a47cdb5ad0034380217e44b2dbd1af0 100644 (file)
@@ -91,8 +91,15 @@ void xsl_objects_dtor(void *object, zend_object_handle handle TSRMLS_DC)
                if (((xsltStylesheetPtr) intern->ptr)->_private != NULL) {
                        ((xsltStylesheetPtr) intern->ptr)->_private = NULL;   
                }
-               /* libxslt uses _private for itself, so turning of the deregistering is maybe a solution 
-                  we copied the doc at import, so it shouldn't be possible to be used from php land */
+               if (intern->document != NULL) {
+                       if (--intern->document->refcount == 0) {
+                               xmlFreeDoc((xmlDocPtr) intern->document->ptr);
+                               efree(intern->document);
+                       }
+                       ((xsltStylesheetPtr) intern->ptr)->doc = NULL;
+                       intern->document = NULL;
+               }
+
                xsltFreeStylesheet((xsltStylesheetPtr) intern->ptr);
                intern->ptr = NULL;
        }
index cfe4fa3dc3142cbd516b52b2ca74a95e1cae6dc4..ad1ad7f4ca5440cbb8b3ad27154035b252e505b6 100644 (file)
@@ -126,7 +126,6 @@ PHP_FUNCTION(xsl_xsltprocessor_import_stylesheet)
        zval *id, *docp = NULL;
        xmlDoc *doc = NULL;
        xsltStylesheetPtr sheetp, oldsheetp;
-       xmlDocPtr newdocp;
        xsl_object *intern;
        node_object *docobj;
        
@@ -135,15 +134,12 @@ PHP_FUNCTION(xsl_xsltprocessor_import_stylesheet)
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &docp) == FAILURE) {
                RETURN_FALSE;
        }
+
        DOC_GET_OBJ(doc, docp, xmlDocPtr, docobj);
-       /* copy the doc, so that it's not accessable from outside
-       FIXME: and doubling memory consumption...
-       */
-       newdocp = xmlCopyDoc(doc, 1);
-       sheetp = xsltParseStylesheetDoc(newdocp);
+
+       sheetp = xsltParseStylesheetDoc(doc);
 
        if (!sheetp) {
-               xmlFreeDoc(newdocp);
                RETURN_FALSE;
        }
 
@@ -154,10 +150,21 @@ PHP_FUNCTION(xsl_xsltprocessor_import_stylesheet)
                        efree(((xsltStylesheetPtr) intern->ptr)->_private);
                        ((xsltStylesheetPtr) intern->ptr)->_private = NULL;   
                }
-               //FIXME: more non-thread safe stuff
+               if (intern->document != NULL) {
+                       if (--intern->document->refcount == 0) {
+                               xmlFreeDoc((xmlDocPtr) intern->document->ptr);
+                               efree(intern->document);
+                       }
+                       ((xsltStylesheetPtr) intern->ptr)->doc = NULL;
+                       intern->document = NULL;
+               }
                xsltFreeStylesheet((xsltStylesheetPtr) intern->ptr);
                intern->ptr = NULL;
-       } 
+       }
+
+       intern->document = docobj->document;
+       intern->document->refcount++;
+
        php_xsl_set_object(id, sheetp TSRMLS_CC);
 }
 /* }}} end xsl_xsltprocessor_import_stylesheet */