Commit e9036d3a authored by Robert Bradshaw's avatar Robert Bradshaw

Merge branch '0.22.x' into release-candidate

parents 1fb644d6 73022d11
...@@ -58,7 +58,7 @@ Other changes ...@@ -58,7 +58,7 @@ Other changes
* ``_`` is no longer considered a cacheable builtin as it could interfere with * ``_`` is no longer considered a cacheable builtin as it could interfere with
gettext. gettext.
* Cythonize-computed metadata now cached in the generate C files. * Cythonize-computed metadata now cached in the generated C files.
* Several corrections and extensions in numpy, cpython, and libcpp pxd files. * Several corrections and extensions in numpy, cpython, and libcpp pxd files.
......
...@@ -6767,11 +6767,18 @@ class ListNode(SequenceNode): ...@@ -6767,11 +6767,18 @@ class ListNode(SequenceNode):
else: else:
offset = '' offset = ''
for i, arg in enumerate(self.args): for i, arg in enumerate(self.args):
code.putln("%s[%s%s] = %s;" % ( if arg.type.is_array:
self.result(), code.globalstate.use_utility_code(UtilityCode.load_cached("IncludeStringH", "StringTools.c"))
i, code.putln("memcpy(&(%s[%s%s]), %s, sizeof(%s[0]));" % (
offset, self.result(), i, offset,
arg.result())) arg.result(), self.result()
))
else:
code.putln("%s[%s%s] = %s;" % (
self.result(),
i,
offset,
arg.result()))
if self.mult_factor: if self.mult_factor:
code.putln("}") code.putln("}")
code.putln("}") code.putln("}")
......
...@@ -552,10 +552,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -552,10 +552,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("/* Generated by Cython %s */" % Version.watermark) code.putln("/* Generated by Cython %s */" % Version.watermark)
code.putln("") code.putln("")
if metadata: if metadata:
code.putln("/* Cython Metadata */") code.putln("/* BEGIN: Cython Metadata")
code.putln("/*")
code.putln(json.dumps(metadata, indent=4)) code.putln(json.dumps(metadata, indent=4))
code.putln("*/") code.putln("END: Cython Metadata */")
code.putln("") code.putln("")
code.putln("#define PY_SSIZE_T_CLEAN") code.putln("#define PY_SSIZE_T_CLEAN")
......
...@@ -35,45 +35,56 @@ ...@@ -35,45 +35,56 @@
#endif #endif
#define __Pyx_TraceDeclarations(codeobj) \ #define __Pyx_TraceDeclarations(codeobj) \
static PyCodeObject *$frame_code_cname = NULL; if (codeobj != NULL) $frame_code_cname = (PyCodeObject*) codeobj; \ static PyCodeObject *$frame_code_cname = NULL; \
CYTHON_FRAME_MODIFIER PyFrameObject *$frame_cname = NULL; \ CYTHON_FRAME_MODIFIER PyFrameObject *$frame_cname = NULL; \
int __Pyx_use_tracing = 0; int __Pyx_use_tracing = 0; \
if (codeobj) $frame_code_cname = (PyCodeObject*) codeobj;
#define __Pyx_TraceCall(funcname, srcfile, firstlineno) \ #define __Pyx_TraceCall(funcname, srcfile, firstlineno) \
if (unlikely(PyThreadState_GET()->use_tracing && \ { PyThreadState* tstate = PyThreadState_GET(); \
(PyThreadState_GET()->c_profilefunc || (CYTHON_TRACE && PyThreadState_GET()->c_tracefunc)))) { \ if (unlikely(tstate->use_tracing) && !tstate->tracing && \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, funcname, srcfile, firstlineno); \ (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, funcname, srcfile, firstlineno); \
} \
} }
#define __Pyx_TraceException() \ #define __Pyx_TraceException() \
if (unlikely(__Pyx_use_tracing) && PyThreadState_GET()->use_tracing && \ if (likely(!__Pyx_use_tracing)); else { \
(PyThreadState_GET()->c_profilefunc || (CYTHON_TRACE && PyThreadState_GET()->c_tracefunc))) { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = PyThreadState_GET(); \
tstate->use_tracing = 0; \ if (tstate->use_tracing && \
PyObject *exc_info = __Pyx_GetExceptionTuple(); \ (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
if (exc_info) { \ tstate->tracing++; \
if (CYTHON_TRACE && tstate->c_tracefunc) \ tstate->use_tracing = 0; \
tstate->c_tracefunc( \ PyObject *exc_info = __Pyx_GetExceptionTuple(); \
tstate->c_traceobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \ if (exc_info) { \
tstate->c_profilefunc( \ if (CYTHON_TRACE && tstate->c_tracefunc) \
tstate->c_profileobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \ tstate->c_tracefunc( \
Py_DECREF(exc_info); \ tstate->c_traceobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \
tstate->c_profilefunc( \
tstate->c_profileobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \
Py_DECREF(exc_info); \
} \
tstate->use_tracing = 1; \
tstate->tracing--; \
} \ } \
tstate->use_tracing = 1; \
} }
#define __Pyx_TraceReturn(result) \ #define __Pyx_TraceReturn(result) \
if (unlikely(__Pyx_use_tracing) && PyThreadState_GET()->use_tracing) { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = PyThreadState_GET(); \
tstate->use_tracing = 0; \ if (tstate->use_tracing) { \
if (CYTHON_TRACE && tstate->c_tracefunc) \ tstate->tracing++; \
tstate->c_tracefunc( \ tstate->use_tracing = 0; \
tstate->c_traceobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \ if (CYTHON_TRACE && tstate->c_tracefunc) \
if (tstate->c_profilefunc) \ tstate->c_tracefunc( \
tstate->c_profilefunc( \ tstate->c_traceobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \
tstate->c_profileobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \ if (tstate->c_profilefunc) \
CYTHON_FRAME_DEL; \ tstate->c_profilefunc( \
tstate->use_tracing = 1; \ tstate->c_profileobj, $frame_cname, PyTrace_RETURN, (PyObject*)result); \
CYTHON_FRAME_DEL; \
tstate->use_tracing = 1; \
tstate->tracing--; \
} \
} }
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/ static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/
...@@ -90,12 +101,16 @@ ...@@ -90,12 +101,16 @@
#if CYTHON_TRACE #if CYTHON_TRACE
#define __Pyx_TraceLine(lineno) \ #define __Pyx_TraceLine(lineno) \
if (unlikely(__Pyx_use_tracing) && unlikely(PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_tracefunc)) { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = PyThreadState_GET(); \
$frame_cname->f_lineno = lineno; \ if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) { \
tstate->use_tracing = 0; \ $frame_cname->f_lineno = lineno; \
tstate->c_tracefunc(tstate->c_traceobj, $frame_cname, PyTrace_LINE, NULL); \ tstate->tracing++; \
tstate->use_tracing = 1; \ tstate->use_tracing = 0; \
tstate->c_tracefunc(tstate->c_traceobj, $frame_cname, PyTrace_LINE, NULL); \
tstate->use_tracing = 1; \
tstate->tracing--; \
} \
} }
#else #else
#define __Pyx_TraceLine(lineno) #define __Pyx_TraceLine(lineno)
...@@ -136,17 +151,18 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, ...@@ -136,17 +151,18 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
#endif #endif
} }
(*frame)->f_lineno = firstlineno; (*frame)->f_lineno = firstlineno;
retval = 1;
tstate->tracing++;
tstate->use_tracing = 0; tstate->use_tracing = 0;
#if CYTHON_TRACE #if CYTHON_TRACE
if (tstate->c_tracefunc) if (tstate->c_tracefunc)
tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL); retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0;
if (!tstate->c_profilefunc) if (retval && tstate->c_profilefunc)
retval = 1;
else
#endif #endif
retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0; retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
tstate->use_tracing = (tstate->c_profilefunc || tstate->use_tracing = (tstate->c_profilefunc ||
(CYTHON_TRACE && tstate->c_tracefunc)); (CYTHON_TRACE && tstate->c_tracefunc));
tstate->tracing--;
return tstate->use_tracing && retval; return tstate->use_tracing && retval;
} }
......
...@@ -66,23 +66,23 @@ which Cython handles specially. ...@@ -66,23 +66,23 @@ which Cython handles specially.
self.shape[1] = self.ncols self.shape[1] = self.ncols
# Stride 1 is the distance, in bytes, between two items in a row; # Stride 1 is the distance, in bytes, between two items in a row;
# this is the distance between two adjance items in the vector. # this is the distance between two adjacent items in the vector.
# Stride 0 is the distance between the first elements of adjacent rows. # Stride 0 is the distance between the first elements of adjacent rows.
self.strides[1] = <Py_ssize_t>( <char *>&(self.v[1]) self.strides[1] = <Py_ssize_t>( <char *>&(self.v[1])
- <char *>&(self.v[0])) - <char *>&(self.v[0]))
self.strides[0] = self.ncols * self.strides[1] self.strides[0] = self.ncols * self.strides[1]
buffer.buf = <char *>&(self.v[0]) buffer.buf = <char *>&(self.v[0])
buffer.format = 'f' buffer.format = 'f' # float
buffer.internal = NULL buffer.internal = NULL # see References
buffer.itemsize = itemsize buffer.itemsize = itemsize
buffer.len = self.v.size() * itemsize buffer.len = self.v.size() * itemsize # product(shape) * itemsize
buffer.ndim = 2 buffer.ndim = 2
buffer.obj = self buffer.obj = self
buffer.readonly = 0 buffer.readonly = 0
buffer.shape = self.shape buffer.shape = self.shape
buffer.strides = self.strides buffer.strides = self.strides
buffer.suboffsets = NULL buffer.suboffsets = NULL # for pointer arrays only
def __releasebuffer__(self, Py_buffer *buffer): def __releasebuffer__(self, Py_buffer *buffer):
pass pass
......
...@@ -102,6 +102,7 @@ EXT_DEP_MODULES = { ...@@ -102,6 +102,7 @@ EXT_DEP_MODULES = {
'tag:pstats': 'pstats', 'tag:pstats': 'pstats',
'tag:posix' : 'posix', 'tag:posix' : 'posix',
'tag:array' : 'array', 'tag:array' : 'array',
'tag:coverage': 'coverage',
'tag:ipython': 'IPython', 'tag:ipython': 'IPython',
'tag:jedi': 'jedi', 'tag:jedi': 'jedi',
} }
......
...@@ -14,6 +14,8 @@ inherited_final_method ...@@ -14,6 +14,8 @@ inherited_final_method
tryfinallychaining # also see FIXME in "yield_from_pep380" test tryfinallychaining # also see FIXME in "yield_from_pep380" test
cimport_alias_subclass cimport_alias_subclass
coverage # depends on newer coverage.py version
# CPython regression tests that don't current work: # CPython regression tests that don't current work:
pyregr.test_signal pyregr.test_signal
pyregr.test_capi pyregr.test_capi
......
...@@ -67,6 +67,57 @@ def from_int_array_array(): ...@@ -67,6 +67,57 @@ def from_int_array_array():
return v return v
def assign_int_array_array():
"""
>>> assign_int_array_array()
[[11, 12, 13], [21, 22, 23]]
"""
cdef int[2][3] v = [[11, 12, 13], [21, 22, 23]]
return v
def assign_int_array_array_from_tuples():
"""
>>> assign_int_array_array_from_tuples()
[[11, 12, 13], [21, 22, 23]]
"""
cdef int[2][3] v = ([11, 12, 13], [21, 22, 23])
return v
''' FIXME: this currently crashes:
def assign_int_array_array_from_tuples():
"""
>>> assign_int_array_array_from_tuples()
[[11, 12, 13], [21, 22, 23]]
"""
cdef int[2][3] v = ((11, 12, 13), (21, 22, 23))
return v
'''
def build_from_list_of_arrays():
"""
>>> build_from_list_of_arrays()
[[11, 12, 13], [21, 22, 23]]
"""
cdef int[3] x = [11, 12, 13]
cdef int[3] y = [21, 22, 23]
cdef int[2][3] v = [x, y]
return v
def build_from_tuple_of_arrays():
"""
>>> build_from_tuple_of_arrays()
[[11, 12, 13], [21, 22, 23]]
"""
cdef int[3] x = [11, 12, 13]
cdef int[3] y = [21, 22, 23]
cdef int[2][3] v = (x, y)
return v
ctypedef struct MyStructType: ctypedef struct MyStructType:
int x int x
double y double y
......
# mode: run
# tag: coverage,trace
"""
PYTHON setup.py build_ext -i
PYTHON coverage_test.py
"""
######## setup.py ########
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize('coverage_test_cy.py'))
######## coverage_test_cy.py ########
# cython: linetrace=True
# distutils: define_macros=CYTHON_TRACE=1
def func1(a, b):
x = 1 # 5
c = func2(a) + b # 6
return x + c # 7
def func2(a):
return a * 2 # 11
######## coverage_test.py ########
try:
# io.StringIO in Py2.x cannot handle str ...
from StringIO import StringIO
except ImportError:
from io import StringIO
from coverage import coverage
import coverage_test_cy
def run_coverage():
cov = coverage()
cov.start()
assert coverage_test_cy.func1(1, 2) == 5
assert coverage_test_cy.func2(2) == 4
cov.stop()
out = StringIO()
cov.report([coverage_test_cy], file=out)
lines = out.getvalue().splitlines()
assert any('coverage_test_cy' in line for line in lines), "coverage_test_cy not found in coverage"
mod_file, exec_lines, excl_lines, missing_lines, _ = cov.analysis2(coverage_test_cy)
assert 'coverage_test_cy' in mod_file
executed = set(exec_lines) - set(missing_lines)
assert all(line in executed for line in [5, 6, 7, 11]), '%s / %s' % (exec_lines, missing_lines)
if __name__ == '__main__':
run_coverage()
...@@ -37,7 +37,8 @@ def test_fp_classif(): ...@@ -37,7 +37,8 @@ def test_fp_classif():
assert not npmath.isnan(d_zero) assert not npmath.isnan(d_zero)
assert not npmath.isnan(f_zero) assert not npmath.isnan(f_zero)
assert npmath.isinf(npmath.INFINITY) assert npmath.isinf(npmath.INFINITY) == 1
assert npmath.isinf(-npmath.INFINITY) == -1
assert npmath.isnan(npmath.NAN) assert npmath.isnan(npmath.NAN)
assert npmath.signbit(npmath.copysign(1., -1.)) assert npmath.signbit(npmath.copysign(1., -1.))
......
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