From 32d6e39b9f6a5479522ab2849bc296d9026d92d5 Mon Sep 17 00:00:00 2001 From: dansanduleac Date: Wed, 1 Jun 2011 02:13:12 +0100 Subject: [PATCH] Updated infrastructure code to compile with DMD 2.052 (at least on x86 arch), while keeping backwards compatibility with D1. --- infrastructure/meta/Demangle.d | 170 ++++++++++++++--------------- infrastructure/meta/Nameof.d | 16 +-- infrastructure/pyd/class_wrap.d | 46 ++++---- infrastructure/pyd/def.d | 14 +-- infrastructure/pyd/exception.d | 18 +++- infrastructure/pyd/func_wrap.d | 4 +- infrastructure/pyd/lib_abstract.d | 28 ++++- infrastructure/pyd/make_object.d | 2 +- infrastructure/pyd/make_wrapper.d | 6 +- infrastructure/pyd/pydobject.d | 30 +++--- infrastructure/pyd/struct_wrap.d | 4 +- infrastructure/python/python.d | 172 +++++++++++++++--------------- 12 files changed, 270 insertions(+), 240 deletions(-) diff --git a/infrastructure/meta/Demangle.d b/infrastructure/meta/Demangle.d index 47307c6..bfad653 100644 --- a/infrastructure/meta/Demangle.d +++ b/infrastructure/meta/Demangle.d @@ -10,7 +10,7 @@ module meta.Demangle; /* Implementation is via pairs of metafunctions: - a 'demangle' metafunction, which returns a const char [], + a 'demangle' metafunction, which returns a const string, and a 'Consumed' metafunction, which returns an integer, the number of characters which are used. */ @@ -34,73 +34,73 @@ template demangleType(string str, MangledNameType wantQualifiedNames = MangledNa // There are only a few types where symbolnameof!(), qualifiednameof!() // make sense. static if (str[0]=='C' || str[0]=='S' || str[0]=='E' || str[0]=='T') - const char [] demangleType = prettyLname!(str[1..$], wantQualifiedNames); + const string demangleType = prettyLname!(str[1..$], wantQualifiedNames); else { static assert(0, "Demangle error: type '" ~ str ~ "' does not contain a qualified name"); } } else static if (str[0] == 'A') // dynamic array - const char [] demangleType = demangleType!(str[1..$], wantQualifiedNames) ~ "[]"; + const string demangleType = demangleType!(str[1..$], wantQualifiedNames) ~ "[]"; else static if (str[0] == 'H') // associative array - const char [] demangleType + const string demangleType = demangleType!(str[1+demangleTypeConsumed!(str[1..$])..$], wantQualifiedNames) ~ "[" ~ demangleType!(str[1..1+(demangleTypeConsumed!(str[1..$]))], wantQualifiedNames) ~ "]"; else static if (str[0] == 'G') // static array - const char [] demangleType + const string demangleType = demangleType!(str[1+countLeadingDigits!(str[1..$])..$], wantQualifiedNames) ~ "[" ~ str[1..1+countLeadingDigits!(str[1..$]) ] ~ "]"; else static if (str[0]=='C') - const char [] demangleType = "class " ~ prettyLname!(str[1..$], wantQualifiedNames); + const string demangleType = "class " ~ prettyLname!(str[1..$], wantQualifiedNames); else static if (str[0]=='S') - const char [] demangleType = "struct " ~ prettyLname!(str[1..$], wantQualifiedNames); + const string demangleType = "struct " ~ prettyLname!(str[1..$], wantQualifiedNames); else static if (str[0]=='E') - const char [] demangleType = "enum " ~ prettyLname!(str[1..$], wantQualifiedNames); + const string demangleType = "enum " ~ prettyLname!(str[1..$], wantQualifiedNames); else static if (str[0]=='T') - const char [] demangleType = "typedef " ~ prettyLname!(str[1..$], wantQualifiedNames); + const string demangleType = "typedef " ~ prettyLname!(str[1..$], wantQualifiedNames); else static if (str[0]=='D' && str.length>2 && isMangledFunction!(( str[1] )) ) // delegate - const char [] demangleType = demangleFunctionOrDelegate!(str[1..$], "delegate ", wantQualifiedNames); + const string demangleType = demangleFunctionOrDelegate!(str[1..$], "delegate ", wantQualifiedNames); else static if (str[0]=='P' && str.length>2 && isMangledFunction!(( str[1] )) ) // function pointer - const char [] demangleType = demangleFunctionOrDelegate!(str[1..$], "function ", wantQualifiedNames); + const string demangleType = demangleFunctionOrDelegate!(str[1..$], "function ", wantQualifiedNames); else static if (str[0]=='P') // only after we've dealt with function pointers - const char [] demangleType = demangleType!(str[1..$], wantQualifiedNames) ~ "*"; + const string demangleType = demangleType!(str[1..$], wantQualifiedNames) ~ "*"; else static if (str[0]=='F') - const char [] demangleType = demangleFunctionOrDelegate!(str, "", wantQualifiedNames); - else const char [] demangleType = demangleBasicType!(str); + const string demangleType = demangleFunctionOrDelegate!(str, "", wantQualifiedNames); + else const string demangleType = demangleBasicType!(str); } // split these off because they're numerous and simple // Note: For portability, could replace "v" with void.mangleof, etc. template demangleBasicType(string str) { - static if (str == "v") const char [] demangleBasicType = "void"; - else static if (str == "b") const char [] demangleBasicType = "bool"; + static if (str == "v") const string demangleBasicType = "void"; + else static if (str == "b") const string demangleBasicType = "bool"; // possibly a bug in the D name mangling algorithm? - else static if (str == "x") const char [] demangleBasicType = "bool"; + else static if (str == "x") const string demangleBasicType = "bool"; // integral types - else static if (str == "g") const char [] demangleBasicType = "byte"; - else static if (str == "h") const char [] demangleBasicType = "ubyte"; - else static if (str == "s") const char [] demangleBasicType = "short"; - else static if (str == "t") const char [] demangleBasicType = "ushort"; - else static if (str == "i") const char [] demangleBasicType = "int"; - else static if (str == "k") const char [] demangleBasicType = "uint"; - else static if (str == "l") const char [] demangleBasicType = "long"; - else static if (str == "m") const char [] demangleBasicType = "ulong"; + else static if (str == "g") const string demangleBasicType = "byte"; + else static if (str == "h") const string demangleBasicType = "ubyte"; + else static if (str == "s") const string demangleBasicType = "short"; + else static if (str == "t") const string demangleBasicType = "ushort"; + else static if (str == "i") const string demangleBasicType = "int"; + else static if (str == "k") const string demangleBasicType = "uint"; + else static if (str == "l") const string demangleBasicType = "long"; + else static if (str == "m") const string demangleBasicType = "ulong"; // floating point - else static if (str == "e") const char [] demangleBasicType = "real"; - else static if (str == "d") const char [] demangleBasicType = "double"; - else static if (str == "f") const char [] demangleBasicType = "float"; - - else static if (str == "j") const char [] demangleBasicType = "ireal"; - else static if (str == "p") const char [] demangleBasicType = "idouble"; - else static if (str == "o") const char [] demangleBasicType = "ifloat"; - - else static if (str == "c") const char [] demangleBasicType = "creal"; - else static if (str == "r") const char [] demangleBasicType = "cdouble"; - else static if (str == "q") const char [] demangleBasicType = "cfloat"; + else static if (str == "e") const string demangleBasicType = "real"; + else static if (str == "d") const string demangleBasicType = "double"; + else static if (str == "f") const string demangleBasicType = "float"; + + else static if (str == "j") const string demangleBasicType = "ireal"; + else static if (str == "p") const string demangleBasicType = "idouble"; + else static if (str == "o") const string demangleBasicType = "ifloat"; + + else static if (str == "c") const string demangleBasicType = "creal"; + else static if (str == "r") const string demangleBasicType = "cdouble"; + else static if (str == "q") const string demangleBasicType = "cfloat"; // Char types - else static if (str == "a") const char [] demangleBasicType = "char"; - else static if (str == "u") const char [] demangleBasicType = "wchar"; - else static if (str == "w") const char [] demangleBasicType = "dchar"; + else static if (str == "a") const string demangleBasicType = "char"; + else static if (str == "u") const string demangleBasicType = "wchar"; + else static if (str == "w") const string demangleBasicType = "dchar"; else static assert(0, "Demangle Error: '" ~ str ~ "' is not a recognised basic type"); } @@ -149,14 +149,14 @@ template countLeadingDigits(string str) template getLname(string str) { static if (str.length <= 9+1 || !beginsWithDigit!(str[1..$]) ) - const char [] getLname = str[1..(str[0]-'0' + 1)]; + const string getLname = str[1..(str[0]-'0' + 1)]; else static if (str.length <= 99+2 || !beginsWithDigit!(str[2..$]) ) - const char [] getLname = str[2..((str[0]-'0')*10 + str[1]-'0'+ 2)]; + const string getLname = str[2..((str[0]-'0')*10 + str[1]-'0'+ 2)]; else static if (str.length <= 999+3 || !beginsWithDigit!(str[3..$]) ) - const char [] getLname = + const string getLname = str[3..((str[0]-'0')*100 + (str[1]-'0')*10 + str[2]-'0' + 3)]; else - const char [] getLname = + const string getLname = str[4..((str[0]-'0')*1000 + (str[1]-'0')*100 + (str[2]-'0')*10 + (str[3]-'0') + 4)]; } @@ -165,15 +165,15 @@ template getLname(string str) template pretty_Dname(string str, int dotnameconsumed, MangledNameType wantQualifiedNames) { static if ( isMangledFunction!( (str[2+dotnameconsumed]))) { - const char [] pretty_Dname = pretty_Dfunction!(str, dotnameconsumed, + const string pretty_Dname = pretty_Dfunction!(str, dotnameconsumed, demangleParamListAndRetValConsumed!(str[3+dotnameconsumed..$]), wantQualifiedNames); } else { static if (wantQualifiedNames == MangledNameType.PrettyName) { - const char [] pretty_Dname = + const string pretty_Dname = demangleType!(str[2+dotnameconsumed..$], wantQualifiedNames) ~ " " ~ getQualifiedName!(str[2..$], wantQualifiedNames); } else { - const char [] pretty_Dname = getQualifiedName!(str[2..$], wantQualifiedNames); + const string pretty_Dname = getQualifiedName!(str[2..$], wantQualifiedNames); } } } @@ -184,19 +184,19 @@ template pretty_Dfunction(string str, int dotnameconsumed, int paramlistconsumed MangledNameType wantQualifiedNames) { static if (wantQualifiedNames == MangledNameType.PrettyName) { - const char [] pretty_Dfunction = + const string pretty_Dfunction = demangleFunctionOrDelegate!(str[2 + dotnameconsumed .. 3 + dotnameconsumed + paramlistconsumed], getQualifiedName!(str[2..2+dotnameconsumed], wantQualifiedNames), wantQualifiedNames) // BUG: This shouldn't be necessary, the string length is wrong somewhere ~ getQualifiedName!(str[3 + dotnameconsumed + paramlistconsumed .. $], wantQualifiedNames, "."); } else static if (wantQualifiedNames == MangledNameType.QualifiedName) { // Qualified name - const char [] pretty_Dfunction = getQualifiedName!(str[2..2+dotnameconsumed], wantQualifiedNames) + const string pretty_Dfunction = getQualifiedName!(str[2..2+dotnameconsumed], wantQualifiedNames) ~ getQualifiedName!(str[3 + dotnameconsumed + paramlistconsumed .. $], wantQualifiedNames, "."); } else { // symbol name static if (3 + dotnameconsumed + paramlistconsumed == str.length) - const char [] pretty_Dfunction = getQualifiedName!(str[2..2+dotnameconsumed], wantQualifiedNames); - else const char [] pretty_Dfunction = getQualifiedName!( + const string pretty_Dfunction = getQualifiedName!(str[2..2+dotnameconsumed], wantQualifiedNames); + else const string pretty_Dfunction = getQualifiedName!( str[3 + dotnameconsumed + paramlistconsumed .. $], wantQualifiedNames); } } @@ -213,19 +213,19 @@ template prettyLname(string str, MangledNameType wantQualifiedNames) { static if (str.length>3 && str[0..3] == "__T") // Template instance name static if (wantQualifiedNames == MangledNameType.PrettyName) { - const char [] prettyLname = + const string prettyLname = prettyLname!(str[3..$], wantQualifiedNames) ~ "!(" ~ prettyTemplateArgList!(str[3+getQualifiedNameConsumed!(str[3..$])..$], wantQualifiedNames) ~ ")"; } else { - const char [] prettyLname = + const string prettyLname = prettyLname!(str[3..$], wantQualifiedNames); } else static if (str.length>2 && str[0..2] == "_D") { - const char [] prettyLname = pretty_Dname!(str, getQualifiedNameConsumed!(str[2..$]), wantQualifiedNames); + const string prettyLname = pretty_Dname!(str, getQualifiedNameConsumed!(str[2..$]), wantQualifiedNames); } else static if ( beginsWithDigit!( str ) ) - const char [] prettyLname = getQualifiedName!(str[0..getQualifiedNameConsumed!(str)], wantQualifiedNames); - else const char [] prettyLname = str; + const string prettyLname = getQualifiedName!(str[0..getQualifiedNameConsumed!(str)], wantQualifiedNames); + else const string prettyLname = str; } // str must start with an lname: first chars give the length @@ -246,24 +246,24 @@ template getLnameConsumed(string str) template getQualifiedName(string str, MangledNameType wantQualifiedNames, string dotstr = "") { - static if (str.length==0) const char [] getQualifiedName=""; + static if (str.length==0) const string getQualifiedName=""; // else static if (str.length>2 && str[0]=='_' && str[1]=='D') -// const char [] getDotName = getQualifiedName!(str[2..$], wantQualifiedNames); +// const string getDotName = getQualifiedName!(str[2..$], wantQualifiedNames); else { static assert (beginsWithDigit!(str)); static if ( getLnameConsumed!(str) < str.length && beginsWithDigit!(str[getLnameConsumed!(str)..$]) ) { static if (wantQualifiedNames == MangledNameType.SymbolName) { // For symbol names, only display the last symbol - const char [] getQualifiedName = + const string getQualifiedName = getQualifiedName!(str[getLnameConsumed!(str) .. $], wantQualifiedNames, ""); } else { // Qualified and pretty names display everything - const char [] getQualifiedName = dotstr + const string getQualifiedName = dotstr ~ prettyLname!(getLname!(str), wantQualifiedNames) ~ getQualifiedName!(str[getLnameConsumed!(str) .. $], wantQualifiedNames, "."); } } else { - const char [] getQualifiedName = dotstr ~ prettyLname!(getLname!(str), wantQualifiedNames); + const string getQualifiedName = dotstr ~ prettyLname!(getLname!(str), wantQualifiedNames); } } } @@ -291,7 +291,7 @@ template getQualifiedNameConsumed (string str) */ template demangleFunctionOrDelegate(string str, string funcOrDelegStr, MangledNameType wantQualifiedNames) { - const char [] demangleFunctionOrDelegate = demangleExtern!(( str[0] )) + const string demangleFunctionOrDelegate = demangleExtern!(( str[0] )) ~ demangleReturnValue!(str[1..$], wantQualifiedNames) ~ " " ~ funcOrDelegStr ~ "(" ~ demangleParamList!(str[1..1+demangleParamListAndRetValConsumed!(str[1..$])], wantQualifiedNames) @@ -303,12 +303,12 @@ template demangleFunctionOrDelegate(string str, string funcOrDelegStr, MangledNa template demangleFunctionParamType(string str, MangledNameType wantQualifiedNames) { static if (str[0]=='L') - const char [] demangleFunctionParamType = "lazy " ~ demangleType!(str[1..$], wantQualifiedNames); + const string demangleFunctionParamType = "lazy " ~ demangleType!(str[1..$], wantQualifiedNames); else static if (str[0]=='K') - const char [] demangleFunctionParamType = "inout " ~ demangleType!(str[1..$], wantQualifiedNames); + const string demangleFunctionParamType = "inout " ~ demangleType!(str[1..$], wantQualifiedNames); else static if (str[0]=='J') - const char [] demangleFunctionParamType = "out " ~ demangleType!(str[1..$], wantQualifiedNames); - else const char [] demangleFunctionParamType = demangleType!(str, wantQualifiedNames); + const string demangleFunctionParamType = "out " ~ demangleType!(str[1..$], wantQualifiedNames); + else const string demangleFunctionParamType = demangleType!(str, wantQualifiedNames); } // Deal with 'out' and 'inout' parameters @@ -327,11 +327,11 @@ template isMangledFunction(char c) template demangleExtern(char c) { - static if (c=='F') const char [] demangleExtern = ""; - else static if (c=='U') const char [] demangleExtern = "extern (C) "; - else static if (c=='W') const char [] demangleExtern = "extern (Windows) "; - else static if (c=='V') const char [] demangleExtern = "extern (Pascal) "; - else static if (c=='R') const char [] demangleExtern = "extern (C++) "; + static if (c=='F') const string demangleExtern = ""; + else static if (c=='U') const string demangleExtern = "extern (C) "; + else static if (c=='W') const string demangleExtern = "extern (Windows) "; + else static if (c=='V') const string demangleExtern = "extern (Pascal) "; + else static if (c=='R') const string demangleExtern = "extern (C++) "; else static assert(0, "Unrecognized extern function."); } @@ -342,20 +342,20 @@ template demangleReturnValue(string str, MangledNameType wantQualifiedNames) static assert(str.length>=1, "Demangle error(Function): No return value found"); static if (str[0]=='Z' || str[0]=='Y' || str[0]=='X') const char[] demangleReturnValue = demangleType!(str[1..$], wantQualifiedNames); - else const char [] demangleReturnValue = demangleReturnValue!(str[demangleFunctionParamTypeConsumed!(str)..$], wantQualifiedNames); + else const string demangleReturnValue = demangleReturnValue!(str[demangleFunctionParamTypeConsumed!(str)..$], wantQualifiedNames); } // Stop when we get to the return value template demangleParamList(string str, MangledNameType wantQualifiedNames, string commastr = "") { static if (str[0] == 'Z') - const char [] demangleParamList = ""; + const string demangleParamList = ""; else static if (str[0] == 'Y') - const char [] demangleParamList = commastr ~ "..."; + const string demangleParamList = commastr ~ "..."; else static if (str[0]=='X') // lazy ... const char[] demangleParamList = commastr ~ "..."; else - const char [] demangleParamList = commastr ~ + const string demangleParamList = commastr ~ demangleFunctionParamType!(str[0..demangleFunctionParamTypeConsumed!(str)], wantQualifiedNames) ~ demangleParamList!(str[demangleFunctionParamTypeConsumed!(str)..$], wantQualifiedNames, ", "); } @@ -388,25 +388,25 @@ template templateValueArgConsumed(string str) // pretty-print a template value argument. template prettyValueArg(string str) { - static if (str[0]=='n') const char [] prettyValueArg = "null"; - else static if (beginsWithDigit!(str)) const char [] prettyValueArg = str; - else static if ( str[0]=='N') const char [] prettyValueArg = "-" ~ str[1..$]; - else static if ( str[0]=='e') const char [] prettyValueArg = "0x" ~ str[1..$]; - else static if ( str[0]=='c') const char [] prettyValueArg = "0x" ~ str[1..22] ~ " + 0x" ~ str[21..41] ~ "i"; - else const char [] prettyValueArg = "Value arg {" ~ str[0..$] ~ "}"; + static if (str[0]=='n') const string prettyValueArg = "null"; + else static if (beginsWithDigit!(str)) const string prettyValueArg = str; + else static if ( str[0]=='N') const string prettyValueArg = "-" ~ str[1..$]; + else static if ( str[0]=='e') const string prettyValueArg = "0x" ~ str[1..$]; + else static if ( str[0]=='c') const string prettyValueArg = "0x" ~ str[1..22] ~ " + 0x" ~ str[21..41] ~ "i"; + else const string prettyValueArg = "Value arg {" ~ str[0..$] ~ "}"; } // Pretty-print a template argument template prettyTemplateArg(string str, MangledNameType wantQualifiedNames) { static if (str[0]=='S') // symbol name - const char [] prettyTemplateArg = prettyLname!(str[1..$], wantQualifiedNames); + const string prettyTemplateArg = prettyLname!(str[1..$], wantQualifiedNames); else static if (str[0]=='V') // value - const char [] prettyTemplateArg = + const string prettyTemplateArg = demangleType!(str[1..1+demangleTypeConsumed!(str[1..$])], wantQualifiedNames) ~ " = " ~ prettyValueArg!(str[1+demangleTypeConsumed!(str[1..$])..$]); else static if (str[0]=='T') // type - const char [] prettyTemplateArg = demangleType!(str[1..$], wantQualifiedNames); + const string prettyTemplateArg = demangleType!(str[1..$], wantQualifiedNames); else static assert(0, "Unrecognised template argument type: {" ~ str ~ "}"); } @@ -429,7 +429,7 @@ template prettyTemplateArgList(string str, MangledNameType wantQualifiedNames, s static if (str[0]=='Z') const char[] prettyTemplateArgList = ""; else - const char [] prettyTemplateArgList = commastr + const string prettyTemplateArgList = commastr ~ prettyTemplateArg!(str[0..templateArgConsumed!(str)], wantQualifiedNames) ~ prettyTemplateArgList!(str[templateArgConsumed!(str)..$], wantQualifiedNames, ", "); } @@ -468,7 +468,7 @@ debug(UnitTest){ private { -const char [] THISFILE = "meta.Demangle"; +const string THISFILE = "meta.Demangle"; ireal SomeFunc(ushort u) { return -3i; } idouble SomeFunc2(inout ushort u, ubyte w) { return -3i; } diff --git a/infrastructure/meta/Nameof.d b/infrastructure/meta/Nameof.d index 25d3478..5484f1d 100644 --- a/infrastructure/meta/Nameof.d +++ b/infrastructure/meta/Nameof.d @@ -42,7 +42,7 @@ private { // We will get the .mangleof for a pointer to this function pointer. template rawmanglednameof(alias A) { - const char [] rawmanglednameof = + const string rawmanglednameof = typeof(&outer!(A)).mangleof; } @@ -90,10 +90,10 @@ template manglednameof(alias A) { static if (rawmanglednameof!(A).length - pointerstartlength <= 100 + 1) { // the length of the template argument requires 2 characters - const char [] manglednameof = + const string manglednameof = rawmanglednameof!(A)[ pointerstartlength + 2 .. $ - pointerendlength]; } else - const char [] manglednameof = + const string manglednameof = rawmanglednameof!(A)[ pointerstartlength + 3 .. $ - pointerendlength]; } @@ -104,7 +104,7 @@ template manglednameof(alias A) */ template prettynameof(alias A) { - const char [] prettynameof = prettyTemplateArg!(manglednameof!(A), MangledNameType.PrettyName); + const string prettynameof = prettyTemplateArg!(manglednameof!(A), MangledNameType.PrettyName); } /** Convert any D type to a human-readable string literal @@ -113,7 +113,7 @@ template prettynameof(alias A) */ template prettytypeof(A) { - const char [] prettytypeof = demangleType!(A.mangleof, MangledNameType.PrettyName); + const string prettytypeof = demangleType!(A.mangleof, MangledNameType.PrettyName); } /** @@ -125,7 +125,7 @@ template prettytypeof(A) */ template qualifiednameof(alias A) { - const char [] qualifiednameof = prettyTemplateArg!(manglednameof!(A), MangledNameType.QualifiedName); + const string qualifiednameof = prettyTemplateArg!(manglednameof!(A), MangledNameType.QualifiedName); } /** @@ -135,7 +135,7 @@ template qualifiednameof(alias A) */ template symbolnameof(alias A) { - const char [] symbolnameof = prettyTemplateArg!(manglednameof!(A), MangledNameType.SymbolName); + const string symbolnameof = prettyTemplateArg!(manglednameof!(A), MangledNameType.SymbolName); } //---------------------------------------------- @@ -173,7 +173,7 @@ enum SomeEnum { ABC = 2 } SomeEnum SomeInt; // remove the ".d" from the end -const char [] THISFILE = "meta.Nameof"; +const string THISFILE = "meta.Nameof"; static assert( prettytypeof!(real) == "real"); static assert( prettytypeof!(OuterClass.SomeClass) == "class " ~ THISFILE ~".OuterClass.SomeClass"); diff --git a/infrastructure/pyd/class_wrap.d b/infrastructure/pyd/class_wrap.d index 6df4864..98c03e1 100644 --- a/infrastructure/pyd/class_wrap.d +++ b/infrastructure/pyd/class_wrap.d @@ -43,7 +43,7 @@ import pyd.lib_abstract : ReturnType, minArgs, objToStr, - ToString + toStringNow ; //import meta.Default; @@ -314,10 +314,10 @@ template _Def(alias fn, /*string _realname,*/ string name, fn_t/+, uint MIN_ARGS pragma(msg, "class.def: " ~ name); static PyMethodDef empty = { null, null, 0, null }; alias wrapped_method_list!(T) list; - list[length-1].ml_name = (name ~ \0).ptr; + list[length-1].ml_name = (name ~ "\0").ptr; list[length-1].ml_meth = &method_wrap!(T, fn, fn_t).func; list[length-1].ml_flags = METH_VARARGS; - list[length-1].ml_doc = (docstring~\0).ptr; + list[length-1].ml_doc = (docstring~"\0").ptr; list ~= empty; // It's possible that appending the empty item invalidated the // pointer in the type struct, so we renew it here. @@ -325,9 +325,9 @@ template _Def(alias fn, /*string _realname,*/ string name, fn_t/+, uint MIN_ARGS } template shim(uint i) { const char[] shim = - " alias Params["~ToString!(i)~"] __pyd_p"~ToString!(i)~";\n" - " ReturnType!(__pyd_p"~ToString!(i)~".func_t) "~realname~"(ParameterTypeTuple!(__pyd_p"~ToString!(i)~".func_t) t) {\n" - " return __pyd_get_overload!(\""~realname~"\", __pyd_p"~ToString!(i)~".func_t).func(\""~name~"\", t);\n" + " alias Params["~toStringNow!(i)~"] __pyd_p"~toStringNow!(i)~";\n" + " ReturnType!(__pyd_p"~toStringNow!(i)~".func_t) "~realname~"(ParameterTypeTuple!(__pyd_p"~toStringNow!(i)~".func_t) t) {\n" + " return __pyd_get_overload!(\""~realname~"\", __pyd_p"~toStringNow!(i)~".func_t).func(\""~name~"\", t);\n" " }\n"; } } @@ -373,10 +373,10 @@ template _StaticDef(alias fn,/+ string _realname,+/ string name, fn_t, uint MIN_ pragma(msg, "class.static_def: " ~ name); static PyMethodDef empty = { null, null, 0, null }; alias wrapped_method_list!(T) list; - list[length-1].ml_name = (name ~ \0).ptr; + list[length-1].ml_name = (name ~ "\0").ptr; list[length-1].ml_meth = &function_wrap!(fn, MIN_ARGS, fn_t).func; list[length-1].ml_flags = METH_VARARGS | METH_STATIC; - list[length-1].ml_doc = (docstring~\0).ptr; + list[length-1].ml_doc = (docstring~"\0").ptr; list ~= empty; wrapped_class_type!(T).tp_methods = list; } @@ -427,14 +427,14 @@ template _Property(alias fn, string _realname, string name, bool RO, string docs static void call(T) () { pragma(msg, "class.prop: " ~ name); static PyGetSetDef empty = { null, null, null, null, null }; - wrapped_prop_list!(T)[length-1].name = (name ~ \0).ptr; + wrapped_prop_list!(T)[length-1].name = (name ~ "\0").ptr; wrapped_prop_list!(T)[length-1].get = &wrapped_get!(T, fn).func; static if (!RO) { wrapped_prop_list!(T)[length-1].set = &wrapped_set!(T, fn).func; } - wrapped_prop_list!(T)[length-1].doc = (docstring~\0).ptr; + wrapped_prop_list!(T)[length-1].doc = (docstring~"\0").ptr; wrapped_prop_list!(T)[length-1].closure = null; wrapped_prop_list!(T) ~= empty; // It's possible that appending the empty item invalidated the @@ -447,16 +447,16 @@ template _Property(alias fn, string _realname, string name, bool RO, string docs const char[] shim_setter = ""; } else { const char[] shim_setter = - " ReturnType!(__pyd_p"~ToString!(i)~".set_t) "~_realname~"(ParameterTypeTuple!(__pyd_p"~ToString!(i)~".set_t) t) {\n" - " return __pyd_get_overload!(\""~_realname~"\", __pyd_p"~ToString!(i)~".set_t).func(\""~name~"\", t);\n" + " ReturnType!(__pyd_p"~toStringNow!(i)~".set_t) "~_realname~"(ParameterTypeTuple!(__pyd_p"~toStringNow!(i)~".set_t) t) {\n" + " return __pyd_get_overload!(\""~_realname~"\", __pyd_p"~toStringNow!(i)~".set_t).func(\""~name~"\", t);\n" " }\n"; } } template shim(uint i) { const char[] shim = - " alias Params["~ToString!(i)~"] __pyd_p"~ToString!(i)~";\n" - " ReturnType!(__pyd_p"~ToString!(i)~".get_t) "~_realname~"() {\n" - " return __pyd_get_overload!(\""~_realname~"\", __pyd_p"~ToString!(i)~".get_t).func(\""~name~"\");\n" + " alias Params["~toStringNow!(i)~"] __pyd_p"~toStringNow!(i)~";\n" + " ReturnType!(__pyd_p"~toStringNow!(i)~".get_t) "~_realname~"() {\n" + " return __pyd_get_overload!(\""~_realname~"\", __pyd_p"~toStringNow!(i)~".get_t).func(\""~name~"\");\n" " }\n" ~ shim_setter!(i); } @@ -502,7 +502,7 @@ struct Init(C ...) { template shim_impl(uint i, uint c=0) { static if (c < ctors.length) { const char[] shim_impl = - " this(ParameterTypeTuple!(__pyd_c"~ToString!(i)~"["~ToString!(c)~"]) t) {\n" + " this(ParameterTypeTuple!(__pyd_c"~toStringNow!(i)~"["~toStringNow!(c)~"]) t) {\n" " super(t);\n" " }\n" ~ shim_impl!(i, c+1); } else { @@ -514,8 +514,8 @@ struct Init(C ...) { } template shim(uint i) { const char[] shim = - " alias Params["~ToString!(i)~"] __pyd_p"~ToString!(i)~";\n" - " alias __pyd_p"~ToString!(i)~".ctors __pyd_c"~ToString!(i)~";\n"~ + " alias Params["~toStringNow!(i)~"] __pyd_p"~toStringNow!(i)~";\n" + " alias __pyd_p"~toStringNow!(i)~".ctors __pyd_c"~toStringNow!(i)~";\n"~ shim_impl!(i); } } @@ -554,10 +554,10 @@ struct AltIter(alias fn, string name = symbolnameof!(fn), iter_t = ParameterType static PyMethodDef empty = { null, null, 0, null }; alias wrapped_method_list!(T) list; PydStackContext_Ready(); - list[length-1].ml_name = name ~ \0; + list[length-1].ml_name = name ~ "\0"; list[length-1].ml_meth = cast(PyCFunction)&wrapped_iter!(T, fn, int function(iter_t)).iter; list[length-1].ml_flags = METH_VARARGS; - list[length-1].ml_doc = "";//(docstring ~ \0).ptr; + list[length-1].ml_doc = "";//(docstring ~ "\0").ptr; list ~= empty; // It's possible that appending the empty item invalidated the // pointer in the type struct, so we renew it here. @@ -617,11 +617,11 @@ void wrap_class(string docstring="", string modulename="") { ////////////////// type.ob_type = python.PyType_Type_p(); type.tp_basicsize = (wrapped_class_object!(T)).sizeof; - type.tp_doc = (docstring ~ \0).ptr; + type.tp_doc = (docstring ~ "\0").ptr; type.tp_flags = python.Py_TPFLAGS_DEFAULT | python.Py_TPFLAGS_BASETYPE; //type.tp_repr = &wrapped_repr!(T).repr; type.tp_methods = wrapped_method_list!(T).ptr; - type.tp_name = (module_name ~ "." ~ name ~ \0).ptr; + type.tp_name = (module_name ~ "." ~ name ~ "\0").ptr; ///////////////// // Inheritance // @@ -698,7 +698,7 @@ void wrap_class(string docstring="", string modulename="") { } //writefln("after Ready: tp_init is %s", type.tp_init); python.Py_INCREF(cast(PyObject*)&type); - python.PyModule_AddObject(Pyd_Module_p(modulename), (name~\0).ptr, cast(PyObject*)&type); + python.PyModule_AddObject(Pyd_Module_p(modulename), (name~"\0").ptr, cast(PyObject*)&type); is_wrapped!(T) = true; static if (is(T == class)) { diff --git a/infrastructure/pyd/def.d b/infrastructure/pyd/def.d index ed533be..54bc973 100644 --- a/infrastructure/pyd/def.d +++ b/infrastructure/pyd/def.d @@ -84,6 +84,7 @@ PyObject* Pyd_Module_p(string modulename="") { *>>> print testdll.foo(20) *It's greater than 10!) */ + void def(alias fn, string name = symbolnameof!(fn), fn_t=typeof(&fn), uint MIN_ARGS = minArgs!(fn, fn_t)) (string docstring="") { def!("", fn, name, fn_t, MIN_ARGS)(docstring); } @@ -94,10 +95,11 @@ void def(string modulename, alias fn, string name = symbolnameof!(fn), fn_t=type ready_module_methods(modulename); PyMethodDef[]* list = &module_methods[modulename]; - (*list)[length-1].ml_name = (name ~ \0).ptr; - (*list)[length-1].ml_meth = &function_wrap!(fn, MIN_ARGS, fn_t).func; - (*list)[length-1].ml_flags = METH_VARARGS; - (*list)[length-1].ml_doc = (docstring ~ \0).ptr; + // was: length-1 + (*list)[$-1].ml_name = (name ~ "\0").ptr; + (*list)[$-1].ml_meth = &function_wrap!(fn, MIN_ARGS, fn_t).func; + (*list)[$-1].ml_flags = METH_VARARGS; + (*list)[$-1].ml_doc = (docstring ~ "\0").ptr; (*list) ~= empty; } @@ -110,7 +112,7 @@ PyObject* module_init(string docstring="") { //_loadPythonSupport(); string name = pyd_module_name; ready_module_methods(""); - pyd_modules[""] = Py_InitModule3((name ~ \0).ptr, module_methods[""].ptr, (docstring ~ \0).ptr); + pyd_modules[""] = Py_InitModule3((name ~ "\0").ptr, module_methods[""].ptr, (docstring ~ "\0").ptr); return pyd_modules[""]; } @@ -119,7 +121,7 @@ PyObject* module_init(string docstring="") { */ PyObject* add_module(string name, string docstring="") { ready_module_methods(name); - pyd_modules[name] = Py_InitModule3((name ~ \0).ptr, module_methods[name].ptr, (docstring ~ \0).ptr); + pyd_modules[name] = Py_InitModule3((name ~ "\0").ptr, module_methods[name].ptr, (docstring ~ "\0").ptr); return pyd_modules[name]; } diff --git a/infrastructure/pyd/exception.d b/infrastructure/pyd/exception.d index 6acc7da..5484d19 100644 --- a/infrastructure/pyd/exception.d +++ b/infrastructure/pyd/exception.d @@ -29,6 +29,9 @@ import pyd.lib_abstract : ; //import meta.Nameof; //import std.string; +version (D_Version2) { + import std.conv : to; +} /** * This function first checks if a Python exception is set, and then (if one @@ -69,6 +72,9 @@ T error_code(T) () { *}) */ T exception_catcher(T) (T delegate() dg) { + version (D_Version2) {} else { + alias Object Throwable; + } try { return dg(); } @@ -81,12 +87,12 @@ T exception_catcher(T) (T delegate() dg) { // A D exception was raised and should be translated into a meaningful // Python exception. catch (Exception e) { - PyErr_SetString(PyExc_RuntimeError, ("D Exception: " ~ e.classinfo.name ~ ": " ~ e.msg ~ \0).ptr); + PyErr_SetString(PyExc_RuntimeError, ("D Exception: " ~ e.classinfo.name ~ ": " ~ e.msg ~ "\0").ptr); return error_code!(T)(); } // Some other D object was thrown. Deal with it. - catch (Object o) { - PyErr_SetString(PyExc_RuntimeError, ("thrown D Object: " ~ o.classinfo.name ~ ": " ~ objToStr(o) ~ \0).ptr); + catch (Throwable o) { + PyErr_SetString(PyExc_RuntimeError, ("thrown D Object: " ~ o.classinfo.name ~ ": " ~ objToStr(o) ~ "\0").ptr); return error_code!(T)(); } } @@ -103,7 +109,11 @@ protected: PyObject* m_type, m_value, m_trace; public: this(PyObject* type, PyObject* value, PyObject* traceback) { - super(.toString(PyString_AsString(value))); + version (D_Version2) { + super(.to!(string)(PyString_AsString(value))); + } else { + super(.toString(PyString_AsString(value))); + } m_type = type; m_value = value; m_trace = traceback; diff --git a/infrastructure/pyd/func_wrap.d b/infrastructure/pyd/func_wrap.d index 075487d..1fa48b9 100644 --- a/infrastructure/pyd/func_wrap.d +++ b/infrastructure/pyd/func_wrap.d @@ -67,7 +67,7 @@ void setWrongArgsError(int gotArgs, uint minArgs, uint maxArgs, string funcName= } char[] argStr(int args) { - char[] temp = toString(args) ~ " argument"; + char[] temp = cast(char[])(toString(args) ~ " argument"); if (args > 1) { temp ~= "s"; } @@ -88,7 +88,7 @@ void setWrongArgsError(int gotArgs, uint minArgs, uint maxArgs, string funcName= } str ~= " (" ~ toString(gotArgs) ~ " given)"; - PyErr_SetString(PyExc_TypeError, (str ~ \0).ptr); + PyErr_SetString(PyExc_TypeError, (str ~ "\0").ptr); } // Calls callable alias fn with PyTuple args. diff --git a/infrastructure/pyd/lib_abstract.d b/infrastructure/pyd/lib_abstract.d index eb2c43e..7e0baff 100644 --- a/infrastructure/pyd/lib_abstract.d +++ b/infrastructure/pyd/lib_abstract.d @@ -44,22 +44,40 @@ version (Tango) { string objToStr(Object o) { return o.toString(); } + /* version (D_Version2) { // D1 issues? template symbolnameof(alias symbol) { static if (is(typeof(symbol) == function)) { - const char[] symbolnameof = (&symbol).stringof[2 .. $]; + string symbolnameof = (&symbol).stringof[2 .. $]; } else { - const char[] symbolnameof = symbol.stringof; + string symbolnameof = symbol.stringof; } } } else { public import meta.Nameof : symbolnameof; - } + }*/ + + public import meta.Nameof : symbolnameof; public import meta.Nameof : /*symbolnameof,*/ prettytypeof, prettynameof; - public import std.string : toString; + version (D_Version2) { + public import std.conv : to; + // provide a "wrapper" using the old toString + auto toString(T)(T obj) { + return to!(string)(obj); + } + } else { + // deprecated in D2 + public import std.string : toString; + } public import std.traits : ParameterTypeTuple, ReturnType; public import meta.Default : minArgs; - public import std.metastrings : ToString; + version (D_Version2) { + public import std.metastrings : toStringNow; + } else { + // deprecated in D2 + public import std.metastrings : ToString; + alias ToString toStringNow; + } } diff --git a/infrastructure/pyd/make_object.d b/infrastructure/pyd/make_object.d index 5d4e847..f961df5 100644 --- a/infrastructure/pyd/make_object.d +++ b/infrastructure/pyd/make_object.d @@ -152,7 +152,7 @@ PyObject* _py(T) (T t) { } else static if (is(T : cdouble)) { return PyComplex_FromDoubles(t.re, t.im); } else static if (is(T : string)) { - return PyString_FromString((t ~ \0).ptr); + return PyString_FromString((t ~ "\0").ptr); } else static if (is(T : wchar[])) { return PyUnicode_FromWideChar(t, t.length); // Converts any array (static or dynamic) to a Python list diff --git a/infrastructure/pyd/make_wrapper.d b/infrastructure/pyd/make_wrapper.d index f588eff..be833a4 100644 --- a/infrastructure/pyd/make_wrapper.d +++ b/infrastructure/pyd/make_wrapper.d @@ -30,7 +30,7 @@ import pyd.func_wrap; import pyd.lib_abstract : ReturnType, ParameterTypeTuple, - ToString + toStringNow ; template T(A ...) { @@ -101,7 +101,7 @@ template OverloadShim() { ReturnType!(fn_t) func(T ...) (char[] name, T t) { PyObject* _pyobj = this.__pyd_get_pyobj(); if (_pyobj !is null) { - PyObject* method = PyObject_GetAttrString(_pyobj, (name ~ \0).ptr); + PyObject* method = PyObject_GetAttrString(_pyobj, (name ~ "\0").ptr); if (method is null) handle_exception(); auto pydg = PydCallable_AsDelegate!(fn_to_dg!(fn_t))(method); Py_DECREF(method); @@ -120,7 +120,7 @@ template OverloadShim() { // If this object's type is not the wrapped class's type (that is, // if this object is actually a Python subclass of the wrapped // class), then call the Python object. - PyObject* method = PyObject_GetAttrString(_pyobj, (name ~ \0).ptr); + PyObject* method = PyObject_GetAttrString(_pyobj, (name ~ "\0").ptr); if (method is null) handle_exception(); auto pydg = PydCallable_AsDelegate!(fn_to_dg!(fn_t))(method); Py_DECREF(method); diff --git a/infrastructure/pyd/pydobject.d b/infrastructure/pyd/pydobject.d index 1bf8cf8..e92e92e 100644 --- a/infrastructure/pyd/pydobject.d +++ b/infrastructure/pyd/pydobject.d @@ -90,7 +90,7 @@ public: /// Same as _hasattr(this, attr_name) in Python. bool hasattr(char[] attr_name) { - return PyObject_HasAttrString(m_ptr, (attr_name ~ \0).ptr) == 1; + return PyObject_HasAttrString(m_ptr, (attr_name ~ "\0").ptr) == 1; } /// Same as _hasattr(this, attr_name) in Python. @@ -100,7 +100,7 @@ public: /// Same as _getattr(this, attr_name) in Python. PydObject getattr(char[] attr_name) { - return new PydObject(PyObject_GetAttrString(m_ptr, (attr_name ~ \0).ptr)); + return new PydObject(PyObject_GetAttrString(m_ptr, (attr_name ~ "\0").ptr)); } /// Same as _getattr(this, attr_name) in Python. @@ -112,7 +112,7 @@ public: * Same as _setattr(this, attr_name, v) in Python. */ void setattr(char[] attr_name, PydObject v) { - if (PyObject_SetAttrString(m_ptr, (attr_name ~ \0).ptr, v.m_ptr) == -1) + if (PyObject_SetAttrString(m_ptr, (attr_name ~ "\0").ptr, v.m_ptr) == -1) handle_exception(); } @@ -128,7 +128,7 @@ public: * Same as del this.attr_name in Python. */ void delattr(char[] attr_name) { - if (PyObject_DelAttrString(m_ptr, (attr_name ~ \0).ptr) == -1) + if (PyObject_DelAttrString(m_ptr, (attr_name ~ "\0").ptr) == -1) handle_exception(); } @@ -176,8 +176,8 @@ public: } } else { /// Allows use of PydObject in writef via %s - char[] toString() { - return d_type!(char[])(m_ptr); + string toString() { + return d_type!(string)(m_ptr); } } @@ -245,7 +245,7 @@ public: */ PydObject methodUnpack(char[] name, PydObject args=null) { // Get the method PydObject - PyObject* m = PyObject_GetAttrString(m_ptr, (name ~ \0).ptr); + PyObject* m = PyObject_GetAttrString(m_ptr, (name ~ "\0").ptr); PyObject* result; // If this method doesn't exist (or other error), throw exception if (m is null) handle_exception(); @@ -258,7 +258,7 @@ public: PydObject methodUnpack(char[] name, PydObject args, PydObject kw) { // Get the method PydObject - PyObject* m = PyObject_GetAttrString(m_ptr, (name ~ \0).ptr); + PyObject* m = PyObject_GetAttrString(m_ptr, (name ~ "\0").ptr); PyObject* result; // If this method doesn't exist (or other error), throw exception. if (m is null) handle_exception(); @@ -273,7 +273,7 @@ public: * Calls a method of the object with any convertible D items. */ PydObject method(T ...) (char[] name, T t) { - PyObject* mthd = PyObject_GetAttrString(m_ptr, (name ~ \0).ptr); + PyObject* mthd = PyObject_GetAttrString(m_ptr, (name ~ "\0").ptr); if (mthd is null) handle_exception(); PyObject* tuple = PyTuple_FromItems(t); if (tuple is null) { @@ -346,7 +346,7 @@ public: * mappings. */ PydObject opIndex(char[] key) { - return new PydObject(PyMapping_GetItemString(m_ptr, (key ~ \0).ptr)); + return new PydObject(PyMapping_GetItemString(m_ptr, (key ~ "\0").ptr)); } /// Equivalent to o[_i] in Python; usually only makes sense for sequences. PydObject opIndex(int i) { @@ -363,7 +363,7 @@ public: * mappings. */ void opIndexAssign(PydObject value, char[] key) { - if (PyMapping_SetItemString(m_ptr, (key ~ \0).ptr, value.m_ptr) == -1) + if (PyMapping_SetItemString(m_ptr, (key ~ "\0").ptr, value.m_ptr) == -1) handle_exception(); } /** @@ -385,7 +385,7 @@ public: * mappings. */ void delItem(char[] key) { - if (PyMapping_DelItemString(m_ptr, (key ~ \0).ptr) == -1) + if (PyMapping_DelItemString(m_ptr, (key ~ "\0").ptr) == -1) handle_exception(); } /** @@ -436,7 +436,7 @@ public: * sequence, keys in a dictionary, or some other iteration defined for the * PydObject's type. */ - int opApply(int delegate(inout PydObject) dg) { + int opApply(int delegate(ref PydObject) dg) { PyObject* iterator = PyObject_GetIter(m_ptr); PyObject* item; int result = 0; @@ -469,7 +469,7 @@ public: * with the exception of modifying values. Adding or removing items while * iterating through it is an especially bad idea. */ - int opApply(int delegate(inout PydObject, inout PydObject) dg) { + int opApply(int delegate(ref PydObject, ref PydObject) dg) { PyObject* key, value; version(Python_2_5_Or_Later) { Py_ssize_t pos = 0; @@ -757,7 +757,7 @@ public: } /// Same as opIn_r bool hasKey(char[] key) { - int result = PyMapping_HasKeyString(m_ptr, (key ~ \0).ptr); + int result = PyMapping_HasKeyString(m_ptr, (key ~ "\0").ptr); if (result == -1) handle_exception(); return result == 1; } diff --git a/infrastructure/pyd/struct_wrap.d b/infrastructure/pyd/struct_wrap.d index a20d97d..e54b89c 100644 --- a/infrastructure/pyd/struct_wrap.d +++ b/infrastructure/pyd/struct_wrap.d @@ -77,10 +77,10 @@ template _Member(string realname, string name, string docstring) { pragma(msg, "struct.member: " ~ name); static PyGetSetDef empty = {null, null, null, null, null}; alias wrapped_prop_list!(T) list; - list[length-1].name = (name ~ \0).ptr; + list[length-1].name = (name ~ "\0").ptr; list[length-1].get = &wrapped_member!(T, realname).get; list[length-1].set = &wrapped_member!(T, realname).set; - list[length-1].doc = (docstring~\0).ptr; + list[length-1].doc = (docstring~"\0").ptr; list[length-1].closure = null; list ~= empty; wrapped_class_type!(T).tp_getset = list.ptr; diff --git a/infrastructure/python/python.d b/infrastructure/python/python.d index 10947a8..266f5ff 100644 --- a/infrastructure/python/python.d +++ b/infrastructure/python/python.d @@ -124,36 +124,36 @@ extern (C) { mixin PyObject_VAR_HEAD; } - alias PyObject * (*unaryfunc)(PyObject *); - alias PyObject * (*binaryfunc)(PyObject *, PyObject *); - alias PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *); - alias int (*inquiry)(PyObject *); - alias Py_ssize_t (*lenfunc)(PyObject *); - alias int (*coercion)(PyObject **, PyObject **); - alias PyObject *(*intargfunc)(PyObject *, int); - alias PyObject *(*intintargfunc)(PyObject *, int, int); - alias PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t); - alias PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t); - alias int(*intobjargproc)(PyObject *, int, PyObject *); - alias int(*intintobjargproc)(PyObject *, int, int, PyObject *); - alias int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *); - alias int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *); - alias int(*objobjargproc)(PyObject *, PyObject *, PyObject *); + alias PyObject * function(PyObject *) unaryfunc; + alias PyObject * function(PyObject *, PyObject *) binaryfunc; + alias PyObject * function(PyObject *, PyObject *, PyObject *) ternaryfunc; + alias int function(PyObject *) inquiry; + alias Py_ssize_t function(PyObject *) lenfunc; + alias int function(PyObject **, PyObject **) coercion; + alias PyObject * function(PyObject *, int) intargfunc; + alias PyObject * function(PyObject *, int, int) intintargfunc; + alias PyObject * function(PyObject *, Py_ssize_t) ssizeargfunc; + alias PyObject * function(PyObject *, Py_ssize_t, Py_ssize_t) ssizessizeargfunc; + alias int function(PyObject *, int, PyObject *) intobjargproc; + alias int function(PyObject *, int, int, PyObject *) intintobjargproc; + alias int function(PyObject *, Py_ssize_t, PyObject *) ssizeobjargproc; + alias int function(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *) ssizessizeobjargproc; + alias int function(PyObject *, PyObject *, PyObject *) objobjargproc; // int-based buffer interface - alias int (*getreadbufferproc)(PyObject *, int, void **); - alias int (*getwritebufferproc)(PyObject *, int, void **); - alias int (*getsegcountproc)(PyObject *, int *); - alias int (*getcharbufferproc)(PyObject *, int, c_str*); + alias int function(PyObject *, int, void **) getreadbufferproc; + alias int function(PyObject *, int, void **) getwritebufferproc; + alias int function(PyObject *, int *) getsegcountproc; + alias int function(PyObject *, int, c_str*) getcharbufferproc; // ssize_t-based buffer interface - alias Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **); - alias Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **); - alias Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *); - alias Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, c_str*); - - alias int (*objobjproc)(PyObject *, PyObject *); - alias int (*visitproc)(PyObject *, void *); - alias int (*traverseproc)(PyObject *, visitproc, void *); + alias Py_ssize_t function(PyObject *, Py_ssize_t, void **) readbufferproc; + alias Py_ssize_t function(PyObject *, Py_ssize_t, void **) writebufferproc; + alias Py_ssize_t function(PyObject *, Py_ssize_t *) segcountproc; + alias Py_ssize_t function(PyObject *, Py_ssize_t, c_str*) charbufferproc; + + alias int function(PyObject *, PyObject *) objobjproc; + alias int function(PyObject *, void *) visitproc; + alias int function(PyObject *, visitproc, void *) traverseproc; // Python-header-file: Include/object.h: struct PyNumberMethods { @@ -230,24 +230,24 @@ extern (C) { } - alias void (*freefunc)(void *); - alias void (*destructor)(PyObject *); - alias int (*printfunc)(PyObject *, FILE *, int); - alias PyObject *(*getattrfunc)(PyObject *, c_str); - alias PyObject *(*getattrofunc)(PyObject *, PyObject *); - alias int (*setattrfunc)(PyObject *, c_str, PyObject *); - alias int (*setattrofunc)(PyObject *, PyObject *, PyObject *); - alias int (*cmpfunc)(PyObject *, PyObject *); - alias PyObject *(*reprfunc)(PyObject *); - alias C_long (*hashfunc)(PyObject *); - alias PyObject *(*richcmpfunc) (PyObject *, PyObject *, int); - alias PyObject *(*getiterfunc) (PyObject *); - alias PyObject *(*iternextfunc) (PyObject *); - alias PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *); - alias int (*descrsetfunc) (PyObject *, PyObject *, PyObject *); - alias int (*initproc)(PyObject *, PyObject *, PyObject *); - alias PyObject *(*newfunc)(PyTypeObject *, PyObject *, PyObject *); - alias PyObject *(*allocfunc)(PyTypeObject *, Py_ssize_t); + alias void function(void *) freefunc; + alias void function(PyObject *) destructor; + alias int function(PyObject *, FILE *, int) printfunc; + alias PyObject * function(PyObject *, c_str) getattrfunc; + alias PyObject * function(PyObject *, PyObject *) getattrofunc; + alias int function(PyObject *, c_str, PyObject *) setattrfunc; + alias int function(PyObject *, PyObject *, PyObject *) setattrofunc; + alias int function(PyObject *, PyObject *) cmpfunc; + alias PyObject * function(PyObject *) reprfunc; + alias C_long function(PyObject *) hashfunc; + alias PyObject * function (PyObject *, PyObject *, int) richcmpfunc; + alias PyObject * function (PyObject *) getiterfunc; + alias PyObject * function (PyObject *) iternextfunc; + alias PyObject * function (PyObject *, PyObject *, PyObject *) descrgetfunc; + alias int function (PyObject *, PyObject *, PyObject *) descrsetfunc; + alias int function(PyObject *, PyObject *, PyObject *) initproc; + alias PyObject * function(PyTypeObject *, PyObject *, PyObject *) newfunc; + alias PyObject * function(PyTypeObject *, Py_ssize_t) allocfunc; struct PyTypeObject { mixin PyObject_VAR_HEAD; @@ -1408,7 +1408,7 @@ extern (C) { Py_ssize_t ma_used; Py_ssize_t ma_mask; PyDictEntry *ma_table; - PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, C_long hash); + PyDictEntry * function(PyDictObject *mp, PyObject *key, C_long hash) ma_lookup; PyDictEntry ma_smalltable[PyDict_MINSIZE]; } alias _dictobject PyDictObject; @@ -1458,9 +1458,9 @@ extern (C) { return op.ob_type == PyCFunction_Type_p; } - alias PyObject *(*PyCFunction)(PyObject *, PyObject *); - alias PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,PyObject *); - alias PyObject *(*PyNoArgsFunction)(PyObject *); + alias PyObject * function(PyObject *, PyObject *) PyCFunction; + alias PyObject * function(PyObject *, PyObject *,PyObject *) PyCFunctionWithKeywords; + alias PyObject * function(PyObject *) PyNoArgsFunction; PyCFunction PyCFunction_GetFunction(PyObject *); PyObject * PyCFunction_GetSelf(PyObject *); @@ -1720,7 +1720,7 @@ extern (C) { FILE *f_fp; PyObject *f_name; PyObject *f_mode; - int (*f_close)(FILE *); + int function(FILE *) f_close; int f_softspace; int f_binary; char* f_buf; @@ -1748,7 +1748,7 @@ extern (C) { void PyFile_SetBufSize(PyObject *, int); int PyFile_SetEncoding(PyObject *, c_str); PyObject * PyFile_FromFile(FILE *, char *, char *, - int (*)(FILE *)); + int function(FILE *)); FILE * PyFile_AsFile(PyObject *); PyObject * PyFile_Name(PyObject *); PyObject * PyFile_GetLine(PyObject *, int); @@ -1780,9 +1780,9 @@ extern (C) { return op.ob_type == PyCObject_Type_p; } - PyObject * PyCObject_FromVoidPtr(void *cobj, void (*destruct)(void*)); + PyObject * function (void *cobj, void function(void*) destruct) PyCObject_FromVoidPtr; PyObject * PyCObject_FromVoidPtrAndDesc(void *cobj, void *desc, - void (*destruct)(void*,void*)); + void function(void*,void*) destruct); void * PyCObject_AsVoidPtr(PyObject *); void * PyCObject_GetDesc(PyObject *); void * PyCObject_Import(c_str module_name, c_str cobject_name); @@ -1892,8 +1892,8 @@ extern (C) { /////////////////////////////////////////////////////////////////////////////// // Python-header-file: Include/descrobject.h: - alias PyObject *(*getter)(PyObject *, void *); - alias int (*setter)(PyObject *, PyObject *, void *); + alias PyObject * function(PyObject *, void *) getter; + alias int function(PyObject *, PyObject *, void *) setter; struct PyGetSetDef { char *name; @@ -1903,8 +1903,8 @@ extern (C) { void *closure; } - alias PyObject *(*wrapperfunc)(PyObject *, PyObject *, void *); - alias PyObject *(*wrapperfunc_kwds)(PyObject *, PyObject *, void *, PyObject *); + alias PyObject * function(PyObject *, PyObject *, void *) wrapperfunc; + alias PyObject * function(PyObject *, PyObject *, void *, PyObject *) wrapperfunc_kwds; struct wrapperbase { char *name; @@ -2436,7 +2436,7 @@ extern (C) { void PyErr_PrintEx(int); void PyErr_Display(PyObject *, PyObject *, PyObject *); - int Py_AtExit(void (*func)()); + int function (void function() func) Py_AtExit; void Py_Exit(int); @@ -2496,8 +2496,8 @@ extern (C) { // VARIOUS (API members documented as having "no proper home") ///////////////////////////////////////////////////////////////////////////// char *PyOS_Readline(FILE *, FILE *, char *); - int (*PyOS_InputHook)(); - char *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *); + int function() PyOS_InputHook; + char * function(FILE *, FILE *, char *) PyOS_ReadlineFunctionPointer; // _PyOS_ReadlineTState omitted. const int PYOS_STACK_MARGIN = 2048; // PyOS_CheckStack omitted. @@ -2506,9 +2506,9 @@ extern (C) { // SIGNALS ///////////////////////////////////////////////////////////////////////////// - alias void (*PyOS_sighandler_t)(int); - PyOS_sighandler_t PyOS_getsig(int); - PyOS_sighandler_t PyOS_setsig(int, PyOS_sighandler_t); + alias void function(int) PyOS_sighandler_t; + PyOS_sighandler_t function(int) PyOS_getsig; + PyOS_sighandler_t function(int, PyOS_sighandler_t) PyOS_setsig; /////////////////////////////////////////////////////////////////////////////// @@ -2533,7 +2533,7 @@ extern (C) { int PyEval_MergeCompilerFlags(PyCompilerFlags *cf); int Py_FlushLine(); - int Py_AddPendingCall(int (*func)(void *), void *arg); + int Py_AddPendingCall(int function(void *) func, void *arg); int Py_MakePendingCalls(); void Py_SetRecursionLimit(int); @@ -2675,7 +2675,7 @@ extern (C) { //#endif } - alias int (*Py_tracefunc)(PyObject *, PyFrameObject *, int, PyObject *); + alias int function(PyObject *, PyFrameObject *, int, PyObject *) Py_tracefunc; const int PyTrace_CALL = 0; const int PyTrace_EXCEPTION = 1; @@ -2740,7 +2740,7 @@ extern (C) { PyThreadState *PyInterpreterState_ThreadHead(PyInterpreterState *); PyThreadState *PyThreadState_Next(PyThreadState *); - alias PyFrameObject *(*PyThreadFrameGetter)(PyThreadState *self_); + alias PyFrameObject * function(PyThreadState *self_) PyThreadFrameGetter; // Python-header-file: Include/ceval.h: PyThreadState *PyEval_SaveThread(); @@ -2797,10 +2797,10 @@ extern (C) { struct _inittab { char *name; - void (*initfunc)(); + void function() initfunc; } - int PyImport_AppendInittab(char *name, void (*initfunc)()); + int PyImport_AppendInittab(char *name, void function() initfunc); int PyImport_ExtendInittab(_inittab *newtab); struct _frozen { @@ -3140,12 +3140,12 @@ PycStringIO_CAPI *PycString_IMPORT() { } struct PycStringIO_CAPI { - int(*cread)(PyObject *, char **, Py_ssize_t); - int(*creadline)(PyObject *, char **); - int(*cwrite)(PyObject *, c_str, Py_ssize_t); - PyObject *(*cgetvalue)(PyObject *); - PyObject *(*NewOutput)(int); - PyObject *(*NewInput)(PyObject *); + int function(PyObject *, char **, Py_ssize_t) cread; + int function(PyObject *, char **) creadline; + int function(PyObject *, c_str, Py_ssize_t) cwrite; + PyObject * function(PyObject *) cgetvalue; + PyObject * function(int) NewOutput; + PyObject * function(PyObject *) NewInput; PyTypeObject *InputType; PyTypeObject *OutputType; } @@ -3279,14 +3279,14 @@ struct PyDateTime_CAPI { PyTypeObject *DeltaType; PyTypeObject *TZInfoType; - PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*); - PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int, - PyObject*, PyTypeObject*); - PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*); - PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*); + PyObject * function(int, int, int, PyTypeObject*) Date_FromDate; + PyObject * function(int, int, int, int, int, int, int, + PyObject*, PyTypeObject*) DateTime_FromDateAndTime; + PyObject * function(int, int, int, int, PyObject*, PyTypeObject*) Time_FromTime; + PyObject * function(int, int, int, int, PyTypeObject*) Delta_FromDelta; - PyObject *(*DateTime_FromTimestamp)(PyObject*, PyObject*, PyObject*); - PyObject *(*Date_FromTimestamp)(PyObject*, PyObject*); + PyObject * function(PyObject*, PyObject*, PyObject*) DateTime_FromTimestamp; + PyObject * function(PyObject*, PyObject*) Date_FromTimestamp; } const int DATETIME_API_MAGIC = 0x414548d5; @@ -3441,7 +3441,7 @@ alias void * PyThread_type_lock; alias void * PyThread_type_sema; void PyThread_init_thread(); -C_long PyThread_start_new_thread(void (*)(void *), void *); +C_long PyThread_start_new_thread(void function(void *), void *); void PyThread_exit_thread(); void PyThread__PyThread_exit_thread(); C_long PyThread_get_thread_ident(); @@ -3492,7 +3492,7 @@ struct PySetObject { Py_ssize_t mask; setentry *table; - setentry *(*lookup)(PySetObject *so, PyObject *key, C_long hash); + setentry * function(PySetObject *so, PyObject *key, C_long hash) lookup; setentry smalltable[PySet_MINSIZE]; } else { PyObject* data; @@ -3764,7 +3764,7 @@ PyObject* m_PyExc_FutureWarning; PyObject *eval(string code) { PyObject *pyGlobals = PyEval_GetGlobals(); /* borrowed ref */ - PyObject *res = PyRun_String((code ~ \0).ptr, Py_eval_input, + PyObject *res = PyRun_String((code ~ "\0").ptr, Py_eval_input, pyGlobals, pyGlobals ); /* New ref, or NULL on error. */ if (res == null) { @@ -3782,7 +3782,7 @@ PyObject* m_builtins, m_types, m_weakref; typeof(Ptr) lazy_sys(alias Ptr, string name) () { if (Ptr is null) { PyObject* sys_modules = PyImport_GetModuleDict(); - Ptr = PyDict_GetItemString(sys_modules, (name ~ \0).ptr); + Ptr = PyDict_GetItemString(sys_modules, (name ~ "\0").ptr); } assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!"); return Ptr; @@ -3794,7 +3794,7 @@ alias lazy_sys!(m_weakref, "weakref") weakref; typeof(Ptr) lazy_load(alias from, alias Ptr, string name) () { if (Ptr is null) { - Ptr = cast(typeof(Ptr)) PyObject_GetAttrString(from(), (name ~ \0).ptr); + Ptr = cast(typeof(Ptr)) PyObject_GetAttrString(from(), (name ~ "\0").ptr); } assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!"); return Ptr;