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