Thread overview | |||||
---|---|---|---|---|---|
|
March 18, 2015 pyd and converting arrays of strings | ||||
---|---|---|---|---|
| ||||
Hi I am using PyD with latest stable LDC on Arch Linux 64 bit. I have various structures I am trying to wrap to pass to python. For example: struct PlotLines { KPDateTime[] start_dates; KPDateTime[] end_dates; double[] y; string[] colors; long[] weights; string[] styles; } import pyd.pyd; extern(C) void PydMain() { def!(bokehDownload,PyName!"bokeh_download", BokehBars function(string,bool))(); def!(bokehCountdown,PyName!"bokeh_countdown",CanvasTable function(BokehBars,bool,bool))(); module_init(); wrap_struct!(BokehBars,Member!("dates"),Member!("opens"),Member!("highs"),Member!("lows"),Member!("closes"),Member!("volumes"),Member!("openinterests")); wrap_struct!(KPDateTime,Member!"year",Member!"month",Member!"day",Member!"hour",Member!"minute",Member!"second"); wrap_struct!(CanvasTable,Member!"plot_title",Member!"x_label",Member!"y_label",Member!"annotations",Member!"lines",Member!"bars",Member!"studies",Member!"grid_sequence"); wrap_struct!(PlotLines,Member!"start_dates",Member!"end_dates",Member!"y",Member!"colors",Member!"weights",Member!"styles"); wrap_struct!(PlotStudy,Member!"title",Member!"dates",Member!"lines",Member!"overbought",Member!"oversold"); wrap_struct!(PlotAnnotations,Member!"directions",Member!"dates",Member!"y",Member!"weights",Member!"values",Member!"colors",Member!"styles"); } PyD doesn't seem to want to wrap a string[] member: /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/make_object.d(773): Error: cannot implicitly convert expression (python_to_d(item)) of type string to dchar[] /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/make_object.d(740): Error: function pyd.make_object.python_iter_to_d!(string[]).python_iter_to_d no return exp; or assert(0); at end of function /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/make_object.d(482): Error: template instance pyd.make_object.python_iter_to_d!(string[]) error instantiating /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/struct_wrap.d-mixin-73(73): instantiated from here: python_to_d!(string[]) /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/struct_wrap.d(105): instantiated from here: wrapped_member!(PlotLines*, "colors", "rw") /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/class_wrap.d(1503): instantiated from here: call!("PlotLines", PlotLines*) /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/class_wrap.d(1474): instantiated from here: _wrap_class!(PlotLines, "PlotLines", "", "", Member!"start_dates", Member!"end_dates", Member!"y", Member!"colors", Member!"weights", Member!"styles") /btrfs0/mirrored/kprop/core/prod/kprop/technical/demark/countdown/main13.d(72): instantiated from here: wrap_struct!(PlotLines, Member!"start_dates", Member!"end_dates", Member!"y", Member!"colors", Member!"weights", Member!"styles") error: command 'ldc2' failed with exit status 1 Any thoughts on whether I am doing something wrong, and if it is a PyD problem, how to circumvent it? Thanks. Laeeth. |
March 18, 2015 Re: pyd and converting arrays of strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Laeeth Isharc | On Wednesday, 18 March 2015 at 17:09:27 UTC, Laeeth Isharc wrote:
> Hi
>
> I am using PyD with latest stable LDC on Arch Linux 64 bit.
>
> I have various structures I am trying to wrap to pass to python. For example:
>
> struct PlotLines
> {
> KPDateTime[] start_dates;
> KPDateTime[] end_dates;
> double[] y;
> string[] colors;
> long[] weights;
> string[] styles;
> }
>
> import pyd.pyd;
> extern(C) void PydMain()
> {
> def!(bokehDownload,PyName!"bokeh_download", BokehBars function(string,bool))();
> def!(bokehCountdown,PyName!"bokeh_countdown",CanvasTable function(BokehBars,bool,bool))();
> module_init();
> wrap_struct!(BokehBars,Member!("dates"),Member!("opens"),Member!("highs"),Member!("lows"),Member!("closes"),Member!("volumes"),Member!("openinterests"));
> wrap_struct!(KPDateTime,Member!"year",Member!"month",Member!"day",Member!"hour",Member!"minute",Member!"second");
> wrap_struct!(CanvasTable,Member!"plot_title",Member!"x_label",Member!"y_label",Member!"annotations",Member!"lines",Member!"bars",Member!"studies",Member!"grid_sequence");
> wrap_struct!(PlotLines,Member!"start_dates",Member!"end_dates",Member!"y",Member!"colors",Member!"weights",Member!"styles");
> wrap_struct!(PlotStudy,Member!"title",Member!"dates",Member!"lines",Member!"overbought",Member!"oversold");
> wrap_struct!(PlotAnnotations,Member!"directions",Member!"dates",Member!"y",Member!"weights",Member!"values",Member!"colors",Member!"styles");
> }
>
> PyD doesn't seem to want to wrap a string[] member:
>
> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/make_object.d(773): Error: cannot implicitly convert expression (python_to_d(item)) of type string to dchar[]
> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/make_object.d(740): Error: function pyd.make_object.python_iter_to_d!(string[]).python_iter_to_d no return exp; or assert(0); at end of function
> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/make_object.d(482): Error: template instance pyd.make_object.python_iter_to_d!(string[]) error instantiating
> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/struct_wrap.d-mixin-73(73):
> instantiated from here: python_to_d!(string[])
> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/struct_wrap.d(105):
> instantiated from here: wrapped_member!(PlotLines*, "colors", "rw")
> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/class_wrap.d(1503):
> instantiated from here: call!("PlotLines", PlotLines*)
> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/class_wrap.d(1474):
> instantiated from here: _wrap_class!(PlotLines, "PlotLines", "", "", Member!"start_dates", Member!"end_dates", Member!"y", Member!"colors", Member!"weights", Member!"styles")
> /btrfs0/mirrored/kprop/core/prod/kprop/technical/demark/countdown/main13.d(72):
> instantiated from here: wrap_struct!(PlotLines, Member!"start_dates", Member!"end_dates", Member!"y", Member!"colors", Member!"weights", Member!"styles")
> error: command 'ldc2' failed with exit status 1
>
> Any thoughts on whether I am doing something wrong, and if it is a PyD problem, how to circumvent it?
>
>
> Thanks.
>
>
> Laeeth.
A quick glance over class_wrap.d suggests that pyd may not handle string[] correctly. I think it has the necessary special casing to deal with ElementType!string being dchar (not char), but this isn't triggered for string[]. I see you've filed a bug, hopefully someone will take a look. I might have time soon if no one else jumps on it.
Can you use immutable(dchar)[][] instead of string[]? That might work, but I haven't tested it.
|
March 18, 2015 Re: pyd and converting arrays of strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Wednesday, 18 March 2015 at 20:58:56 UTC, John Colvin wrote:
> On Wednesday, 18 March 2015 at 17:09:27 UTC, Laeeth Isharc wrote:
>> Hi
>>
>> I am using PyD with latest stable LDC on Arch Linux 64 bit.
>>
>> I have various structures I am trying to wrap to pass to python. For example:
>>
>> struct PlotLines
>> {
>> KPDateTime[] start_dates;
>> KPDateTime[] end_dates;
>> double[] y;
>> string[] colors;
>> long[] weights;
>> string[] styles;
>> }
>>
>> import pyd.pyd;
>> extern(C) void PydMain()
>> {
>> def!(bokehDownload,PyName!"bokeh_download", BokehBars function(string,bool))();
>> def!(bokehCountdown,PyName!"bokeh_countdown",CanvasTable function(BokehBars,bool,bool))();
>> module_init();
>> wrap_struct!(BokehBars,Member!("dates"),Member!("opens"),Member!("highs"),Member!("lows"),Member!("closes"),Member!("volumes"),Member!("openinterests"));
>> wrap_struct!(KPDateTime,Member!"year",Member!"month",Member!"day",Member!"hour",Member!"minute",Member!"second");
>> wrap_struct!(CanvasTable,Member!"plot_title",Member!"x_label",Member!"y_label",Member!"annotations",Member!"lines",Member!"bars",Member!"studies",Member!"grid_sequence");
>> wrap_struct!(PlotLines,Member!"start_dates",Member!"end_dates",Member!"y",Member!"colors",Member!"weights",Member!"styles");
>> wrap_struct!(PlotStudy,Member!"title",Member!"dates",Member!"lines",Member!"overbought",Member!"oversold");
>> wrap_struct!(PlotAnnotations,Member!"directions",Member!"dates",Member!"y",Member!"weights",Member!"values",Member!"colors",Member!"styles");
>> }
>>
>> PyD doesn't seem to want to wrap a string[] member:
>>
>> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/make_object.d(773): Error: cannot implicitly convert expression (python_to_d(item)) of type string to dchar[]
>> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/make_object.d(740): Error: function pyd.make_object.python_iter_to_d!(string[]).python_iter_to_d no return exp; or assert(0); at end of function
>> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/make_object.d(482): Error: template instance pyd.make_object.python_iter_to_d!(string[]) error instantiating
>> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/struct_wrap.d-mixin-73(73):
>> instantiated from here: python_to_d!(string[])
>> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/struct_wrap.d(105):
>> instantiated from here: wrapped_member!(PlotLines*, "colors", "rw")
>> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/class_wrap.d(1503):
>> instantiated from here: call!("PlotLines", PlotLines*)
>> /home/laeeth/anaconda/lib/python2.7/site-packages/pyd/infrastructure/pyd/class_wrap.d(1474):
>> instantiated from here: _wrap_class!(PlotLines, "PlotLines", "", "", Member!"start_dates", Member!"end_dates", Member!"y", Member!"colors", Member!"weights", Member!"styles")
>> /btrfs0/mirrored/kprop/core/prod/kprop/technical/demark/countdown/main13.d(72):
>> instantiated from here: wrap_struct!(PlotLines, Member!"start_dates", Member!"end_dates", Member!"y", Member!"colors", Member!"weights", Member!"styles")
>> error: command 'ldc2' failed with exit status 1
>>
>> Any thoughts on whether I am doing something wrong, and if it is a PyD problem, how to circumvent it?
>>
>>
>> Thanks.
>>
>>
>> Laeeth.
>
> A quick glance over class_wrap.d suggests that pyd may not handle string[] correctly. I think it has the necessary special casing to deal with ElementType!string being dchar (not char), but this isn't triggered for string[]. I see you've filed a bug, hopefully someone will take a look. I might have time soon if no one else jumps on it.
>
> Can you use immutable(dchar)[][] instead of string[]? That might work, but I haven't tested it.
Hi John.
dchar[] works, but I am not sure about immutable. I turned the strings used to populate the struct into dchar by appending .array to the end (there may be a better way).
Thanks for looking at it.
Laeeth
|
Copyright © 1999-2021 by the D Language Foundation