summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex-xnor <alex@xnor.ai>2019-10-16 11:48:51 -0700
committerStefan Behnel <stefan_ml@behnel.de>2019-10-16 20:48:51 +0200
commit7773dd51e4826ba01e0349f11144697dd5645edf (patch)
tree71d63c9dc871b836a759b0cd2681ba61a252575f
parent70dd7561d431f248e20c2a1365111418ea494cbd (diff)
downloadcython-7773dd51e4826ba01e0349f11144697dd5645edf.tar.gz
Make sure not to emit duplicate typedefs for fused nodes (GH-3112)
-rw-r--r--Cython/Compiler/FusedNode.py14
-rw-r--r--tests/compile/fused_redeclare_T3111.pyx39
2 files changed, 47 insertions, 6 deletions
diff --git a/Cython/Compiler/FusedNode.py b/Cython/Compiler/FusedNode.py
index e2e7d6fce..9b55c73e6 100644
--- a/Cython/Compiler/FusedNode.py
+++ b/Cython/Compiler/FusedNode.py
@@ -507,20 +507,22 @@ class FusedCFuncDefNode(StatListNode):
ndarray = __Pyx_ImportNumPyArrayTypeIfAvailable()
""")
+ seen_typedefs = set()
seen_int_dtypes = set()
for buffer_type in all_buffer_types:
dtype = buffer_type.dtype
+ dtype_name = self._dtype_name(dtype)
if dtype.is_typedef:
- #decl_code.putln("ctypedef %s %s" % (dtype.resolve(),
- # self._dtype_name(dtype)))
- decl_code.putln('ctypedef %s %s "%s"' % (dtype.resolve(),
- self._dtype_name(dtype),
- dtype.empty_declaration_code()))
+ if dtype_name not in seen_typedefs:
+ seen_typedefs.add(dtype_name)
+ decl_code.putln(
+ 'ctypedef %s %s "%s"' % (dtype.resolve(), dtype_name,
+ dtype.empty_declaration_code()))
if buffer_type.dtype.is_int:
if str(dtype) not in seen_int_dtypes:
seen_int_dtypes.add(str(dtype))
- pyx_code.context.update(dtype_name=self._dtype_name(dtype),
+ pyx_code.context.update(dtype_name=dtype_name,
dtype_type=self._dtype_type(dtype))
pyx_code.local_variable_declarations.put_chunk(
u"""
diff --git a/tests/compile/fused_redeclare_T3111.pyx b/tests/compile/fused_redeclare_T3111.pyx
new file mode 100644
index 000000000..3dfed9f38
--- /dev/null
+++ b/tests/compile/fused_redeclare_T3111.pyx
@@ -0,0 +1,39 @@
+# ticket: 3111
+# mode: compile
+# tag: warnings
+
+ctypedef unsigned char npy_uint8
+ctypedef unsigned short npy_uint16
+
+
+ctypedef fused dtype_t:
+ npy_uint8
+
+ctypedef fused dtype_t_out:
+ npy_uint8
+ npy_uint16
+
+
+def foo(dtype_t[:] a, dtype_t_out[:, :] b):
+ pass
+
+
+# The primary thing we're trying to test here is the _absence_ of the warning
+# "__pyxutil:16:4: '___pyx_npy_uint8' redeclared". The remaining warnings are
+# unrelated to this test.
+_WARNINGS = """
+22:10: 'cpdef_method' redeclared
+33:10: 'cpdef_cname_method' redeclared
+446:72: Argument evaluation order in C function call is undefined and may not be as expected
+446:72: Argument evaluation order in C function call is undefined and may not be as expected
+749:34: Argument evaluation order in C function call is undefined and may not be as expected
+749:34: Argument evaluation order in C function call is undefined and may not be as expected
+943:27: Ambiguous exception value, same as default return value: 0
+943:27: Ambiguous exception value, same as default return value: 0
+974:29: Ambiguous exception value, same as default return value: 0
+974:29: Ambiguous exception value, same as default return value: 0
+1002:46: Ambiguous exception value, same as default return value: 0
+1002:46: Ambiguous exception value, same as default return value: 0
+1092:29: Ambiguous exception value, same as default return value: 0
+1092:29: Ambiguous exception value, same as default return value: 0
+"""