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
d7109c87
Commit
d7109c87
authored
Jul 07, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add builtin 'isinstanceof' function for cypclass typechecks at runtime
parent
0da5c3e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+14
-0
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+11
-0
No files found.
Cython/Compiler/Builtin.py
View file @
d7109c87
...
@@ -673,6 +673,19 @@ def inject_cypclass_lock_macros():
...
@@ -673,6 +673,19 @@ def inject_cypclass_lock_macros():
for
macro
in
(
"Cy_TRYRLOCK"
,
"Cy_TRYWLOCK"
):
for
macro
in
(
"Cy_TRYRLOCK"
,
"Cy_TRYWLOCK"
):
builtin_scope
.
declare_builtin_cfunction
(
macro
,
nonblocking_macro_type
,
macro
)
builtin_scope
.
declare_builtin_cfunction
(
macro
,
nonblocking_macro_type
,
macro
)
def
inject_cypclass_typecheck_functions
():
template_placeholder_type
=
PyrexTypes
.
TemplatePlaceholderType
(
"T"
)
isinstanceof_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_int_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
PyrexTypes
.
cy_object_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"type"
,
template_placeholder_type
,
None
)
],
nogil
=
1
,
templates
=
[
template_placeholder_type
]
)
builtin_scope
.
declare_builtin_cfunction
(
"isinstanceof"
,
isinstanceof_type
,
"isinstanceof"
)
def
init_builtins
():
def
init_builtins
():
init_builtin_structs
()
init_builtin_structs
()
init_builtin_types
()
init_builtin_types
()
...
@@ -702,6 +715,7 @@ def init_builtins():
...
@@ -702,6 +715,7 @@ def init_builtins():
complex_type
=
builtin_scope
.
lookup
(
'complex'
).
type
complex_type
=
builtin_scope
.
lookup
(
'complex'
).
type
inject_cypclass_refcount_macros
()
inject_cypclass_refcount_macros
()
inject_cypclass_lock_macros
()
inject_cypclass_lock_macros
()
inject_cypclass_typecheck_functions
()
inject_acthon_interfaces
(
builtin_scope
)
inject_acthon_interfaces
(
builtin_scope
)
inject_cy_object
(
builtin_scope
)
inject_cy_object
(
builtin_scope
)
...
...
Cython/Utility/CyObjects.cpp
View file @
d7109c87
...
@@ -168,6 +168,17 @@
...
@@ -168,6 +168,17 @@
return
op
->
CyObject_TRYWLOCK
();
return
op
->
CyObject_TRYWLOCK
();
}
}
/*
* Check whether a CyObject is an instance of a given type.
*
* template:
* - T: the type
*/
template
<
typename
T
>
static
inline
int
isinstanceof
(
CyObject
*
ob
)
{
return
dynamic_cast
<
T
*>
(
ob
)
!=
NULL
;
}
/*
/*
* Cast from CyObject to PyObject:
* Cast from CyObject to PyObject:
* - borrow an atomic reference
* - borrow an atomic reference
...
...
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