summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2020-07-29 06:32:17 +0100
committerGitHub <noreply@github.com>2020-07-29 07:32:17 +0200
commitb9cecd602878334173aa9f6ed635d48739bfa2b1 (patch)
treebfd726507dac218bce70e91b5663c45ce6b73efa
parent12a2ad5a090637248200563f4659a583664b70db (diff)
downloadcython-b9cecd602878334173aa9f6ed635d48739bfa2b1.tar.gz
Fixed reference types being passed to getitemint (GH-3755)
-rw-r--r--Cython/Compiler/ExprNodes.py2
-rw-r--r--tests/run/lvalue_refs.pyx12
2 files changed, 14 insertions, 0 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index 9c3dd3952..3cf0d8623 100644
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -3739,6 +3739,8 @@ class IndexNode(_IndexingBaseNode):
if not base_type.is_cfunction:
self.index = self.index.analyse_types(env)
self.original_index_type = self.index.type
+ if self.original_index_type.is_reference:
+ self.original_index_type = self.original_index_type.ref_base_type
if base_type.is_unicode_char:
# we infer Py_UNICODE/Py_UCS4 for unicode strings in some
diff --git a/tests/run/lvalue_refs.pyx b/tests/run/lvalue_refs.pyx
index d42f2407e..6bd0d88bc 100644
--- a/tests/run/lvalue_refs.pyx
+++ b/tests/run/lvalue_refs.pyx
@@ -28,3 +28,15 @@ def test_lvalue_ref_assignment():
assert bar[0] == &baz[0][0]
assert bar[0][0] == bongle
+
+# not *strictly* lvalue refs but this file seems the closest applicable place for it.
+# GH 3754 - std::vector operator[] returns a reference, and this causes problems if
+# the reference is passed into Cython __Pyx_GetItemInt
+def test_ref_used_for_indexing():
+ """
+ >>> test_ref_used_for_indexing()
+ 'looked up correctly'
+ """
+ cdef vector[int] idx = [1,2,3]
+ d = {1: "looked up correctly", 2:"oops"}
+ return d[idx[0]]