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

merge

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