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
2d45696c
Commit
2d45696c
authored
Jul 20, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let cypclass refcount functions also accept non-cypclass args and just do nothing
parent
8d3b0171
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
14 deletions
+47
-14
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+16
-7
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+31
-7
No files found.
Cython/Compiler/Builtin.py
View file @
2d45696c
...
@@ -652,15 +652,24 @@ def init_builtin_structs():
...
@@ -652,15 +652,24 @@ def init_builtin_structs():
name
,
"struct"
,
scope
,
1
,
None
,
cname
=
cname
)
name
,
"struct"
,
scope
,
1
,
None
,
cname
=
cname
)
def
inject_cypclass_refcount_macros
():
def
inject_cypclass_refcount_macros
():
incref_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_void_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
PyrexTypes
.
cy_object_type
,
None
)],
nogil
=
1
)
template_placeholder_type
=
PyrexTypes
.
TemplatePlaceholderType
(
"T"
)
incref_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_void_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
template_placeholder_type
,
None
)],
nogil
=
1
,
templates
=
[
template_placeholder_type
]
)
# The decref macros set their argument to NULL when the counter reaches 0,
reference_to_template_type
=
PyrexTypes
.
CReferenceType
(
template_placeholder_type
)
# so we pretend to Cython that it's a c++ function with the argument passed by reference.
decref_type
=
PyrexTypes
.
CFuncType
(
# This keeps the compiler from using std::move when calling the macro for instance.
PyrexTypes
.
c_void_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
reference_to_template_type
,
None
)],
reference_to_cy_object_type
=
PyrexTypes
.
CReferenceType
(
PyrexTypes
.
cy_object_type
)
nogil
=
1
,
decref_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_void_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
reference_to_cy_object_type
,
None
)],
nogil
=
1
)
templates
=
[
template_placeholder_type
]
)
getref_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_int_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
PyrexTypes
.
cy_object_type
,
None
)],
nogil
=
1
)
getref_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_int_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
PyrexTypes
.
cy_object_type
,
None
)],
nogil
=
1
,
)
for
macro
,
macro_type
in
[(
"Cy_INCREF"
,
incref_type
),
(
"Cy_DECREF"
,
decref_type
),
(
"Cy_XDECREF"
,
decref_type
),
(
"Cy_GETREF"
,
getref_type
)]:
for
macro
,
macro_type
in
[(
"Cy_INCREF"
,
incref_type
),
(
"Cy_DECREF"
,
decref_type
),
(
"Cy_XDECREF"
,
decref_type
),
(
"Cy_GETREF"
,
getref_type
)]:
builtin_scope
.
declare_builtin_cfunction
(
macro
,
macro_type
,
macro
)
builtin_scope
.
declare_builtin_cfunction
(
macro
,
macro_type
,
macro
)
...
...
Cython/Utility/CyObjects.cpp
View file @
2d45696c
...
@@ -123,12 +123,38 @@
...
@@ -123,12 +123,38 @@
virtual
~
ActhonActivableClass
();
virtual
~
ActhonActivableClass
();
};
};
static
inline
int
_Cy_DECREF
(
CyObject
*
op
)
{
return
op
->
CyObject_DECREF
();
/*
* Let Cy_INCREF, Cy_DECREF and Cy_XDECREF accept any argument type
* but only do the work when the argument is actually a CyObject
*/
template
<
typename
T
,
typename
std
::
enable_if
<!
std
::
is_convertible
<
T
,
CyObject
*
>
::
value
,
int
>::
type
=
0
>
static
inline
void
Cy_DECREF
(
T
)
{}
template
<
typename
T
,
typename
std
::
enable_if
<!
std
::
is_convertible
<
T
,
CyObject
*
>
::
value
,
int
>::
type
=
0
>
static
inline
void
Cy_XDECREF
(
T
)
{}
template
<
typename
T
,
typename
std
::
enable_if
<!
std
::
is_convertible
<
T
,
CyObject
*
>
::
value
,
int
>::
type
=
0
>
static
inline
void
Cy_INCREF
(
T
)
{}
template
<
typename
T
,
typename
std
::
enable_if
<
std
::
is_convertible
<
T
,
CyObject
*
>
::
value
,
int
>::
type
=
0
>
static
inline
void
Cy_DECREF
(
T
&
op
)
{
if
(
op
->
CyObject_DECREF
())
op
=
NULL
;
}
}
static
inline
void
_Cy_INCREF
(
CyObject
*
op
)
{
template
<
typename
T
,
typename
std
::
enable_if
<
std
::
is_convertible
<
T
,
CyObject
*
>
::
value
,
int
>::
type
=
0
>
op
->
CyObject_INCREF
();
static
inline
void
Cy_XDECREF
(
T
&
op
)
{
if
(
op
!=
NULL
)
{
if
(
op
->
CyObject_DECREF
())
op
=
NULL
;
}
}
template
<
typename
T
,
typename
std
::
enable_if
<
std
::
is_convertible
<
T
,
CyObject
*
>
::
value
,
int
>::
type
=
0
>
static
inline
void
Cy_INCREF
(
T
op
)
{
if
(
op
!=
NULL
)
op
->
CyObject_INCREF
();
}
}
static
inline
int
_Cy_GETREF
(
CyObject
*
op
)
{
static
inline
int
_Cy_GETREF
(
CyObject
*
op
)
{
...
@@ -241,12 +267,10 @@
...
@@ -241,12 +267,10 @@
return
underlying
;
return
underlying
;
}
}
/* Cast argument to CyObject* type. */
/* Cast argument to CyObject* type. */
#define _CyObject_CAST(op) op
#define _CyObject_CAST(op) op
#define Cy_INCREF(op) do {if (op != NULL) {_Cy_INCREF(_CyObject_CAST(op));}} while(0)
#define Cy_DECREF(op) do {if (_Cy_DECREF(_CyObject_CAST(op))) {op = NULL;}} while(0)
#define Cy_XDECREF(op) do {if (op != NULL) {Cy_DECREF(op);}} while(0)
#define Cy_GETREF(op) (_Cy_GETREF(_CyObject_CAST(op)))
#define Cy_GETREF(op) (_Cy_GETREF(_CyObject_CAST(op)))
#define Cy_GOTREF(op)
#define Cy_GOTREF(op)
#define Cy_XGOTREF(op)
#define Cy_XGOTREF(op)
...
...
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