Commit 5c61ab41 authored by Lisandro Dalcin's avatar Lisandro Dalcin

merge

parents 4416dc66 97034caf
...@@ -1707,8 +1707,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1707,8 +1707,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
nanny=False) nanny=False)
for entry in env.default_entries: for entry in env.default_entries:
if entry.type.is_pyobject and entry.used: if entry.type.is_pyobject and entry.used:
code.putln("Py_DECREF(%s); %s = 0;" % ( code.put_var_decref_clear(entry)
code.entry_as_pyobject(entry), entry.cname))
code.putln("Py_INCREF(Py_None); return Py_None;") code.putln("Py_INCREF(Py_None); return Py_None;")
code.putln('}') code.putln('}')
......
...@@ -1233,15 +1233,14 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -1233,15 +1233,14 @@ class FuncDefNode(StatNode, BlockNode):
if default: if default:
if not default.is_literal: if not default.is_literal:
default.generate_evaluation_code(code) default.generate_evaluation_code(code)
assign_code = "%s = %s;" % ( default.make_owned_reference(code)
arg.default_entry.cname, code.putln(
default.result_as(arg.default_entry.type)) "%s = %s;" % (
if default.type.is_pyobject: arg.default_entry.cname,
assign_code += " Py_INCREF(%s);" % \ default.result_as(arg.default_entry.type)))
arg.type.as_pyobject(arg.default_entry.cname) default.generate_post_assignment_code(code)
code.putln(assign_code)
default.generate_disposal_code(code)
default.free_temps(code) default.free_temps(code)
code.put_giveref(arg.default_entry.cname)
# For Python class methods, create and store function object # For Python class methods, create and store function object
if self.assmt: if self.assmt:
self.assmt.generate_execution_code(code) self.assmt.generate_execution_code(code)
......
...@@ -4,13 +4,18 @@ the installed distutils infrastructure. Call: ...@@ -4,13 +4,18 @@ the installed distutils infrastructure. Call:
out_fname = pyx_to_dll("foo.pyx") out_fname = pyx_to_dll("foo.pyx")
""" """
import os import os
import sys
import distutils import distutils
from distutils.dist import Distribution from distutils.dist import Distribution
from distutils.errors import DistutilsArgError, DistutilsError, CCompilerError from distutils.errors import DistutilsArgError, DistutilsError, CCompilerError
from distutils.extension import Extension from distutils.extension import Extension
from distutils.util import grok_environment_error from distutils.util import grok_environment_error
from Cython.Distutils import build_ext try:
from Cython.Distutils import build_ext
HAS_CYTHON = True
except ImportError:
HAS_CYTHON = False
import shutil import shutil
DEBUG = 0 DEBUG = 0
...@@ -25,6 +30,8 @@ def pyx_to_dll(filename, ext = None, force_rebuild = 0, ...@@ -25,6 +30,8 @@ def pyx_to_dll(filename, ext = None, force_rebuild = 0,
if not ext: if not ext:
modname, extension = os.path.splitext(name) modname, extension = os.path.splitext(name)
assert extension in (".pyx", ".py"), extension assert extension in (".pyx", ".py"), extension
if not HAS_CYTHON:
filename = filename[:-len(extension)] + '.c'
ext = Extension(name=modname, sources=[filename]) ext = Extension(name=modname, sources=[filename])
if not pyxbuild_dir: if not pyxbuild_dir:
...@@ -37,23 +44,24 @@ def pyx_to_dll(filename, ext = None, force_rebuild = 0, ...@@ -37,23 +44,24 @@ def pyx_to_dll(filename, ext = None, force_rebuild = 0,
args = [quiet, "build_ext"] args = [quiet, "build_ext"]
if force_rebuild: if force_rebuild:
args.append("--force") args.append("--force")
if build_in_temp: if HAS_CYTHON and build_in_temp:
args.append("--pyrex-c-in-temp") args.append("--pyrex-c-in-temp")
dist = Distribution({"script_name": None, "script_args": args}) dist = Distribution({"script_name": None, "script_args": args})
if not dist.ext_modules: if not dist.ext_modules:
dist.ext_modules = [] dist.ext_modules = []
dist.ext_modules.append(ext) dist.ext_modules.append(ext)
dist.cmdclass = {'build_ext': build_ext} if HAS_CYTHON:
dist.cmdclass = {'build_ext': build_ext}
build = dist.get_command_obj('build') build = dist.get_command_obj('build')
build.build_base = pyxbuild_dir build.build_base = pyxbuild_dir
try: try:
ok = dist.parse_command_line() ok = dist.parse_command_line()
except DistutilsArgError, msg: except DistutilsArgError:
raise raise
if DEBUG: if DEBUG:
print "options (after parsing command line):" print("options (after parsing command line):")
dist.dump_option_dicts() dist.dump_option_dicts()
assert ok assert ok
...@@ -62,22 +70,23 @@ def pyx_to_dll(filename, ext = None, force_rebuild = 0, ...@@ -62,22 +70,23 @@ def pyx_to_dll(filename, ext = None, force_rebuild = 0,
dist.run_commands() dist.run_commands()
return dist.get_command_obj("build_ext").get_outputs()[0] return dist.get_command_obj("build_ext").get_outputs()[0]
except KeyboardInterrupt: except KeyboardInterrupt:
raise SystemExit, "interrupted" sys.exit(1)
except (IOError, os.error), exc: except (IOError, os.error):
exc = sys.exc_info()[1]
error = grok_environment_error(exc) error = grok_environment_error(exc)
if DEBUG: if DEBUG:
sys.stderr.write(error + "\n") sys.stderr.write(error + "\n")
raise raise
else: else:
raise RuntimeError, error raise RuntimeError(error)
except (DistutilsError, except (DistutilsError, CCompilerError):
CCompilerError), msg:
if DEBUG: if DEBUG:
raise raise
else: else:
raise RuntimeError(repr(msg)) exc = sys.exc_info()[1]
raise RuntimeError(repr(exc))
if __name__=="__main__": if __name__=="__main__":
pyx_to_dll("dummy.pyx") pyx_to_dll("dummy.pyx")
......
...@@ -483,7 +483,7 @@ if __name__ == '__main__': ...@@ -483,7 +483,7 @@ if __name__ == '__main__':
action="store_true", default=False, action="store_true", default=False,
help="only compile pyx to c, do not run C compiler or run the tests") help="only compile pyx to c, do not run C compiler or run the tests")
parser.add_option("--no-refnanny", dest="with_refnanny", parser.add_option("--no-refnanny", dest="with_refnanny",
action="store_false", default=(sys.version_info[0] < 3), action="store_false", default=True,
help="do not regression test reference counting") help="do not regression test reference counting")
parser.add_option("--sys-pyregr", dest="system_pyregr", parser.add_option("--sys-pyregr", dest="system_pyregr",
action="store_true", default=False, action="store_true", default=False,
......
__doc__ = """ __doc__ = u"""
>>> f0() >>> f0()
(1, 2) (1, 2)
>>> g0() >>> g0()
...@@ -15,19 +15,19 @@ __doc__ = """ ...@@ -15,19 +15,19 @@ __doc__ = """
{1: 2} {1: 2}
>>> f3() #doctest: +ELLIPSIS >>> f3() #doctest: +ELLIPSIS
<argdefaultglb.Foo object at ...> <argdefault.Foo object at ...>
>>> g3() #doctest: +ELLIPSIS >>> g3() #doctest: +ELLIPSIS
<argdefaultglb.Foo object at ...> <argdefault.Foo object at ...>
>>> f4() #doctest: +ELLIPSIS >>> f4() #doctest: +ELLIPSIS
<argdefaultglb.Bar object at ...> <argdefault.Bar object at ...>
>>> g4() #doctest: +ELLIPSIS >>> g4() #doctest: +ELLIPSIS
<argdefaultglb.Bar object at ...> <argdefault.Bar object at ...>
>>> f5() #doctest: +ELLIPSIS >>> f5() #doctest: +ELLIPSIS
<argdefaultglb.Bla object at ...> <argdefault.Bla object at ...>
>>> g5() #doctest: +ELLIPSIS >>> g5() #doctest: +ELLIPSIS
<argdefaultglb.Bla object at ...> <argdefault.Bla object at ...>
""" """
GLB0 = (1, 2) GLB0 = (1, 2)
......
...@@ -165,17 +165,17 @@ def ndarray_str(arr): ...@@ -165,17 +165,17 @@ def ndarray_str(arr):
return unicode(arr).replace(u'\n\n', u'\n<_BLANKLINE_>\n') return unicode(arr).replace(u'\n\n', u'\n<_BLANKLINE_>\n')
def basic(): def basic():
cdef object[int, ndim=2] buf = np.arange(10, dtype=u'i').reshape((2, 5)) cdef object[int, ndim=2] buf = np.arange(10, dtype=b'i').reshape((2, 5))
print buf print buf
print buf[0, 2], buf[0, 0], buf[1, 4], buf[1, 0] print buf[0, 2], buf[0, 0], buf[1, 4], buf[1, 0]
def three_dim(): def three_dim():
cdef object[double, ndim=3] buf = np.arange(24, dtype=u'd').reshape((3,2,4)) cdef object[double, ndim=3] buf = np.arange(24, dtype=b'd').reshape((3,2,4))
print ndarray_str(buf) print ndarray_str(buf)
print buf[0, 1, 2], buf[0, 0, 0], buf[1, 1, 1], buf[1, 0, 0] print buf[0, 1, 2], buf[0, 0, 0], buf[1, 1, 1], buf[1, 0, 0]
def obj_array(): def obj_array():
cdef object[object, ndim=1] buf = np.array([u"a", 1, {}]) cdef object[object, ndim=1] buf = np.array([b"a", 1, {}])
print buf print buf
print buf[0], buf[1], buf[2] print buf[0], buf[1], buf[2]
...@@ -192,12 +192,12 @@ def put_range_long_1d(np.ndarray[long] arr): ...@@ -192,12 +192,12 @@ def put_range_long_1d(np.ndarray[long] arr):
arr[i] = value arr[i] = value
value += 1 value += 1
def test_c_contig(np.ndarray[int, ndim=2, mode=u'c'] arr): def test_c_contig(np.ndarray[int, ndim=2, mode=b'c'] arr):
cdef int i, j cdef int i, j
for i in range(arr.shape[0]): for i in range(arr.shape[0]):
print u" ".join([unicode(arr[i, j]) for j in range(arr.shape[1])]) print u" ".join([unicode(arr[i, j]) for j in range(arr.shape[1])])
def test_f_contig(np.ndarray[int, ndim=2, mode=u'fortran'] arr): def test_f_contig(np.ndarray[int, ndim=2, mode=b'fortran'] arr):
cdef int i, j cdef int i, j
for i in range(arr.shape[0]): for i in range(arr.shape[0]):
print u" ".join([unicode(arr[i, j]) for j in range(arr.shape[1])]) print u" ".join([unicode(arr[i, j]) for j in range(arr.shape[1])])
...@@ -250,7 +250,7 @@ def inc1_float64_t(np.ndarray[np.float64_t] arr): arr[1] += 1 ...@@ -250,7 +250,7 @@ def inc1_float64_t(np.ndarray[np.float64_t] arr): arr[1] += 1
def test_dtype(dtype, inc1): def test_dtype(dtype, inc1):
if dtype in (u'F', u'D', u'G'): if dtype in (b'F', b'D', b'G'):
a = np.array([0, 10+10j], dtype=dtype) a = np.array([0, 10+10j], dtype=dtype)
inc1(a) inc1(a)
if a[1] != (11 + 11j): print u"failed!", a[1] if a[1] != (11 + 11j): print u"failed!", a[1]
...@@ -264,7 +264,7 @@ cdef struct DoubleInt: ...@@ -264,7 +264,7 @@ cdef struct DoubleInt:
def test_recordarray(): def test_recordarray():
cdef object[DoubleInt] arr cdef object[DoubleInt] arr
arr = np.array([(5,5), (4, 6)], dtype=np.dtype(u'i,i')) arr = np.array([(5,5), (4, 6)], dtype=np.dtype(b'i,i'))
cdef DoubleInt rec cdef DoubleInt rec
rec = arr[0] rec = arr[0]
if rec.x != 5: print u"failed" if rec.x != 5: print u"failed"
...@@ -304,10 +304,10 @@ def test_bad_nested_dtypes(): ...@@ -304,10 +304,10 @@ def test_bad_nested_dtypes():
def test_good_cast(): def test_good_cast():
# Check that a signed int can round-trip through casted unsigned int access # Check that a signed int can round-trip through casted unsigned int access
cdef np.ndarray[unsigned int, cast=True] arr = np.array([-100], dtype=u'i') cdef np.ndarray[unsigned int, cast=True] arr = np.array([-100], dtype=b'i')
cdef unsigned int data = arr[0] cdef unsigned int data = arr[0]
return -100 == <int>data return -100 == <int>data
def test_bad_cast(): def test_bad_cast():
# This should raise an exception # This should raise an exception
cdef np.ndarray[long, cast=True] arr = np.array([1], dtype=u'b') cdef np.ndarray[long, cast=True] arr = np.array([1], dtype=b'b')
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