|
@@ -224,15 +224,29 @@ PyObject *build_stat( const struct Stat *stat )
|
|
|
|
|
|
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 @@ void strings_completion_dispatch(int rc, const struct String_vector *strings, co
|
|
|
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_exists(PyObject *self, PyObject *args)
|
|
|
|
|
|
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 @@ static PyObject *pyzoo_get_children(PyObject *self, PyObject *args)
|
|
|
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;
|
|
|
}
|
|
|
|