Fedora Linux Support Community & Resources Center
Old 28th July 2010, 11:34 AM
CowTux Offline
Registered User
Join Date: Feb 2010
Posts: 32
extending python with type whose member is a pointer to a function


I'm trying to write some extensions to python, and the point I am at now is such that I have a new type and I would like a member of this type to be a pointer to another python extension which is only a module method in a different module. The reason for this situation is that there is already an extension module written which consists only of various functions (all requiring the same arguments) and no types. No I have a type, and I would like to assign to this new type any of the previously defined funtions from the Python interpreter. For example:

from OldModule import oldfunc
from NewModule import MyType

cl = MyType()
cl.meth = oldfunc
My C structure looks like this.

typedef struct {
PyObject * (*func)(PyObject *,PyObject *) meth;
} MyType_obj;
The compiler doesn't complain at that, but that isn't really saying much. The problem I'm encountering is in the getter and setter for the meth member. Any attempt to Py_INCREF or Py_DECREF on the meth member is a problem for the compiler. Perhaps I'm mistaken in the way Python counts references to function pointers. For the moment I'm concentrating on the setter function. If I ignore the reference counting I just mentioned, there is still a problem converting the generic PyObject pointer passed to the function to this function pointer type. I've assumed this is properly done by something like

However, how is it best to define the pointer MyFunc_Type?

I'm looking into this because I think this is in the end is the more elegant option, but I do realise that I could simply rewrite the old module extensions. What are your thoughts and suggestions; I am interested to read them.

Reply With Quote

extending, function, member, pointer, python, type

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
error: dereferencing pointer to incomplete type Maninder Servers & Networking 0 11th May 2008 10:23 AM
Member Position/Member Size (Of Structure) RuledOut My Datagram Packets (WHY?) amosa Programming & Packaging 6 24th September 2007 07:50 AM
error "incompatible pointer type" when compiling from source honduraz10 Using Fedora 0 21st January 2007 09:32 PM
Extending LVM Partitions alphonsebrown Using Fedora 0 21st June 2005 12:47 PM
looking for a "my computer" type function in KDE themadscientist Using Fedora 9 20th April 2005 07:14 PM

Current GMT-time: 17:53 (Monday, 21-08-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat