summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2018-09-25 03:14:34 +0300
committermattip <matti.picus@gmail.com>2018-09-25 03:14:34 +0300
commit37fb8a2d43924fd9d616e3c16718bc137c015bf0 (patch)
treec89a1a5e8409e826e0386e6749ba080a21eb6ab0
parentb27baf0413d7ec4cbfeb694bc636e751c583a817 (diff)
downloadcython-37fb8a2d43924fd9d616e3c16718bc137c015bf0.tar.gz
MAINT: cannot use local enum in __Pyx functions
-rw-r--r--Cython/Compiler/ModuleNode.py10
-rw-r--r--Cython/Utility/ImportExport.c22
-rwxr-xr-xruntests.py13
3 files changed, 26 insertions, 19 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 026b4323f..f948cfa11 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -3061,17 +3061,17 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# check_size
if not type.is_external or type.is_subclassed:
- cs = '__PYX_CHECKSIZE_STRICT'
+ cs = 0
elif type.check_size == b'min':
- cs = '__PYX_CHECKSIZE_MIN'
+ cs = 1
elif type.check_size is True:
- cs = '__PYX_CHECKSIZE_STRICT'
+ cs = 0
elif type.check_size is False:
- cs = '__PYX_CHECKSIZE_LOOSE'
+ cs = 2
else:
raise AttributeError("invalid value for check_size '%r' when compiling "
"%s.%s" % (type.check_size, module_name, type.name))
- code.putln('%s);' % cs)
+ code.putln('%d);' % cs)
code.putln(' if (!%s) %s' % (type.typeptr_cname, error_code))
diff --git a/Cython/Utility/ImportExport.c b/Cython/Utility/ImportExport.c
index 86d090fc2..77ff3b850 100644
--- a/Cython/Utility/ImportExport.c
+++ b/Cython/Utility/ImportExport.c
@@ -308,22 +308,22 @@ set_path:
/////////////// TypeImport.proto ///////////////
-typedef enum { /* What to do if tp_basicsize is different from size? */
- __PYX_CHECKSIZE_STRICT, /* Error */
- __PYX_CHECKSIZE_MIN, /* Error if tp_basicsize is smaller, warn if larger */
- __PYX_CHECKSIZE_LOOSE, /* Error if tp_basicsize is smaller */
-} __pyx_CheckSizeState;
-
-static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, __pyx_CheckSizeState check_size); /*proto*/
+static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, int 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, __pyx_CheckSizeState check_size)
+ size_t size, int check_size)
{
+ /*
+ * check_size tells what to do if tp_basicsize is different from size:
+ * 0 - Error (originates in check_size=True)
+ * 1 - Error if tp_basicsize is smaller, warn if larger (originates in check_size='min')
+ * 2 - Error if tp_basicsize is smaller (originates in check_size=False)
+ */
PyObject *result = 0;
char warning[200];
Py_ssize_t basicsize;
@@ -359,21 +359,21 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name,
module_name, class_name, size, basicsize);
goto bad;
}
- if (check_size == __PYX_CHECKSIZE_STRICT && (size_t)basicsize != size) {
+ if (check_size == 0 && (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 == __PYX_CHECKSIZE_MIN && (size_t)basicsize > size) {
+ else if (check_size == 1 && (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;
}
- /* __PYX_CHECKSIZE_LOOSE does not warn nor error */
+ /* check_size == 2 does not warn nor error */
return (PyTypeObject *)result;
bad:
Py_XDECREF(result);
diff --git a/runtests.py b/runtests.py
index 4d9f58fd6..59f55ec4f 100755
--- a/runtests.py
+++ b/runtests.py
@@ -1735,6 +1735,9 @@ 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'):
@@ -1743,11 +1746,15 @@ class EndToEndTest(unittest.TestCase):
stdout=subprocess.PIPE,
shell=True,
env=env)
- out, err = p.communicate()
+ _out, _err = p.communicate()
+ cmd.append(command)
+ out.append(_out)
+ err.append(_err)
res = p.returncode
if res != 0:
- sys.stderr.write("%s\n%s\n%s\n" % (
- command, self._try_decode(out), self._try_decode(err)))
+ 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)))
self.assertEqual(0, res, "non-zero exit status")
self.success = True