diff options
author | mattip <matti.picus@gmail.com> | 2018-09-25 09:37:30 +0300 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2018-09-25 09:37:30 +0300 |
commit | 920aee8428edecc367865cc806ca026c61fd6827 (patch) | |
tree | 7d43cf08944c5200403e7f84a3e1045f8a1fd5ac | |
parent | 37fb8a2d43924fd9d616e3c16718bc137c015bf0 (diff) | |
download | cython-920aee8428edecc367865cc806ca026c61fd6827.tar.gz |
MAINT: fixes from review
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 13 | ||||
-rw-r--r-- | Cython/Compiler/Nodes.py | 4 | ||||
-rw-r--r-- | Cython/Compiler/Parsing.py | 6 | ||||
-rw-r--r-- | Cython/Compiler/PyrexTypes.py | 5 | ||||
-rw-r--r-- | Cython/Compiler/Symtab.py | 2 | ||||
-rw-r--r-- | docs/src/userguide/extension_types.rst | 8 | ||||
-rwxr-xr-x | runtests.py | 13 | ||||
-rw-r--r-- | tests/run/check_size.srctree | 6 |
8 files changed, 27 insertions, 30 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index f948cfa11..2152f4847 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -3061,15 +3061,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): # check_size if not type.is_external or type.is_subclassed: - cs = 0 - elif type.check_size == b'min': + 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 - elif type.check_size is True: + elif type.check_size == 'True': cs = 0 - elif type.check_size is False: + elif type.check_size == 'False': cs = 2 else: - raise AttributeError("invalid value for check_size '%r' when compiling " + raise AttributeError("invalid value for check_size '%s' when compiling " "%s.%s" % (type.check_size, module_name, type.name)) code.putln('%d);' % cs) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index fce38f88a..b36a7c1dd 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -4629,7 +4629,7 @@ class CClassDefNode(ClassDefNode): # bases TupleNode Base class(es) # objstruct_name string or None Specified C name of object struct # typeobj_name string or None Specified C name of type object - # check_size b'min' or boolean Issue warning if tp_basicsize does not match + # check_size 'min' or boolean What to do if tp_basicsize does not match # in_pxd boolean Is in a .pxd file # decorators [DecoratorNode] list of decorators or None # doc string or None @@ -4646,7 +4646,7 @@ class CClassDefNode(ClassDefNode): api = False objstruct_name = None typeobj_name = None - check_size = b'min' + check_size = 'min' decorators = None shadow = False diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index f217dac12..300615a43 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 = b'min' + check_size = 'min' if s.sy == '(': positional_args, keyword_args = p_call_parse_args(s, allow_genexp=False) if keyword_args: @@ -3530,7 +3530,7 @@ def p_c_class_definition(s, pos, ctx): def p_c_class_options(s): objstruct_name = None typeobj_name = None - check_size = b'min' + check_size = 'min' s.expect('[') while 1: if s.sy != 'IDENT': @@ -3543,7 +3543,7 @@ def p_c_class_options(s): typeobj_name = p_ident(s) elif s.systring == 'check_size': s.next() - check_size = p_atom(s).value + check_size = p_ident(s) if s.sy != ',': break s.next() diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 761d2d0b3..548b8f98d 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1345,14 +1345,15 @@ class PyExtensionType(PyObjectType): # vtable_cname string Name of C method table definition # 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 b'min' or boolean should tp_basicsize match sizeof(obstruct_cname) + # 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=b'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 aa0b029b1..19c3fe27e 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1476,7 +1476,7 @@ class ModuleScope(Scope): 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=b'min', + 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 diff --git a/docs/src/userguide/extension_types.rst b/docs/src/userguide/extension_types.rst index 17d5e22ee..52974b31f 100644 --- a/docs/src/userguide/extension_types.rst +++ b/docs/src/userguide/extension_types.rst @@ -736,11 +736,11 @@ built-in complex object.:: ... } PyComplexObject; - At runtime, a check will be performed when importing the cython + At runtime, a check will be performed when importing the Cython c-extension module that ``__builtin__.complex``'s ``tp_basicsize`` - matches ``sizeof(`PyComplexObject)``. This check can fail if in the cython + matches ``sizeof(`PyComplexObject)``. This check can fail if the Cython c-extension module was compiled with one version of the - ``complexobject.h`` header but imported into a python with a changed + ``complexobject.h`` header but imported into a Python with a changed header. This check can be tweaked by using ``check_size`` in the name specification clause. @@ -771,7 +771,7 @@ Where: - ``object_struct_name`` is the name to assume for the type's C struct. - ``type_object_name`` is the name to assume for the type's statically declared type object. -- ``cs_option`` is ``'min'`` (the default), ``True``, or ``False`` and is only +- ``cs_option`` is ``min`` (the default), ``True``, or ``False`` and is only used for external extension types. If ``True``, ``sizeof(object_struct)`` must match the type's ``tp_basicsize``. If ``False``, or ``min``, the ``object_struct`` may be smaller than the type's ``tp_basicsize``, which diff --git a/runtests.py b/runtests.py index 59f55ec4f..4d9f58fd6 100755 --- a/runtests.py +++ b/runtests.py @@ -1735,9 +1735,6 @@ class EndToEndTest(unittest.TestCase): old_path = os.environ.get('PYTHONPATH') env = dict(os.environ) env['PYTHONPATH'] = self.cython_syspath + os.pathsep + (old_path or '') - cmd = [] - out = [] - err = [] for command_no, command in enumerate(filter(None, commands.splitlines()), 1): with self.stats.time('%s(%d)' % (self.name, command_no), 'c', 'etoe-build' if ' setup.py ' in command else 'etoe-run'): @@ -1746,15 +1743,11 @@ class EndToEndTest(unittest.TestCase): stdout=subprocess.PIPE, shell=True, env=env) - _out, _err = p.communicate() - cmd.append(command) - out.append(_out) - err.append(_err) + out, err = p.communicate() res = p.returncode if res != 0: - for c, o, e in zip(cmd, out, err): - sys.stderr.write("%s\n%s\n%s\n\n" % ( - c, self._try_decode(o), self._try_decode(e))) + sys.stderr.write("%s\n%s\n%s\n" % ( + command, self._try_decode(out), self._try_decode(err))) self.assertEqual(0, res, "non-zero exit status") self.success = True diff --git a/tests/run/check_size.srctree b/tests/run/check_size.srctree index aa1fb407f..0c4116184 100644 --- a/tests/run/check_size.srctree +++ b/tests/run/check_size.srctree @@ -129,8 +129,8 @@ cpdef public int testme(Foo f) except -1: cdef extern from "check_size_smaller.h": - # make sure missing check_size is equivalent to 'min' - ctypedef class check_size.Foo [object FooStructSmall, check_size 'min']: + # make sure missing check_size is equivalent to min + ctypedef class check_size.Foo [object FooStructSmall, check_size min]: cdef: int f9 @@ -169,7 +169,7 @@ cpdef public int testme(Foo f) except -1: cdef extern from "check_size_smaller.h": # Raise AttributeError when using bad value - ctypedef class check_size.Foo [object FooStructSmall, check_size 'max']: + ctypedef class check_size.Foo [object FooStructSmall, check_size max]: cdef: int f9 |