Re: [libvirt] [PATCH] fix python events
David Lively [EMAIL PROTECTED] wrote: On Sat, 2008-11-22 at 08:21 +0100, Jim Meyering wrote: David Lively [EMAIL PROTECTED] wrote: On Fri, 2008-11-21 at 17:51 +0100, Jim Meyering wrote: I'm printing the (user-supplied) object names to help in debugging misbehaving python EventImpls (since there's no static type checking to catch these kinds of things). So instead of printing NULL when we can't alloc the name, I'm printing something a little more helpful (the appropriate generic name). That's better, indeed. I prefer your NAME macro, too. ACK, modulo syntax: ... Reversed diff? Better to split long lines, not to join. Ok. Fixed in attached patch. + Trailing white space ^^. .. along with this one ... and the trailing whitespace on line 1982. *This* time I ran syntax-check :-) ;-) Unqualified ACK, then, assuming those are the only changes. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] fix python events
On Fri, Nov 21, 2008 at 02:14:57PM -0500, David Lively wrote: On Fri, 2008-11-21 at 17:51 +0100, Jim Meyering wrote: No big deal, but there are several debug printf uses here that look like they try to print NULL pointers upon memory allocation failure. It's ok with glibc's printf of course, but not for others. You're right. Attached patch fixes those issues. It also fixes some cases in which I got some printf string operands switched around ... I'm printing the (user-supplied) object names to help in debugging misbehaving python EventImpls (since there's no static type checking to catch these kinds of things). So instead of printing NULL when we can't alloc the name, I'm printing something a little more helpful (the appropriate generic name). ACK. This looks ok to me now. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] fix python events
On Mon, 2008-11-24 at 17:30 +0100, Jim Meyering wrote: David Lively [EMAIL PROTECTED] wrote: On Sat, 2008-11-22 at 08:21 +0100, Jim Meyering wrote: David Lively [EMAIL PROTECTED] wrote: On Fri, 2008-11-21 at 17:51 +0100, Jim Meyering wrote: I'm printing the (user-supplied) object names to help in debugging misbehaving python EventImpls (since there's no static type checking to catch these kinds of things). So instead of printing NULL when we can't alloc the name, I'm printing something a little more helpful (the appropriate generic name). That's better, indeed. I prefer your NAME macro, too. ACK, modulo syntax: ... Reversed diff? Better to split long lines, not to join. Ok. Fixed in attached patch. + Trailing white space ^^. .. along with this one ... and the trailing whitespace on line 1982. *This* time I ran syntax-check :-) ;-) Unqualified ACK, then, assuming those are the only changes. Those are the only changes. Dave -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] fix python events
On Sat, 2008-11-22 at 08:21 +0100, Jim Meyering wrote: David Lively [EMAIL PROTECTED] wrote: On Fri, 2008-11-21 at 17:51 +0100, Jim Meyering wrote: I'm printing the (user-supplied) object names to help in debugging misbehaving python EventImpls (since there's no static type checking to catch these kinds of things). So instead of printing NULL when we can't alloc the name, I'm printing something a little more helpful (the appropriate generic name). That's better, indeed. I prefer your NAME macro, too. ACK, modulo syntax: ... Reversed diff? Better to split long lines, not to join. Ok. Fixed in attached patch. + Trailing white space ^^. .. along with this one ... and the trailing whitespace on line 1982. *This* time I ran syntax-check :-) Dave examples/domain-events/events-python/event-test.py | 26 +- python/libvir.c| 203 + python/libvir.py |4 python/libvirt_wrap.h |8 python/types.c |1 python/virConnect.py |4 6 files changed, 196 insertions(+), 50 deletions(-) diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py index 45aaa93..7bea606 100644 --- a/examples/domain-events/events-python/event-test.py +++ b/examples/domain-events/events-python/event-test.py @@ -72,22 +72,22 @@ def myAddHandle(fd, events, cb, opaque): h_events = events h_cb = cb h_opaque = opaque - mypoll.register(fd, myEventHandleTypeToPollEvent(events)) +return 0 def myUpdateHandle(watch, event): global h_fd, h_events -#print Updating Handle %s %s % (str(fd), str(events)) -h_fd = fd +#print Updating Handle %s %s % (str(h_fd), str(event)) h_events = event -mypoll.unregister(watch) -mypoll.register(watch, myEventHandleTypeToPollEvent(event)) +mypoll.unregister(h_fd) +mypoll.register(h_fd, myEventHandleTypeToPollEvent(event)) def myRemoveHandle(watch): global h_fd -#print Removing Handle %s % str(fd) +#print Removing Handle %s % str(h_fd) +mypoll.unregister(h_fd) h_fd = 0 -mypoll.unregister(watch) +return h_opaque def myAddTimeout(timeout, cb, opaque): global t_active, t_timeout, t_cb, t_opaque @@ -96,16 +96,18 @@ def myAddTimeout(timeout, cb, opaque): t_timeout = timeout; t_cb = cb; t_opaque = opaque; +return 0 def myUpdateTimeout(timer, timeout): global t_timeout -#print Updating Timeout %s % (str(timer), str(timeout)) +#print Updating Timeout %s %s % (str(timer), str(timeout)) t_timeout = timeout; def myRemoveTimeout(timer): global t_active #print Removing Timeout %s % str(timer) t_active = 0; +return t_opaque ## # Main @@ -143,6 +145,14 @@ def main(): myRemoveTimeout ); vc = libvirt.open(uri) +# Close connection on exit (to test cleanup paths) +old_exitfunc = getattr(sys, 'exitfunc', None) +def exit(): +print Closing + str(vc) +vc.close() +if (old_exitfunc): old_exitfunc() +sys.exitfunc = exit + #Add 2 callbacks to prove this works with more than just one vc.domainEventRegister(myDomainEventCallback1,None) vc.domainEventRegister(myDomainEventCallback2,None) diff --git a/python/libvir.c b/python/libvir.c index 7d58442..ca1e890 100644 --- a/python/libvir.c +++ b/python/libvir.c @@ -35,6 +35,18 @@ extern void initcygvirtmod(void); #define VIR_PY_INT_FAIL (libvirt_intWrap(-1)) #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0)) +static char *py_str(PyObject *obj) +{ +PyObject *str = PyObject_Str(obj); +if (!str) { +PyErr_Print(); +PyErr_Clear(); +return NULL; +}; +return PyString_AsString(str); +} + + / * * * Statistics * @@ -484,7 +496,8 @@ libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, virErrorPtr err) PyObject *result; #ifdef DEBUG_ERROR -printf(libvirt_virErrorFuncHandler(%p, %s, ...) called\n, ctx, msg); +printf(libvirt_virErrorFuncHandler(%p, %s, ...) called\n, ctx, + err-message); #endif if ((err == NULL) || (err-code == VIR_ERR_OK)) @@ -1780,12 +1793,19 @@ libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject * self, * Event Impl ***/ static PyObject *addHandleObj = NULL; +static char *addHandleName= NULL; static PyObject *updateHandleObj = NULL; +static char *updateHandleName = NULL; static PyObject *removeHandleObj = NULL; +static char *removeHandleName = NULL; static PyObject *addTimeoutObj= NULL; +static char *addTimeoutName = NULL; static PyObject
Re: [libvirt] [PATCH] fix python events
On Mon, Nov 24, 2008 at 11:44:15AM -0500, David Lively wrote: On Mon, 2008-11-24 at 17:30 +0100, Jim Meyering wrote: David Lively [EMAIL PROTECTED] wrote: On Sat, 2008-11-22 at 08:21 +0100, Jim Meyering wrote: David Lively [EMAIL PROTECTED] wrote: On Fri, 2008-11-21 at 17:51 +0100, Jim Meyering wrote: I'm printing the (user-supplied) object names to help in debugging misbehaving python EventImpls (since there's no static type checking to catch these kinds of things). So instead of printing NULL when we can't alloc the name, I'm printing something a little more helpful (the appropriate generic name). That's better, indeed. I prefer your NAME macro, too. ACK, modulo syntax: ... Reversed diff? Better to split long lines, not to join. Ok. Fixed in attached patch. + Trailing white space ^^. .. along with this one ... and the trailing whitespace on line 1982. *This* time I ran syntax-check :-) ;-) Unqualified ACK, then, assuming those are the only changes. Those are the only changes. Ok, I committed this patch now. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] fix python events
Doh! ... attached :-) On Fri, 2008-11-21 at 10:30 +0100, Jim Meyering wrote: David Lively [EMAIL PROTECTED] wrote: This patch gets python events working again after upstream changes, and make the test implementation properly clean up after itself and implement the new EventImpl API properly. Note that the Python RemoveHandle and RemoveTimeout implementations should return the opaque object registered by the corresponding AddHandle/Timeout calls, in lieu of calling the (C) freefunc. (The binding code will then call freefunc if it's not NULL.) Ignoring this means you'll leak memory in the same way that C RemoveHandle/Timeout leak if they don't (now) call the freefunc. I also moved around some of the error checking code to unclutter (and speed up) the common code paths. For instance, we now check that the virRegisterEventImpl arguments are callable just once (and return failure if they're not), rather than checking them before every call and blithely ignoring them if they're not callable. Dave examples/domain-events/events-python/event-test.py | 29 +-- python/libvir.c| 200+++ python/libvir.py |4 python/libvirt_wrap.h |8 python/types.c |1 python/virConnect.py |4 6 files changed, 194 insertions(+), 52 deletions(-) Hi Dave, It looks like this patch didn't make it to the list. commit efd5098e9a834562cddbf1618e36eb43c272f8ea Author: David Lively [EMAIL PROTECTED] Date: Thu Nov 20 16:36:14 2008 -0500 vi-patch: fix-python-events Get python events working again after upstream changes, and make the test implementation properly clean up after itself and implement the new EventImpl properly. diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py index 45aaa93..1ad436f 100644 --- a/examples/domain-events/events-python/event-test.py +++ b/examples/domain-events/events-python/event-test.py @@ -72,22 +72,22 @@ def myAddHandle(fd, events, cb, opaque): h_events = events h_cb = cb h_opaque = opaque - mypoll.register(fd, myEventHandleTypeToPollEvent(events)) +return 0 def myUpdateHandle(watch, event): global h_fd, h_events -#print Updating Handle %s %s % (str(fd), str(events)) -h_fd = fd +#print Updating Handle %s %s % (str(h_fd), str(event)) h_events = event -mypoll.unregister(watch) -mypoll.register(watch, myEventHandleTypeToPollEvent(event)) +mypoll.unregister(h_fd) +mypoll.register(h_fd, myEventHandleTypeToPollEvent(event)) def myRemoveHandle(watch): global h_fd -#print Removing Handle %s % str(fd) +#print Removing Handle %s % str(h_fd) +mypoll.unregister(h_fd) h_fd = 0 -mypoll.unregister(watch) +return h_opaque def myAddTimeout(timeout, cb, opaque): global t_active, t_timeout, t_cb, t_opaque @@ -96,16 +96,18 @@ def myAddTimeout(timeout, cb, opaque): t_timeout = timeout; t_cb = cb; t_opaque = opaque; +return 0 def myUpdateTimeout(timer, timeout): global t_timeout -#print Updating Timeout %s % (str(timer), str(timeout)) +#print Updating Timeout %s %s % (str(timer), str(timeout)) t_timeout = timeout; def myRemoveTimeout(timer): global t_active #print Removing Timeout %s % str(timer) t_active = 0; +return t_opaque ## # Main @@ -143,6 +145,14 @@ def main(): myRemoveTimeout ); vc = libvirt.open(uri) +# Close connection on exit (to test cleanup paths) +old_exitfunc = getattr(sys, 'exitfunc', None) +def exit(): +print Closing + str(vc) +vc.close() +if (old_exitfunc): old_exitfunc() +sys.exitfunc = exit + #Add 2 callbacks to prove this works with more than just one vc.domainEventRegister(myDomainEventCallback1,None) vc.domainEventRegister(myDomainEventCallback2,None) @@ -175,8 +185,7 @@ def main(): if h_cb != None: #print Invoking Handle CB -h_cb(0, h_fd, myPollEventToEventHandleType(revents h_events), - h_opaque[0], h_opaque[1]) +h_cb(0, h_fd, myPollEventToEventHandleType(revents h_events), h_opaque[0], h_opaque[1]) #print DEBUG EXIT #break diff --git a/python/libvir.c b/python/libvir.c index 07ed09e..6ae7cc1 100644 --- a/python/libvir.c +++ b/python/libvir.c @@ -35,6 +35,18 @@ extern void initcygvirtmod(void); #define VIR_PY_INT_FAIL (libvirt_intWrap(-1)) #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0)) +static char *py_str(PyObject *obj) +{ +PyObject *str = PyObject_Str(obj); +if (!str) { +PyErr_Print(); +PyErr_Clear(); +return NULL; +}; +return
Re: [libvirt] [PATCH] fix python events
David Lively [EMAIL PROTECTED] wrote: ... Hi David, No big deal, but there are several debug printf uses here that look like they try to print NULL pointers upon memory allocation failure. It's ok with glibc's printf of course, but not for others. commit efd5098e9a834562cddbf1618e36eb43c272f8ea Author: David Lively [EMAIL PROTECTED] Date: Thu Nov 20 16:36:14 2008 -0500 vi-patch: fix-python-events Get python events working again after upstream changes, and make the test implementation properly clean up after itself and implement the new EventImpl properly. ... diff --git a/python/libvir.c b/python/libvir.c ... @@ -1725,9 +1745,18 @@ libvirt_virEventAddHandleFunc (int fd, eventInvokeHandleCallback); if(!python_cb) { #if DEBUG_ERROR -printf(%s Error finding eventInvokeHandleCallback\n, __FUNCTION__); +printf(%s: Error finding eventInvokeHandleCallback\n, __FUNCTION__); #endif PyErr_Print(); +PyErr_Clear(); +goto cleanup; +} +if (!PyCallable_Check(python_cb)) { +#if DEBUG_ERROR +char *name = py_str(python_cb); +printf(%s: %s is not callable\n, __FUNCTION__, name); Please handle name == NULL. Otherwise, with DEBUG_ERROR, the printf will segfault on most non-glibc-based systems. E.g., define this, then wrap the arg with NN(...). static inline char *NN (const char *s) { return s ? s : (char *) NULL; } printf(%s: %s is not callable\n, __FUNCTION__, NN(name)); +free(name); +#endif goto cleanup; } Py_INCREF(python_cb); @@ -1748,8 +1777,17 @@ libvirt_virEventAddHandleFunc (int fd, PyTuple_SetItem(pyobj_args, 2, python_cb); PyTuple_SetItem(pyobj_args, 3, cb_args); -if(addHandleObj PyCallable_Check(addHandleObj)) -result = PyEval_CallObject(addHandleObj, pyobj_args); +result = PyEval_CallObject(addHandleObj, pyobj_args); +if (!result) { +PyErr_Print(); +PyErr_Clear(); +} else if (!PyInt_Check(result)) { +#if DEBUG_ERROR +printf(%s: %s should return an int\n, addHandleName, __FUNCTION__); Same here, addHandleName can be NULL. +#endif +} else { +retval = (int)PyInt_AsLong(result); +} Py_XDECREF(result); Py_DECREF(pyobj_args); @@ -1757,23 +1795,26 @@ libvirt_virEventAddHandleFunc (int fd, cleanup: LIBVIRT_RELEASE_THREAD_STATE; -return 0; +return retval; } static void -libvirt_virEventUpdateHandleFunc(int fd, int event) +libvirt_virEventUpdateHandleFunc(int watch, int event) { -PyObject *result = NULL; +PyObject *result; PyObject *pyobj_args; LIBVIRT_ENSURE_THREAD_STATE; pyobj_args = PyTuple_New(2); -PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(fd)); +PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch)); PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(event)); -if(updateHandleObj PyCallable_Check(updateHandleObj)) -result = PyEval_CallObject(updateHandleObj, pyobj_args); +result = PyEval_CallObject(updateHandleObj, pyobj_args); +if (!result) { +PyErr_Print(); +PyErr_Clear(); +} Py_XDECREF(result); Py_DECREF(pyobj_args); @@ -1783,25 +1824,45 @@ libvirt_virEventUpdateHandleFunc(int fd, int event) static int -libvirt_virEventRemoveHandleFunc(int fd) +libvirt_virEventRemoveHandleFunc(int watch) { -PyObject *result = NULL; +PyObject *result; PyObject *pyobj_args; +PyObject *opaque; +PyObject *ff; +int retval = -1; +virFreeCallback cff; LIBVIRT_ENSURE_THREAD_STATE; pyobj_args = PyTuple_New(1); -PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(fd)); +PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch)); -if(removeHandleObj PyCallable_Check(removeHandleObj)) -result = PyEval_CallObject(removeHandleObj, pyobj_args); +result = PyEval_CallObject(removeHandleObj, pyobj_args); +if (!result) { +PyErr_Print(); +PyErr_Clear(); +} else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) { +#if DEBUG_ERROR +printf(%s: %s must return opaque obj registered with %s + to avoid leaking libvirt memory\n, + __FUNCTION__, removeHandleName, addHandleName); Same here, for both. +#endif +} else { +opaque = PyTuple_GetItem(result, 1); +ff = PyTuple_GetItem(result, 2); +cff = PyvirFreeCallback_Get(ff); +if (cff) +(*cff)(PyvirVoidPtr_Get(opaque)); +retval = 0; +} Py_XDECREF(result); Py_DECREF(pyobj_args); LIBVIRT_RELEASE_THREAD_STATE; -return 0; +return retval; } static int @@ -1810,7 +1871,7 @@ libvirt_virEventAddTimeoutFunc(int timeout, void *opaque, virFreeCallback ff)
Re: [libvirt] [PATCH] fix python events
On Fri, 2008-11-21 at 17:51 +0100, Jim Meyering wrote: No big deal, but there are several debug printf uses here that look like they try to print NULL pointers upon memory allocation failure. It's ok with glibc's printf of course, but not for others. You're right. Attached patch fixes those issues. It also fixes some cases in which I got some printf string operands switched around ... I'm printing the (user-supplied) object names to help in debugging misbehaving python EventImpls (since there's no static type checking to catch these kinds of things). So instead of printing NULL when we can't alloc the name, I'm printing something a little more helpful (the appropriate generic name). Dave examples/domain-events/events-python/event-test.py | 29 +-- python/libvir.c| 203 + python/libvir.py |4 python/libvirt_wrap.h |8 python/types.c |1 python/virConnect.py |4 6 files changed, 197 insertions(+), 52 deletions(-) diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py index 45aaa93..1ad436f 100644 --- a/examples/domain-events/events-python/event-test.py +++ b/examples/domain-events/events-python/event-test.py @@ -72,22 +72,22 @@ def myAddHandle(fd, events, cb, opaque): h_events = events h_cb = cb h_opaque = opaque - mypoll.register(fd, myEventHandleTypeToPollEvent(events)) +return 0 def myUpdateHandle(watch, event): global h_fd, h_events -#print Updating Handle %s %s % (str(fd), str(events)) -h_fd = fd +#print Updating Handle %s %s % (str(h_fd), str(event)) h_events = event -mypoll.unregister(watch) -mypoll.register(watch, myEventHandleTypeToPollEvent(event)) +mypoll.unregister(h_fd) +mypoll.register(h_fd, myEventHandleTypeToPollEvent(event)) def myRemoveHandle(watch): global h_fd -#print Removing Handle %s % str(fd) +#print Removing Handle %s % str(h_fd) +mypoll.unregister(h_fd) h_fd = 0 -mypoll.unregister(watch) +return h_opaque def myAddTimeout(timeout, cb, opaque): global t_active, t_timeout, t_cb, t_opaque @@ -96,16 +96,18 @@ def myAddTimeout(timeout, cb, opaque): t_timeout = timeout; t_cb = cb; t_opaque = opaque; +return 0 def myUpdateTimeout(timer, timeout): global t_timeout -#print Updating Timeout %s % (str(timer), str(timeout)) +#print Updating Timeout %s %s % (str(timer), str(timeout)) t_timeout = timeout; def myRemoveTimeout(timer): global t_active #print Removing Timeout %s % str(timer) t_active = 0; +return t_opaque ## # Main @@ -143,6 +145,14 @@ def main(): myRemoveTimeout ); vc = libvirt.open(uri) +# Close connection on exit (to test cleanup paths) +old_exitfunc = getattr(sys, 'exitfunc', None) +def exit(): +print Closing + str(vc) +vc.close() +if (old_exitfunc): old_exitfunc() +sys.exitfunc = exit + #Add 2 callbacks to prove this works with more than just one vc.domainEventRegister(myDomainEventCallback1,None) vc.domainEventRegister(myDomainEventCallback2,None) @@ -175,8 +185,7 @@ def main(): if h_cb != None: #print Invoking Handle CB -h_cb(0, h_fd, myPollEventToEventHandleType(revents h_events), - h_opaque[0], h_opaque[1]) +h_cb(0, h_fd, myPollEventToEventHandleType(revents h_events), h_opaque[0], h_opaque[1]) #print DEBUG EXIT #break diff --git a/python/libvir.c b/python/libvir.c index 7d58442..fed1031 100644 --- a/python/libvir.c +++ b/python/libvir.c @@ -35,6 +35,18 @@ extern void initcygvirtmod(void); #define VIR_PY_INT_FAIL (libvirt_intWrap(-1)) #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0)) +static char *py_str(PyObject *obj) +{ +PyObject *str = PyObject_Str(obj); +if (!str) { +PyErr_Print(); +PyErr_Clear(); +return NULL; +}; +return PyString_AsString(str); +} + + / * * * Statistics * @@ -484,7 +496,8 @@ libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, virErrorPtr err) PyObject *result; #ifdef DEBUG_ERROR -printf(libvirt_virErrorFuncHandler(%p, %s, ...) called\n, ctx, msg); +printf(libvirt_virErrorFuncHandler(%p, %s, ...) called\n, ctx, + err-message); #endif if ((err == NULL) || (err-code == VIR_ERR_OK)) @@ -1780,12 +1793,19 @@ libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject * self, * Event Impl ***/ static PyObject *addHandleObj = NULL; +static char *addHandleName=
Re: [libvirt] [PATCH] fix python events
David Lively [EMAIL PROTECTED] wrote: On Fri, 2008-11-21 at 17:51 +0100, Jim Meyering wrote: No big deal, but there are several debug printf uses here that look like they try to print NULL pointers upon memory allocation failure. It's ok with glibc's printf of course, but not for others. You're right. Attached patch fixes those issues. It also fixes some cases in which I got some printf string operands switched around ... I'm printing the (user-supplied) object names to help in debugging misbehaving python EventImpls (since there's no static type checking to catch these kinds of things). So instead of printing NULL when we can't alloc the name, I'm printing something a little more helpful (the appropriate generic name). That's better, indeed. I prefer your NAME macro, too. ACK, modulo syntax: diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py @@ -175,8 +185,7 @@ def main(): if h_cb != None: #print Invoking Handle CB -h_cb(0, h_fd, myPollEventToEventHandleType(revents h_events), - h_opaque[0], h_opaque[1]) +h_cb(0, h_fd, myPollEventToEventHandleType(revents h_events), h_opaque[0], h_opaque[1]) Reversed diff? Better to split long lines, not to join. #print DEBUG EXIT #break diff --git a/python/libvir.c b/python/libvir.c index 7d58442..fed1031 100644 --- a/python/libvir.c +++ b/python/libvir.c @@ -35,6 +35,18 @@ extern void initcygvirtmod(void); #define VIR_PY_INT_FAIL (libvirt_intWrap(-1)) #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0)) +static char *py_str(PyObject *obj) +{ +PyObject *str = PyObject_Str(obj); +if (!str) { +PyErr_Print(); +PyErr_Clear(); +return NULL; +}; +return PyString_AsString(str); +} + Trailing white space ^^. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list