helly           Wed Oct 12 18:52:15 2005 EDT

  Modified files:              
    /php-src/ext/spl    spl_iterators.c spl_iterators.h 
  Log:
  - Use pcre_cache_entry* rather than pcre* directly for refcounting
  # This prevents a theoretical crash when using too many regexes
  
  
http://cvs.php.net/diff.php/php-src/ext/spl/spl_iterators.c?r1=1.91&r2=1.92&ty=u
Index: php-src/ext/spl/spl_iterators.c
diff -u php-src/ext/spl/spl_iterators.c:1.91 
php-src/ext/spl/spl_iterators.c:1.92
--- php-src/ext/spl/spl_iterators.c:1.91        Mon Oct 10 20:18:31 2005
+++ php-src/ext/spl/spl_iterators.c     Wed Oct 12 18:52:08 2005
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_iterators.c,v 1.91 2005/10/11 00:18:31 helly Exp $ */
+/* $Id: spl_iterators.c,v 1.92 2005/10/12 22:52:08 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -903,16 +903,16 @@
                case DIT_RegExIterator:
                case DIT_RecursiveRegExIterator: {
                        char *regex;
-                       int len;
+                       int len, poptions, coptions;
+                       pcre_extra *extra;
 
                        intern->u.regex.flags = 0;
                        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 
"Os|l", &zobject, ce_inner, &regex, &len, &intern->u.regex.flags) == FAILURE) {
                                php_set_error_handling(EH_NORMAL, NULL 
TSRMLS_CC);
                                return NULL;
                        }
-                       intern->u.regex.extra = NULL;
-                       intern->u.regex.options = 0;
-                       intern->u.regex.re = pcre_get_compiled_regex(regex, 
&intern->u.regex.extra, &intern->u.regex.options TSRMLS_CC);
+                       intern->u.regex.pce = 
pcre_get_compiled_regex_cache(regex, len, &extra, &poptions, &coptions 
TSRMLS_CC);
+                       intern->u.regex.pce->refcount++;
                        break;;
                }
 #endif
@@ -1265,6 +1265,7 @@
        char *subject, tmp[32];
        int subject_len, use_copy = 0;
        zval subject_copy;
+       pcre_extra *extra;
 
        intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() 
TSRMLS_CC);
        
@@ -1287,7 +1288,8 @@
                }
        }
 
-       count = pcre_exec(intern->u.regex.re, intern->u.regex.extra, subject, 
subject_len, 0, 0, NULL, 0);
+       extra = intern->u.regex.pce->extra;
+       count = pcre_exec(intern->u.regex.pce->re, extra, subject, subject_len, 
0, 0, NULL, 0);
 
        if (use_copy) {
                zval_dtor(&subject_copy);
@@ -1331,10 +1333,10 @@
                }
        }
 
-#if MBO_0
+#if HAVE_PCRE || HAVE_BUNDLED_PCRE
        if (object->dit_type == DIT_RegExIterator || object->dit_type == 
DIT_RecursiveRegExIterator) {
-               if (object->u.regex.re) {
-                       /* actually there's no way to get rid of this early */
+               if (object->u.regex.pce) {
+                       object->u.regex.pce->refcount--;
                }
        }
 #endif
http://cvs.php.net/diff.php/php-src/ext/spl/spl_iterators.h?r1=1.26&r2=1.27&ty=u
Index: php-src/ext/spl/spl_iterators.h
diff -u php-src/ext/spl/spl_iterators.h:1.26 
php-src/ext/spl/spl_iterators.h:1.27
--- php-src/ext/spl/spl_iterators.h:1.26        Mon Oct 10 20:18:31 2005
+++ php-src/ext/spl/spl_iterators.h     Wed Oct 12 18:52:09 2005
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_iterators.h,v 1.26 2005/10/11 00:18:31 helly Exp $ */
+/* $Id: spl_iterators.h,v 1.27 2005/10/12 22:52:09 helly Exp $ */
 
 #ifndef SPL_ITERATORS_H
 #define SPL_ITERATORS_H
@@ -125,9 +125,7 @@
 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
                struct {
                        int              flags;
-                       pcre             *re;
-                       pcre_extra               *extra;
-                       int              options;
+                       pcre_cache_entry *pce;
                } regex;
 #endif
        } u;

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

Reply via email to