[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pecl-cvs
Subject:    [PECL-CVS] =?utf-8?q?svn:_/pecl/wincache/trunk/_package.xml_php=5Fwincache.c_wincache=5Ferror.h_winc
From:       Kanwaljeet_Singla <ksingla () php ! net>
Date:       2010-02-26 2:27:45
Message-ID: svn-ksingla-1267151265-295522-664266610 () svn ! php ! net
[Download RAW message or body]

ksingla                                  Fri, 26 Feb 2010 02:27:45 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=295522

Log:
Fixed inconsistencies in ucache APIs. Included session entries lookups in hit/miss counts.

Changed paths:
    U   pecl/wincache/trunk/package.xml
    U   pecl/wincache/trunk/php_wincache.c
    U   pecl/wincache/trunk/wincache_error.h
    U   pecl/wincache/trunk/wincache_zvcache.c


["svn-diffs-295522.txt" (text/x-diff)]

Modified: pecl/wincache/trunk/package.xml
===================================================================
--- pecl/wincache/trunk/package.xml	2010-02-26 00:30:44 UTC (rev 295521)
+++ pecl/wincache/trunk/package.xml	2010-02-26 02:27:45 UTC (rev 295522)
@@ -39,6 +39,7 @@
 - Added wincache session handler. Now wincache user cache can be used to store \
                session data.
 - Made behavior of user cache functions handle arrays and other key types.\
 - Fixed a bug in session handler to make it work for SugarCRM.
+- Fixed inconsistencies in wincache_ucache APIs. Included session entries lookups in \
hit/miss counts.  </notes>
   <contents>
     <dir name="/">

Modified: pecl/wincache/trunk/php_wincache.c
===================================================================
--- pecl/wincache/trunk/php_wincache.c	2010-02-26 00:30:44 UTC (rev 295521)
+++ pecl/wincache/trunk/php_wincache.c	2010-02-26 02:27:45 UTC (rev 295522)
@@ -1613,6 +1613,8 @@
     zval **      hentry    = NULL;
     HashPosition hposition;
     zval *       nentry    = NULL;
+    char *       key       = NULL;
+    unsigned int keylen    = 0;

     /* If user cache is enabled, return false */
     if(!WCG(zvenabled))
@@ -1658,24 +1660,46 @@
         zend_hash_internal_pointer_reset_ex(htable, &hposition);
         while(zend_hash_get_current_data_ex(htable, (void **)&hentry, &hposition) == \
SUCCESS)  {
-            if(Z_TYPE_PP(hentry) != IS_STRING)
+            if(Z_TYPE_PP(hentry) != IS_STRING && Z_TYPE_PP(hentry) != IS_LONG)
             {
-                php_error_docref(NULL TSRMLS_CC, E_WARNING, "key array elements can \
only be string"); +                php_error_docref(NULL TSRMLS_CC, E_WARNING, "key \
array elements can only be string or long");

                 result = WARNING_ZVCACHE_ARGUMENT;
                 goto Finished;
             }

+            if(Z_TYPE_PP(hentry) == IS_LONG)
+            {
+                spprintf(&key, 0, "%ld", Z_LVAL_PP(hentry));
+                keylen = strlen(key);
+            }
+            else
+            {
+                _ASSERT(Z_TYPE_PP(hentry) == IS_STRING);
+
+                key = Z_STRVAL_PP(hentry);
+                keylen = Z_STRLEN_PP(hentry);
+            }
+
             MAKE_STD_ZVAL(nentry);
-            result = zvcache_get(WCG(zvcache), Z_STRVAL_PP(hentry), 0, &nentry \
TSRMLS_CC); +            result = zvcache_get(WCG(zvcache), key, 0, &nentry \
TSRMLS_CC);

             /* Ignore failures and try getting values of other keys */
             if(SUCCEEDED(result))
             {
-                zend_hash_add(Z_ARRVAL_P(return_value), Z_STRVAL_PP(hentry), \
Z_STRLEN_PP(hentry) + 1, &nentry, sizeof(zval *), NULL); +                \
zend_hash_add(Z_ARRVAL_P(return_value), key, keylen + 1, &nentry, sizeof(zval *), \
NULL);  }

+            if(Z_TYPE_PP(hentry) == IS_LONG && key != NULL)
+            {
+                efree(key);
+                key = NULL;
+            }
+
+            result = NONFATAL;
             nentry = NULL;
+            key    = NULL;
+            keylen = 0;
             zend_hash_move_forward_ex(htable, &hposition);
         }
     }
