Commit 45e59971 authored by Vitja Makarov's avatar Vitja Makarov

Merge remote branch 'upstream/master'

parents 351d69aa d93ea8d2
...@@ -17,6 +17,16 @@ from Cython.Compiler.ParseTreeTransforms import CythonTransform, SkipDeclaration ...@@ -17,6 +17,16 @@ from Cython.Compiler.ParseTreeTransforms import CythonTransform, SkipDeclaration
from Cython.Compiler.TreeFragment import parse_from_strings from Cython.Compiler.TreeFragment import parse_from_strings
from Cython.Build.Dependencies import strip_string_literals, cythonize from Cython.Build.Dependencies import strip_string_literals, cythonize
# A utility function to convert user-supplied ASCII strings to unicode.
if sys.version_info[0] < 3:
def to_unicode(s):
if not isinstance(s, unicode):
return s.decode('ascii')
else:
return s
else:
to_unicode = lambda x: x
_code_cache = {} _code_cache = {}
...@@ -28,11 +38,10 @@ class AllSymbols(CythonTransform, SkipDeclarations): ...@@ -28,11 +38,10 @@ class AllSymbols(CythonTransform, SkipDeclarations):
self.names.add(node.name) self.names.add(node.name)
def unbound_symbols(code, context=None): def unbound_symbols(code, context=None):
code = to_unicode(code)
if context is None: if context is None:
context = Context([], default_options) context = Context([], default_options)
from Cython.Compiler.ParseTreeTransforms import AnalyseDeclarationsTransform from Cython.Compiler.ParseTreeTransforms import AnalyseDeclarationsTransform
if isinstance(code, str):
code = code.decode('ascii')
tree = parse_from_strings('(tree fragment)', code) tree = parse_from_strings('(tree fragment)', code)
for phase in context.create_pipeline(pxd=False): for phase in context.create_pipeline(pxd=False):
if phase is None: if phase is None:
...@@ -90,6 +99,7 @@ def cython_inline(code, ...@@ -90,6 +99,7 @@ def cython_inline(code,
**kwds): **kwds):
if get_type is None: if get_type is None:
get_type = lambda x: 'object' get_type = lambda x: 'object'
code = to_unicode(code)
code, literals = strip_string_literals(code) code, literals = strip_string_literals(code)
code = strip_common_indent(code) code = strip_common_indent(code)
ctx = Context(cython_include_dirs, default_options) ctx = Context(cython_include_dirs, default_options)
......
...@@ -12,7 +12,7 @@ test_kwds = dict(force=True, quiet=True) ...@@ -12,7 +12,7 @@ test_kwds = dict(force=True, quiet=True)
global_value = 100 global_value = 100
class TestStripLiterals(CythonTest): class TestInline(CythonTest):
def test_simple(self): def test_simple(self):
self.assertEquals(inline("return 1+2", **test_kwds), 3) self.assertEquals(inline("return 1+2", **test_kwds), 3)
......
...@@ -4051,7 +4051,7 @@ class ListNode(SequenceNode): ...@@ -4051,7 +4051,7 @@ class ListNode(SequenceNode):
self.obj_conversion_errors = [] self.obj_conversion_errors = []
if not self.type.subtype_of(dst_type): if not self.type.subtype_of(dst_type):
error(self.pos, "Cannot coerce list to type '%s'" % dst_type) error(self.pos, "Cannot coerce list to type '%s'" % dst_type)
elif dst_type.is_ptr: elif dst_type.is_ptr and dst_type.base_type is not PyrexTypes.c_void_type:
base_type = dst_type.base_type base_type = dst_type.base_type
self.type = PyrexTypes.CArrayType(base_type, len(self.args)) self.type = PyrexTypes.CArrayType(base_type, len(self.args))
for i in range(len(self.original_args)): for i in range(len(self.original_args)):
......
...@@ -635,6 +635,8 @@ class CNumericType(CType): ...@@ -635,6 +635,8 @@ class CNumericType(CType):
is_numeric = 1 is_numeric = 1
default_value = "0" default_value = "0"
has_attributes = True
scope = None
sign_words = ("unsigned ", "", "signed ") sign_words = ("unsigned ", "", "signed ")
...@@ -658,6 +660,23 @@ class CNumericType(CType): ...@@ -658,6 +660,23 @@ class CNumericType(CType):
else: else:
base_code = public_decl(type_name, dll_linkage) base_code = public_decl(type_name, dll_linkage)
return self.base_declaration_code(base_code, entity_code) return self.base_declaration_code(base_code, entity_code)
def attributes_known(self):
if self.scope is None:
import Symtab
self.scope = scope = Symtab.CClassScope(
'',
None,
visibility="extern")
scope.parent_type = self
scope.directives = {}
entry = scope.declare_cfunction(
"conjugate",
CFuncType(self, [CFuncTypeArg("self", self, None)], nogil=True),
pos=None,
defining=1,
cname=" ")
return True
type_conversion_predeclarations = "" type_conversion_predeclarations = ""
...@@ -1080,7 +1099,7 @@ class CComplexType(CNumericType): ...@@ -1080,7 +1099,7 @@ class CComplexType(CNumericType):
scope.declare_var("imag", self.real_type, None, "imag", is_cdef=True) scope.declare_var("imag", self.real_type, None, "imag", is_cdef=True)
entry = scope.declare_cfunction( entry = scope.declare_cfunction(
"conjugate", "conjugate",
CFuncType(self, [CFuncTypeArg("self", self, None)]), CFuncType(self, [CFuncTypeArg("self", self, None)], nogil=True),
pos=None, pos=None,
defining=1, defining=1,
cname="__Pyx_c_conj%s" % self.funcsuffix) cname="__Pyx_c_conj%s" % self.funcsuffix)
......
...@@ -162,6 +162,11 @@ def test_conjugate_typedef(cdouble z): ...@@ -162,6 +162,11 @@ def test_conjugate_typedef(cdouble z):
""" """
return z.conjugate() return z.conjugate()
cdef cdouble test_conjugate_nogil(cdouble z) nogil:
# Really just a compile test.
return z.conjugate()
test_conjugate_nogil(0) # use it
## cdef extern from "complex_numbers_T305.h": ## cdef extern from "complex_numbers_T305.h":
## ctypedef double double_really_float "myfloat" ## ctypedef double double_really_float "myfloat"
## ctypedef float float_really_double "mydouble" ## ctypedef float float_really_double "mydouble"
......
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