ariovistus / pyd

Interoperability between Python and D
MIT License
158 stars 32 forks source link

Structs with a std.datetime.DateTime member can't be converted to Python #106

Closed atilaneves closed 6 years ago

atilaneves commented 6 years ago

This fails:

// api.d
struct PriceBar {
    import std.datetime: DateTime;

    DateTime date;
    double open, high, low, close;

    this(DateTime date, double open, double high, double low, double close) {
        this.date = date;
        this.open = open;
        this.high = high;
        this.low = low;
        this.close = close;
    }
}
from oops import PriceBar
from datetime import datetime as Date

date = Date(2004, 8, 19)
date.year  # fine

bar = PriceBar(Date(2004, 8, 19), 100.01, 104.06, 95.96, 100.335)
bar.date.year  # oops
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    bar.date.year  # oops
RuntimeError: D conversion function d_to_python failed with type std.datetime.date.DateTime*

According to git bisect, this regression was introduced in this commit:

commit 7a9b56d4e362fee92a7381f1feba97656d3db62e (HEAD, refs/bisect/bad)
Author: Ellery Newcomer <ellery-newcomer@utulsa.edu>
Date:   Fri Aug 31 20:16:03 2018 -0700

    support structs in structs

    also, dmd 2.067.1 doesn't seem to want to work in debian 9

Rest of the dub project to reproduce:

// app.d
import autowrap.python;
mixin(
    wrapAll(
        LibraryName("oops"),
        Modules("api"),
    )
);
# dub.sdl
name "pyd_datetime"
targetType "dynamicLibrary"
postBuildCommands "mv libpyd_datetime.so oops.so"

dependency "autowrap:python" version="==0.2.8"
#  The above dependency means pyd v0.10.3
subConfiguration "autowrap:python" "python37"