@@ -1805,9 +1829,9 @@
                 keylen = strlen(key);
             }

-            if(key)
+            if(key && *key != '\0')
             {
-                if(keylen > 4096)
+                if(keylen > 4096 || Z_TYPE_PP(hentry) == IS_RESOURCE)
                 {
                     result = WARNING_ZVCACHE_ARGUMENT;
                 }
@@ -1833,6 +1857,7 @@
                 add_index_long(return_value, longkey, -1);
             }

+            result  = NONFATAL;
             key     = NULL;
             keylen  = 0;
             longkey = 0;
@@ -1944,6 +1969,8 @@
         zend_hash_internal_pointer_reset_ex(htable, &hposition);
         while(zend_hash_get_current_data_ex(htable, (void **)&hentry, &hposition) == \
SUCCESS)  {
+            zend_hash_get_current_key_ex(htable, &key, &keylen, &longkey, 0, \
&hposition); +
             /* We are taking care of long keys properly */
             if(!key && longkey != 0)
             {
@@ -1952,9 +1979,9 @@
                 keylen = strlen(key);
             }

-            if(key)
+            if(key && *key != '\0')
             {
-                if(keylen > 4096)
+                if(keylen > 4096 || Z_TYPE_PP(hentry) == IS_RESOURCE)
                 {
                     result = WARNING_ZVCACHE_ARGUMENT;
                 }
@@ -1980,6 +2007,7 @@
                 add_index_long(return_value, longkey, -1);
             }

+            result  = NONFATAL;
             key     = NULL;
             keylen  = 0;
             longkey = 0;
@@ -2016,6 +2044,8 @@
     HashTable *   htable   = NULL;
     HashPosition  hposition;
     zval **       hentry   = NULL;
+    char *        key      = NULL;
+    unsigned int  keylen   = 0;

     /* If user cache is enabled, return false */
     if(!WCG(zvenabled))
@@ -2057,15 +2087,28 @@
         zend_hash_internal_pointer_reset_ex(htable, &hposition);
         while(zend_hash_get_current_data_ex(htable, (void **)&hentry, &hposition) == \
SUCCESS)  {
-            if(Z_TYPE_PP(hentry) != IS_STRING)
+            if(Z_TYPE_PP(hentry) != IS_STRING && Z_TYPE_PP(hentry) != IS_LONG)
             {
-                php_error_docref(NULL TSRMLS_CC, E_WARNING, "key array elements can \
only be string"); +                php_error_docref(NULL TSRMLS_CC, E_WARNING, "key \
array elements can only be string or long");

                 result = WARNING_ZVCACHE_ARGUMENT;
                 goto Finished;
             }

-            result = zvcache_delete(WCG(zvcache), Z_STRVAL_PP(hentry), 0);
+            if(Z_TYPE_PP(hentry) == IS_LONG)
+            {
+                spprintf(&key, 0, "%ld", Z_LVAL_PP(hentry));
+                keylen = strlen(key);
+            }
+            else
+            {
+                _ASSERT(Z_TYPE_PP(hentry) == IS_STRING);
+
+                key = Z_STRVAL_PP(hentry);
+                keylen = Z_STRLEN_PP(hentry);
+            }
+
+            result = zvcache_delete(WCG(zvcache), key, 0);
             if(SUCCEEDED(result))
             {
                 add_next_index_zval(return_value, *hentry);
@@ -2076,6 +2119,14 @@
 #endif
             }

+            if(Z_TYPE_PP(hentry) == IS_LONG && key != NULL)
+            {
+                efree(key);
+                key = NULL;
+            }
+
+            key    = NULL;
+            keylen = 0;
             zend_hash_move_forward_ex(htable, &hposition);
         }
     }
