summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@gmail.com>2018-10-02 12:17:53 +0200
committerRobert Bradshaw <robertwb@gmail.com>2018-10-02 12:17:53 +0200
commit34bc649fa15776c412e3a3e28454c439e51b972a (patch)
tree0d8095f68ea09671257d20f6bad97fecca0df3ae
parentfbd2fd09d099f51db44c28a768812758222b9208 (diff)
downloadcython-34bc649fa15776c412e3a3e28454c439e51b972a.tar.gz
Use enum rather than int for size_check.
-rw-r--r--Cython/Compiler/ModuleNode.py14
-rw-r--r--Cython/Utility/ImportExport.c17
2 files changed, 17 insertions, 14 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index a9955326a..f8392e1f3 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -3060,18 +3060,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.put('sizeof(%s), ' % objstruct)
# check_size
- if not type.is_external or type.is_subclassed:
- cs = 0
- elif type.check_size == 'error':
- cs = 0
- elif type.check_size == 'warn':
- cs = 1
- elif type.check_size == 'ignore':
- cs = 2
+ if type.check_size and type.check_size in ('error', 'warn', 'ignore'):
+ check_size = type.check_size
+ elif not type.is_external or type.is_subclassed:
+ check_size = 'error'
else:
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('__Pyx_ImportType_CheckSize_%s);' % check_size.title())
code.putln(' if (!%s) %s' % (type.typeptr_cname, error_code))
diff --git a/Cython/Utility/ImportExport.c b/Cython/Utility/ImportExport.c
index 9b2b4acfc..148d1d4ce 100644
--- a/Cython/Utility/ImportExport.c
+++ b/Cython/Utility/ImportExport.c
@@ -309,14 +309,21 @@ set_path:
/////////////// 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 ///////////////
#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
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:
@@ -359,21 +366,21 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name,
module_name, class_name, size, basicsize);
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,
"%.200s.%.200s size changed, may indicate binary incompatibility. "
"Expected %zd from C header, got %zd from PyObject",
module_name, class_name, size, basicsize);
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),
"%s.%s size changed, may indicate binary incompatibility. "
"Expected %zd from C header, got %zd from PyObject",
module_name, class_name, size, basicsize);
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;
bad:
Py_XDECREF(result);