Changeset 119

Show
Ignore:
Timestamp:
07/25/07 20:15:18 (1 year ago)
Author:
KirkMcDonald
Message:

* Merged 2.4 and 2.5 Python headers into a single file.
* This is prep work for D 2.0 support.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dcompiler.py

    r112 r119  
    161161        # To sources, add the appropriate D header file python.d, as well as 
    162162        # any platform-specific boilerplate. 
    163         pythonHeaderPath = os.path.join(_infraDir, 'python', _pyVerXDotY, 'python.d') 
     163        pythonHeaderPath = os.path.join(_infraDir, 'python', 'python.d') 
    164164        # Add the python header's directory to the include path 
    165165        includePathOpts += self._includeOpts 
    166         includePathOpts[-1] = includePathOpts[-1] % os.path.join(_infraDir, 'python', _pyVerXDotY
     166        includePathOpts[-1] = includePathOpts[-1] % os.path.join(_infraDir, 'python'
    167167        if not os.path.isfile(pythonHeaderPath): 
    168168            raise DistutilsPlatformError('Required D translation of Python' 
     
    450450            # more convenient to distribute a pre-extracted .lib file to the 
    451451            # users and spare them the need for the "Basic Utilities" package. 
    452             pythonDMDLibPath = _qp(os.path.join(_infraDir, 'python', _pyVerXDotY, 
     452            pythonDMDLibPath = _qp(os.path.join(_infraDir, 'python', 
    453453                'python%s_digitalmars.lib' % _pyVerXY 
    454454            )) 
  • trunk/infrastructure/python/python.d

    r107 r119  
    1515    version (DigitalMars) { 
    1616        version (Windows) { 
    17             pragma(link, "python25_digitalmars"); 
     17            version (Python_2_5_Or_Later) { 
     18                pragma(link, "python25_digitalmars"); 
     19            } else { 
     20                pragma(link, "python24_digitalmars"); 
     21            } 
    1822        } 
    1923    } else { 
    20         pragma(link, "python2.5"); 
     24        version (Python_2_5_Or_Later) { 
     25            pragma(link, "python2.5"); 
     26        } else { 
     27            pragma(link, "python2.4"); 
     28        } 
    2129    } 
    2230} 
     
    5765 * bytes on X86. 
    5866 */ 
    59 version (X86_64) { 
    60     alias long Py_ssize_t; 
     67version (Python_2_5_Or_Later) { 
     68    version (X86_64) { 
     69        alias long Py_ssize_t; 
     70    } else { 
     71        alias int Py_ssize_t; 
     72    } 
    6173} else { 
    62     alias int Py_ssize_t; 
     74    alias C_long Py_ssize_t; 
    6375} 
    6476 
     
    179191    binaryfunc nb_inplace_true_divide; 
    180192 
    181     /* Added in release 2.5 */ 
    182     unaryfunc nb_index; 
     193    version (Python_2_5_Or_Later) { 
     194        unaryfunc nb_index; 
     195    } 
    183196  } 
    184197 
     
    293306 
    294307  struct _heaptypeobject { 
     308    // Some of these names changed between 2.4 and 2.5; not a serious issue. 
    295309    PyTypeObject ht_type; 
    296310    PyNumberMethods as_number; 
     
    396410  const int Py_TPFLAGS_HAVE_STACKLESS_EXTENSION = 0; 
    397411  //#endif 
    398   const int Py_TPFLAGS_HAVE_INDEX               = 1L<<17; 
     412  version (Python_2_5_Or_Later) { 
     413      const int Py_TPFLAGS_HAVE_INDEX = 1L<<17; 
     414  } else { 
     415      const int Py_TPFLAGS_HAVE_INDEX = 0; 
     416  } 
    399417 
    400418  const int Py_TPFLAGS_DEFAULT = 
     
    602620    PyObject *PyUnicodeUCS2_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit); 
    603621    PyObject *PyUnicodeUCS2_Splitlines(PyObject *s, int keepends); 
    604     PyObject *PyUnicodeUCS2_Partition(PyObject* s, PyObject* sep); 
    605     PyObject *PyUnicodeUCS2_RPartition(PyObject* s, PyObject* sep); 
     622    version (Python_2_5_Or_Later) { 
     623        PyObject *PyUnicodeUCS2_Partition(PyObject* s, PyObject* sep); 
     624        PyObject *PyUnicodeUCS2_RPartition(PyObject* s, PyObject* sep); 
     625    } 
    606626    PyObject *PyUnicodeUCS2_RSplit(PyObject *s, PyObject *sep, Py_ssize_t maxsplit); 
    607627    PyObject *PyUnicodeUCS2_Translate(PyObject *str, PyObject *table, char *errors); 
     
    726746    PyObject *PyUnicodeUCS4_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit); 
    727747    PyObject *PyUnicodeUCS4_Splitlines(PyObject *s, int keepends); 
    728     PyObject *PyUnicodeUCS4_Partition(PyObject* s, PyObject* sep); 
    729     PyObject *PyUnicodeUCS4_RPartition(PyObject* s, PyObject* sep); 
     748    version (Python_2_5_Or_Later) { 
     749        PyObject *PyUnicodeUCS4_Partition(PyObject* s, PyObject* sep); 
     750        PyObject *PyUnicodeUCS4_RPartition(PyObject* s, PyObject* sep); 
     751    } 
    730752    PyObject *PyUnicodeUCS4_RSplit(PyObject *s, PyObject *sep, Py_ssize_t maxsplit); 
    731753    PyObject *PyUnicodeUCS4_Translate(PyObject *str, PyObject *table, char *errors); 
     
    814836    alias PyUnicodeUCS2_GetSize PyUnicode_GetSize; 
    815837    alias PyUnicodeUCS2_Join PyUnicode_Join; 
    816     alias PyUnicodeUCS2_Partition PyUnicode_Partition; 
     838    version (Python_2_5_Or_Later) { 
     839        alias PyUnicodeUCS2_Partition PyUnicode_Partition; 
     840        alias PyUnicodeUCS2_RPartition PyUnicode_RPartition; 
     841    } 
    817842    alias PyUnicodeUCS2_Replace PyUnicode_Replace; 
    818843    alias PyUnicodeUCS2_Resize PyUnicode_Resize; 
    819844    alias PyUnicodeUCS2_SetDefaultEncoding PyUnicode_SetDefaultEncoding; 
    820845    alias PyUnicodeUCS2_Split PyUnicode_Split; 
    821     alias PyUnicodeUCS2_RPartition PyUnicode_RPartition; 
    822846    alias PyUnicodeUCS2_RSplit PyUnicode_RSplit; 
    823847    alias PyUnicodeUCS2_Splitlines PyUnicode_Splitlines; 
     
    889913    alias PyUnicodeUCS4_GetSize PyUnicode_GetSize; 
    890914    alias PyUnicodeUCS4_Join PyUnicode_Join; 
    891     alias PyUnicodeUCS4_Partition PyUnicode_Partition; 
    892915    alias PyUnicodeUCS4_Replace PyUnicode_Replace; 
    893916    alias PyUnicodeUCS4_Resize PyUnicode_Resize; 
    894     alias PyUnicodeUCS4_RPartition PyUnicode_RPartition; 
     917    version (Python_2_5_Or_Later) { 
     918        alias PyUnicodeUCS4_Partition PyUnicode_Partition; 
     919        alias PyUnicodeUCS4_RPartition PyUnicode_RPartition; 
     920    } 
    895921    alias PyUnicodeUCS4_RSplit PyUnicode_RSplit; 
    896922    alias PyUnicodeUCS4_SetDefaultEncoding PyUnicode_SetDefaultEncoding; 
     
    9931019  PyObject *PyInt_FromUnicode(Py_UNICODE *, Py_ssize_t, int); 
    9941020  PyObject *PyInt_FromLong(C_long); 
    995   PyObject *PyInt_FromSize_t(size_t); 
    996   PyObject *PyInt_FromSsize_t(Py_ssize_t); 
     1021  version (Python_2_5_Or_Later) { 
     1022      PyObject *PyInt_FromSize_t(size_t); 
     1023      PyObject *PyInt_FromSsize_t(Py_ssize_t); 
     1024  } 
    9971025 
    9981026  C_long PyInt_AsLong(PyObject *); 
     
    10491077 
    10501078  PyObject * PyLong_FromDouble(double); 
    1051   PyObject * PyLong_FromVoidPtr(void *); 
    10521079 
    10531080  C_long PyLong_AsLong(PyObject *); 
     
    11521179 
    11531180  // Removed in 2.5 
    1154   //PyObject * PyRange_New(C_long, C_long, C_long, int); 
     1181  version (Python_2_5_Or_Later) { 
     1182  } else { 
     1183    PyObject * PyRange_New(C_long, C_long, C_long, int); 
     1184  } 
    11551185 
    11561186 
     
    14891519  char * PyModule_GetName(PyObject *); 
    14901520  char * PyModule_GetFilename(PyObject *); 
    1491   void _PyModule_Clear(PyObject *); 
     1521  version (Python_2_5_Or_Later) { 
     1522      void _PyModule_Clear(PyObject *); 
     1523  } 
    14921524 
    14931525  // Python-header-file: Include/modsupport.h: 
     
    15571589  int PyFunction_SetClosure(PyObject *, PyObject *); 
    15581590 
     1591  // These are not present in the 2.4 API, but do no harm in it, either. 
    15591592  PyObject* PyFunction_GET_CODE(PyObject* func) { 
    15601593    return (cast(PyFunctionObject*)func).func_code; 
     
    16441677  PyObject * _PyInstance_Lookup(PyObject *pinst, PyObject *name); 
    16451678 
     1679  // These are not present in the 2.4 API, but do no harm in it, either. 
    16461680  PyObject * PyMethod_GET_FUNCTION(PyObject* meth) { 
    16471681    return (cast(PyMethodObject*)meth).im_func; 
     
    19892023 
    19902024  /* Error objects */ 
    1991  
     2025  version (Python_2_5_Or_Later) { 
    19922026  struct PyBaseExceptionObject { 
    19932027      mixin PyObject_HEAD; 
     
    20522086    } 
    20532087  } 
     2088  } /*Python_2_5_Or_Later*/ 
    20542089 
    20552090  void PyErr_SetNone(PyObject *); 
     
    20932128  void PyErr_WriteUnraisable(PyObject *); 
    20942129 
    2095   //int PyErr_Warn(PyObject *, char *); 
    2096   int PyErr_WarnEx(PyObject*, char*, Py_ssize_t); 
     2130  version (Python_2_5_Or_Later) { 
     2131      int PyErr_WarnEx(PyObject*, char*, Py_ssize_t); 
     2132  } else { 
     2133      int PyErr_Warn(PyObject *, char *); 
     2134  } 
    20972135  int PyErr_WarnExplicit(PyObject *, char *, char *, int, char *, PyObject *); 
    20982136 
     
    21692207    int co_firstlineno; 
    21702208    PyObject *co_lnotab; 
    2171     void *co_zombieframe; 
     2209    version (Python_2_5_Or_Later) { 
     2210        void *co_zombieframe; 
     2211    } 
    21722212  } 
    21732213 
     
    21812221  const int CO_NOFREE      = 0x0040; 
    21822222 
    2183   // Removed in 2.5 
    2184   //const int CO_GENERATOR_ALLOWED      = 0x1000; 
    21852223  const int CO_FUTURE_DIVISION        = 0x2000; 
    2186   const int CO_FUTURE_ABSOLUTE_IMPORT = 0x4000; 
    2187   const int CO_FUTURE_WITH_STATEMENT  = 0x8000; 
     2224  version (Python_2_5_Or_Later) { 
     2225      const int CO_FUTURE_ABSOLUTE_IMPORT = 0x4000; 
     2226      const int CO_FUTURE_WITH_STATEMENT  = 0x8000; 
     2227  } else { 
     2228      const int CO_GENERATOR_ALLOWED      = 0x1000; 
     2229  } 
    21882230 
    21892231  const int CO_MAXBLOCKS = 20; 
     
    21982240  } 
    21992241 
    2200   PyCodeObject *PyCode_New( 
    2201     int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *, 
    2202     PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *); 
    2203   int PyCode_Addr2Line(PyCodeObject *, int); 
    2204  
    2205   struct PyAddrPair { 
    2206     int ap_lower; 
    2207     int ap_upper; 
    2208   } 
    2209  
    2210   int PyCode_CheckLineNumber(PyCodeObject* co, int lasti, PyAddrPair *bounds); 
    2211  
    2212   // Python-header-file: Include/pyarena.h: 
    2213   struct PyArena; 
    2214  
    2215   PyArena* PyArena_New(); 
    2216   void PyArena_Free(PyArena*); 
    2217  
    2218   void* PyArena_Malloc(PyArena*, size_t); 
    2219   int PyArena_AddPyObject(PyArena*, PyObject*); 
     2242  version (Python_2_5_Or_Later) { 
     2243      struct PyAddrPair { 
     2244        int ap_lower; 
     2245        int ap_upper; 
     2246      } 
     2247 
     2248      int PyCode_CheckLineNumber(PyCodeObject* co, int lasti, PyAddrPair *bounds); 
     2249 
     2250      // Python-header-file: Include/pyarena.h: 
     2251      struct PyArena; 
     2252 
     2253      PyArena* PyArena_New(); 
     2254      void PyArena_Free(PyArena*); 
     2255 
     2256      void* PyArena_Malloc(PyArena*, size_t); 
     2257      int PyArena_AddPyObject(PyArena*, PyObject*); 
     2258  } 
    22202259 
    22212260/////////////////////////////////////////////////////////////////////////////// 
     
    22272266    char    *n_str; 
    22282267    int     n_lineno; 
    2229     int     n_col_offset; 
     2268    version (Python_2_5_Or_Later) { 
     2269        int n_col_offset; 
     2270    } 
    22302271    int     n_nchildren; 
    22312272    node    *n_child; 
    22322273  } 
    2233   node * PyNode_New(int type); 
    2234   int PyNode_AddChild(node *n, int type, 
    2235         char *str, int lineno, int col_offset); 
    2236   void PyNode_Free(node *n); 
    2237   void PyNode_ListTree(node *); 
     2274  version (Python_2_5_Or_Later) { 
     2275      node * PyNode_New(int type); 
     2276      int PyNode_AddChild(node *n, int type, 
     2277            char *str, int lineno, int col_offset); 
     2278      void PyNode_Free(node *n); 
     2279      void PyNode_ListTree(node *); 
     2280  } 
    22382281 
    22392282  // Python-header-file: Include/compile.h: 
    22402283  PyCodeObject *PyNode_Compile(node *, char *); 
     2284  PyCodeObject *PyCode_New( 
     2285    int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *, 
     2286    PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *); 
     2287  int PyCode_Addr2Line(PyCodeObject *, int); 
     2288 
    22412289 
    22422290  struct PyFutureFeatures { 
     2291    version (Python_2_5_Or_Later) {} else { 
     2292        int ff_found_docstring; 
     2293        int ff_last_lineno; 
     2294    } 
    22432295    int ff_features; 
    2244     int ff_lineno; 
    2245   } 
    2246  
    2247 //  PyFutureFeatures *PyNode_Future(node *, char *); 
    2248 //  PyCodeObject *PyNode_CompileFlags(node *, char *, PyCompilerFlags *); 
     2296    version (Python_2_5_Or_Later) { 
     2297        int ff_lineno; 
     2298    } 
     2299  } 
     2300 
     2301  version (Python_2_5_Or_Later) {} else { 
     2302      PyFutureFeatures *PyNode_Future(node *, char *); 
     2303      PyCodeObject *PyNode_CompileFlags(node *, char *, PyCompilerFlags *); 
     2304  } 
    22492305 
    22502306  const char[] FUTURE_NESTED_SCOPES = "nested_scopes"; 
    22512307  const char[] FUTURE_GENERATORS = "generators"; 
    22522308  const char[] FUTURE_DIVISION = "division"; 
    2253   const char[] FUTURE_ABSOLUTE_IMPORT = "absolute_import"; 
    2254   const char[] FUTURE_WITH_STATEMENT = "with_statement"; 
    2255  
    2256   struct _mod; /* Declare the existence of this type */ 
    2257   PyCodeObject * PyAST_Compile(_mod *, char *, PyCompilerFlags *, PyArena *); 
    2258   PyFutureFeatures * PyFuture_FromAST(_mod *, char *); 
    2259  
    2260   // Python-header-file: Include/ast.h 
    2261   _mod* PyAST_FromNode(node*, PyCompilerFlags*, char*, PyArena*); 
     2309  version (Python_2_5_Or_Later) { 
     2310      const char[] FUTURE_ABSOLUTE_IMPORT = "absolute_import"; 
     2311      const char[] FUTURE_WITH_STATEMENT = "with_statement"; 
     2312 
     2313      struct _mod; /* Declare the existence of this type */ 
     2314      PyCodeObject * PyAST_Compile(_mod *, char *, PyCompilerFlags *, PyArena *); 
     2315      PyFutureFeatures * PyFuture_FromAST(_mod *, char *); 
     2316 
     2317      // Python-header-file: Include/ast.h 
     2318      _mod* PyAST_FromNode(node*, PyCompilerFlags*, char*, PyArena*); 
     2319  } 
    22622320 
    22632321/////////////////////////////////////////////////////////////////////////////// 
     
    22832341  void Py_EndInterpreter(PyThreadState *); 
    22842342 
     2343  // These are slightly different in 2.4, but the 2.5 form should still work. 
    22852344  int PyRun_AnyFileExFlags(FILE *, char *, int, PyCompilerFlags *); 
    22862345 
     
    23172376  } 
    23182377 
    2319   _mod* PyParser_ASTFromString(char *, char *,  
     2378  version (Python_2_5_Or_Later) { 
     2379    _mod* PyParser_ASTFromString(char *, char *,  
    23202380                        int, PyCompilerFlags *, PyArena *); 
    2321   _mod* PyParser_ASTFromFile(FILE *, char *, int,  
     2381    _mod* PyParser_ASTFromFile(FILE *, char *, int,  
    23222382                        char *, char *, PyCompilerFlags *, int *, PyArena *); 
     2383  } 
    23232384 
    23242385  node *PyParser_SimpleParseStringFlags(char *, int, int); 
     
    23802441  char *Py_GetCompiler(); 
    23812442  char *Py_GetBuildInfo(); 
    2382   char * _Py_svnversion(); 
    2383   char * Py_SubversionRevision(); 
    2384   char * Py_SubversionShortBranch(); 
     2443  version (Python_2_5_Or_Later) { 
     2444      char * _Py_svnversion(); 
     2445      char * Py_SubversionRevision(); 
     2446      char * Py_SubversionShortBranch(); 
     2447  } 
    23852448 
    23862449  ///////////////////////////////////////////////////////////////////////////// 
     
    24702533  PyObject *PyEval_GetCallStats(PyObject *); 
    24712534  PyObject *PyEval_EvalFrame(PyFrameObject *); 
    2472   PyObject *PyEval_EvalFrameEx(PyFrameObject *, int); 
    2473  
     2535  version (Python_2_5_Or_Later) { 
     2536      PyObject *PyEval_EvalFrameEx(PyFrameObject *, int); 
     2537  } 
    24742538 
    24752539/////////////////////////////////////////////////////////////////////////////// 
     
    25292593    int f_lasti; 
    25302594    int f_lineno; 
     2595    version (Python_2_5_Or_Later) {} else { 
     2596        int f_restricted; 
     2597    } 
    25312598    int f_iblock; 
    25322599    PyTryBlock f_blockstack[CO_MAXBLOCKS]; 
     2600    version (Python_2_5_Or_Later) {} else { 
     2601        int f_nlocals; 
     2602        int f_ncells; 
     2603        int f_nfreevars; 
     2604        int f_stacksize; 
     2605    } 
    25332606    PyObject *_f_localsplus[1]; 
    25342607    PyObject** f_localsplus() { 
     
    25422615    return op.ob_type == PyFrame_Type_p; 
    25432616  } 
    2544   int PyFrame_IsRestricted(PyFrameObject* f) { 
    2545     return f.f_builtins != f.f_tstate.interp.builtins; 
     2617  version (Python_2_5_Or_Later) { 
     2618      int PyFrame_IsRestricted(PyFrameObject* f) { 
     2619        return f.f_builtins != f.f_tstate.interp.builtins; 
     2620      } 
    25462621  } 
    25472622 
     
    26802755  PyObject *PyImport_AddModule(char *name); 
    26812756  PyObject *PyImport_ImportModule(char *name); 
    2682   PyObject *PyImport_ImportModuleLevel(char *name, 
    2683     PyObject *globals, PyObject *locals, PyObject *fromlist, int level); 
    2684   PyObject *PyImport_ImportModuleEx(char *n, PyObject *g, PyObject *l, PyObject *f) { 
    2685     return PyImport_ImportModuleLevel(n, g, l, f, -1); 
     2757  version (Python_2_5_Or_Later) { 
     2758      PyObject *PyImport_ImportModuleLevel(char *name, 
     2759        PyObject *globals, PyObject *locals, PyObject *fromlist, int level); 
     2760      PyObject *PyImport_ImportModuleEx(char *n, PyObject *g, PyObject *l, PyObject *f) { 
     2761        return PyImport_ImportModuleLevel(n, g, l, f, -1); 
     2762      } 
     2763  } else { 
     2764      PyObject *PyImport_ImportModuleEx(char *n, PyObject *g, PyObject *l, PyObject *f); 
    26862765  } 
    26872766  PyObject *PyImport_Import(PyObject *name); 
     
    27382817  PyObject *PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw); 
    27392818  PyObject *PyObject_CallObject(PyObject *callable_object, PyObject *args); 
    2740 //  PyObject *PyObject_CallFunction(PyObject *callable_object, char *format, ...); 
    2741 //  PyObject *PyObject_CallMethod(PyObject *o, char *m, char *format, ...); 
    2742   PyObject *_PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...); 
    2743   PyObject *_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...); 
    2744   alias _PyObject_CallFunction_SizeT PyObject_CallFunction; 
    2745   alias _PyObject_CallMethod_SizeT PyObject_CallMethod; 
     2819  version (Python_2_5_Or_Later) { 
     2820      PyObject *_PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...); 
     2821      PyObject *_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...); 
     2822      alias _PyObject_CallFunction_SizeT PyObject_CallFunction; 
     2823      alias _PyObject_CallMethod_SizeT PyObject_CallMethod; 
     2824  } else { 
     2825      PyObject *PyObject_CallFunction(PyObject *callable_object, char *format, ...); 
     2826      PyObject *PyObject_CallMethod(PyObject *o, char *m, char *format, ...); 
     2827  } 
    27462828  PyObject *PyObject_CallFunctionObjArgs(PyObject *callable, ...); 
    27472829  PyObject *PyObject_CallMethodObjArgs(PyObject *o,PyObject *m, ...); 
     
    27572839 
    27582840  Py_ssize_t PyObject_Size(PyObject *o); 
    2759   //int PyObject_Length(PyObject *o); 
    2760   alias PyObject_Size PyObject_Length; 
     2841  version (Python_2_5_Or_Later) { 
     2842      alias PyObject_Size PyObject_Length; 
     2843  } else { 
     2844      int PyObject_Length(PyObject *o); 
     2845  } 
    27612846 
    27622847  PyObject *PyObject_GetItem(PyObject *o, PyObject *key); 
     
    28082893  PyObject *PyNumber_Or(PyObject *o1, PyObject *o2); 
    28092894 
    2810   int PyIndex_Check(PyObject* obj) { 
    2811     return obj.ob_type.tp_as_number !is null && 
    2812         PyType_HasFeature(obj.ob_type, Py_TPFLAGS_HAVE_INDEX) && 
    2813         obj.ob_type.tp_as_number.nb_index !is null; 
    2814   } 
    2815   PyObject *PyNumber_Index(PyObject *o); 
    2816   Py_ssize_t PyNumber_AsSsize_t(PyObject* o, PyObject* exc); 
     2895  version (Python_2_5_Or_Later) { 
     2896      int PyIndex_Check(PyObject* obj) { 
     2897        return obj.ob_type.tp_as_number !is null && 
     2898            PyType_HasFeature(obj.ob_type, Py_TPFLAGS_HAVE_INDEX) && 
     2899            obj.ob_type.tp_as_number.nb_index !is null; 
     2900      } 
     2901      PyObject *PyNumber_Index(PyObject *o); 
     2902      Py_ssize_t PyNumber_AsSsize_t(PyObject* o, PyObject* exc); 
     2903  } 
    28172904  PyObject *PyNumber_Int(PyObject *o); 
    28182905  PyObject *PyNumber_Long(PyObject *o); 
     
    28392926  int PySequence_Check(PyObject *o); 
    28402927  Py_ssize_t PySequence_Size(PyObject *o); 
    2841   //int PySequence_Length(PyObject *o); 
    2842   alias PySequence_Size PySequence_Length; 
     2928  version (Python_2_5_Or_Later) { 
     2929      alias PySequence_Size PySequence_Length; 
     2930  } else { 
     2931      int PySequence_Length(PyObject *o); 
     2932  } 
    28432933 
    28442934  PyObject *PySequence_Concat(PyObject *o1, PyObject *o2); 
     
    28822972 
    28832973  Py_ssize_t _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation); 
    2884   //int PySequence_In(PyObject *o, PyObject *value); 
    2885   alias PySequence_Contains PySequence_In; 
     2974  version (Python_2_5_Or_Later) { 
     2975      alias PySequence_Contains PySequence_In; 
     2976  } else { 
     2977      int PySequence_In(PyObject *o, PyObject *value); 
     2978  } 
    28862979  Py_ssize_t PySequence_Index(PyObject *o, PyObject *value); 
    28872980 
     
    28942987  int PyMapping_Check(PyObject *o); 
    28952988  Py_ssize_t PyMapping_Size(PyObject *o); 
    2896   //int PyMapping_Length(PyObject *o); 
    2897   alias PyMapping_Size PyMapping_Length; 
     2989  version (Python_2_5_Or_Later) { 
     2990      alias PyMapping_Size PyMapping_Length; 
     2991  } else { 
     2992      int PyMapping_Length(PyObject *o); 
     2993  } 
    28982994 
    28992995  // D translations of C macros: 
     
    32813377 
    32823378PyObject *PyGen_New(PyFrameObject *); 
    3283 int PyGen_NeedsFinalizing(PyGenObject *); 
     3379version (Python_2_5_Or_Later) { 
     3380    int PyGen_NeedsFinalizing(PyGenObject *); 
     3381
    32843382 
    32853383 
     
    32893387// Python-header-file: Include/marshal.h: 
    32903388 
    3291 const int Py_MARSHAL_VERSION = 2; 
     3389version (Python_2_5_Or_Later) { 
     3390    const int Py_MARSHAL_VERSION = 2; 
     3391} else { 
     3392    const int Py_MARSHAL_VERSION = 1; 
     3393
    32923394 
    32933395void PyMarshal_WriteLongToFile(C_long, FILE *, int); 
     
    33333435void PyThread_release_lock(PyThread_type_lock); 
    33343436 
    3335 size_t PyThread_get_stacksize(); 
    3336 int PyThread_set_stacksize(size_t); 
     3437version (Python_2_5_Or_Later) { 
     3438    size_t PyThread_get_stacksize(); 
     3439    int PyThread_set_stacksize(size_t); 
     3440
    33373441 
    33383442void PyThread_exit_prog(int); 
     
    33513455// Python-header-file: Include/setobject.h: 
    33523456 
    3353 const int PySet_MINSIZE = 8; 
    3354  
    3355 struct setentry { 
    3356     C_long hash; 
    3357     PyObject *key; 
     3457version (Python_2_5_Or_Later) { 
     3458    const int PySet_MINSIZE = 8; 
     3459 
     3460    struct setentry { 
     3461        C_long hash; 
     3462        PyObject *key; 
     3463    } 
    33583464} 
    33593465 
     
    33613467    mixin PyObject_HEAD; 
    33623468 
    3363     Py_ssize_t fill; 
    3364     Py_ssize_t used; 
    3365  
    3366     Py_ssize_t mask; 
    3367  
    3368     setentry *table; 
    3369     setentry *(*lookup)(PySetObject *so, PyObject *key, C_long hash); 
    3370     setentry smalltable[PySet_MINSIZE]; 
     3469    version (Python_2_5_Or_Later) { 
     3470        Py_ssize_t fill; 
     3471        Py_ssize_t used; 
     3472 
     3473        Py_ssize_t mask; 
     3474 
     3475        setentry *table; 
     3476        setentry *(*lookup)(PySetObject *so, PyObject *key, C_long hash); 
     3477        setentry smalltable[PySet_MINSIZE]; 
     3478    } else { 
     3479        PyObject* data; 
     3480    } 
    33713481 
    33723482    C_long hash; 
     
    33813491    return ob.ob_type == PyFrozenSet_Type_p; 
    33823492} 
     3493// Not technically part of the 2.4 API, included anyway. 
    33833494int PyAnySet_CheckExact(PyObject* ob) { 
    33843495    return ob.ob_type == PySet_Type_p || ob.ob_type == PyFrozenSet_Type_p; 
     
    33933504} 
    33943505 
    3395 PyObject *PySet_New(PyObject *); 
    3396 PyObject *PyFrozenSet_New(PyObject *); 
    3397 Py_ssize_t PySet_Size(PyObject *anyset); 
    3398 Py_ssize_t PySet_GET_SIZE(PyObject* so) { 
    3399     return (cast(PySetObject*)so).used; 
    3400 
    3401 int PySet_Clear(PyObject *set); 
    3402 int PySet_Contains(PyObject *anyset, PyObject *key); 
    3403 int PySet_Discard(PyObject *set, PyObject *key); 
    3404 int PySet_Add(PyObject *set, PyObject *key); 
    3405 int _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **entry); 
    3406 PyObject *PySet_Pop(PyObject *set); 
    3407 int _PySet_Update(PyObject *set, PyObject *iterable); 
     3506version (Python_2_5_Or_Later) { 
     3507    PyObject *PySet_New(PyObject *); 
     3508    PyObject *PyFrozenSet_New(PyObject *); 
     3509    Py_ssize_t PySet_Size(PyObject *anyset); 
     3510    Py_ssize_t PySet_GET_SIZE(PyObject* so) { 
     3511        return (cast(PySetObject*)so).used; 
     3512    } 
     3513    int PySet_Clear(PyObject *set); 
     3514    int PySet_Contains(PyObject *anyset, PyObject *key); 
     3515    int PySet_Discard(PyObject *set, PyObject *key); 
     3516    int PySet_Add(PyObject *set, PyObject *key); 
     3517    int _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **entry); 
     3518    PyObject *PySet_Pop(PyObject *set); 
     3519    int _PySet_Update(PyObject *set, PyObject *iterable); 
     3520
    34083521 
    34093522/////////////////////////////////////////////////////////////////////////////// 
     
    34353548const int T_STRING_INPLACE = 13; 
    34363549const int T_OBJECT_EX = 16; 
    3437 const int T_LONGLONG = 17; 
    3438 const int T_ULONGLONG = 18; 
     3550version (Python_2_5_Or_Later) { 
     3551    const int T_LONGLONG = 17; 
     3552    const int T_ULONGLONG = 18; 
     3553
    34393554 
    34403555const int READONLY = 1;