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
e2aa8aec
Commit
e2aa8aec
authored
Sep 10, 2014
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support multiple custom string conversions.
parent
c67e8954
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+2
-0
tests/run/cpp_custom_string.srctree
tests/run/cpp_custom_string.srctree
+17
-1
No files found.
Cython/Compiler/PyrexTypes.py
View file @
e2aa8aec
...
@@ -3057,6 +3057,7 @@ class CppClassType(CType):
...
@@ -3057,6 +3057,7 @@ class CppClassType(CType):
X
[
ix
],
X
[
ix
],
T
.
from_py_function
,
except_clause
))
X
[
ix
],
X
[
ix
],
T
.
from_py_function
,
except_clause
))
if
self
.
cname
in
cpp_string_conversions
:
if
self
.
cname
in
cpp_string_conversions
:
cls
=
'string'
cls
=
'string'
tags
=
self
.
cname
.
replace
(
':'
,
'_'
),
else
:
else
:
cls
=
self
.
cname
[
5
:]
cls
=
self
.
cname
[
5
:]
cname
=
'__pyx_convert_%s_from_py_%s'
%
(
cls
,
'____'
.
join
(
tags
))
cname
=
'__pyx_convert_%s_from_py_%s'
%
(
cls
,
'____'
.
join
(
tags
))
...
@@ -3090,6 +3091,7 @@ class CppClassType(CType):
...
@@ -3090,6 +3091,7 @@ class CppClassType(CType):
X
[
ix
],
T
.
to_py_function
,
X
[
ix
]))
X
[
ix
],
T
.
to_py_function
,
X
[
ix
]))
if
self
.
cname
in
cpp_string_conversions
:
if
self
.
cname
in
cpp_string_conversions
:
cls
=
'string'
cls
=
'string'
tags
=
self
.
cname
.
replace
(
':'
,
'_'
),
else
:
else
:
cls
=
self
.
cname
[
5
:]
cls
=
self
.
cname
[
5
:]
cname
=
"__pyx_convert_%s_to_py_%s"
%
(
cls
,
"____"
.
join
(
tags
))
cname
=
"__pyx_convert_%s_to_py_%s"
%
(
cls
,
"____"
.
join
(
tags
))
...
...
tests/run/cpp_custom_string.srctree
View file @
e2aa8aec
...
@@ -7,7 +7,7 @@ PYTHON -c "import a; a.test_convert()"
...
@@ -7,7 +7,7 @@ PYTHON -c "import a; a.test_convert()"
from Cython.Build.Dependencies import cythonize
from Cython.Build.Dependencies import cythonize
from Cython.Compiler import PyrexTypes
from Cython.Compiler import PyrexTypes
PyrexTypes.cpp_string_conversions += ("MyString",)
PyrexTypes.cpp_string_conversions += ("MyString",
"MyString2"
)
from distutils.core import setup
from distutils.core import setup
...
@@ -29,6 +29,12 @@ class MyString {
...
@@ -29,6 +29,12 @@ class MyString {
std::string value_;
std::string value_;
};
};
class MyString2 : public MyString {
public:
MyString2() : MyString() { }
MyString2(const char* data, size_t size) : MyString(data, size) { }
};
######## a.pyx ########
######## a.pyx ########
# distutils: language = c++
# distutils: language = c++
...
@@ -37,9 +43,19 @@ cdef extern from "my_string.cpp":
...
@@ -37,9 +43,19 @@ cdef extern from "my_string.cpp":
cdef cppclass MyString:
cdef cppclass MyString:
pass
pass
cdef extern from "my_string.cpp":
cdef cppclass MyString2:
pass
def do_convert(MyString value):
def do_convert(MyString value):
return value
return value
def do_convert2(MyString2 value):
return value
def test_convert():
def test_convert():
assert do_convert(b"abc") == b"abc"
assert do_convert(b"abc") == b"abc"
assert do_convert(b"ab\0c") == b"ab\0c"
assert do_convert(b"ab\0c") == b"ab\0c"
assert do_convert2(b"abc") == b"abc"
assert do_convert2(b"ab\0c") == b"ab\0c"
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