hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r892001 - in /hadoop/zookeeper/trunk: CHANGES.txt src/contrib/zkpython/src/c/zookeeper.c
Date Thu, 17 Dec 2009 23:38:36 GMT
Author: mahadev
Date: Thu Dec 17 23:38:33 2009
New Revision: 892001

URL: http://svn.apache.org/viewvc?rev=892001&view=rev
Log:
ZOOKEEPER-600. TODO pondering about allocation behavior in zkpython may be removed (gustavo
via mahadev)

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=892001&r1=892000&r2=892001&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Thu Dec 17 23:38:33 2009
@@ -184,6 +184,9 @@
 
   ZOOKEEPER-623. ClientBase in bookkeeper.util requires junit (fpj via breed)
 
+  ZOOKEEPER-600. TODO pondering about allocation behavior in zkpython may be
+  removed (gustavo via mahadev)
+
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)

Modified: hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c?rev=892001&r1=892000&r2=892001&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c (original)
+++ hadoop/zookeeper/trunk/src/contrib/zkpython/src/c/zookeeper.c Thu Dec 17 23:38:33 2009
@@ -224,15 +224,29 @@
 
 PyObject *build_string_vector(const struct String_vector *sv)
 {
-	if (!sv) {
-		return PyList_New(0);
-	}
-  PyObject *ret = PyList_New(sv->count);
-  int i;
-  for (i=0;i<sv->count;++i) 
+  PyObject *ret;
+  if (!sv)
     {
-      PyObject *s = PyString_FromString(sv->data[i]);
-      PyList_SetItem(ret, i, s);
+      ret = PyList_New(0);
+    }
+  else
+    {
+      ret = PyList_New(sv->count);
+      if (ret)
+        {
+          int i;
+          for (i=0;i<sv->count;++i) 
+            {
+              PyObject *s = PyString_FromString(sv->data[i]);
+              if (!s)
+                {
+                  Py_DECREF(ret);
+                  ret = NULL;
+                  break;
+                }
+              PyList_SetItem(ret, i, s);
+            }
+        }
     }
   return ret;
 }
@@ -407,8 +421,14 @@
     return;
   PyObject *callback = pyw->callback;
   gstate = PyGILState_Ensure();
-  PyObject *arglist = Py_BuildValue("(i,i,O)", pyw->zhandle,rc, build_string_vector(strings));
-  if (PyObject_CallObject((PyObject*)callback, arglist) == NULL)
+  PyObject *pystrings = build_string_vector(strings);
+  if (pystrings)
+    {
+      PyObject *arglist = Py_BuildValue("(i,i,O)", pyw->zhandle, rc, pystrings);
+      if (arglist == NULL || PyObject_CallObject((PyObject*)callback, arglist) == NULL)
+        PyErr_Print();
+    }
+  else
     PyErr_Print();
   free_pywatcher(pyw);
   PyGILState_Release(gstate);
@@ -774,8 +794,6 @@
 
 static PyObject *pyzoo_get_children(PyObject *self, PyObject *args)
 {
-  // TO DO: Does Python copy the string or the reference? If it's the former
-  // we should free the String_vector
   int zkhid;
   char *path;
   PyObject *watcherfn = Py_None;
@@ -796,13 +814,8 @@
       return NULL;
     }
 
-  PyObject *ret = PyList_New(strings.count);
-  int i;
-  for (i=0;i<strings.count;++i) 
-    {
-      PyObject *s = PyString_FromString(strings.data[i]);
-      PyList_SetItem(ret, i, s);
-    }
+  PyObject *ret = build_string_vector(&strings);
+  deallocate_String_vector(&strings);
   return ret;
 }
 



Mime
View raw message