Changeset 19

Show
Ignore:
Timestamp:
07/01/06 01:05:59 (6 years ago)
Author:
KirkMcDonald
Message:

Stability improvement to class wrapping.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pyd/class_wrap.d

    r18 r19  
    110110    void wrapped_dealloc(PyObject* _self) { 
    111111        wrap_object* self = cast(wrap_object*)_self; 
    112         wrap_class_instances!(T).remove(self.d_obj); 
     112        if (self.d_obj !is null) { 
     113            wrap_class_instances!(T)[self.d_obj] = wrap_class_instances!(T)[self.d_obj] - 1; 
     114            if (wrap_class_instances!(T)[self.d_obj] == 0) { 
     115                wrap_class_instances!(T).remove(self.d_obj); 
     116            } 
     117        } 
    113118        self.ob_type.tp_free(self); 
    114119    } 
     
    129134        T t = new T; 
    130135        (cast(wrap_object*)self).d_obj = t; 
    131         wrap_class_instances!(T)[t] = null
     136        wrap_class_instances!(T)[t] = 1
    132137        return 0; 
    133138    } 
     
    139144// objects. 
    140145template wrap_class_instances(T) { 
    141     void*[T] wrap_class_instances; 
     146    int[T] wrap_class_instances; 
    142147} 
    143148 
     
    179184            void init() { 
    180185                wrapped_class_type!(classname, T).tp_init = 
    181                     &wrapped_ctors!(T, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10).init
     186                    &wrapped_ctors!(T, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10).init_func
    182187            } 
    183188        } 
  • trunk/pyd/ctor_wrap.d

    r18 r19  
    7070    int wrapped_ctor(PyObject* self, PyObject* args, PyObject* kwds) { 
    7171        T t; 
    72          
     72 
    7373        try { /* begin try */ 
    74          
     74 
    7575        static if (Ctor.ARGS == 1) { 
    7676            t = new T( 
     
    176176 
    177177        (cast(wrapped_class_object!(T)*)self).d_obj = t; 
    178         wrap_class_instances!(T)[t] = null
     178        wrap_class_instances!(T)[t] = 1
    179179 
    180180        return 0; 
     
    208208        const uint ARGS = 0; 
    209209    extern(C) 
    210     int init(PyObject* self, PyObject* args, PyObject* kwds) { 
     210    int init_func(PyObject* self, PyObject* args, PyObject* kwds) { 
    211211        int len = PyObject_Length(args); 
    212212        // Default ctor 
     
    215215                T t = new T; 
    216216                (cast(wrap_object*)self).d_obj = t; 
    217                 wrap_class_instances!(T)[t] = null
     217                wrap_class_instances!(T)[t] = 1
    218218                return 0; 
    219219            } 
  • trunk/pyd/make_object.d

    r10 r19  
    249249        return res; 
    250250    } else static if (is(C_long : T)) { 
     251        if (!PyNumber_Check(o)) could_not_convert!(T)(o); 
    251252        C_long res = PyInt_AsLong(o); 
    252253        handle_exception(); 
    253254        return res; 
    254255    } else static if (is(bool : T)) { 
     256        if (!PyNumber_Check(o)) could_not_convert!(T)(o); 
    255257        int res = PyObject_IsTrue(o); 
    256258        handle_exception();