Commit df1b2449 authored by Stefan Behnel's avatar Stefan Behnel

Minor cleanups of 'check_size' implementation (#2627).

parent a6990434
......@@ -3061,9 +3061,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# check_size
if not type.is_external or type.is_subclassed:
if type.check_size != 'min':
raise AttributeError("unexpected check_size value '%s' when "
"compiling %s.%s" % (type.check_size, module_name, type.name))
cs = 0
elif type.check_size == 'min':
cs = 1
......@@ -3072,8 +3069,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
elif type.check_size == False:
cs = 2
else:
raise AttributeError("invalid value for check_size '%s' when compiling "
"%s.%s" % (type.check_size, module_name, type.name))
raise RuntimeError("invalid value for check_size '%s' when compiling %s.%s" % (
type.check_size, module_name, type.name))
code.putln('%d);' % cs)
code.putln(' if (!%s) %s' % (type.typeptr_cname, error_code))
......
......@@ -4617,6 +4617,7 @@ class PyClassDefNode(ClassDefNode):
self.bases.free_temps(code)
code.pyclass_stack.pop()
class CClassDefNode(ClassDefNode):
# An extension type definition.
#
......
......@@ -188,7 +188,7 @@ cdef p_varargslist(PyrexScanner s, terminator=*, bint annotated = *)
cdef p_py_arg_decl(PyrexScanner s, bint annotated = *)
cdef p_class_statement(PyrexScanner s, decorators)
cdef p_c_class_definition(PyrexScanner s, pos, ctx)
cdef p_c_class_options(PyrexScanner s)
cdef tuple p_c_class_options(PyrexScanner s)
cdef p_property_decl(PyrexScanner s)
cdef p_doc_string(PyrexScanner s)
cdef p_ignorable_statement(PyrexScanner s)
......
......@@ -3471,7 +3471,7 @@ def p_c_class_definition(s, pos, ctx):
objstruct_name = None
typeobj_name = None
bases = None
check_size = 'min'
check_size = None
if s.sy == '(':
positional_args, keyword_args = p_call_parse_args(s, allow_genexp=False)
if keyword_args:
......@@ -3512,6 +3512,8 @@ def p_c_class_definition(s, pos, ctx):
error(pos, "Type object name specification required for 'api' C class")
else:
error(pos, "Invalid class visibility '%s'" % ctx.visibility)
if check_size is None:
check_size = 'min' # TODO: move into 'CClassDefNode'
return Nodes.CClassDefNode(pos,
visibility = ctx.visibility,
typedef_flag = ctx.typedef_flag,
......@@ -3527,10 +3529,11 @@ def p_c_class_definition(s, pos, ctx):
doc = doc,
body = body)
def p_c_class_options(s):
objstruct_name = None
typeobj_name = None
check_size = 'min'
check_size = None
s.expect('[')
while 1:
if s.sy != 'IDENT':
......
......@@ -1346,14 +1346,14 @@ class PyExtensionType(PyObjectType):
# early_init boolean Whether to initialize early (as opposed to during module execution).
# defered_declarations [thunk] Used to declare class hierarchies in order
# check_size 'min' or boolean What to do if tp_basicsize does not match
is_extension_type = 1
has_attributes = 1
early_init = 1
objtypedef_cname = None
def __init__(self, name, typedef_flag, base_type, is_external=0,
check_size='min'):
def __init__(self, name, typedef_flag, base_type, is_external=0, check_size='min'):
self.name = name
self.scope = None
self.typedef_flag = typedef_flag
......
......@@ -1479,11 +1479,11 @@ class ModuleScope(Scope):
if entry.utility_code_definition:
self.utility_code_list.append(entry.utility_code_definition)
def declare_c_class(self, name, pos, defining = 0, implementing = 0,
module_name = None, base_type = None, objstruct_cname = None,
typeobj_cname = None, typeptr_cname = None, visibility = 'private',
typedef_flag = 0, api = 0, check_size='min',
buffer_defaults = None, shadow = 0):
def declare_c_class(self, name, pos, defining=0, implementing=0,
module_name=None, base_type=None, objstruct_cname=None,
typeobj_cname=None, typeptr_cname=None, visibility='private',
typedef_flag=0, api=0, check_size='min',
buffer_defaults=None, shadow=0):
# If this is a non-extern typedef class, expose the typedef, but use
# the non-typedef struct internally to avoid needing forward
# declarations for anonymous structs.
......@@ -1515,8 +1515,8 @@ class ModuleScope(Scope):
# Make a new entry if needed
#
if not entry or shadow:
type = PyrexTypes.PyExtensionType(name, typedef_flag, base_type,
visibility == 'extern', check_size=check_size)
type = PyrexTypes.PyExtensionType(
name, typedef_flag, base_type, visibility == 'extern', check_size=check_size)
type.pos = pos
type.buffer_defaults = buffer_defaults
if objtypedef_cname is not None:
......
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