Commit ff0fc55b authored by Robert Bradshaw's avatar Robert Bradshaw

Allow taking address of fake references.

This fixes #1519.
parent f8c223d7
......@@ -466,6 +466,7 @@ class __Pyx_FakeReference {
// Const version needed as Cython doesn't know about const overloads (e.g. for stl containers).
__Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { }
T *operator->() { return ptr; }
T *operator&() { return ptr; }
operator T&() { return *ptr; }
// TODO(robertwb): Delegate all operators (or auto-generate unwrapping code where needed).
template<typename U> bool operator ==(U other) { return *ptr == other; }
......
......@@ -5,6 +5,7 @@ cimport cython
cdef extern from "cpp_references_helper.h":
cdef int& ref_func(int&)
cdef int& except_ref_func "ref_func" (int&) except +
cdef int ref_var_value
cdef int& ref_var
......@@ -29,6 +30,16 @@ def test_ref_func_address(int x):
cdef int* i_ptr = &ref_func(x)
return i_ptr[0]
def test_except_ref_func_address(int x):
"""
>>> test_except_ref_func_address(5)
5
>>> test_except_ref_func_address(7)
7
"""
cdef int* i_ptr = &except_ref_func(x)
return i_ptr[0]
def test_ref_var(int x):
"""
>>> test_ref_func(11)
......
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