5
5
6
6
#if PY_VERSION_HEX >= 0x03000000
7
7
#include "numpy/npy_3kcompat.h"
8
- #define PyCObject_AsVoidPtr NpyCapsule_AsVoidPtr
9
- #define PyCObject_GetDesc NpyCapsule_GetDesc
10
- #define PyCObject_Check NpyCapsule_Check
11
8
#endif
12
9
13
10
#ifndef Py_TYPE
@@ -323,9 +320,9 @@ static int CLazyLinker_init(CLazyLinker *self, PyObject *args, PyObject *kwds) {
323
320
if (PyObject_HasAttrString (thunk , "cthunk" )) {
324
321
PyObject * cthunk = PyObject_GetAttrString (thunk , "cthunk" );
325
322
// new reference
326
- assert (cthunk && PyCObject_Check (cthunk ));
327
- self -> thunk_cptr_fn [i ] = PyCObject_AsVoidPtr (cthunk );
328
- self -> thunk_cptr_data [i ] = PyCObject_GetDesc (cthunk );
323
+ assert (cthunk && NpyCapsule_Check (cthunk ));
324
+ self -> thunk_cptr_fn [i ] = NpyCapsule_AsVoidPtr (cthunk );
325
+ self -> thunk_cptr_data [i ] = NpyCapsule_GetDesc (cthunk );
329
326
Py_DECREF (cthunk );
330
327
// cthunk is kept alive by membership in self->thunks
331
328
}
@@ -487,8 +484,8 @@ static PyObject *pycall(CLazyLinker *self, Py_ssize_t node_idx, int verbose) {
487
484
PyList_SetItem (self -> call_times , node_idx ,
488
485
PyFloat_FromDouble (t1 - t0 + ti ));
489
486
PyObject * count = PyList_GetItem (self -> call_counts , node_idx );
490
- long icount = PyInt_AsLong (count );
491
- PyList_SetItem (self -> call_counts , node_idx , PyInt_FromLong (icount + 1 ));
487
+ long icount = PyLong_AsLong (count );
488
+ PyList_SetItem (self -> call_counts , node_idx , PyLong_FromLong (icount + 1 ));
492
489
}
493
490
} else {
494
491
if (verbose ) {
@@ -512,8 +509,8 @@ static int c_call(CLazyLinker *self, Py_ssize_t node_idx, int verbose) {
512
509
PyList_SetItem (self -> call_times , node_idx ,
513
510
PyFloat_FromDouble (t1 - t0 + ti ));
514
511
PyObject * count = PyList_GetItem (self -> call_counts , node_idx );
515
- long icount = PyInt_AsLong (count );
516
- PyList_SetItem (self -> call_counts , node_idx , PyInt_FromLong (icount + 1 ));
512
+ long icount = PyLong_AsLong (count );
513
+ PyList_SetItem (self -> call_counts , node_idx , PyLong_FromLong (icount + 1 ));
517
514
} else {
518
515
err = fn (self -> thunk_cptr_data [node_idx ]);
519
516
}
@@ -774,20 +771,20 @@ static PyObject *CLazyLinker_call(PyObject *_self, PyObject *args,
774
771
output_subset = (char * )calloc (self -> n_output_vars , sizeof (char ));
775
772
for (int it = 0 ; it < output_subset_size ; ++ it ) {
776
773
PyObject * elem = PyList_GetItem (output_subset_ptr , it );
777
- if (!PyInt_Check (elem )) {
774
+ if (!PyLong_Check (elem )) {
778
775
err = 1 ;
779
776
PyErr_SetString (PyExc_RuntimeError ,
780
777
"Some elements of output_subset list are not int" );
781
778
}
782
- output_subset [PyInt_AsLong (elem )] = 1 ;
779
+ output_subset [PyLong_AsLong (elem )] = 1 ;
783
780
}
784
781
}
785
782
}
786
783
787
784
self -> position_of_error = -1 ;
788
785
// create constants used to fill the var_compute_cells
789
- PyObject * one = PyInt_FromLong (1 );
790
- PyObject * zero = PyInt_FromLong (0 );
786
+ PyObject * one = PyLong_FromLong (1 );
787
+ PyObject * zero = PyLong_FromLong (0 );
791
788
792
789
// pre-allocate our return value
793
790
Py_INCREF (Py_None );
@@ -942,11 +939,8 @@ static PyMemberDef CLazyLinker_members[] = {
942
939
};
943
940
944
941
static PyTypeObject lazylinker_ext_CLazyLinkerType = {
945
- #if defined(NPY_PY3K )
946
942
PyVarObject_HEAD_INIT (NULL , 0 )
947
- #else
948
- PyObject_HEAD_INIT (NULL ) 0 , /*ob_size*/
949
- #endif
943
+
950
944
"lazylinker_ext.CLazyLinker" , /*tp_name*/
951
945
sizeof (CLazyLinker ), /*tp_basicsize*/
952
946
0 , /*tp_itemsize*/
@@ -996,7 +990,7 @@ static PyMethodDef lazylinker_ext_methods[] = {
996
990
{NULL , NULL , 0 , NULL } /* Sentinel */
997
991
};
998
992
999
- #if defined( NPY_PY3K )
993
+
1000
994
static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT ,
1001
995
"lazylinker_ext" ,
1002
996
NULL ,
@@ -1006,28 +1000,19 @@ static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT,
1006
1000
NULL ,
1007
1001
NULL ,
1008
1002
NULL };
1009
- #endif
1010
- #if defined(NPY_PY3K )
1011
- #define RETVAL m
1003
+
1012
1004
PyMODINIT_FUNC PyInit_lazylinker_ext (void ) {
1013
- #else
1014
- #define RETVAL
1015
- PyMODINIT_FUNC initlazylinker_ext (void ) {
1016
- #endif
1005
+
1017
1006
PyObject * m ;
1018
1007
1019
1008
lazylinker_ext_CLazyLinkerType .tp_new = PyType_GenericNew ;
1020
1009
if (PyType_Ready (& lazylinker_ext_CLazyLinkerType ) < 0 )
1021
- return RETVAL ;
1022
- #if defined( NPY_PY3K )
1010
+ return NULL ;
1011
+
1023
1012
m = PyModule_Create (& moduledef );
1024
- #else
1025
- m = Py_InitModule3 ("lazylinker_ext" , lazylinker_ext_methods ,
1026
- "Example module that creates an extension type." );
1027
- #endif
1028
1013
Py_INCREF (& lazylinker_ext_CLazyLinkerType );
1029
1014
PyModule_AddObject (m , "CLazyLinker" ,
1030
1015
(PyObject * )& lazylinker_ext_CLazyLinkerType );
1031
1016
1032
- return RETVAL ;
1017
+ return m ;
1033
1018
}
0 commit comments