|
From: Chris F. <cd...@fo...> - 2012-06-05 23:30:05
|
On Mon, Jun 04, 2012 at 11:41:11PM +0200, Nicolas wrote:
> Le lundi 04 juin 2012 ?? 17:08 -0400, Chris Frey a ??crit :
> > wrapper/opensync-error.i:51: Warning 321: 'set' conflicts with a built-in name in python
> >
> > I'm thinking that renaming the member from "set" to "set_error" is the
> > best solution, but I'm not a python guy, so maybe there's an even better
> > way?
> >
> > Let me know... otherwise, I'll rename it. :-)
>
> Indeed, I have renamed.
>
> Not yet published, because I haven't already tested my modifications.
In my testing, I've run into a problem that occurs with or without the
rename, in my opinion.
The API osync_error_set() actually modifies the OSyncError pointer passed
into it, and this does not play well with Python.
The wrapper code, opensync-error.i uses the PyCObject to store the OSyncError
pointer, but if the pointer changes in a call such as set_error(), then
the Python world has an outdated pointer, and the set_error() member
function has no way to update it, as far as I can see.
The SWIG wrapper automatically passes in the PyCObject to set_error() and
calls it "self", but I don't see any way to find the PyObject from that
"self" PyCObject. Is there a way? If there is, then I could just update
it with PyCObject_SetVoidPtr() like below:
wrapper/opensync-error.i:
@@ -46,8 +48,13 @@ typedef struct {} Error;
osync_error_set_from_error(&self, &source);
}
- void set(ErrorType type, const char *msg) {
- osync_error_set(&self, type, "%s", msg);
+ void set_error(ErrorType type, const char *msg) {
+ PyObject *obj = MysteryFunction(self);
+ Error *error = PyCObject_AsVoidPtr(obj);
+ osync_error_set(&error, type, "%s", msg);
+ if( !PyCObject_SetVoidPtr(obj, error) ) {
+ blah;
+ }
}
Note the "MysteryFunction" which I need, but don't know if it exists.
If MysteryFunction() does not exist, then I need to use a serious hack,
and wrap the Error object in another struct, so that the OSyncError pointer
can change at will.
Any SWIG experts out there who can point me in the right direction?
I'm currently working on a fairly hacky patch, but I'd rather find that
MysteryFunction. :-)
- Chris
|