Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
cdef public class and vtab export
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
PatN  
View profile  
 More options Feb 15 2012, 2:23 pm
From: PatN <nyst...@gmail.com>
Date: Wed, 15 Feb 2012 11:23:55 -0800 (PST)
Local: Wed, Feb 15 2012 2:23 pm
Subject: cdef public class and vtab export
I am pretty new to Cython but have wrapped C/C++ using other methods
(C api, PyCXX, Boost::Python, and ctypes.) I'm really enjoying Cython
so far, but have the following question:

I have a c++ class which needs to invoke a bound Python method. The
cleanest way I see is to have the usual Cython extension class
(declared 'cdef public class..) with a thisptr to the c++ object, and
have the c++ object have a void *py_obj which holds a pointer to the
extension class struct. So far, so good - except that when the c++
wants to call a bound method in the Cython extension class, it needs
the virtual function table which Cython emits in the .cpp source, but
not in the .h file (generated because I declared the class public.) I
find it odd that the vtab struct is not exported into the .h file,
because the extension class object structure which gets exported
includes a member called __pyx_vtab, but the actual structure of the
vtab isn't in the .h file; so I can *almost* get everything I need! Am
I missing something? A keyword perhaps, which causes the vtab to be
exported?

===== cython code
cdef public class MyTestClass(object)[object MyTestClassObject, type
MyTestType] :
    cdef TPyBathControl *ths      # hold a C++ instance which we're
wrapping
              # This is the class whose c++ method wants to call this
object's cb method.

    def __cinit__(self):
        self.ths = new TPyBathControl()
        self.ths.py_obj = <void *>self   # put reference to this
object in the cpp object

    def __dealloc__(self):
        del self.ths

    cdef void cb(MyTestClass self):
        print 'called python'

===== generated .h file snippet
struct MyTestClassObject {
  PyObject_HEAD
  struct __pyx_vtabstruct_11basf_ext_cy_MyTestClass *__pyx_vtab;
  TPyBathControl *ths;

};

===== What's missing from .h file?
struct __pyx_vtabstruct_11basf_ext_cy_MyTestClass ...

Thanks in advance for any advice.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »