Re: [Pyobjc-dev] Handling (void *)
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2002-11-08 10:31:49
|
On Friday, Nov 8, 2002, at 10:59 Europe/Amsterdam, Peter Montagner wrote: > So you think that we should treat (void*) as an integer rather than a > pointer, right? That works for me but it does seem a bit inelegant. At least for now and only for specific methods. It is not very elegant, but at least it allows you to use a number of APIs that are off-limits at the moment. BTW. I did not propose to treat all void* as integers, that would make it impossible to use some other APIs. > > Is there anything in python (2.2 onwards of course) that isn't an > object? If not, I think we should consider (void *) to be synonymous > with (id). The other use for (void*), as a pointer to block of memory > (eg. write()), can't really be done in python without wrapping it in > an object, right? So any API using (void *) for that purpose would > need to be specially wrapped anyway. Am I wrong? Everything in python is an object from at Python 1.0, and probably right from the start. This doesn't mean we can just go on and use python objects for the userInfo argument, because of reference counting: Because the invoked method doesn't know we actually pas in a PyObject* or id, it doesn't know that it should increase the refcount. This means that the object may be garbage collected before it is passed back to us, unless we make sure a reference to it stays alive for as long as needed. I'd prefer not to introduce ways to easily memory corruption bugs in Python programs ;-). BTW. Jack's solution (None->nil, PyCObject->extract the pointer, ...) is a better solution for almost anything with the possible exception of the userInfo arguments in some Cocoa APIs. This does work correctly with 'void*-as-pointer-to-block-of-memory'. BTW2. A python object is _not_ an objective-C object, the pyobjc module just hides the differences. In some instances the difference is important, mostly when Objective-C code doesn't play by the rules (see the iClass example for an example of this) Ronald |