Commit 34bc649f authored by Robert Bradshaw's avatar Robert Bradshaw

Use enum rather than int for size_check.

parent fbd2fd09
...@@ -3060,18 +3060,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -3060,18 +3060,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.put('sizeof(%s), ' % objstruct) code.put('sizeof(%s), ' % objstruct)
# check_size # check_size
if not type.is_external or type.is_subclassed: if type.check_size and type.check_size in ('error', 'warn', 'ignore'):
cs = 0 check_size = type.check_size
elif type.check_size == 'error': elif not type.is_external or type.is_subclassed:
cs = 0 check_size = 'error'
elif type.check_size == 'warn':
cs = 1
elif type.check_size == 'ignore':
cs = 2
else: else:
raise RuntimeError("invalid value for check_size '%s' when compiling %s.%s" % ( raise RuntimeError("invalid value for check_size '%s' when compiling %s.%s" % (
type.check_size, module_name, type.name)) type.check_size, module_name, type.name))
code.putln('%d);' % cs) code.putln('__Pyx_ImportType_CheckSize_%s);' % check_size.title())
code.putln(' if (!%s) %s' % (type.typeptr_cname, error_code)) code.putln(' if (!%s) %s' % (type.typeptr_cname, error_code))
......
...@@ -309,14 +309,21 @@ set_path: ...@@ -309,14 +309,21 @@ set_path:
/////////////// TypeImport.proto /////////////// /////////////// TypeImport.proto ///////////////
static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, int check_size); /*proto*/ enum __Pyx_ImportType_CheckSize {
__Pyx_ImportType_CheckSize_Error = 0,
__Pyx_ImportType_CheckSize_Warn = 1,
__Pyx_ImportType_CheckSize_Ignore = 2
};
static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); /*proto*/
/////////////// TypeImport /////////////// /////////////// TypeImport ///////////////
#ifndef __PYX_HAVE_RT_ImportType #ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
size_t size, int check_size) size_t size, enum __Pyx_ImportType_CheckSize check_size)
{ {
/* /*
* 'check_size' tells what to do if tp_basicsize is different from size: * 'check_size' tells what to do if tp_basicsize is different from size:
...@@ -359,21 +366,21 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, ...@@ -359,21 +366,21 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name,
module_name, class_name, size, basicsize); module_name, class_name, size, basicsize);
goto bad; goto bad;
} }
if (check_size == 0 && (size_t)basicsize != size) { if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"%.200s.%.200s size changed, may indicate binary incompatibility. " "%.200s.%.200s size changed, may indicate binary incompatibility. "
"Expected %zd from C header, got %zd from PyObject", "Expected %zd from C header, got %zd from PyObject",
module_name, class_name, size, basicsize); module_name, class_name, size, basicsize);
goto bad; goto bad;
} }
else if (check_size == 1 && (size_t)basicsize > size) { else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
PyOS_snprintf(warning, sizeof(warning), PyOS_snprintf(warning, sizeof(warning),
"%s.%s size changed, may indicate binary incompatibility. " "%s.%s size changed, may indicate binary incompatibility. "
"Expected %zd from C header, got %zd from PyObject", "Expected %zd from C header, got %zd from PyObject",
module_name, class_name, size, basicsize); module_name, class_name, size, basicsize);
if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
} }
/* check_size == 2 does not warn nor error */ /* check_size == __Pyx_ImportType_CheckSize_Ignore does not warn nor error */
return (PyTypeObject *)result; return (PyTypeObject *)result;
bad: bad:
Py_XDECREF(result); Py_XDECREF(result);
......
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