~gjc/pybindgen/old-trunk

« back to all changes in this revision

Viewing changes to pybindgen/cppclass.py

  • Committer: Gustavo J. A. M. Carneiro
  • Date: 2008-01-02 18:51:27 UTC
  • Revision ID: gjc@gnome.org-20080102185127-p9y1mr1x1oyhqu0q
Add peekref_method support, to solve an issue related to virtual methods, user classes, and reference counting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
260
260
 
261
261
    def __init__(self, name, parent=None, incref_method=None, decref_method=None,
262
262
                 automatic_type_narrowing=None, allow_subclassing=None,
263
 
                 is_singleton=False, outer_class=None):
 
263
                 is_singleton=False, outer_class=None,
 
264
                 peekref_method=None):
264
265
        """Constructor
265
266
        name -- class name
266
267
        parent -- optional parent class wrapper
282
283
        is_singleton -- if True, the class is considered a singleton,
283
284
                        and so the python wrapper will never call the
284
285
                        C++ class destructor to free the value.
 
286
        peekref_method -- if the class supports reference counting, the
 
287
                          name of the method that returns the current reference count.
285
288
        """
286
289
        assert outer_class is None or isinstance(outer_class, CppClass)
287
290
        self.outer_class = outer_class
318
321
        if incref_method is None and parent is not None:
319
322
            self.incref_method = parent.incref_method
320
323
            self.decref_method = parent.decref_method
 
324
            self.peekref_method = parent.peekref_method
321
325
        else:
322
326
            self.incref_method = incref_method
323
327
            self.decref_method = decref_method
 
328
            self.peekref_method = peekref_method
324
329
 
325
330
        if automatic_type_narrowing is None:
326
331
            if parent is None:
962
967
        if self.helper_class is None:
963
968
            visit_self = ''
964
969
        else:
 
970
            if self.peekref_method is None:
 
971
                peekref_code = ''
 
972
            else:
 
973
                peekref_code = " && self->obj->%s() == 1" % self.peekref_method
965
974
            visit_self = '''
966
 
    if (self->obj && typeid(*self->obj) == typeid(%s))
 
975
    if (self->obj && typeid(*self->obj) == typeid(%s)%s)
967
976
        Py_VISIT(self);
968
 
''' % self.helper_class.name
 
977
''' % (self.helper_class.name, peekref_code)
969
978
 
970
979
        code_sink.writeln(r'''
971
980
static int