Changeset 122 for trunk/infrastructure/pyd
- Timestamp:
- 08/13/07 17:12:37 (1 year ago)
- Files:
-
- trunk/infrastructure/pyd/class_wrap.d (modified) (9 diffs)
- trunk/infrastructure/pyd/ctor_wrap.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/infrastructure/pyd/class_wrap.d
r121 r122 156 156 ////////////////////// 157 157 158 //import std.stdio; 159 158 160 /// Various wrapped methods 159 161 template wrapped_methods(T) { … … 178 180 void wrapped_dealloc(PyObject* self) { 179 181 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); 181 184 self.ob_type.tp_free(self); 182 185 }); … … 489 492 alias C ctors; 490 493 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; 493 496 static void call() { 494 497 wrapped_class_type!(T).tp_init = 495 &Ctors.init_func; 498 //&Ctors.init_func; 499 &wrapped_ctors!(shim, C).init_func; 496 500 } 497 501 } … … 572 576 } 573 577 +/ 578 //import std.stdio; 574 579 template _wrap_class(_T, string name, Params...) { 575 580 static if (is(_T == class)) { 576 581 pragma(msg, "wrap_class: " ~ name); 577 mixin pyd.make_wrapper.make_wrapper!(_T, Params);578 aliaswrapper shim_class;582 alias pyd.make_wrapper.make_wrapper!(_T, Params).wrapper shim_class; 583 //alias W.wrapper shim_class; 579 584 alias _T T; 580 585 // } else static if (is(_T == interface)) { … … 590 595 pragma(msg, "shim.mangleof: " ~ shim_class.mangleof); 591 596 alias wrapped_class_type!(T) type; 597 //writefln("entering wrap_class for %s", typeid(T)); 592 598 //pragma(msg, "wrap_class, T is " ~ prettytypeof!(T)); 593 599 594 600 //Params params; 601 //writefln("before params: tp_init is %s", type.tp_init); 595 602 foreach (param; Params) { 596 603 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)(); 599 606 } else { 600 607 param.call!(T)(); 601 608 } 602 609 } 610 //writefln("after params: tp_init is %s", type.tp_init); 603 611 604 612 assert(Pyd_Module_p(modulename) !is null, "Must initialize module before wrapping classes."); … … 681 689 } 682 690 } 691 //writefln("after default check: tp_init is %s", type.tp_init); 683 692 684 693 ////////////////// … … 688 697 throw new Exception("Couldn't ready wrapped type!"); 689 698 } 699 //writefln("after Ready: tp_init is %s", type.tp_init); 690 700 python.Py_INCREF(cast(PyObject*)&type); 691 701 python.PyModule_AddObject(Pyd_Module_p(modulename), (name~\0).ptr, cast(PyObject*)&type); … … 697 707 wrapped_classes[shim_class.classinfo] = &type; 698 708 } 709 //writefln("leaving wrap_class for %s", typeid(T)); 699 710 } 700 711 } … … 784 795 alias wrapped_class_type!(T) type; 785 796 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 } 788 810 } 789 811 return self.d_obj; trunk/infrastructure/pyd/ctor_wrap.d
r121 r122 65 65 } 66 66 67 //import std.stdio; 67 68 // This template accepts a tuple of function pointer types, which each describe 68 69 // 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;70 template wrapped_ctors(T, C ...) { 71 //alias shim_class T; 71 72 alias wrapped_class_object!(T) wrap_object; 72 73 … … 76 77 77 78 return exception_catcher({ 79 //writefln("in init_func: len=%s, T=%s, C.length=%s", len, typeid(T), C.length); 78 80 // Default ctor 79 81 static if (is(typeof(new T))) { … … 87 89 foreach(i, arg; c) { 88 90 alias ParameterTypeTuple!(typeof(arg)) Ctor; 91 //writefln(" init_func: i=%s, Ctor.length=%s, Ctor=%s", i, Ctor.length, typeid(typeof(arg))); 89 92 if (Ctor.length == len) { 90 93 auto fn = &call_ctor!(T, ParameterTypeTuple!(typeof(arg))); … … 94 97 } 95 98 alias typeof(fn) dg_t; 96 mixin applyPyTupleToDelegate!(dg_t);99 //mixin applyPyTupleToDelegate!(dg_t) A; 97 100 T t = applyPyTupleToDelegate(fn, args); 98 101 if (t is null) {
