Commit b820fbba authored by Robert Bradshaw's avatar Robert Bradshaw

Merge 0.12 release.

parents 55bc639d 0b8b1fb9
......@@ -18,3 +18,5 @@ af6f1bed8cd40a2edefb57d3eacbc9274a8788b4 0.11.2.rc1
eb00d00a73c13b6aa8b440fe07cd7acb52a060e8 0.11.3.rc0
7c695fe49fd6912f52d995fe512d66baacf90ee6 0.11.3
4208042ceeae634f5c0999b8ab75f69faf46b6db 0.12.alpha0
e77827f09af67560aa82a18feab778f71ca0a9d3 0.12.rc0
fae19937e4945c59a5d9d62c63f1c3b09046c3a3 0.12
......@@ -126,6 +126,7 @@ def parse_command_line(args):
sys.stderr.write("Error in compiler directive: %s\n" % e.message)
sys.exit(1)
else:
sys.stderr.write("Unknown compiler flag: %s\n" % option)
bad_usage()
else:
arg = pop_arg()
......
......@@ -3091,6 +3091,11 @@ class AttributeNode(ExprNode):
rhs.py_result()))
rhs.generate_disposal_code(code)
rhs.free_temps(code)
elif self.obj.type.is_complex:
code.putln("__Pyx_SET_C%s(%s, %s);" % (
self.member.upper(),
self.obj.result_as(self.obj.type),
rhs.result_as(self.ctype())))
else:
if (self.obj.type.is_extension_type
and self.needs_none_check
......@@ -5317,9 +5322,16 @@ class CmpNode(object):
coerce_result = "__Pyx_PyBool_FromLong"
else:
coerce_result = ""
if 'not' in op: negation = "!"
else: negation = ""
if 'not' in op:
negation = "!"
else:
negation = ""
if op == 'in' or op == 'not_in':
code.globalstate.use_utility_code(contians_utility_code)
if self.type is PyrexTypes.py_object_type:
coerce_result = "__Pyx_PyBoolOrNull_FromLong"
if op == 'not_in':
negation = "__Pyx_NegateNonNeg"
if operand2.type is dict_type:
code.globalstate.use_utility_code(
raise_none_iter_error_utility_code)
......@@ -5327,24 +5339,28 @@ class CmpNode(object):
code.putln("__Pyx_RaiseNoneNotIterableError(); %s" %
code.error_goto(self.pos))
code.putln("} else {")
code.putln(
"%s = %s(%sPyDict_Contains(%s, %s)); %s" % (
result_code,
coerce_result,
negation,
operand2.py_result(),
operand1.py_result(),
code.error_goto_if_neg(result_code, self.pos)))
code.putln("}")
method = "PyDict_Contains"
else:
code.putln(
"%s = %s(%sPySequence_Contains(%s, %s)); %s" % (
result_code,
coerce_result,
negation,
operand2.py_result(),
operand1.py_result(),
code.error_goto_if_neg(result_code, self.pos)))
method = "PySequence_Contains"
if self.type is PyrexTypes.py_object_type:
error_clause = code.error_goto_if_null
got_ref = "__Pyx_XGOTREF(%s); " % result_code
else:
error_clause = code.error_goto_if_neg
got_ref = ""
code.putln(
"%s = %s(%s(%s(%s, %s))); %s%s" % (
result_code,
coerce_result,
negation,
method,
operand2.py_result(),
operand1.py_result(),
got_ref,
error_clause(result_code, self.pos)))
if operand2.type is dict_type:
code.putln("}")
elif (operand1.type.is_pyobject
and op not in ('is', 'is_not')):
code.putln("%s = PyObject_RichCompare(%s, %s, %s); %s" % (
......@@ -5393,6 +5409,14 @@ class CmpNode(object):
else:
return op
contians_utility_code = UtilityCode(
proto="""
static INLINE long __Pyx_NegateNonNeg(long b) { return unlikely(b < 0) ? b : !b; }
static INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
}
""")
class PrimaryCmpNode(ExprNode, CmpNode):
# Non-cascaded comparison or first comparison of
......
......@@ -743,6 +743,8 @@ def compile(source, options = None, c_compile = 0, c_link = 0,
# Main command-line entry point
#
#------------------------------------------------------------------------
def setuptools_main():
return main(command_line = 1)
def main(command_line = 0):
args = sys.argv[1:]
......
......@@ -458,7 +458,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln(" #define PyVarObject_HEAD_INIT(type, size) \\")
code.putln(" PyObject_HEAD_INIT(type) size,")
code.putln(" #define PyType_Modified(t)")
code.putln(" #define PyBytes_CheckExact PyString_CheckExact")
code.putln("")
code.putln(" typedef struct {")
code.putln(" void *buf;")
......@@ -501,6 +500,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln(" #define PyBaseString_Type PyUnicode_Type")
code.putln(" #define PyString_Type PyUnicode_Type")
code.putln(" #define PyString_CheckExact PyUnicode_CheckExact")
code.putln("#else")
code.putln(" #define PyBytes_Type PyString_Type")
code.putln(" #define PyBytes_CheckExact PyString_CheckExact")
code.putln("#endif")
code.putln("#if PY_MAJOR_VERSION >= 3")
code.putln(" #define PyInt_Type PyLong_Type")
code.putln(" #define PyInt_Check(op) PyLong_Check(op)")
code.putln(" #define PyInt_CheckExact(op) PyLong_CheckExact(op)")
......@@ -523,7 +528,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else:
code.putln(" #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)")
code.putln(" #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)")
code.putln(" #define PyBytes_Type PyString_Type")
code.putln("#endif")
code.putln("#if PY_MAJOR_VERSION >= 3")
......
......@@ -1104,10 +1104,10 @@ class FuncDefNode(StatNode, BlockNode):
env.use_utility_code(force_init_threads_utility_code)
code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
# ----- Automatic lead-ins for certain special functions
if profile:
code.put_trace_call(self.entry.name, self.pos)
if not lenv.nogil:
code.put_setup_refcount_context(self.entry.name)
if profile:
code.put_trace_call(self.entry.name, self.pos)
if is_getbuffer_slot:
self.getbuffer_init(code)
# ----- Create closure scope object
......@@ -1257,18 +1257,19 @@ class FuncDefNode(StatNode, BlockNode):
if self.return_type.is_pyobject:
code.put_xgiveref(self.return_type.as_pyobject(Naming.retval_cname))
code.put_finish_refcount_context()
if self.entry.is_special and self.entry.name == "__hash__":
# Returning -1 for __hash__ is supposed to signal an error
# We do as Python instances and coerce -1 into -2.
code.putln("if (unlikely(%s == -1) && !PyErr_Occurred()) %s = -2;" % (Naming.retval_cname, Naming.retval_cname))
code.putln("if (unlikely(%s == -1) && !PyErr_Occurred()) %s = -2;" % (
Naming.retval_cname, Naming.retval_cname))
if profile:
if self.return_type.is_pyobject:
code.put_trace_return(Naming.retval_cname)
else:
code.put_trace_return("Py_None")
if not lenv.nogil:
code.put_finish_refcount_context()
if acquire_gil:
code.putln("PyGILState_Release(_save);")
......@@ -1424,6 +1425,7 @@ class CFuncDefNode(FuncDefNode):
if not env.is_module_scope or Options.lookup_module_cpdef:
self.override = OverrideCheckNode(self.pos, py_func = self.py_func)
self.body = StatListNode(self.pos, stats=[self.override, self.body])
self.create_local_scope(env)
def call_self_node(self, omit_optional_args=0, is_module_scope=0):
import ExprNodes
......@@ -1756,6 +1758,7 @@ class DefNode(FuncDefNode):
self.declare_pyfunction(env)
self.analyse_signature(env)
self.return_type = self.entry.signature.return_type()
self.create_local_scope(env)
def analyse_signature(self, env):
any_type_tests_needed = 0
......@@ -5115,7 +5118,7 @@ raise_error:
return;
}
#else // Python 3+
#else /* Python 3+ */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
if (tb == Py_None) {
......
......@@ -1068,8 +1068,10 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
# different types - may or may not lead to an error at runtime
return node
# FIXME: we could potentially look up the actual tp_new C method
# of the extension type and call that instead of the generic slot
# FIXME: we could potentially look up the actual tp_new C
# method of the extension type and call that instead of the
# generic slot. That would also allow us to pass parameters
# efficiently.
if not type_arg.type_entry:
# arbitrary variable, needs a None check for safety
......
......@@ -733,7 +733,7 @@ property NAME:
def visit_FuncDefNode(self, node):
self.seen_vars_stack.append(set())
lenv = node.create_local_scope(self.env_stack[-1])
lenv = node.local_scope
node.body.analyse_control_flow(lenv) # this will be totally refactored
node.declare_arguments(lenv)
for var, type_node in node.directive_locals.items():
......
......@@ -202,7 +202,11 @@ class CTypedefType(BaseType):
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0):
name = self.declaration_name(for_display, pyrex)
return self.base_declaration_code(name, entity_code)
if pyrex or for_display:
base_code = name
else:
base_code = public_decl(name, dll_linkage)
return self.base_declaration_code(base_code, entity_code)
def declaration_name(self, for_display = 0, pyrex = 0):
if pyrex or for_display:
......@@ -1053,6 +1057,14 @@ proto="""
#define __Pyx_CREAL(z) ((z).real)
#define __Pyx_CIMAG(z) ((z).imag)
#endif
#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX
#define __Pyx_SET_CREAL(z,x) ((z).real(x))
#define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
#define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
#define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif
""")
complex_type_utility_code = UtilityCode(
......
version = '0.12.alpha0'
version = '0.12'
......@@ -9,6 +9,7 @@ import shutil
import unittest
import doctest
import operator
import tempfile
try:
from StringIO import StringIO
except ImportError:
......@@ -401,12 +402,12 @@ class CythonRunTestCase(CythonCompileTestCase):
return
# fork to make sure we do not keep the tested module loaded
input, output = os.pipe()
result_handle, result_file = tempfile.mkstemp()
child_id = os.fork()
if not child_id:
result_code = 0
try:
output = os.fdopen(output, 'wb')
output = os.fdopen(result_handle, 'wb')
tests = None
try:
partial_result = PartialTestResult(result)
......@@ -423,29 +424,38 @@ class CythonRunTestCase(CythonCompileTestCase):
partial_result.addError(tests, sys.exc_info())
result_code = 1
pickle.dump(partial_result.data(), output)
except:
import traceback
traceback.print_exc()
finally:
try: output.close()
except: pass
os._exit(result_code)
cid, result_code = os.waitpid(child_id, 0)
if result_code in (0,1):
input = os.fdopen(input, 'rb')
try:
PartialTestResult.join_results(result, pickle.load(input))
finally:
input.close()
if result_code:
raise Exception("Tests in module '%s' exited with status %d" %
(module_name, result_code >> 8))
try:
cid, result_code = os.waitpid(child_id, 0)
if result_code in (0,1):
input = open(result_file, 'rb')
try:
PartialTestResult.join_results(result, pickle.load(input))
finally:
input.close()
if result_code:
raise Exception("Tests in module '%s' exited with status %d" %
(module_name, result_code >> 8))
finally:
try: os.unlink(result_file)
except: pass
is_private_field = re.compile('^_[^_]').match
class _FakeClass(object):
def __init__(self, **kwargs):
self.shortDescription = lambda x: kwargs.get('module_name')
self._shortDescription = kwargs.get('module_name')
self.__dict__.update(kwargs)
def shortDescription(self):
return self._shortDescription
try: # Py2.7+ and Py3.2+
from unittest.runner import _TextTestResult
......@@ -809,6 +819,9 @@ if __name__ == '__main__':
if not test_bugs:
exclude_selectors += [ FileListExcluder("tests/bugs.txt") ]
if sys.platform in ['win32', 'cygwin'] and sys.version_info < (2,6):
exclude_selectors += [ lambda x: x == "run.specialfloat" ]
languages = []
if options.use_c:
......
......@@ -7,6 +7,11 @@ compiler_dir = os.path.join(get_python_lib(prefix=''), 'Cython/Compiler')
if sys.platform == "win32":
compiler_dir = compiler_dir[len(sys.prefix)+1:]
if sys.platform == "darwin":
# Don't create resource files on OS X tar.
os.environ['COPY_EXTENDED_ATTRIBUTES_DISABLE'] = 'true'
os.environ['COPYFILE_DISABLE'] = 'true'
setup_args = {}
if sys.version_info[0] >= 3:
......@@ -40,10 +45,24 @@ else:
'Compiler/*.pxd',
'Runtime/*.pyx']}
if os.name == "posix":
scripts = ["bin/cython"]
# This dict is used for passing extra arguments that are setuptools
# specific to setup
setuptools_extra_args = {}
if 'setuptools' in sys.modules:
setuptools_extra_args['zip_safe'] = False
setuptools_extra_args['entry_points'] = {
'console_scripts': [
'cython = Cython.Compiler.Main:setuptools_main',
]
}
scripts = []
else:
scripts = ["cython.py"]
if os.name == "posix":
scripts = ["bin/cython"]
else:
scripts = ["cython.py"]
try:
if sys.version_info[0] >= 3:
......@@ -93,6 +112,7 @@ except ValueError:
print("ERROR: %s" % sys.exc_info()[1])
print("Extension module compilation failed, using plain Python implementation")
setup_args.update(setuptools_extra_args)
from Cython.Compiler.Version import version
......
#!/usr/bin/env python
"""Wrapper to run setup.py using setuptools."""
import setuptools
execfile('setup.py')
# This file contains tests corresponding to of unresolved bugs,
# This file contains tests corresponding to unresolved bugs,
# which will be skipped in the normal testing run.
methodmangling_T5
......@@ -6,3 +6,4 @@ class_attribute_init_values_T18
numpy_ValueError_T172
unsignedbehaviour_T184
missing_baseclass_in_predecl_T262
tp_new_T454
def in_sequence(x, seq):
"""
>>> in_sequence(1, [])
False
>>> in_sequence(1, ())
False
>>> in_sequence(1, {})
False
>>> in_sequence(1, [1])
True
>>> in_sequence(1, (1,))
True
>>> in_sequence(1, {1:None})
True
>>> in_sequence(1, None)
Traceback (most recent call last):
...
TypeError: argument of type 'NoneType' is not iterable
>>> in_sequence(1, 1)
Traceback (most recent call last):
...
TypeError: argument of type 'int' is not iterable
"""
return x in seq
def not_in_sequence(x, seq):
"""
>>> not_in_sequence(1, [])
True
>>> not_in_sequence(1, ())
True
>>> not_in_sequence(1, {})
True
>>> not_in_sequence(1, [1])
False
>>> not_in_sequence(1, (1,))
False
>>> not_in_sequence(1, {1:None})
False
>>> not_in_sequence(1, None)
Traceback (most recent call last):
...
TypeError: argument of type 'NoneType' is not iterable
>>> not_in_sequence(1, 1)
Traceback (most recent call last):
...
TypeError: argument of type 'int' is not iterable
"""
return x not in seq
def in_dict(k, dict dct):
"""
>>> in_dict(1, {})
False
>>> in_dict(1, {1:None})
True
>>> in_dict(1, None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is not iterable
"""
return k in dct
def not_in_dict(k, dict dct):
"""
>>> not_in_dict(1, {})
True
>>> not_in_dict(1, {1:None})
False
>>> not_in_dict(1, None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is not iterable
"""
return k not in dct
def cascaded(a, b, c):
"""
>>> cascaded(1, 2, 3)
Traceback (most recent call last):
...
TypeError: argument of type 'int' is not iterable
>>> cascaded(-1, (1,2), (1,3))
True
>>> cascaded(1, (1,2), (1,3))
False
>>> cascaded(-1, (1,2), (1,0))
False
"""
return a not in b < c
......@@ -6,7 +6,7 @@ def floor_div_float(double a, double b):
-2.0
>>> floor_div_float(-2.3, 1.5)
-2.0
>>> floor_div_float(1e10, 1e-10)
1e+20
>>> floor_div_float(1e10, 1e-10) == 1e20
True
"""
return a // b
......@@ -26,7 +26,7 @@ class MyTypeSubClass(MyType):
def __init__(self):
print "INIT"
# only this can be safely optimised:
# only these can be safely optimised:
@cython.test_assert_path_exists('//PythonCapiCallNode')
@cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode')
......
cimport cython
cdef class TypeWithFactory:
@cython.test_assert_path_exists('//PythonCapiCallNode')
@cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode')
@classmethod
def new(cls):
return cls.__new__(cls)
def make_new_factory():
"""
>>> isinstance(make_new_factory(), TypeWithFactory)
True
"""
return TypeWithFactory.new()
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