1 /** 2 Mirror _pyport.h 3 */ 4 module deimos.python.pyport; 5 6 import core.stdc.config; 7 8 /* D long is always 64 bits, but when the Python/C API mentions long, it is of 9 * course referring to the C type long, the size of which is 32 bits on both 10 * X86 and X86_64 under Windows, but 32 bits on X86 and 64 bits on X86_64 under 11 * most other operating systems. */ 12 13 /// _ 14 alias long C_longlong; 15 /// _ 16 alias ulong C_ulonglong; 17 18 alias core.stdc.config.c_long C_long; 19 alias core.stdc.config.c_ulong C_ulong; 20 21 /* 22 * Py_ssize_t is defined as a signed type which is 8 bytes on X86_64 and 4 23 * bytes on X86. 24 */ 25 version(Python_2_5_Or_Later){ 26 version (X86_64) { 27 /// _ 28 alias long Py_ssize_t; 29 } else { 30 /// _ 31 alias int Py_ssize_t; 32 } 33 version(Python_3_2_Or_Later) { 34 /// Availability: >= 3.2 35 /// (Py_hash_t invariably replaces C_long, so we always define it for 36 /// convenience) 37 alias Py_ssize_t Py_hash_t; 38 /// Availability: >= 3.2 39 alias size_t Py_uhash_t; 40 }else{ 41 alias C_long Py_hash_t; 42 } 43 }else { 44 /* 45 * Seems Py_ssize_t didn't exist in 2.4, and int was everywhere it is now. 46 */ 47 /// _ 48 alias int Py_ssize_t; 49 /* 50 * Seems Py_hash_t didn't exist in 2.4, and C_long was everywhere it is now. 51 */ 52 /// _ 53 alias C_long Py_hash_t; 54 } 55 56 version(linux) version(DigitalMars) version = dmd_linux; 57 version(OSX) version(DigitalMars) version = dmd_osx; 58 template PyAPI_DATA(string decl) { 59 60 version(dmd_linux) { 61 // has to be special 62 63 // todo: why does ldc/linux not work this way? 64 // --export-dynamic seems not to change anything 65 // export causes dmd to prepend symbols with _imp__, so no use. 66 // extern is not necessary for single-command builds 67 // necessary for traditional per-file builds. 68 enum PyAPI_DATA = (q{ 69 extern(C) 70 extern 71 __gshared 72 } ~ decl ~ ";"); 73 } else version(dmd_osx) { 74 enum PyAPI_DATA = (q{ 75 extern(C) 76 extern 77 __gshared 78 } ~ decl ~ ";"); 79 } else { 80 enum PyAPI_DATA = (q{ 81 extern(C) 82 extern 83 export 84 __gshared 85 } ~ decl ~ ";"); 86 } 87 }