Commit ca525fde authored by Boxiang Sun's avatar Boxiang Sun

Initial attempt to add cdef magic method to nogil extension

parent 1f183ba5
...@@ -1977,6 +1977,8 @@ class CCodeWriter(object): ...@@ -1977,6 +1977,8 @@ class CCodeWriter(object):
elif type.is_memoryviewslice: elif type.is_memoryviewslice:
from . import MemoryView from . import MemoryView
self.putln("%s = %s;" % (decl, MemoryView.memslice_entry_init)) self.putln("%s = %s;" % (decl, MemoryView.memslice_entry_init))
elif type.is_struct and type.is_extension_type and type.nogil:
self.putln("%s;" % decl)
else: else:
self.putln("%s%s;" % (static and "static " or "", decl)) self.putln("%s%s;" % (static and "static " or "", decl))
......
...@@ -5827,6 +5827,8 @@ class DelStatNode(StatNode): ...@@ -5827,6 +5827,8 @@ class DelStatNode(StatNode):
error(arg.pos, "Deletion of global C variable") error(arg.pos, "Deletion of global C variable")
elif arg.type.is_ptr and arg.type.base_type.is_cpp_class: elif arg.type.is_ptr and arg.type.base_type.is_cpp_class:
self.cpp_check(env) self.cpp_check(env)
elif arg.type.is_struct_or_union and arg.type.nogil:
pass # del nogil extension
elif arg.type.is_cpp_class: elif arg.type.is_cpp_class:
error(arg.pos, "Deletion of non-heap C++ object") error(arg.pos, "Deletion of non-heap C++ object")
elif arg.is_subscript and arg.base.type is Builtin.bytearray_type: elif arg.is_subscript and arg.base.type is Builtin.bytearray_type:
...@@ -5855,6 +5857,8 @@ class DelStatNode(StatNode): ...@@ -5855,6 +5857,8 @@ class DelStatNode(StatNode):
arg.generate_evaluation_code(code) arg.generate_evaluation_code(code)
code.putln("delete %s;" % arg.result()) code.putln("delete %s;" % arg.result())
arg.generate_disposal_code(code) arg.generate_disposal_code(code)
elif arg.type.is_struct_or_union and hasattr(arg.type, "nogil") and arg.type.nogil:
code.putln("free(&%s);" % arg.result())
# else error reported earlier # else error reported earlier
def annotate(self, code): def annotate(self, code):
......
...@@ -2223,6 +2223,7 @@ class CClassScope(ClassScope): ...@@ -2223,6 +2223,7 @@ class CClassScope(ClassScope):
cname=None, visibility='private', api=0, in_pxd=0, cname=None, visibility='private', api=0, in_pxd=0,
defining=0, modifiers=(), utility_code=None, overridable=False): defining=0, modifiers=(), utility_code=None, overridable=False):
if get_special_method_signature(name) and not self.parent_type.is_builtin_type: if get_special_method_signature(name) and not self.parent_type.is_builtin_type:
if not(hasattr(self.parent_type, "nogil") and self.parent_type.nogil and self.parent_type.is_struct_or_union):
error(pos, "Special methods must be declared with 'def', not 'cdef'") error(pos, "Special methods must be declared with 'def', not 'cdef'")
args = type.args args = type.args
if not type.is_static_method: if not type.is_static_method:
......
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