Commit 505a104f authored by scoder's avatar scoder

Merge pull request #275 from cython/no-old-python

Get rid of obsolete Python cruft.
parents f9835e7a 7c499675
...@@ -2,11 +2,7 @@ import cython ...@@ -2,11 +2,7 @@ import cython
from Cython import __version__ from Cython import __version__
import re, os, sys, time import re, os, sys, time
try: from glob import iglob
from glob import iglob
except ImportError:
# Py2.4
from glob import glob as iglob
try: try:
import gzip import gzip
......
...@@ -18,11 +18,7 @@ pyexec_utility_code = UtilityCode.load("PyExec", "Builtins.c") ...@@ -18,11 +18,7 @@ pyexec_utility_code = UtilityCode.load("PyExec", "Builtins.c")
pyexec_globals_utility_code = UtilityCode.load("PyExecGlobals", "Builtins.c") pyexec_globals_utility_code = UtilityCode.load("PyExecGlobals", "Builtins.c")
globals_utility_code = UtilityCode.load("Globals", "Builtins.c") globals_utility_code = UtilityCode.load("Globals", "Builtins.c")
py_set_utility_code = UtilityCode.load("pyset_compat", "Builtins.c")
builtin_utility_code = { builtin_utility_code = {
'set' : py_set_utility_code,
'frozenset' : py_set_utility_code,
} }
...@@ -294,15 +290,11 @@ builtin_types_table = [ ...@@ -294,15 +290,11 @@ builtin_types_table = [
# ("file", "PyFile_Type", []), # not in Py3 # ("file", "PyFile_Type", []), # not in Py3
("set", "PySet_Type", [BuiltinMethod("__contains__", "TO", "b", "PySequence_Contains"), ("set", "PySet_Type", [BuiltinMethod("__contains__", "TO", "b", "PySequence_Contains"),
BuiltinMethod("clear", "T", "r", "PySet_Clear", BuiltinMethod("clear", "T", "r", "PySet_Clear"),
utility_code = py_set_utility_code),
# discard() and remove() have a special treatment for unhashable values # discard() and remove() have a special treatment for unhashable values
# BuiltinMethod("discard", "TO", "r", "PySet_Discard", # BuiltinMethod("discard", "TO", "r", "PySet_Discard"),
# utility_code = py_set_utility_code), BuiltinMethod("add", "TO", "r", "PySet_Add"),
BuiltinMethod("add", "TO", "r", "PySet_Add", BuiltinMethod("pop", "T", "O", "PySet_Pop")]),
utility_code = py_set_utility_code),
BuiltinMethod("pop", "T", "O", "PySet_Pop",
utility_code = py_set_utility_code)]),
("frozenset", "PyFrozenSet_Type", []), ("frozenset", "PyFrozenSet_Type", []),
] ]
......
...@@ -3998,7 +3998,7 @@ class SliceIndexNode(ExprNode): ...@@ -3998,7 +3998,7 @@ class SliceIndexNode(ExprNode):
TempitaUtilityCode.load_cached("SliceTupleAndList", "ObjectHandling.c")) TempitaUtilityCode.load_cached("SliceTupleAndList", "ObjectHandling.c"))
cfunc = '__Pyx_PyTuple_GetSlice' cfunc = '__Pyx_PyTuple_GetSlice'
else: else:
cfunc = '__Pyx_PySequence_GetSlice' cfunc = 'PySequence_GetSlice'
code.putln( code.putln(
"%s = %s(%s, %s, %s); %s" % ( "%s = %s(%s, %s, %s); %s" % (
result, result,
...@@ -6686,7 +6686,6 @@ class SetNode(ExprNode): ...@@ -6686,7 +6686,6 @@ class SetNode(ExprNode):
self.compile_time_value_error(e) self.compile_time_value_error(e)
def generate_evaluation_code(self, code): def generate_evaluation_code(self, code):
code.globalstate.use_utility_code(Builtin.py_set_utility_code)
self.allocate_temp_result(code) self.allocate_temp_result(code)
code.putln( code.putln(
"%s = PySet_New(0); %s" % ( "%s = PySet_New(0); %s" % (
...@@ -9205,7 +9204,7 @@ class AddNode(NumBinopNode): ...@@ -9205,7 +9204,7 @@ class AddNode(NumBinopNode):
def infer_builtin_types_operation(self, type1, type2): def infer_builtin_types_operation(self, type1, type2):
# b'abc' + 'abc' raises an exception in Py3, # b'abc' + 'abc' raises an exception in Py3,
# so we can safely infer the Py2 type for bytes here # so we can safely infer the Py2 type for bytes here
string_types = [bytes_type, str_type, basestring_type, unicode_type] # Py2.4 lacks tuple.index() string_types = (bytes_type, str_type, basestring_type, unicode_type)
if type1 in string_types and type2 in string_types: if type1 in string_types and type2 in string_types:
return string_types[max(string_types.index(type1), return string_types[max(string_types.index(type1),
string_types.index(type2))] string_types.index(type2))]
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
# #
import os, sys, re, codecs import os, sys, re, codecs
if sys.version_info[:2] < (2, 4): if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[:2] < (3, 2):
sys.stderr.write("Sorry, Cython requires Python 2.4 or later\n") sys.stderr.write("Sorry, Cython requires Python 2.6+ or 3.2+\n")
sys.exit(1) sys.exit(1)
import Errors import Errors
...@@ -461,8 +461,8 @@ class CompilationOptions(object): ...@@ -461,8 +461,8 @@ class CompilationOptions(object):
include_path [string] Directories to search for include files include_path [string] Directories to search for include files
output_file string Name of generated .c file output_file string Name of generated .c file
generate_pxi boolean Generate .pxi file for public declarations generate_pxi boolean Generate .pxi file for public declarations
capi_reexport_cincludes capi_reexport_cincludes
boolean Add cincluded headers to any auto-generated boolean Add cincluded headers to any auto-generated
header files. header files.
timestamps boolean Only compile changed source files. timestamps boolean Only compile changed source files.
verbose boolean Always print source names being compiled verbose boolean Always print source names being compiled
......
...@@ -572,8 +572,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -572,8 +572,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln('#include "%s"' % filename) code.putln('#include "%s"' % filename)
code.putln("#ifndef Py_PYTHON_H") code.putln("#ifndef Py_PYTHON_H")
code.putln(" #error Python headers needed to compile C extensions, please install development version of Python.") code.putln(" #error Python headers needed to compile C extensions, please install development version of Python.")
code.putln("#elif PY_VERSION_HEX < 0x02040000") code.putln("#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)")
code.putln(" #error Cython requires Python 2.4+.") code.putln(" #error Cython requires Python 2.6+ or Python 3.2+.")
code.putln("#else") code.putln("#else")
code.globalstate["end"].putln("#endif /* Py_PYTHON_H */") code.globalstate["end"].putln("#endif /* Py_PYTHON_H */")
......
...@@ -2029,7 +2029,6 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform): ...@@ -2029,7 +2029,6 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
self.PySet_New_func_type, self.PySet_New_func_type,
args=pos_args, args=pos_args,
is_temp=node.is_temp, is_temp=node.is_temp,
utility_code=UtilityCode.load_cached('pyset_compat', 'Builtins.c'),
py_name="set") py_name="set")
PyFrozenSet_New_func_type = PyrexTypes.CFuncType( PyFrozenSet_New_func_type = PyrexTypes.CFuncType(
...@@ -3708,7 +3707,7 @@ class ConsolidateOverflowCheck(Visitor.CythonTransform): ...@@ -3708,7 +3707,7 @@ class ConsolidateOverflowCheck(Visitor.CythonTransform):
sequence will be evaluated and the overflow bit checked only at the end. sequence will be evaluated and the overflow bit checked only at the end.
""" """
overflow_bit_node = None overflow_bit_node = None
def visit_Node(self, node): def visit_Node(self, node):
if self.overflow_bit_node is not None: if self.overflow_bit_node is not None:
saved = self.overflow_bit_node saved = self.overflow_bit_node
...@@ -3718,7 +3717,7 @@ class ConsolidateOverflowCheck(Visitor.CythonTransform): ...@@ -3718,7 +3717,7 @@ class ConsolidateOverflowCheck(Visitor.CythonTransform):
else: else:
self.visitchildren(node) self.visitchildren(node)
return node return node
def visit_NumBinopNode(self, node): def visit_NumBinopNode(self, node):
if node.overflow_check and node.overflow_fold: if node.overflow_check and node.overflow_fold:
top_level_overflow = self.overflow_bit_node is None top_level_overflow = self.overflow_bit_node is None
......
...@@ -107,9 +107,7 @@ typedef struct { ...@@ -107,9 +107,7 @@ typedef struct {
/////////////// GetAndReleaseBuffer /////////////// /////////////// GetAndReleaseBuffer ///////////////
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
#if PY_VERSION_HEX >= 0x02060000
if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags); if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
#endif
{{for type_ptr, getbuffer, releasebuffer in types}} {{for type_ptr, getbuffer, releasebuffer in types}}
{{if getbuffer}} {{if getbuffer}}
...@@ -117,29 +115,7 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { ...@@ -117,29 +115,7 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
{{endif}} {{endif}}
{{endfor}} {{endfor}}
#if PY_VERSION_HEX < 0x02060000
if (obj->ob_type->tp_dict) {
PyObject *getbuffer_cobj = PyObject_GetItem(
obj->ob_type->tp_dict, PYIDENT("__pyx_getbuffer"));
if (getbuffer_cobj) {
getbufferproc func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj);
Py_DECREF(getbuffer_cobj);
if (!func)
goto fail;
return func(obj, view, flags);
} else {
PyErr_Clear();
}
}
#endif
PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name); PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name);
#if PY_VERSION_HEX < 0x02060000
fail:
#endif
return -1; return -1;
} }
...@@ -147,12 +123,10 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { ...@@ -147,12 +123,10 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) {
PyObject *obj = view->obj; PyObject *obj = view->obj;
if (!obj) return; if (!obj) return;
#if PY_VERSION_HEX >= 0x02060000
if (PyObject_CheckBuffer(obj)) { if (PyObject_CheckBuffer(obj)) {
PyBuffer_Release(view); PyBuffer_Release(view);
return; return;
} }
#endif
{{for type_ptr, getbuffer, releasebuffer in types}} {{for type_ptr, getbuffer, releasebuffer in types}}
{{if releasebuffer}} {{if releasebuffer}}
...@@ -160,31 +134,6 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { ...@@ -160,31 +134,6 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) {
{{endif}} {{endif}}
{{endfor}} {{endfor}}
#if PY_VERSION_HEX < 0x02060000
if (obj->ob_type->tp_dict) {
PyObject *releasebuffer_cobj = PyObject_GetItem(
obj->ob_type->tp_dict, PYIDENT("__pyx_releasebuffer"));
if (releasebuffer_cobj) {
releasebufferproc func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj);
Py_DECREF(releasebuffer_cobj);
if (!func)
goto fail;
func(obj, view);
return;
} else {
PyErr_Clear();
}
}
#endif
goto nofail;
#if PY_VERSION_HEX < 0x02060000
fail:
#endif
PyErr_WriteUnraisable(obj);
nofail:
Py_DECREF(obj); Py_DECREF(obj);
view->obj = NULL; view->obj = NULL;
} }
......
...@@ -370,57 +370,8 @@ static CYTHON_INLINE PyObject* __Pyx_PyDict_ViewItems(PyObject* d) { ...@@ -370,57 +370,8 @@ static CYTHON_INLINE PyObject* __Pyx_PyDict_ViewItems(PyObject* d) {
return __Pyx_PyObject_CallMethod0(d, (PY_MAJOR_VERSION >= 3) ? PYIDENT("items") : PYIDENT("viewitems")); return __Pyx_PyObject_CallMethod0(d, (PY_MAJOR_VERSION >= 3) ? PYIDENT("items") : PYIDENT("viewitems"));
} }
//////////////////// pyset_compat.proto ////////////////////
#if PY_VERSION_HEX < 0x02050000
#ifndef PyAnySet_CheckExact
#define PyAnySet_CheckExact(ob) \
((ob)->ob_type == &PySet_Type || \
(ob)->ob_type == &PyFrozenSet_Type)
#define PySet_New(iterable) \
PyObject_CallFunctionObjArgs((PyObject *)&PySet_Type, (iterable), NULL)
#define PyFrozenSet_New(iterable) \
PyObject_CallFunctionObjArgs((PyObject *)&PyFrozenSet_Type, (iterable), NULL)
#define PySet_Size(anyset) \
PyObject_Size((anyset))
#define PySet_GET_SIZE(anyset) \
PyObject_Size((anyset))
#define PySet_Contains(anyset, key) \
PySequence_Contains((anyset), (key))
#define PySet_Pop(set) \
PyObject_CallMethod((set), (char*)"pop", NULL)
static CYTHON_INLINE int PySet_Clear(PyObject *set) {
PyObject *ret = PyObject_CallMethod(set, (char*)"clear", NULL);
if (!ret) return -1;
Py_DECREF(ret); return 0;
}
static CYTHON_INLINE int PySet_Discard(PyObject *set, PyObject *key) {
PyObject *ret = PyObject_CallMethod(set, (char*)"discard", (char*)"(O)", key);
if (!ret) return -1;
Py_DECREF(ret); return 0;
}
static CYTHON_INLINE int PySet_Add(PyObject *set, PyObject *key) {
PyObject *ret = PyObject_CallMethod(set, (char*)"add", (char*)"(O)", key);
if (!ret) return -1;
Py_DECREF(ret); return 0;
}
#endif /* PyAnySet_CheckExact (<= Py2.4) */
#endif /* < Py2.5 */
//////////////////// pyfrozenset_new.proto //////////////////// //////////////////// pyfrozenset_new.proto ////////////////////
//@substitute: naming //@substitute: naming
//@requires: pyset_compat
static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) { static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) {
if (it) { if (it) {
......
...@@ -660,9 +660,7 @@ static PyTypeObject __pyx_CyFunctionType_type = { ...@@ -660,9 +660,7 @@ static PyTypeObject __pyx_CyFunctionType_type = {
0, /*tp_subclasses*/ 0, /*tp_subclasses*/
0, /*tp_weaklist*/ 0, /*tp_weaklist*/
0, /*tp_del*/ 0, /*tp_del*/
#if PY_VERSION_HEX >= 0x02060000
0, /*tp_version_tag*/ 0, /*tp_version_tag*/
#endif
#if PY_VERSION_HEX >= 0x030400a1 #if PY_VERSION_HEX >= 0x030400a1
0, /*tp_finalize*/ 0, /*tp_finalize*/
#endif #endif
...@@ -1112,9 +1110,7 @@ static PyTypeObject __pyx_FusedFunctionType_type = { ...@@ -1112,9 +1110,7 @@ static PyTypeObject __pyx_FusedFunctionType_type = {
0, /*tp_subclasses*/ 0, /*tp_subclasses*/
0, /*tp_weaklist*/ 0, /*tp_weaklist*/
0, /*tp_del*/ 0, /*tp_del*/
#if PY_VERSION_HEX >= 0x02060000
0, /*tp_version_tag*/ 0, /*tp_version_tag*/
#endif
#if PY_VERSION_HEX >= 0x030400a1 #if PY_VERSION_HEX >= 0x030400a1
0, /*tp_finalize*/ 0, /*tp_finalize*/
#endif #endif
......
...@@ -78,11 +78,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, ...@@ -78,11 +78,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
} }
} }
#if PY_VERSION_HEX < 0x02050000
if (PyClass_Check(type)) {
#else
if (PyType_Check(type)) { if (PyType_Check(type)) {
#endif
/* instantiate the type now (we don't know when and how it will be caught) */ /* instantiate the type now (we don't know when and how it will be caught) */
#if CYTHON_COMPILING_IN_PYPY #if CYTHON_COMPILING_IN_PYPY
/* PyPy can't handle value == NULL */ /* PyPy can't handle value == NULL */
...@@ -102,17 +98,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, ...@@ -102,17 +98,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
} }
/* Normalize to raise <class>, <instance> */ /* Normalize to raise <class>, <instance> */
value = type; value = type;
#if PY_VERSION_HEX < 0x02050000
if (PyInstance_Check(type)) {
type = (PyObject*) ((PyInstanceObject*)type)->in_class;
Py_INCREF(type);
} else {
type = 0;
PyErr_SetString(PyExc_TypeError,
"raise: exception must be an old-style class or instance");
goto raise_error;
}
#else
type = (PyObject*) Py_TYPE(type); type = (PyObject*) Py_TYPE(type);
Py_INCREF(type); Py_INCREF(type);
if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
...@@ -120,7 +105,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, ...@@ -120,7 +105,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
"raise: exception class must be a subclass of BaseException"); "raise: exception class must be a subclass of BaseException");
goto raise_error; goto raise_error;
} }
#endif
} }
__Pyx_ErrRestore(type, value, tb); __Pyx_ErrRestore(type, value, tb);
......
...@@ -347,11 +347,7 @@ static PyObject *__Pyx_Generator_Close(PyObject *self) { ...@@ -347,11 +347,7 @@ static PyObject *__Pyx_Generator_Close(PyObject *self) {
Py_DECREF(yf); Py_DECREF(yf);
} }
if (err == 0) if (err == 0)
#if PY_VERSION_HEX < 0x02050000
PyErr_SetNone(PyExc_StopIteration);
#else
PyErr_SetNone(PyExc_GeneratorExit); PyErr_SetNone(PyExc_GeneratorExit);
#endif
retval = __Pyx_Generator_SendEx(gen, NULL); retval = __Pyx_Generator_SendEx(gen, NULL);
if (retval) { if (retval) {
Py_DECREF(retval); Py_DECREF(retval);
...@@ -362,10 +358,8 @@ static PyObject *__Pyx_Generator_Close(PyObject *self) { ...@@ -362,10 +358,8 @@ static PyObject *__Pyx_Generator_Close(PyObject *self) {
raised_exception = PyErr_Occurred(); raised_exception = PyErr_Occurred();
if (!raised_exception if (!raised_exception
|| raised_exception == PyExc_StopIteration || raised_exception == PyExc_StopIteration
#if PY_VERSION_HEX >= 0x02050000
|| raised_exception == PyExc_GeneratorExit || raised_exception == PyExc_GeneratorExit
|| PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit) || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit)
#endif
|| PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration)) || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration))
{ {
if (raised_exception) PyErr_Clear(); /* ignore these errors */ if (raised_exception) PyErr_Clear(); /* ignore these errors */
...@@ -391,7 +385,6 @@ static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) { ...@@ -391,7 +385,6 @@ static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
if (yf) { if (yf) {
PyObject *ret; PyObject *ret;
Py_INCREF(yf); Py_INCREF(yf);
#if PY_VERSION_HEX >= 0x02050000
if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) { if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
int err = __Pyx_Generator_CloseIter(gen, yf); int err = __Pyx_Generator_CloseIter(gen, yf);
Py_DECREF(yf); Py_DECREF(yf);
...@@ -400,7 +393,6 @@ static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) { ...@@ -400,7 +393,6 @@ static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
return __Pyx_Generator_SendEx(gen, NULL); return __Pyx_Generator_SendEx(gen, NULL);
goto throw_here; goto throw_here;
} }
#endif
gen->is_running = 1; gen->is_running = 1;
if (__Pyx_Generator_CheckExact(yf)) { if (__Pyx_Generator_CheckExact(yf)) {
ret = __Pyx_Generator_Throw(yf, args); ret = __Pyx_Generator_Throw(yf, args);
...@@ -546,11 +538,7 @@ static void __Pyx_Generator_del(PyObject *self) { ...@@ -546,11 +538,7 @@ static void __Pyx_Generator_del(PyObject *self) {
static PyMemberDef __pyx_Generator_memberlist[] = { static PyMemberDef __pyx_Generator_memberlist[] = {
{(char *) "gi_running", {(char *) "gi_running",
#if PY_VERSION_HEX >= 0x02060000
T_BOOL, T_BOOL,
#else
T_BYTE,
#endif
offsetof(__pyx_GeneratorObject, is_running), offsetof(__pyx_GeneratorObject, is_running),
READONLY, READONLY,
NULL}, NULL},
...@@ -619,9 +607,7 @@ static PyTypeObject __pyx_GeneratorType_type = { ...@@ -619,9 +607,7 @@ static PyTypeObject __pyx_GeneratorType_type = {
#else #else
__Pyx_Generator_del, /*tp_del*/ __Pyx_Generator_del, /*tp_del*/
#endif #endif
#if PY_VERSION_HEX >= 0x02060000
0, /*tp_version_tag*/ 0, /*tp_version_tag*/
#endif
#if PY_VERSION_HEX >= 0x030400a1 #if PY_VERSION_HEX >= 0x030400a1
__Pyx_Generator_del, /*tp_finalize*/ __Pyx_Generator_del, /*tp_finalize*/
#endif #endif
......
...@@ -43,7 +43,6 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { ...@@ -43,7 +43,6 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
empty_dict = PyDict_New(); empty_dict = PyDict_New();
if (!empty_dict) if (!empty_dict)
goto bad; goto bad;
#if PY_VERSION_HEX >= 0x02050000
{ {
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
if (level == -1) { if (level == -1) {
...@@ -83,14 +82,6 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { ...@@ -83,14 +82,6 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
#endif #endif
} }
} }
#else
if (level>0) {
PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
goto bad;
}
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, NULL);
#endif
bad: bad:
#if PY_VERSION_HEX < 0x03030000 #if PY_VERSION_HEX < 0x03030000
Py_XDECREF(py_import); Py_XDECREF(py_import);
...@@ -287,11 +278,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class ...@@ -287,11 +278,7 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class
PyOS_snprintf(warning, sizeof(warning), PyOS_snprintf(warning, sizeof(warning),
"%s.%s size changed, may indicate binary incompatibility", "%s.%s size changed, may indicate binary incompatibility",
module_name, class_name); module_name, class_name);
#if PY_VERSION_HEX < 0x02050000
if (PyErr_Warn(NULL, warning) < 0) goto bad;
#else
if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
#endif
} }
else if ((size_t)basicsize != size) { else if ((size_t)basicsize != size) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
......
...@@ -44,66 +44,9 @@ ...@@ -44,66 +44,9 @@
#define Py_OptimizeFlag 0 #define Py_OptimizeFlag 0
#endif #endif
#if PY_VERSION_HEX < 0x02050000 #define __PYX_BUILD_PY_SSIZE_T "n"
typedef int Py_ssize_t; #define CYTHON_FORMAT_SSIZE_T "z"
#define PY_SSIZE_T_MAX INT_MAX #define __Pyx_PyIndex_Check PyIndex_Check
#define PY_SSIZE_T_MIN INT_MIN
#define PY_FORMAT_SIZE_T ""
#define CYTHON_FORMAT_SSIZE_T ""
#define PyInt_FromSsize_t(z) PyInt_FromLong(z)
#define PyInt_AsSsize_t(o) __Pyx_PyInt_As_int(o)
#define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
(PyErr_Format(PyExc_TypeError, \
"expected index value, got %.200s", Py_TYPE(o)->tp_name), \
(PyObject*)0))
#define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
!PyComplex_Check(o))
#define PyIndex_Check __Pyx_PyIndex_Check
#define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#define __PYX_BUILD_PY_SSIZE_T "i"
#else
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#define __Pyx_PyIndex_Check PyIndex_Check
#endif
#if PY_VERSION_HEX < 0x02060000
#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
#define PyVarObject_HEAD_INIT(type, size) \
PyObject_HEAD_INIT(type) size,
#define PyType_Modified(t)
typedef struct {
void *buf;
PyObject *obj;
Py_ssize_t len;
Py_ssize_t itemsize;
int readonly;
int ndim;
char *format;
Py_ssize_t *shape;
Py_ssize_t *strides;
Py_ssize_t *suboffsets;
void *internal;
} Py_buffer;
#define PyBUF_SIMPLE 0
#define PyBUF_WRITABLE 0x0001
#define PyBUF_FORMAT 0x0004
#define PyBUF_ND 0x0008
#define PyBUF_STRIDES (0x0010 | PyBUF_ND)
#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
#define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
#define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
#endif
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
#define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
...@@ -117,25 +60,15 @@ ...@@ -117,25 +60,15 @@
#define __Pyx_DefaultClassType PyType_Type #define __Pyx_DefaultClassType PyType_Type
#endif #endif
#if PY_VERSION_HEX < 0x02060000
#define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
#endif
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define Py_TPFLAGS_CHECKTYPES 0 #define Py_TPFLAGS_CHECKTYPES 0
#define Py_TPFLAGS_HAVE_INDEX 0 #define Py_TPFLAGS_HAVE_INDEX 0
#endif #endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) #if PY_MAJOR_VERSION >= 3
#define Py_TPFLAGS_HAVE_NEWBUFFER 0 #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif #endif
#if PY_VERSION_HEX < 0x02060000
#define Py_TPFLAGS_HAVE_VERSION_TAG 0
#endif
#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TPFLAGS_IS_ABSTRACT)
#define Py_TPFLAGS_IS_ABSTRACT 0
#endif
#if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE) #if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE)
#define Py_TPFLAGS_HAVE_FINALIZE 0 #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif #endif
...@@ -187,25 +120,6 @@ ...@@ -187,25 +120,6 @@
#define PyString_CheckExact PyUnicode_CheckExact #define PyString_CheckExact PyUnicode_CheckExact
#endif #endif
#if PY_VERSION_HEX < 0x02060000
#define PyBytesObject PyStringObject
#define PyBytes_Type PyString_Type
#define PyBytes_Check PyString_Check
#define PyBytes_CheckExact PyString_CheckExact
#define PyBytes_FromString PyString_FromString
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
#define PyBytes_FromFormat PyString_FromFormat
#define PyBytes_DecodeEscape PyString_DecodeEscape
#define PyBytes_AsString PyString_AsString
#define PyBytes_AsStringAndSize PyString_AsStringAndSize
#define PyBytes_Size PyString_Size
#define PyBytes_AS_STRING PyString_AS_STRING
#define PyBytes_GET_SIZE PyString_GET_SIZE
#define PyBytes_Repr PyString_Repr
#define PyBytes_Concat PyString_Concat
#define PyBytes_ConcatAndDel PyString_ConcatAndDel
#endif
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
#define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
...@@ -215,10 +129,6 @@ ...@@ -215,10 +129,6 @@
#define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif #endif
#if PY_VERSION_HEX < 0x02060000
#define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
#define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#endif
#ifndef PySet_CheckExact #ifndef PySet_CheckExact
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
#endif #endif
...@@ -256,38 +166,13 @@ ...@@ -256,38 +166,13 @@
#define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
#endif #endif
#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
#define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
#define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
#define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
#define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
(PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
(likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
(PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
#define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
(PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
(likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
(PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
#define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
(PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
(likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
(PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif #endif
#if PY_VERSION_HEX < 0x02050000 #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))
#define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
#define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))
#define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n)))
#else
#define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))
#define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
#define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000 #if PY_VERSION_HEX < 0x02050000
#define __Pyx_NAMESTR(n) ((char *)(n)) #define __Pyx_NAMESTR(n) ((char *)(n))
...@@ -510,11 +395,7 @@ static int __Pyx_check_binary_version(void) { ...@@ -510,11 +395,7 @@ static int __Pyx_check_binary_version(void) {
"compiletime version %s of module '%.100s' " "compiletime version %s of module '%.100s' "
"does not match runtime version %s", "does not match runtime version %s",
ctversion, __Pyx_MODULE_NAME, rtversion); ctversion, __Pyx_MODULE_NAME, rtversion);
#if PY_VERSION_HEX < 0x02050000
return PyErr_Warn(NULL, message);
#else
return PyErr_WarnEx(NULL, message, 1); return PyErr_WarnEx(NULL, message, 1);
#endif
} }
return 0; return 0;
} }
......
...@@ -158,7 +158,7 @@ static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* ...@@ -158,7 +158,7 @@ static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject*
if (likely(next)) if (likely(next))
return next; return next;
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_COMPILING_IN_CPYTHON
#if PY_VERSION_HEX >= 0x03010000 || (PY_MAJOR_VERSION < 3 && PY_VERSION_HEX >= 0x02070000) #if PY_VERSION_HEX >= 0x02070000
if (unlikely(iternext == &_PyObject_NextNotImplemented)) if (unlikely(iternext == &_PyObject_NextNotImplemented))
return NULL; return NULL;
#endif #endif
...@@ -1029,7 +1029,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { ...@@ -1029,7 +1029,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
/////////////// PyObjectLookupSpecial.proto /////////////// /////////////// PyObjectLookupSpecial.proto ///////////////
//@requires: PyObjectGetAttrStr //@requires: PyObjectGetAttrStr
#if CYTHON_COMPILING_IN_CPYTHON && (PY_VERSION_HEX >= 0x03020000 || PY_MAJOR_VERSION < 3 && PY_VERSION_HEX >= 0x02070000) #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
// looks like calling _PyType_Lookup() isn't safe in Py<=2.6/3.1 // looks like calling _PyType_Lookup() isn't safe in Py<=2.6/3.1
static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) { static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) {
PyObject *res; PyObject *res;
...@@ -1144,14 +1144,10 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg ...@@ -1144,14 +1144,10 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg
if (unlikely(!call)) if (unlikely(!call))
return PyObject_Call(func, arg, kw); return PyObject_Call(func, arg, kw);
#if PY_VERSION_HEX >= 0x02060000
if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
return NULL; return NULL;
#endif
result = (*call)(func, arg, kw); result = (*call)(func, arg, kw);
#if PY_VERSION_HEX >= 0x02060000
Py_LeaveRecursiveCall(); Py_LeaveRecursiveCall();
#endif
if (unlikely(!result) && unlikely(!PyErr_Occurred())) { if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
PyErr_SetString( PyErr_SetString(
PyExc_SystemError, PyExc_SystemError,
......
...@@ -88,7 +88,7 @@ static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L); /*proto*/ ...@@ -88,7 +88,7 @@ static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L); /*proto*/
//@requires: ObjectHandling.c::PyObjectCallMethod //@requires: ObjectHandling.c::PyObjectCallMethod
static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) { static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02050000 #if CYTHON_COMPILING_IN_CPYTHON
if (Py_TYPE(L) == &PySet_Type) { if (Py_TYPE(L) == &PySet_Type) {
return PySet_Pop(L); return PySet_Pop(L);
} }
...@@ -97,7 +97,7 @@ static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) { ...@@ -97,7 +97,7 @@ static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
} }
static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) { static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02040000 #if CYTHON_COMPILING_IN_CPYTHON
/* Check that both the size is positive and no reallocation shrinking needs to be done. */ /* Check that both the size is positive and no reallocation shrinking needs to be done. */
if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) { if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
Py_SIZE(L) -= 1; Py_SIZE(L) -= 1;
......
...@@ -567,10 +567,8 @@ static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize ...@@ -567,10 +567,8 @@ static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize
Py_ssize_t sub_len; Py_ssize_t sub_len;
int retval; int retval;
#if PY_VERSION_HEX >= 0x02060000
Py_buffer view; Py_buffer view;
view.obj = NULL; view.obj = NULL;
#endif
if ( PyBytes_Check(arg) ) { if ( PyBytes_Check(arg) ) {
sub_ptr = PyBytes_AS_STRING(arg); sub_ptr = PyBytes_AS_STRING(arg);
...@@ -583,15 +581,10 @@ static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize ...@@ -583,15 +581,10 @@ static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize
} }
#endif #endif
else { else {
#if PY_VERSION_HEX < 0x02060000
if (unlikely(PyObject_AsCharBuffer(arg, &sub_ptr, &sub_len)))
return -1;
#else
if (unlikely(PyObject_GetBuffer(self, &view, PyBUF_SIMPLE) == -1)) if (unlikely(PyObject_GetBuffer(self, &view, PyBUF_SIMPLE) == -1))
return -1; return -1;
sub_ptr = (const char*) view.buf; sub_ptr = (const char*) view.buf;
sub_len = view.len; sub_len = view.len;
#endif
} }
if (end > self_len) if (end > self_len)
...@@ -616,10 +609,8 @@ static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize ...@@ -616,10 +609,8 @@ static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize
else else
retval = 0; retval = 0;
#if PY_VERSION_HEX >= 0x02060000
if (view.obj) if (view.obj)
PyBuffer_Release(&view); PyBuffer_Release(&view);
#endif
return retval; return retval;
} }
......
...@@ -207,12 +207,10 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_ ...@@ -207,12 +207,10 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_
#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */ #endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */
#if !CYTHON_COMPILING_IN_PYPY #if !CYTHON_COMPILING_IN_PYPY
#if PY_VERSION_HEX >= 0x02060000
if (PyByteArray_Check(o)) { if (PyByteArray_Check(o)) {
*length = PyByteArray_GET_SIZE(o); *length = PyByteArray_GET_SIZE(o);
return PyByteArray_AS_STRING(o); return PyByteArray_AS_STRING(o);
} else } else
#endif
#endif #endif
{ {
char* result; char* result;
...@@ -300,11 +298,7 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { ...@@ -300,11 +298,7 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
} }
#endif #endif
#endif #endif
#if PY_VERSION_HEX < 0x02060000
return PyInt_AsSsize_t(b);
#else
return PyLong_AsSsize_t(b); return PyLong_AsSsize_t(b);
#endif
} }
x = PyNumber_Index(b); x = PyNumber_Index(b);
if (!x) return -1; if (!x) return -1;
...@@ -314,17 +308,7 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { ...@@ -314,17 +308,7 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
} }
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000 return PyInt_FromSize_t(ival);
if (ival <= LONG_MAX)
return PyInt_FromLong((long)ival);
else {
unsigned char *bytes = (unsigned char *) &ival;
int one = 1; int little = (int)*(unsigned char*)&one;
return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
}
#else
return PyInt_FromSize_t(ival);
#endif
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment