On 21 May, 2008, at 1:04, Shalev wrote:
> Hello List,
>
> I've been combing through the latest PyObjC sources to try to figure
> out how to wrap a pointer in a python object, but what I've found is
> slightly confusing. My situation is this:
>
> I am writing a plugin to an Cocoa app in python, using py2app to
> compile my python code into a loadable bundle. The main Cocoa app
> then loads my bundle, giving me full access to its internal runtime.
> However, one of the classes in the runtime returns a float pointer
> (representing some image data.) I want to take that pointer and wrap
> it in a Python object (in this case, a NumPy array.) I see in the
> source that there may be some way of registering callbacks for types
> not natively supported by PyObjC, but I'm not quite sure how to use
> them.
>
> Is their some way to write custom wrapping code (in C, I assume) and
> let my (pure) Python bundle know about how to deal with that method?
> Right now, calling that method just returns an opaque PyObjCPointer
> object that doesn't let me do very much.
You can add custom metadata that will tell PyObjC about your method,
there are samples of that in the testsuite. One way that will work is
something like this:
objc.registerMetaDataForSelector("OC_MetaDataTest",
"unknownLengthArray",
dict(
retval=dict(c_array_of_variable_length=True),
))
What is the method signature for your method? Does the method also
return the size of the array, or is that implied somewhere? If the
length of the array is also returned (such as by an output parameter)
you can provide better metadata, the metadata above results in a
return value that doesn't perform array-bounds checking, which means
you could (a) change the result array and (b) write outside of the
actual array and cause a hard crash.
Ronald
>
>
> -Thanks
> Shalev
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Pyobjc-dev mailing list
> Pyo...@li...
> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
|