@@ -2491,6 +2542,11 @@

     if(FAILED(result))
     {
+        if(result == WARNING_ZVCACHE_CASNEQ)
+        {
+            RETURN_FALSE;
+        }
+
         WCG(zvlasterror) = result;

         dprintimportant("failure %d in wincache_ucache_cas", result);

Modified: pecl/wincache/trunk/wincache_error.h
===================================================================
--- pecl/wincache/trunk/wincache_error.h	2010-02-26 00:30:44 UTC (rev 295521)
+++ pecl/wincache/trunk/wincache_error.h	2010-02-26 02:27:45 UTC (rev 295522)
@@ -139,6 +139,7 @@
 #define WARNING_ZVCACHE_NOTLONG             WARNING_COMMON_BASE + 6
 #define WARNING_ZVCACHE_ARGUMENT            WARNING_COMMON_BASE + 7
 #define WARNING_ZVCACHE_RESCOPYIN           WARNING_COMMON_BASE + 8
+#define WARNING_ZVCACHE_CASNEQ              WARNING_COMMON_BASE + 9

 /* SUCCEEDED and FAILED macros */
 #ifdef SUCCEEDED

Modified: pecl/wincache/trunk/wincache_zvcache.c
===================================================================
--- pecl/wincache/trunk/wincache_zvcache.c	2010-02-26 00:30:44 UTC (rev 295521)
+++ pecl/wincache/trunk/wincache_zvcache.c	2010-02-26 02:27:45 UTC (rev 295522)
@@ -68,8 +68,6 @@
 /* Private functions */
 static int copyin_zval(zvcache_context * pcache, zvcopy_context * pcopy, zval * \
poriginal, zv_zval ** pcopied TSRMLS_DC)  {
-    /* TBD?? When zval is already copied only refcount need to be incremented */
-    /* TBD?? If not already copied, copy to hashtable to keep track of copied ones \
*/  int                  result     = NONFATAL;
     zv_zval *            pnewzv     = NULL;
     int                  allocated  = 0;
@@ -1131,10 +1129,7 @@
         pvalue->prev_value = 0;
     }

-    if(!pvalue->issession)
-    {
-        header->itemcount++;
-    }
+    header->itemcount++;

     dprintverbose("end add_zvcache_entry");

@@ -1158,10 +1153,7 @@
     header  = pcache->zvheader;

     /* Decrement itemcount and remove entry from hashtable */
-    if(!pvalue->issession)
-    {
-        header->itemcount--;
-    }
+    header->itemcount--;

     if(pvalue->prev_value == 0)
     {
@@ -1623,25 +1615,18 @@
         goto Finished;
     }

-    /* Adjust overall cache hitcount/misscount and entry */
-    /* hitcount for non-session lookups */
+    /* Adjust overall cache hitcount/misscount and entry hitcount */
     if(pentry == NULL)
     {
-        if(!issession)
-        {
-            InterlockedIncrement(&header->misscount);
-        }
+        InterlockedIncrement(&header->misscount);

         result = WARNING_ZVCACHE_EMISSING;
         goto Finished;
     }
     else
     {
-        if(!issession)
-        {
-            InterlockedIncrement(&pentry->hitcount);
-            InterlockedIncrement(&header->hitcount);
-        }
+        InterlockedIncrement(&pentry->hitcount);
+        InterlockedIncrement(&header->hitcount);
     }

     /* Entry found. copyout to local memory */
@@ -2191,6 +2176,11 @@
     {
         pzval->value.lval = newvalue;
     }
+    else
+    {
+	result = WARNING_ZVCACHE_CASNEQ;
+	goto Finished;
+    }

     _ASSERT(SUCCEEDED(result));



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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic