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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
cython
Commits
c329db8f
Commit
c329db8f
authored
Dec 22, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement runtime 'iso' check for generic containers
parent
e1939449
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletion
+52
-1
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+6
-1
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+46
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
c329db8f
...
...
@@ -977,6 +977,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
scope
=
entry
.
type
.
scope
check_cypclass_attrs
=
[]
check_template_attrs
=
[]
check_cpp_attrs
=
[]
for
e
in
scope
.
entries
.
values
():
if
e
.
is_type
or
e
.
name
==
"this"
:
continue
...
...
@@ -984,6 +985,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
check_cypclass_attrs
.
append
(
e
)
elif
e
.
type
.
is_template_typename
:
check_template_attrs
.
append
(
e
)
elif
e
.
type
.
is_cpp_class
and
not
e
.
type
.
is_cyp_class
:
check_cpp_attrs
.
append
(
e
)
# potential template
if
entry
.
type
.
templates
:
templates_code
=
"template <typename %s>"
%
", typename "
.
join
(
t
.
name
for
t
in
entry
.
type
.
templates
)
...
...
@@ -999,13 +1002,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"visit(this->%s, arg);"
%
attr
.
cname
)
for
attr
in
check_template_attrs
:
code
.
putln
(
"__Pyx_CyObject_visit_template(visit, this->%s, arg);"
%
attr
.
cname
)
for
attr
in
check_cpp_attrs
:
code
.
putln
(
"__Pyx_CyObject_visit_generic(visit, this->%s, arg);"
%
attr
.
cname
)
code
.
putln
(
"}"
)
# isolation check method
if
templates_code
:
code
.
putln
(
templates_code
)
code
.
putln
(
"int %s::CyObject_iso() const"
%
namespace
)
code
.
putln
(
"{"
)
if
check_cypclass_attrs
or
check_template_attrs
:
if
check_cypclass_attrs
or
check_template_attrs
or
check_cpp_attrs
:
code
.
putln
(
"return __Pyx_CyObject_owning(this) == 1;"
)
else
:
code
.
putln
(
"return this->CyObject_GETREF() == 1;"
)
...
...
Cython/Utility/CyObjects.cpp
View file @
c329db8f
...
...
@@ -517,6 +517,52 @@
visit
(
o
.
uobj
,
arg
);
}
/*
* Traverse generic containers.
*/
template
<
typename
...
Ts
>
struct
Cy_make_void
{
typedef
void
type
;};
template
<
typename
...
Ts
>
using
Cy_void_t
=
typename
Cy_make_void
<
Ts
...
>::
type
;
// C++11 compatible version of std::void_t
template
<
typename
T
,
typename
=
void
>
struct
Cy_is_iterable
:
std
::
false_type
{};
template
<
typename
T
>
struct
Cy_is_iterable
<
T
,
Cy_void_t
<
decltype
(
std
::
begin
(
std
::
declval
<
T
>
())
!=
std
::
end
(
std
::
declval
<
T
>
())),
decltype
(
++
std
::
begin
(
std
::
declval
<
T
>
())),
decltype
(
*
std
::
begin
(
std
::
declval
<
T
>
()))
>
>
:
std
::
true_type
{};
template
<
typename
T
>
struct
Cy_is_pair
:
std
::
false_type
{};
template
<
typename
...
Ts
>
struct
Cy_is_pair
<
std
::
pair
<
Ts
...
>>
:
std
::
true_type
{};
template
<
typename
T
,
typename
std
::
enable_if
<
Cy_traverse_iso
<
T
>
::
value
,
int
>::
type
=
0
>
static
inline
void
__Pyx_CyObject_visit_generic
(
void
(
*
visit
)(
const
CyObject
*
o
,
void
*
arg
),
const
T
&
o
,
void
*
arg
)
{
visit
(
o
.
uobj
,
arg
);
}
template
<
typename
T
,
typename
std
::
enable_if
<
Cy_is_iterable
<
T
>
::
value
,
int
>::
type
=
0
>
static
inline
void
__Pyx_CyObject_visit_generic
(
void
(
*
visit
)(
const
CyObject
*
o
,
void
*
arg
),
const
T
&
o
,
void
*
arg
)
{
for
(
auto
&
e
:
o
)
{
__Pyx_CyObject_visit_generic
(
visit
,
e
,
arg
);
}
}
template
<
typename
T
,
typename
std
::
enable_if
<
Cy_is_pair
<
T
>
::
value
,
int
>::
type
=
0
>
static
inline
void
__Pyx_CyObject_visit_generic
(
void
(
*
visit
)(
const
CyObject
*
o
,
void
*
arg
),
const
T
&
o
,
void
*
arg
)
{
__Pyx_CyObject_visit_generic
(
visit
,
o
.
first
,
arg
);
__Pyx_CyObject_visit_generic
(
visit
,
o
.
second
,
arg
);
}
template
<
typename
T
,
typename
std
::
enable_if
<
!
Cy_is_pair
<
T
>
::
value
&&
!
Cy_is_iterable
<
T
>::
value
&&
!
Cy_traverse_iso
<
T
>::
value
,
int
>::
type
=
0
>
static
inline
void
__Pyx_CyObject_visit_generic
(
void
(
*
visit
)(
const
CyObject
*
o
,
void
*
arg
),
const
T
&
o
,
void
*
arg
)
{}
/*
* Visit callback to collect reachable fields.
...
...
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