Commit c041335f authored by Kurt Smith's avatar Kurt Smith Committed by Mark Florisson

nonecheck directive works for memoryviewslices.

parent bd77c8db
...@@ -3929,7 +3929,7 @@ class AttributeNode(ExprNode): ...@@ -3929,7 +3929,7 @@ class AttributeNode(ExprNode):
self.obj.result_as(self.obj.type), self.obj.result_as(self.obj.type),
rhs.result_as(self.ctype()))) rhs.result_as(self.ctype())))
else: else:
if (self.obj.type.is_extension_type if (self.obj.type.needs_nonecheck()
and self.needs_none_check and self.needs_none_check
and code.globalstate.directives['nonecheck']): and code.globalstate.directives['nonecheck']):
self.put_nonecheck(code) self.put_nonecheck(code)
...@@ -3978,7 +3978,13 @@ class AttributeNode(ExprNode): ...@@ -3978,7 +3978,13 @@ class AttributeNode(ExprNode):
def put_nonecheck(self, code): def put_nonecheck(self, code):
code.globalstate.use_utility_code(raise_noneattr_error_utility_code) code.globalstate.use_utility_code(raise_noneattr_error_utility_code)
code.putln("if (%s) {" % code.unlikely("%s == Py_None") % self.obj.result_as(PyrexTypes.py_object_type)) if self.obj.type.is_extension_type:
test = "%s == Py_None" % self.obj.result_as(PyrexTypes.py_object_type)
elif self.obj.type.is_memoryviewslice:
test = "!%s.memview" % self.obj.result()
else:
assert False
code.putln("if (%s) {" % code.unlikely(test))
code.putln("__Pyx_RaiseNoneAttributeError(\"%s\");" % self.attribute) code.putln("__Pyx_RaiseNoneAttributeError(\"%s\");" % self.attribute)
code.putln(code.error_goto(self.pos)) code.putln(code.error_goto(self.pos))
code.putln("}") code.putln("}")
......
...@@ -218,6 +218,14 @@ static int %s(const __Pyx_memviewslice mvs) { ...@@ -218,6 +218,14 @@ static int %s(const __Pyx_memviewslice mvs) {
return decl, impl return decl, impl
copy_to_template = '''
static int %(copy_to_name)s(const __Pyx_memviewslice from_mvs, __Pyx_memviewslice to_mvs) {
/* ensure from_mvs & to_mvs have the same shape & dtype */
}
'''
copy_template = ''' copy_template = '''
static __Pyx_memviewslice %(copy_name)s(const __Pyx_memviewslice from_mvs) { static __Pyx_memviewslice %(copy_name)s(const __Pyx_memviewslice from_mvs) {
......
...@@ -174,6 +174,9 @@ class PyrexType(BaseType): ...@@ -174,6 +174,9 @@ class PyrexType(BaseType):
# abstract # abstract
pass pass
def needs_nonecheck(self):
return 0
def public_decl(base_code, dll_linkage): def public_decl(base_code, dll_linkage):
if dll_linkage: if dll_linkage:
...@@ -362,6 +365,9 @@ class MemoryViewSliceType(PyrexType): ...@@ -362,6 +365,9 @@ class MemoryViewSliceType(PyrexType):
self.is_c_contig, self.is_f_contig = MemoryView.is_cf_contig(self.axes) self.is_c_contig, self.is_f_contig = MemoryView.is_cf_contig(self.axes)
assert not (self.is_c_contig and self.is_f_contig) assert not (self.is_c_contig and self.is_f_contig)
def needs_nonecheck(self):
return True
def is_complete(self): def is_complete(self):
# incomplete since the underlying struct doesn't have a cython.memoryview object. # incomplete since the underlying struct doesn't have a cython.memoryview object.
return 0 return 0
...@@ -671,6 +677,9 @@ class PyExtensionType(PyObjectType): ...@@ -671,6 +677,9 @@ class PyExtensionType(PyObjectType):
is_extension_type = 1 is_extension_type = 1
has_attributes = 1 has_attributes = 1
def needs_nonecheck(self):
return True
objtypedef_cname = None objtypedef_cname = None
def __init__(self, name, typedef_flag, base_type, is_external=0): def __init__(self, name, typedef_flag, base_type, is_external=0):
......
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