Commit 920aee84 authored by mattip's avatar mattip

MAINT: fixes from review

parent 37fb8a2d
...@@ -3061,15 +3061,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -3061,15 +3061,18 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# check_size # check_size
if not type.is_external or type.is_subclassed: if not type.is_external or type.is_subclassed:
cs = 0 if type.check_size != 'min':
elif type.check_size == b'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 cs = 1
elif type.check_size is True: elif type.check_size == 'True':
cs = 0 cs = 0
elif type.check_size is False: elif type.check_size == 'False':
cs = 2 cs = 2
else: 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)) "%s.%s" % (type.check_size, module_name, type.name))
code.putln('%d);' % cs) code.putln('%d);' % cs)
......
...@@ -4629,7 +4629,7 @@ class CClassDefNode(ClassDefNode): ...@@ -4629,7 +4629,7 @@ class CClassDefNode(ClassDefNode):
# bases TupleNode Base class(es) # bases TupleNode Base class(es)
# objstruct_name string or None Specified C name of object struct # objstruct_name string or None Specified C name of object struct
# typeobj_name string or None Specified C name of type object # 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 # in_pxd boolean Is in a .pxd file
# decorators [DecoratorNode] list of decorators or None # decorators [DecoratorNode] list of decorators or None
# doc string or None # doc string or None
...@@ -4646,7 +4646,7 @@ class CClassDefNode(ClassDefNode): ...@@ -4646,7 +4646,7 @@ class CClassDefNode(ClassDefNode):
api = False api = False
objstruct_name = None objstruct_name = None
typeobj_name = None typeobj_name = None
check_size = b'min' check_size = 'min'
decorators = None decorators = None
shadow = False shadow = False
......
...@@ -3471,7 +3471,7 @@ def p_c_class_definition(s, pos, ctx): ...@@ -3471,7 +3471,7 @@ def p_c_class_definition(s, pos, ctx):
objstruct_name = None objstruct_name = None
typeobj_name = None typeobj_name = None
bases = None bases = None
check_size = b'min' check_size = 'min'
if s.sy == '(': if s.sy == '(':
positional_args, keyword_args = p_call_parse_args(s, allow_genexp=False) positional_args, keyword_args = p_call_parse_args(s, allow_genexp=False)
if keyword_args: if keyword_args:
...@@ -3530,7 +3530,7 @@ def p_c_class_definition(s, pos, ctx): ...@@ -3530,7 +3530,7 @@ def p_c_class_definition(s, pos, ctx):
def p_c_class_options(s): def p_c_class_options(s):
objstruct_name = None objstruct_name = None
typeobj_name = None typeobj_name = None
check_size = b'min' check_size = 'min'
s.expect('[') s.expect('[')
while 1: while 1:
if s.sy != 'IDENT': if s.sy != 'IDENT':
...@@ -3543,7 +3543,7 @@ def p_c_class_options(s): ...@@ -3543,7 +3543,7 @@ def p_c_class_options(s):
typeobj_name = p_ident(s) typeobj_name = p_ident(s)
elif s.systring == 'check_size': elif s.systring == 'check_size':
s.next() s.next()
check_size = p_atom(s).value check_size = p_ident(s)
if s.sy != ',': if s.sy != ',':
break break
s.next() s.next()
......
...@@ -1345,14 +1345,15 @@ class PyExtensionType(PyObjectType): ...@@ -1345,14 +1345,15 @@ class PyExtensionType(PyObjectType):
# vtable_cname string Name of C method table definition # vtable_cname string Name of C method table definition
# early_init boolean Whether to initialize early (as opposed to during module execution). # early_init boolean Whether to initialize early (as opposed to during module execution).
# defered_declarations [thunk] Used to declare class hierarchies in order # 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 is_extension_type = 1
has_attributes = 1 has_attributes = 1
early_init = 1 early_init = 1
objtypedef_cname = None 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.name = name
self.scope = None self.scope = None
self.typedef_flag = typedef_flag self.typedef_flag = typedef_flag
......
...@@ -1476,7 +1476,7 @@ class ModuleScope(Scope): ...@@ -1476,7 +1476,7 @@ class ModuleScope(Scope):
def declare_c_class(self, name, pos, defining = 0, implementing = 0, def declare_c_class(self, name, pos, defining = 0, implementing = 0,
module_name = None, base_type = None, objstruct_cname = None, module_name = None, base_type = None, objstruct_cname = None,
typeobj_cname = None, typeptr_cname = None, visibility = 'private', 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): buffer_defaults = None, shadow = 0):
# If this is a non-extern typedef class, expose the typedef, but use # If this is a non-extern typedef class, expose the typedef, but use
# the non-typedef struct internally to avoid needing forward # the non-typedef struct internally to avoid needing forward
......
...@@ -736,11 +736,11 @@ built-in complex object.:: ...@@ -736,11 +736,11 @@ built-in complex object.::
... ...
} PyComplexObject; } 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`` 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 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 header. This check can be tweaked by using ``check_size`` in the name
specification clause. specification clause.
...@@ -771,7 +771,7 @@ Where: ...@@ -771,7 +771,7 @@ Where:
- ``object_struct_name`` is the name to assume for the type's C struct. - ``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 - ``type_object_name`` is the name to assume for the type's statically
declared type object. 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 used for external extension types. If ``True``, ``sizeof(object_struct)`` must
match the type's ``tp_basicsize``. If ``False``, or ``min``, the match the type's ``tp_basicsize``. If ``False``, or ``min``, the
``object_struct`` may be smaller than the type's ``tp_basicsize``, which ``object_struct`` may be smaller than the type's ``tp_basicsize``, which
......
...@@ -1735,9 +1735,6 @@ class EndToEndTest(unittest.TestCase): ...@@ -1735,9 +1735,6 @@ class EndToEndTest(unittest.TestCase):
old_path = os.environ.get('PYTHONPATH') old_path = os.environ.get('PYTHONPATH')
env = dict(os.environ) env = dict(os.environ)
env['PYTHONPATH'] = self.cython_syspath + os.pathsep + (old_path or '') env['PYTHONPATH'] = self.cython_syspath + os.pathsep + (old_path or '')
cmd = []
out = []
err = []
for command_no, command in enumerate(filter(None, commands.splitlines()), 1): for command_no, command in enumerate(filter(None, commands.splitlines()), 1):
with self.stats.time('%s(%d)' % (self.name, command_no), 'c', with self.stats.time('%s(%d)' % (self.name, command_no), 'c',
'etoe-build' if ' setup.py ' in command else 'etoe-run'): 'etoe-build' if ' setup.py ' in command else 'etoe-run'):
...@@ -1746,15 +1743,11 @@ class EndToEndTest(unittest.TestCase): ...@@ -1746,15 +1743,11 @@ class EndToEndTest(unittest.TestCase):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
shell=True, shell=True,
env=env) env=env)
_out, _err = p.communicate() out, err = p.communicate()
cmd.append(command)
out.append(_out)
err.append(_err)
res = p.returncode res = p.returncode
if res != 0: if res != 0:
for c, o, e in zip(cmd, out, err): sys.stderr.write("%s\n%s\n%s\n" % (
sys.stderr.write("%s\n%s\n%s\n\n" % ( command, self._try_decode(out), self._try_decode(err)))
c, self._try_decode(o), self._try_decode(e)))
self.assertEqual(0, res, "non-zero exit status") self.assertEqual(0, res, "non-zero exit status")
self.success = True self.success = True
......
...@@ -129,8 +129,8 @@ cpdef public int testme(Foo f) except -1: ...@@ -129,8 +129,8 @@ cpdef public int testme(Foo f) except -1:
cdef extern from "check_size_smaller.h": cdef extern from "check_size_smaller.h":
# make sure missing check_size is equivalent to 'min' # make sure missing check_size is equivalent to min
ctypedef class check_size.Foo [object FooStructSmall, check_size 'min']: ctypedef class check_size.Foo [object FooStructSmall, check_size min]:
cdef: cdef:
int f9 int f9
...@@ -169,7 +169,7 @@ cpdef public int testme(Foo f) except -1: ...@@ -169,7 +169,7 @@ cpdef public int testme(Foo f) except -1:
cdef extern from "check_size_smaller.h": cdef extern from "check_size_smaller.h":
# Raise AttributeError when using bad value # 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: cdef:
int f9 int f9
......
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