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
eb5fc339
Commit
eb5fc339
authored
Sep 08, 2016
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't require typeinfo cimport for typeid.
parent
89723dc5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
20 deletions
+11
-20
CHANGES.rst
CHANGES.rst
+2
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+7
-16
docs/src/userguide/wrapping_CPlusPlus.rst
docs/src/userguide/wrapping_CPlusPlus.rst
+2
-3
tests/run/cpp_operators.pyx
tests/run/cpp_operators.pyx
+0
-1
No files found.
CHANGES.rst
View file @
eb5fc339
...
@@ -27,6 +27,8 @@ Features added
...
@@ -27,6 +27,8 @@ Features added
* ``libc/math.pxd`` provides ``e`` and ``pi`` as alias constants to simplify
* ``libc/math.pxd`` provides ``e`` and ``pi`` as alias constants to simplify
usage as a drop-in replacement for Python's math module.
usage as a drop-in replacement for Python's math module.
* Support for the C++ ``typeid`` operator.
Bugs fixed
Bugs fixed
----------
----------
...
...
Cython/Compiler/ExprNodes.py
View file @
eb5fc339
...
@@ -10204,16 +10204,12 @@ class TypeidNode(ExprNode):
...
@@ -10204,16 +10204,12 @@ class TypeidNode(ExprNode):
is_temp
=
1
is_temp
=
1
def
get_type_info_type
(
self
,
env
):
def
get_type_info_type
(
self
,
env
):
if
env
.
is_module_scope
:
env_module
=
env
env_module
=
env
while
not
env_module
.
is_module_scope
:
else
:
env_module
=
env_module
.
outer_scope
env_module
=
env
.
outer_scope
typeinfo_module
=
env_module
.
find_module
(
'libcpp.typeinfo'
,
self
.
pos
)
for
module
in
env_module
.
cimported_modules
:
typeinfo_entry
=
typeinfo_module
.
lookup
(
'type_info'
)
if
module
.
qualified_name
==
'libcpp.typeinfo'
:
return
PyrexTypes
.
CFakeReferenceType
(
PyrexTypes
.
c_const_type
(
typeinfo_entry
.
type
))
type_info
=
module
.
lookup
(
'type_info'
)
type_info
=
PyrexTypes
.
CFakeReferenceType
(
PyrexTypes
.
c_const_type
(
type_info
.
type
))
return
type_info
return
None
def
analyse_types
(
self
,
env
):
def
analyse_types
(
self
,
env
):
type_info
=
self
.
get_type_info_type
(
env
)
type_info
=
self
.
get_type_info_type
(
env
)
...
@@ -10253,12 +10249,7 @@ class TypeidNode(ExprNode):
...
@@ -10253,12 +10249,7 @@ class TypeidNode(ExprNode):
def
generate_result_code
(
self
,
code
):
def
generate_result_code
(
self
,
code
):
if
self
.
is_type
:
if
self
.
is_type
:
if
self
.
arg_type
.
is_extension_type
:
arg_code
=
self
.
arg_type
.
empty_declaration_code
()
# the size of the pointer is boring
# we want the size of the actual struct
arg_code
=
self
.
arg_type
.
declaration_code
(
""
,
deref
=
1
)
else
:
arg_code
=
self
.
arg_type
.
empty_declaration_code
()
else
:
else
:
arg_code
=
self
.
arg_type
.
result
()
arg_code
=
self
.
arg_type
.
result
()
translate_cpp_exception
(
code
,
self
.
pos
,
translate_cpp_exception
(
code
,
self
.
pos
,
...
...
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
eb5fc339
...
@@ -606,17 +606,16 @@ you can declare it using the Python @staticmethod decorator, i.e.::
...
@@ -606,17 +606,16 @@ you can declare it using the Python @staticmethod decorator, i.e.::
RTTI and typeid()
RTTI and typeid()
=================
=================
Cython has support for the ``typeid(...)`` operator. To use it, you need to import
Cython has support for the ``typeid(...)`` operator.
it and the ``libcpp.typeinfo`` module first:
from cython.operator cimport typeid
from cython.operator cimport typeid
from libcpp.typeinfo cimport type_info
The ``typeid(...)`` operator returns an object of the type ``const type_info &``.
The ``typeid(...)`` operator returns an object of the type ``const type_info &``.
If you want to store a type_info value in a C variable, you will need to store it
If you want to store a type_info value in a C variable, you will need to store it
as a pointer rather than a reference:
as a pointer rather than a reference:
from libcpp.typeinfo cimport type_info
cdef const type_info* info = &typeid(MyClass)
cdef const type_info* info = &typeid(MyClass)
If an invalid type is passed to ``typeid``, it will throw an ``std::bad_typeid``
If an invalid type is passed to ``typeid``, it will throw an ``std::bad_typeid``
...
...
tests/run/cpp_operators.pyx
View file @
eb5fc339
...
@@ -8,7 +8,6 @@ from cython.operator cimport typeid, dereference as deref
...
@@ -8,7 +8,6 @@ from cython.operator cimport typeid, dereference as deref
from
libc.string
cimport
const_char
from
libc.string
cimport
const_char
from
libcpp
cimport
bool
from
libcpp
cimport
bool
cimport
libcpp.typeinfo
cdef
out
(
s
,
result_type
=
None
):
cdef
out
(
s
,
result_type
=
None
):
print
'%s [%s]'
%
(
s
.
decode
(
'ascii'
),
result_type
)
print
'%s [%s]'
%
(
s
.
decode
(
'ascii'
),
result_type
)
...
...
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