Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
ff0fc55b
Commit
ff0fc55b
authored
Nov 15, 2016
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow taking address of fake references.
This fixes #1519.
parent
f8c223d7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+1
-0
tests/wrappers/cpp_references.pyx
tests/wrappers/cpp_references.pyx
+11
-0
No files found.
Cython/Utility/ModuleSetupCode.c
View file @
ff0fc55b
...
...
@@ -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
;
}
...
...
tests/wrappers/cpp_references.pyx
View file @
ff0fc55b
...
...
@@ -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)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment