Commit c66287f6 authored by root's avatar root

Added tests, adjusted warning message, and fixed the line in PyrexTypes.

parent b3ee89c7
......@@ -11379,7 +11379,8 @@ class CoerceFromPyTypeNode(CoercionNode):
"Cannot convert Python object to '%s'" % result_type)
elif result_type.is_reference:
warning(arg.pos,
"Cannot pass Python object as %s reference, will pass by copy." % result_type,
"Cannot pass Python object as C++ data structure "
"reference (%s &), will pass by copy." % result_type,
level=1)
if self.type.is_string or self.type.is_pyunicode_ptr:
if self.arg.is_name and self.arg.entry and self.arg.entry.is_pyglobal:
......
......@@ -3373,7 +3373,7 @@ class CppClassType(CType):
return self
if self.templates is None:
self.templates = []
key = tuple(values.items() + [is_reference]) # Python 3?
key = tuple(values.items()) + (is_reference,)
if key in self.specializations:
return self.specializations[key]
template_values = [t.specialize(values) for t in self.templates]
......
# mode: error
# tag: werror
import numpy as np
cimport numpy as np
from libcpp.vector cimport vector
cdef extern from *:
void cpp_function_vector1(vector[int])
void cpp_function_vector2(vector[int] &)
void cpp_function_2_vec_refs(vector[int] &, vector[int] &)
def main():
cdef np.ndarray[int, ndim=1, mode="c"] arr = np.zeros(10, dtype='intc')
cpp_function_vector1(arr)
cpp_function_vector2(arr)
cpp_function_vector2(arr)
cpp_function_2_vec_refs(arr, arr)
cdef vector[int] vec
vec.push_back(0)
cpp_function_vector2(vec)
_ERRORS = """
17:28: Cannot pass Python object as C++ data structure reference (vector[int] &), will pass by copy.
18:28: Cannot pass Python object as C++ data structure reference (vector[int] &), will pass by copy.
19:31: Cannot pass Python object as C++ data structure reference (vector[int] &), will pass by copy.
19:36: Cannot pass Python object as C++ data structure reference (vector[int] &), will pass by copy.
31:15: '<init>' redeclared
31:15: '<init>' redeclared
32:15: '<init>' redeclared
32:15: '<init>' redeclared
32:15: '<init>' redeclared
33:15: '<init>' redeclared
33:15: '<init>' redeclared
33:15: '<init>' redeclared
34:15: '<init>' redeclared
44:19: 'assign' redeclared
44:19: 'assign' redeclared
45:35: 'assign' redeclared
55:22: 'erase' redeclared
55:22: 'erase' redeclared
56:22: 'erase' redeclared
58:23: 'insert' redeclared
58:23: 'insert' redeclared
59:19: 'insert' redeclared
59:19: 'insert' redeclared
59:19: 'insert' redeclared
60:19: 'insert' redeclared
69:19: 'resize' redeclared
69:19: 'resize' redeclared
70:19: 'resize' redeclared
"""
# mode: error
# tag: werror
from libcpp.set cimport set
cdef extern from "foo.cpp":
void cpp_function_set1(set[int])
void cpp_function_set2(set[int] &)
def pass_py_obj_as_cpp_cont_ref():
cdef list ordered_set = [0, 0, 0, 0, 0]
cpp_function_set1(ordered_set)
cpp_function_set2(ordered_set)
_ERRORS = """
5:13: '<init>' redeclared
5:13: '<init>' redeclared
6:13: '<init>' redeclared
6:13: '<init>' redeclared
6:13: '<init>' redeclared
6:13: '<init>' redeclared
6:13: '<init>' redeclared
7:13: '<init>' redeclared
7:13: '<init>' redeclared
7:13: '<init>' redeclared
14:33: Cannot pass Python object as C++ data structure reference (set[int] &), will pass by copy.
21:12: '<init>' redeclared
21:12: '<init>' redeclared
22:12: '<init>' redeclared
40:18: 'erase' redeclared
40:18: 'erase' redeclared
41:18: 'erase' redeclared
41:18: 'erase' redeclared
41:18: 'erase' redeclared
42:20: 'erase' redeclared
45:35: 'insert' redeclared
45:35: 'insert' redeclared
46:23: 'insert' redeclared
"""
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