[Zope-CVS] SVN: zope.ucol/trunk/src/zope/ucol/_zope_ucol. Changed the strategy for managing the sort key buffer. It seems that

Jim Fulton jim at zope.com
Wed Dec 7 11:33:13 EST 2005


Log message for revision 40624:
  Changed the strategy for managing the sort key buffer.  It seems that
  the size reported by ucol_getSortKey actually does depend on the input
  buffer size, which is a bit odd.
  

Changed:
  U   zope.ucol/trunk/src/zope/ucol/_zope_ucol.c
  U   zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx

-=-
Modified: zope.ucol/trunk/src/zope/ucol/_zope_ucol.c
===================================================================
--- zope.ucol/trunk/src/zope/ucol/_zope_ucol.c	2005-12-07 16:11:20 UTC (rev 40623)
+++ zope.ucol/trunk/src/zope/ucol/_zope_ucol.c	2005-12-07 16:33:13 UTC (rev 40624)
@@ -1,4 +1,4 @@
-/* Generated by Pyrex 0.9.3.1 on Tue Dec  6 15:36:00 2005 */
+/* Generated by Pyrex 0.9.3 on Wed Dec  7 11:30:33 2005 */
 
 #include "Python.h"
 #include "structmember.h"
@@ -258,10 +258,6 @@
   Py_DECREF(__pyx_v_self);
 }
 
-static PyObject *__pyx_k4p;
-
-static char (__pyx_k4[]) = "size from ucol_getSortKey changed %d %d";
-
 static PyObject *__pyx_f_10_zope_ucol_10KeyFactory___call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 static PyObject *__pyx_f_10_zope_ucol_10KeyFactory___call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyUnicodeObject *__pyx_v_text = 0;
@@ -274,7 +270,6 @@
   PyObject *__pyx_1 = 0;
   PyObject *__pyx_2 = 0;
   int __pyx_3;
-  PyObject *__pyx_4 = 0;
   static char *__pyx_argnames[] = {"text",0};
   if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_text)) return 0;
   Py_INCREF(__pyx_v_self);
@@ -300,11 +295,12 @@
   __pyx_v_buffer = ((char (*))PyMem_Malloc(__pyx_v_bufsize));
 
   /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":132 */
-  __pyx_v_size = ucol_getSortKey(((struct __pyx_obj_10_zope_ucol_KeyFactory *)__pyx_v_self)->collator,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->data,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->length,__pyx_v_buffer,__pyx_v_bufsize);
+  __pyx_v_size = ucol_getSortKey(((struct __pyx_obj_10_zope_ucol_KeyFactory *)__pyx_v_self)->collator,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->data,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->length,((uint8_t (*))__pyx_v_buffer),__pyx_v_bufsize);
 
   /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":136 */
-  __pyx_3 = (__pyx_v_size > __pyx_v_bufsize);
-  if (__pyx_3) {
+  while (1) {
+    __pyx_3 = (__pyx_v_size > __pyx_v_bufsize);
+    if (!__pyx_3) break;
 
     /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":137 */
     __pyx_v_bufsize = __pyx_v_size;
@@ -316,37 +312,19 @@
     __pyx_v_buffer = ((char (*))PyMem_Malloc(__pyx_v_bufsize));
 
     /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":140 */
-    __pyx_v_size = ucol_getSortKey(((struct __pyx_obj_10_zope_ucol_KeyFactory *)__pyx_v_self)->collator,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->data,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->length,__pyx_v_buffer,__pyx_v_bufsize);
-
-    /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":144 */
-    __pyx_1 = PyInt_FromLong(__pyx_v_size); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; goto __pyx_L1;}
-    __pyx_2 = PyInt_FromLong(__pyx_v_bufsize); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; goto __pyx_L1;}
-    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; goto __pyx_L1;}
-    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_1);
-    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_2);
-    __pyx_1 = 0;
-    __pyx_2 = 0;
-    __pyx_1 = PyNumber_Remainder(__pyx_k4p, __pyx_4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; goto __pyx_L1;}
-    Py_DECREF(__pyx_4); __pyx_4 = 0;
-    if (!(__pyx_v_size == __pyx_v_bufsize)) {
-      PyErr_SetObject(PyExc_AssertionError, __pyx_1);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; goto __pyx_L1;}
-    }
-    Py_DECREF(__pyx_1); __pyx_1 = 0;
-    goto __pyx_L2;
+    __pyx_v_size = ucol_getSortKey(((struct __pyx_obj_10_zope_ucol_KeyFactory *)__pyx_v_self)->collator,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->data,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->length,((uint8_t (*))__pyx_v_buffer),__pyx_v_bufsize);
   }
-  __pyx_L2:;
 
-  /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":147 */
-  __pyx_2 = PyString_FromStringAndSize(__pyx_v_buffer,__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; goto __pyx_L1;}
+  /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":145 */
+  __pyx_1 = PyString_FromStringAndSize(__pyx_v_buffer,__pyx_v_size); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; goto __pyx_L1;}
   Py_DECREF(__pyx_v_result);
-  __pyx_v_result = __pyx_2;
-  __pyx_2 = 0;
+  __pyx_v_result = __pyx_1;
+  __pyx_1 = 0;
 
-  /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":148 */
+  /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":146 */
   PyMem_Free(__pyx_v_buffer);
 
-  /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":149 */
+  /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":147 */
   Py_INCREF(__pyx_v_result);
   __pyx_r = __pyx_v_result;
   goto __pyx_L0;
@@ -356,7 +334,6 @@
   __pyx_L1:;
   Py_XDECREF(__pyx_1);
   Py_XDECREF(__pyx_2);
-  Py_XDECREF(__pyx_4);
   __Pyx_AddTraceback("_zope_ucol.KeyFactory.__call__");
   __pyx_r = 0;
   __pyx_L0:;
@@ -376,7 +353,6 @@
 static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_k2p, __pyx_k2, sizeof(__pyx_k2)},
   {&__pyx_k3p, __pyx_k3, sizeof(__pyx_k3)},
-  {&__pyx_k4p, __pyx_k4, sizeof(__pyx_k4)},
   {0, 0, 0}
 };
 

Modified: zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx
===================================================================
--- zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx	2005-12-07 16:11:20 UTC (rev 40623)
+++ zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx	2005-12-07 16:33:13 UTC (rev 40624)
@@ -132,17 +132,15 @@
         size = ucol_getSortKey(self.collator,
                                (<UCharString>icutext).data,
                                (<UCharString>icutext).length,
-                               buffer, bufsize)
-        if size > bufsize:
+                               <uint8_t*>buffer, bufsize)
+        while size > bufsize:
             bufsize = size
             PyMem_Free(buffer)
             buffer = <char*>PyMem_Malloc(bufsize)
             size = ucol_getSortKey(self.collator,
                                    (<UCharString>icutext).data,
                                    (<UCharString>icutext).length,
-                                   buffer, bufsize)
-            assert size == bufsize, ("size from ucol_getSortKey changed %d %d"
-                                     % (size, bufsize))
+                                   <uint8_t*>buffer, bufsize)
 
         result = PyString_FromStringAndSize(buffer, size)
         PyMem_Free(buffer)



More information about the Zope-CVS mailing list