Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merged PyPy branch into mainline

  • Loading branch information...
commit 2a07d9a083cc051d1a3581e4154c3efd21ab3501 2 parents 26032d3 + 8fbf75a
@scoder authored
View
14 Cython/Compiler/ModuleNode.py
@@ -1910,6 +1910,9 @@ def generate_module_cleanup_func(self, env, code):
# if entry.type.is_pyobject and entry.used:
# code.putln("Py_DECREF(%s); %s = 0;" % (
# code.entry_as_pyobject(entry), entry.cname))
+ code.putln('#if CYTHON_COMPILING_IN_PYPY')
+ code.putln('Py_CLEAR(%s);' % Naming.builtins_cname)
+ code.putln('#endif')
code.putln("Py_INCREF(Py_None); return Py_None;")
def generate_main_method(self, env, code):
@@ -1968,7 +1971,7 @@ def generate_module_creation_code(self, env, code):
code.putln(
"if (!%s) %s;" % (
env.module_cname,
- code.error_goto(self.pos)));
+ code.error_goto(self.pos)))
code.putln("#if PY_MAJOR_VERSION < 3")
code.putln(
"Py_INCREF(%s);" %
@@ -1980,7 +1983,10 @@ def generate_module_creation_code(self, env, code):
code.putln(
"if (!%s) %s;" % (
Naming.builtins_cname,
- code.error_goto(self.pos)));
+ code.error_goto(self.pos)))
+ code.putln('#if CYTHON_COMPILING_IN_PYPY')
+ code.putln('Py_INCREF(%s);' % Naming.builtins_cname)
+ code.putln('#endif')
code.putln(
'if (__Pyx_SetAttrString(%s, "__builtins__", %s) < 0) %s;' % (
env.module_cname,
@@ -1994,7 +2000,7 @@ def generate_module_creation_code(self, env, code):
code.putln(
"if (!%s) %s;" % (
Naming.preimport_cname,
- code.error_goto(self.pos)));
+ code.error_goto(self.pos)))
def generate_global_init_code(self, env, code):
# Generate code to initialise global PyObject *
@@ -2208,6 +2214,7 @@ def generate_type_ready_code(self, env, entry, code):
# a significant performance hit. (See trac #561.)
for func in entry.type.scope.pyfunc_entries:
if func.is_special and Options.docstrings and func.wrapperbase_cname:
+ code.putln('#if CYTHON_COMPILING_IN_CPYTHON')
code.putln("{")
code.putln(
'PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&%s, "%s"); %s' % (
@@ -2226,6 +2233,7 @@ def generate_type_ready_code(self, env, entry, code):
func.wrapperbase_cname))
code.putln("}")
code.putln("}")
+ code.putln('#endif')
if type.vtable_cname:
code.putln(
"if (__Pyx_SetVtable(%s.tp_dict, %s) < 0) %s" % (
View
10 Cython/Compiler/Nodes.py
@@ -3429,8 +3429,10 @@ def generate_function_header(self, code, with_pymethdef, proto_only=0):
split_string_literal(escape_byte_string(docstr))))
if entry.is_special:
+ code.putln('#if CYTHON_COMPILING_IN_CPYTHON')
code.putln(
"struct wrapperbase %s;" % entry.wrapperbase_cname)
+ code.putln('#endif')
if with_pymethdef or self.target.fused_py_func:
code.put(
@@ -8389,19 +8391,19 @@ def generate_execution_code(self, code):
printing_utility_code = UtilityCode(
proto = """
static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/
-#if PY_MAJOR_VERSION >= 3
+#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
static PyObject* %s = 0;
static PyObject* %s = 0;
#endif
""" % (Naming.print_function, Naming.print_function_kwargs),
cleanup = """
-#if PY_MAJOR_VERSION >= 3
+#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
Py_CLEAR(%s);
Py_CLEAR(%s);
#endif
""" % (Naming.print_function, Naming.print_function_kwargs),
impl = r"""
-#if PY_MAJOR_VERSION < 3
+#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
PyObject *f = PySys_GetObject((char *)"stdout");
if (!f) {
@@ -8511,7 +8513,7 @@ def generate_execution_code(self, code):
static int __Pyx_PrintOne(PyObject* stream, PyObject *o); /*proto*/
""",
impl = r"""
-#if PY_MAJOR_VERSION < 3
+#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
if (!f) {
View
54 Cython/Compiler/Symtab.py
@@ -367,7 +367,7 @@ def declare(self, name, cname, type, pos, visibility, shadow = 0):
# name is not None. Reports a warning if already
# declared.
if type.is_buffer and not isinstance(self, LocalScope):
- error(pos, ERR_BUF_LOCALONLY)
+ error(pos, 'Buffer types only allowed as function local variables')
if not self.in_cinclude and cname and re.match("^_[_A-Z]+$", cname):
# See http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html#Reserved-Names
warning(pos, "'%s' is a reserved name in C." % cname, -1)
@@ -1635,7 +1635,7 @@ def lookup(self, name):
# right thing in this scope (as the class memebers aren't still functions).
# Don't want to add a cfunction to this scope 'cause that would mess with
# the type definition, so we just return the right entry.
- self.use_utility_code(classmethod_utility_code)
+ self.use_utility_code(Code.UtilityCode.load_cached("ClassMethod", "CythonFunction.c"))
entry = Entry(
"classmethod",
"__Pyx_Method_ClassMethod",
@@ -2093,53 +2093,3 @@ def declare_pyfunction(self, name, pos, allow_redefine=False):
error(pos, "Only __get__, __set__ and __del__ methods allowed "
"in a property declaration")
return None
-
-
-# Should this go elsewhere (and then get imported)?
-#------------------------------------------------------------------------------------
-
-classmethod_utility_code = Code.UtilityCode(
-proto = """
-#include "descrobject.h"
-static PyObject* __Pyx_Method_ClassMethod(PyObject *method); /*proto*/
-""",
-impl = """
-static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
- /* It appears that PyMethodDescr_Type is not anywhere exposed in the Python/C API */
- static PyTypeObject *methoddescr_type = NULL;
- if (methoddescr_type == NULL) {
- PyObject *meth = __Pyx_GetAttrString((PyObject*)&PyList_Type, "append");
- if (!meth) return NULL;
- methoddescr_type = Py_TYPE(meth);
- Py_DECREF(meth);
- }
- if (PyObject_TypeCheck(method, methoddescr_type)) { /* cdef classes */
- PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
- #if PY_VERSION_HEX < 0x03020000
- PyTypeObject *d_type = descr->d_type;
- #else
- PyTypeObject *d_type = descr->d_common.d_type;
- #endif
- return PyDescr_NewClassMethod(d_type, descr->d_method);
- }
- else if (PyMethod_Check(method)) { /* python classes */
- return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
- }
- else if (PyCFunction_Check(method)) {
- return PyClassMethod_New(method);
- }
-#ifdef __Pyx_CyFunction_USED
- else if (PyObject_TypeCheck(method, __pyx_CyFunctionType)) {
- return PyClassMethod_New(method);
- }
-#endif
- PyErr_Format(PyExc_TypeError,
- "Class-level classmethod() can only be called on "
- "a method_descriptor or instance method.");
- return NULL;
-}
-""")
-
-#------------------------------------------------------------------------------------
-
-ERR_BUF_LOCALONLY = 'Buffer types only allowed as function local variables'
View
48 Cython/Utility/CythonFunction.c
@@ -881,3 +881,51 @@ static int __pyx_FusedFunction_init(void) {
__pyx_FusedFunctionType = &__pyx_FusedFunctionType_type;
return 0;
}
+
+//////////////////// ClassMethod.proto ////////////////////
+
+#include "descrobject.h"
+static PyObject* __Pyx_Method_ClassMethod(PyObject *method); /*proto*/
+
+//////////////////// ClassMethod ////////////////////
+
+static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
+#if CYTHON_COMPILING_IN_PYPY
+ if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) { /* cdef classes */
+ return PyClassMethod_New(method);
+ }
+#else
+ /* It appears that PyMethodDescr_Type is not anywhere exposed in the Python/C API */
+ static PyTypeObject *methoddescr_type = NULL;
+ if (methoddescr_type == NULL) {
+ PyObject *meth = __Pyx_GetAttrString((PyObject*)&PyList_Type, "append");
+ if (!meth) return NULL;
+ methoddescr_type = Py_TYPE(meth);
+ Py_DECREF(meth);
+ }
+ if (PyObject_TypeCheck(method, methoddescr_type)) { /* cdef classes */
+ PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
+ #if PY_VERSION_HEX < 0x03020000
+ PyTypeObject *d_type = descr->d_type;
+ #else
+ PyTypeObject *d_type = descr->d_common.d_type;
+ #endif
+ return PyDescr_NewClassMethod(d_type, descr->d_method);
+ }
+#endif
+ else if (PyMethod_Check(method)) { /* python classes */
+ return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
+ }
+ else if (PyCFunction_Check(method)) {
+ return PyClassMethod_New(method);
+ }
+#ifdef __Pyx_CyFunction_USED
+ else if (PyObject_TypeCheck(method, __pyx_CyFunctionType)) {
+ return PyClassMethod_New(method);
+ }
+#endif
+ PyErr_Format(PyExc_TypeError,
+ "Class-level classmethod() can only be called on "
+ "a method_descriptor or instance method.");
+ return NULL;
+}
View
33 Cython/Utility/Exceptions.c
@@ -200,6 +200,7 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
PyObject *local_type, *local_value, *local_tb;
+#if CYTHON_COMPILING_IN_CPYTHON
PyObject *tmp_type, *tmp_value, *tmp_tb;
PyThreadState *tstate = PyThreadState_GET();
local_type = tstate->curexc_type;
@@ -208,19 +209,27 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
tstate->curexc_type = 0;
tstate->curexc_value = 0;
tstate->curexc_traceback = 0;
+#else
+ PyErr_Fetch(&local_type, &local_value, &local_tb);
+#endif
PyErr_NormalizeException(&local_type, &local_value, &local_tb);
+#if CYTHON_COMPILING_IN_CPYTHON
if (unlikely(tstate->curexc_type))
+#else
+ if (unlikely(PyErr_Occurred()))
+#endif
goto bad;
#if PY_MAJOR_VERSION >= 3
if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
goto bad;
#endif
- *type = local_type;
- *value = local_value;
- *tb = local_tb;
Py_INCREF(local_type);
Py_INCREF(local_value);
Py_INCREF(local_tb);
+ *type = local_type;
+ *value = local_value;
+ *tb = local_tb;
+#if CYTHON_COMPILING_IN_CPYTHON
tmp_type = tstate->exc_type;
tmp_value = tstate->exc_value;
tmp_tb = tstate->exc_traceback;
@@ -228,10 +237,13 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
tstate->exc_value = local_value;
tstate->exc_traceback = local_tb;
/* Make sure tstate is in a consistent state when we XDECREF
- these objects (XDECREF may run arbitrary code). */
+ these objects (DECREF may run arbitrary code). */
Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb);
+#else
+ PyErr_SetExcInfo(local_type, local_value, local_tb);
+#endif
return 0;
bad:
*type = 0;
@@ -251,6 +263,7 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb);
/////////////// SaveResetException ///////////////
static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
PyThreadState *tstate = PyThreadState_GET();
*type = tstate->exc_type;
*value = tstate->exc_value;
@@ -258,9 +271,13 @@ static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value,
Py_XINCREF(*type);
Py_XINCREF(*value);
Py_XINCREF(*tb);
+#else
+ PyErr_GetExcInfo(type, value, tb);
+#endif
}
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
+#if CYTHON_COMPILING_IN_CPYTHON
PyObject *tmp_type, *tmp_value, *tmp_tb;
PyThreadState *tstate = PyThreadState_GET();
tmp_type = tstate->exc_type;
@@ -272,6 +289,9 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb)
Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb);
+#else
+ PyErr_SetExcInfo(type, value, tb);
+#endif
}
/////////////// SwapException.proto ///////////////
@@ -282,6 +302,7 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value,
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
+#if CYTHON_COMPILING_IN_CPYTHON
PyThreadState *tstate = PyThreadState_GET();
tmp_type = tstate->exc_type;
@@ -291,6 +312,10 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value,
tstate->exc_type = *type;
tstate->exc_value = *value;
tstate->exc_traceback = *tb;
+#else
+ PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
+ PyErr_SetExcInfo(*type, *value, *tb);
+#endif
*type = tmp_type;
*value = tmp_value;
View
7 Cython/Utility/FunctionArguments.c
@@ -121,6 +121,12 @@ static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
{
PyObject* key = 0;
Py_ssize_t pos = 0;
+#if CPYTHON_COMPILING_IN_PYPY
+ /* PyPy appears to check keywords at call time, not at unpacking time => not much to do here */
+ if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
+ goto invalid_keyword;
+ return 1;
+#else
while (PyDict_Next(kwdict, &pos, &key, 0)) {
#if PY_MAJOR_VERSION < 3
if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
@@ -136,6 +142,7 @@ static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
PyErr_Format(PyExc_TypeError,
"%s() keywords must be strings", function_name);
return 0;
+#endif
invalid_keyword:
PyErr_Format(PyExc_TypeError,
#if PY_MAJOR_VERSION < 3
View
2  Cython/Utility/Generator.c
@@ -506,12 +506,14 @@ static void __Pyx_Generator_del(PyObject *self) {
_Py_NewReference(self);
self->ob_refcnt = refcnt;
}
+#if CYTHON_COMPILING_FOR_CPYTHON
assert(PyType_IS_GC(self->ob_type) &&
_Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
/* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
* we need to undo that. */
_Py_DEC_REFTOTAL;
+#endif
/* If Py_TRACE_REFS, _Py_NewReference re-added self to the object
* chain, so no more to do there.
* If COUNT_ALLOCS, the original decref bumped tp_frees, and
View
7 Cython/Utility/ObjectHandling.c
@@ -119,10 +119,17 @@ static CYTHON_INLINE int __Pyx_unpack_tuple2(PyObject* tuple, PyObject** pvalue1
__Pyx_UnpackTupleError(tuple, 2);
goto bad;
}
+#if CYTHON_COMPILING_IN_PYPY
+ value1 = PySequence_GetItem(tuple, 0);
+ if (unlikely(!value1)) goto bad;
+ value2 = PySequence_GetItem(tuple, 1);
+ if (unlikely(!value2)) goto bad;
+#else
value1 = PyTuple_GET_ITEM(tuple, 0);
value2 = PyTuple_GET_ITEM(tuple, 1);
Py_INCREF(value1);
Py_INCREF(value2);
+#endif
if (decref_tuple) { Py_DECREF(tuple); }
}
*pvalue1 = value1;
Please sign in to comment.
Something went wrong with that request. Please try again.