Pyd: Stackthreads and returning arrays from D

Simen Haugen simen at norstat.no
Wed Jun 27 02:16:21 PDT 2007


Ok, I just cannot get it to work..
Look at this simple example:

import pyd.pyd;


class Item {
}


class Container {
    private:
    Item[] _items;

    public:
    Item[] items() {
        return _items;
    }

    void items(Item[] items) {
        _items = items;
    }
}


extern(C) void PydMain() {
    module_init();

    wrap_class!(Item);

    wrap_class!(
        Container,
        Property!(Container.items)
    );
}

When trying to compile this I get an error "expected to return a value of 
type Item[]" for the Container.items property:

running build
running build_ext
building 'test' extension
sources:  ['test.d', 'python.d', 'class_wrap.d', 'ctor_wrap.d', 'def.d', 
'dg_con
vert.d', 'exception.d', 'func_wrap.d', 'lib_abstract.d', 'make_object.d', 
'make_
wrapper.d', 'op_wrap.d', 'pyd.d', 'pydobject.d', 'struct_wrap.d', 
'pydmain.d', '
Default.d', 'Demangle.d', 'Nameof.d', 'Util.d', 
'python_dll_windows_boilerplate.
d']
c:\d\dmd\bin\dmd.exe -c -version=Python_2_4_Or_Later -version=Python_Unicode_UCS
2 -debug -IC:\Python24\lib\site-packages\celerid\infrastructure\python\2.4 -IC:\
Python24\lib\site-packages\celerid\infrastructure -ofbuild\temp.win32-2.4\Releas
e\project\test.obj test.d
wrap_class: Item
class wrapper : T {
    mixin OverloadShim;

}

wrap_class: Container
class wrapper : T {
    mixin OverloadShim;
    alias Params[0] __pyd_p0;
    ReturnType!(__pyd_p0.get_t) items() {
        return __pyd_get_overload!("items", __pyd_p0.get_t).func("items");
    }
    ReturnType!(__pyd_p0.set_t) items(ParameterTypeTuple!(__pyd_p0.set_t) t) 
{
        return __pyd_get_overload!("items", __pyd_p0.set_t).func("items", 
t);
    }

}

C:\Python24\lib\site-packages\celerid\infrastructure\pyd\make_object.d(228): 
fun
ction pyd.make_object.d_type!(Item[]).d_type expected to return a value of 
type
Item[]
C:\Python24\lib\site-packages\celerid\infrastructure\pyd\make_object.d(289): 
tem
plate instance pyd.make_object.d_type!(Item[]) error instantiating
C:\Python24\lib\site-packages\celerid\infrastructure\pyd\func_wrap.d(274): 
templ
ate instance pyd.func_wrap.PydWrappedFunc.fn!(Item[]) error instantiating
C:\Python24\lib\site-packages\celerid\infrastructure\pyd\func_wrap.d(264): 
templ
ate instance pyd.func_wrap._pycallable_asdgT!(Item[] delegate(())) error 
instant
iating
error: command 'c:\d\dmd\bin\dmd.exe' failed with exit status 1


When I used stackthreads I had no problem returning array of classes.



"Kirk McDonald" <kirklin.mcdonald at gmail.com> wrote in message 
news:f5rsov$apc$1 at digitalmars.com...
> Simen Haugen wrote:
>> Pyd doesn't work with stackthreads in newers versions of the dmd compiler 
>> (1.014+ at least). As I understand from the documentation and my testing, 
>> this means I cannot return arrays from D to Python (and renders Pyd quite 
>> useless for me).
>>
>> "Pyd uses StackThreads for its iteration wrapping support. By setting 
>> this to False, opApply wrapping, Iter, and AltIter will be unavailable."
>>
>> Has anyone found a simple workaround for this?
>>
>>
>
> No, StackThreads has nothing to do with arrays. It is strictly for 
> wrapping opApply overloads in classes. Currently, Pyd will convert D 
> arrays to Python lists (except for char[] and wchar[], which are converted 
> to the Python str and unicode types, respectively). Because this is a 
> less-than-optimal solution in a number of ways, I plan on eventually 
> writing a Python type that wraps D arrays more directly.
>
> -- 
> Kirk McDonald
> http://kirkmcdonald.blogspot.com
> Pyd: Connecting D and Python
> http://pyd.dsource.org 





More information about the Digitalmars-d mailing list