rrichards               Sat Jul  5 19:43:11 2003 EDT

  Modified files:              
    /php-src/ext/xsl    xsltprocessor.c php_xsl.c 
  Log:
  use common doc with ref counting rather than copy
  
Index: php-src/ext/xsl/xsltprocessor.c
diff -u php-src/ext/xsl/xsltprocessor.c:1.6 php-src/ext/xsl/xsltprocessor.c:1.7
--- php-src/ext/xsl/xsltprocessor.c:1.6 Thu Jun 19 11:00:28 2003
+++ php-src/ext/xsl/xsltprocessor.c     Sat Jul  5 19:43:10 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: xsltprocessor.c,v 1.6 2003/06/19 15:00:28 rrichards Exp $ */
+/* $Id: xsltprocessor.c,v 1.7 2003/07/05 23:43:10 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -126,7 +126,6 @@
        zval *id, *docp = NULL;
        xmlDoc *doc = NULL;
        xsltStylesheetPtr sheetp, oldsheetp;
-       xmlDocPtr newdocp;
        xsl_object *intern;
        node_object *docobj;
        
@@ -135,15 +134,12 @@
        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 @@
                        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 */
Index: php-src/ext/xsl/php_xsl.c
diff -u php-src/ext/xsl/php_xsl.c:1.5 php-src/ext/xsl/php_xsl.c:1.6
--- php-src/ext/xsl/php_xsl.c:1.5       Fri Jun 20 10:07:51 2003
+++ php-src/ext/xsl/php_xsl.c   Sat Jul  5 19:43:10 2003
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_xsl.c,v 1.5 2003/06/20 14:07:51 rrichards Exp $ */
+/* $Id: php_xsl.c,v 1.6 2003/07/05 23:43:10 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -91,8 +91,15 @@
                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;
        }



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to