Changeset 122

Show
Ignore:
Timestamp:
08/13/07 17:12:37 (9 months ago)
Author:
KirkMcDonald
Message:

* Un-broke Init. (Oops.)
* Reverted some symbol-length-shortening code, which caused the above problem.

Files:

Legend:

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

    r121 r122  
    156156////////////////////// 
    157157 
     158//import std.stdio; 
     159 
    158160/// Various wrapped methods 
    159161template wrapped_methods(T) { 
     
    178180    void wrapped_dealloc(PyObject* self) { 
    179181        exception_catcher(delegate void() { 
    180             WrapPyObject_SetObj(self, cast(T)null); 
     182            //writefln("wrapped_dealloc: T is %s", typeid(T)); 
     183            WrapPyObject_SetObj!(T)(self, cast(T)null); 
    181184            self.ob_type.tp_free(self); 
    182185        }); 
     
    489492    alias C ctors; 
    490493    static const bool needs_shim = true; 
    491     template call(T) { 
    492         mixin wrapped_ctors!(param.ctors) Ctors; 
     494    template call(T, shim) { 
     495        //mixin wrapped_ctors!(param.ctors) Ctors; 
    493496        static void call() { 
    494497            wrapped_class_type!(T).tp_init = 
    495                 &Ctors.init_func; 
     498                //&Ctors.init_func; 
     499                &wrapped_ctors!(shim, C).init_func; 
    496500        } 
    497501    } 
     
    572576} 
    573577+/ 
     578//import std.stdio; 
    574579template _wrap_class(_T, string name, Params...) { 
    575580    static if (is(_T == class)) { 
    576581        pragma(msg, "wrap_class: " ~ name); 
    577         mixin pyd.make_wrapper.make_wrapper!(_T, Params)
    578         alias wrapper shim_class; 
     582        alias pyd.make_wrapper.make_wrapper!(_T, Params).wrapper shim_class
     583        //alias W.wrapper shim_class; 
    579584        alias _T T; 
    580585//    } else static if (is(_T == interface)) { 
     
    590595    pragma(msg, "shim.mangleof: " ~ shim_class.mangleof); 
    591596    alias wrapped_class_type!(T) type; 
     597    //writefln("entering wrap_class for %s", typeid(T)); 
    592598    //pragma(msg, "wrap_class, T is " ~ prettytypeof!(T)); 
    593599 
    594600    //Params params; 
     601    //writefln("before params: tp_init is %s", type.tp_init); 
    595602    foreach (param; Params) { 
    596603        static if (param.needs_shim) { 
    597             mixin param.call!(T) PCall; 
    598             PCall.call(); 
     604            //mixin param.call!(T) PCall; 
     605            param.call!(T, shim_class)(); 
    599606        } else { 
    600607            param.call!(T)(); 
    601608        } 
    602609    } 
     610    //writefln("after params: tp_init is %s", type.tp_init); 
    603611 
    604612    assert(Pyd_Module_p(modulename) !is null, "Must initialize module before wrapping classes."); 
     
    681689        } 
    682690    } 
     691    //writefln("after default check: tp_init is %s", type.tp_init); 
    683692 
    684693    ////////////////// 
     
    688697        throw new Exception("Couldn't ready wrapped type!"); 
    689698    } 
     699    //writefln("after Ready: tp_init is %s", type.tp_init); 
    690700    python.Py_INCREF(cast(PyObject*)&type); 
    691701    python.PyModule_AddObject(Pyd_Module_p(modulename), (name~\0).ptr, cast(PyObject*)&type); 
     
    697707        wrapped_classes[shim_class.classinfo] = &type; 
    698708    } 
     709    //writefln("leaving wrap_class for %s", typeid(T)); 
    699710} 
    700711} 
     
    784795    alias wrapped_class_type!(T) type; 
    785796    wrapped_object* self = cast(wrapped_object*)_self; 
    786     if (!is_wrapped!(T) || self is null || (is(T : Object) && cast(T)cast(Object)(self.d_obj) is null)) { 
    787         throw new Exception("Error extracting D object from Python object..."); 
     797    if (!is_wrapped!(T)) { 
     798        throw new Exception("Error extracting D object: Type " ~ objToStr(typeid(T)) ~ " is not wrapped."); 
     799    } 
     800    if (self is null) { 
     801        throw new Exception("Error extracting D object: 'self' was null!"); 
     802    } 
     803    static if (is(T == class)) { 
     804        if (cast(Object)(self.d_obj) is null) { 
     805            throw new Exception("Error extracting D object: Reference was not castable to Object!"); 
     806        } 
     807        if (cast(T)cast(Object)(self.d_obj) is null) { 
     808            throw new Exception("Error extracting D object: Object was not castable to type "~objToStr(typeid(T))~"."); 
     809        } 
    788810    } 
    789811    return self.d_obj; 
  • trunk/infrastructure/pyd/ctor_wrap.d

    r121 r122  
    6565} 
    6666 
     67//import std.stdio; 
    6768// This template accepts a tuple of function pointer types, which each describe 
    6869// a ctor of T, and  uses them to wrap a Python tp_init function. 
    69 template wrapped_ctors(/*T,*/ C ...) { 
    70     alias shim_class T; 
     70template wrapped_ctors(T, C ...) { 
     71    //alias shim_class T; 
    7172    alias wrapped_class_object!(T) wrap_object; 
    7273 
     
    7677 
    7778        return exception_catcher({ 
     79            //writefln("in init_func: len=%s, T=%s, C.length=%s", len, typeid(T), C.length); 
    7880            // Default ctor 
    7981            static if (is(typeof(new T))) { 
     
    8789            foreach(i, arg; c) { 
    8890                alias ParameterTypeTuple!(typeof(arg)) Ctor; 
     91                //writefln("  init_func: i=%s, Ctor.length=%s, Ctor=%s", i, Ctor.length, typeid(typeof(arg))); 
    8992                if (Ctor.length == len) { 
    9093                    auto fn = &call_ctor!(T, ParameterTypeTuple!(typeof(arg))); 
     
    9497                    } 
    9598                    alias typeof(fn) dg_t; 
    96                     mixin applyPyTupleToDelegate!(dg_t)
     99                    //mixin applyPyTupleToDelegate!(dg_t) A
    97100                    T t = applyPyTupleToDelegate(fn, args); 
    98101                    if (t is null) {