Commit 920aee84 authored by mattip's avatar mattip

MAINT: fixes from review

parent 37fb8a2d
......@@ -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)
......
......@@ -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
......
......@@ -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()
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
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