diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2018-09-29 10:21:24 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2018-09-29 10:21:24 +0200 |
commit | df1b2449468aa8809c21e74e7ed494daf93b3516 (patch) | |
tree | 83d6924f4f2e60a4b4729aecc479f74a498cf5e2 /Cython | |
parent | a6990434f908b9aa075a79ebe23d3daf0efccaa8 (diff) | |
download | cython-df1b2449468aa8809c21e74e7ed494daf93b3516.tar.gz |
Minor cleanups of 'check_size' implementation (#2627).
Diffstat (limited to 'Cython')
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 7 | ||||
-rw-r--r-- | Cython/Compiler/Nodes.py | 1 | ||||
-rw-r--r-- | Cython/Compiler/Parsing.pxd | 2 | ||||
-rw-r--r-- | Cython/Compiler/Parsing.py | 7 | ||||
-rw-r--r-- | Cython/Compiler/PyrexTypes.py | 4 | ||||
-rw-r--r-- | Cython/Compiler/Symtab.py | 14 |
6 files changed, 18 insertions, 17 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 6764e6db9..fd65855c2 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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)) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index b36a7c1dd..dad9b70cd 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -4617,6 +4617,7 @@ class PyClassDefNode(ClassDefNode): self.bases.free_temps(code) code.pyclass_stack.pop() + class CClassDefNode(ClassDefNode): # An extension type definition. # diff --git a/Cython/Compiler/Parsing.pxd b/Cython/Compiler/Parsing.pxd index c8bbda9e5..1b38d8e91 100644 --- a/Cython/Compiler/Parsing.pxd +++ b/Cython/Compiler/Parsing.pxd @@ -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) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 25a7b97fb..a5c924489 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -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': diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 548b8f98d..54259ea50 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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 diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 7221c3875..743cd0ebf 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -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: |