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
8459ec96
Commit
8459ec96
authored
Jun 24, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a builtin macro to get current cypclass nogil refcount
parent
2bcc2325
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+6
-4
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+11
-0
No files found.
Cython/Compiler/Builtin.py
View file @
8459ec96
...
@@ -652,15 +652,17 @@ def init_builtin_structs():
...
@@ -652,15 +652,17 @@ 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
():
reference_to_cy_object_type
=
PyrexTypes
.
CReferenceType
(
PyrexTypes
.
cy_object_type
)
incref_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_void_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
PyrexTypes
.
cy_object_type
,
None
)],
nogil
=
1
)
incref_macro_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_void_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
PyrexTypes
.
cy_object_type
,
None
)],
nogil
=
1
)
# The decref macros set their argument to NULL when the counter reaches 0,
# The decref macros set their argument to NULL when the counter reaches 0,
# so we pretend to Cython that it's a c++ function with the argument passed by reference.
# so we pretend to Cython that it's a c++ function with the argument passed by reference.
# This keeps the compiler from using std::move when calling the macro for instance.
# This keeps the compiler from using std::move when calling the macro for instance.
decref_macro_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_void_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
reference_to_cy_object_type
,
None
)],
nogil
=
1
)
reference_to_cy_object_type
=
PyrexTypes
.
CReferenceType
(
PyrexTypes
.
cy_object_type
)
decref_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_void_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"obj"
,
reference_to_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_
macro_type
),
(
"Cy_DECREF"
,
decref_macro_type
),
(
"Cy_XDECREF"
,
decref_macro
_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
)
def
inject_cypclass_lock_macros
():
def
inject_cypclass_lock_macros
():
...
...
Cython/Utility/CyObjects.cpp
View file @
8459ec96
...
@@ -67,6 +67,7 @@
...
@@ -67,6 +67,7 @@
virtual
~
CyObject
();
virtual
~
CyObject
();
void
CyObject_INCREF
();
void
CyObject_INCREF
();
int
CyObject_DECREF
();
int
CyObject_DECREF
();
int
CyObject_GETREF
();
void
CyObject_RLOCK
();
void
CyObject_RLOCK
();
void
CyObject_WLOCK
();
void
CyObject_WLOCK
();
void
CyObject_UNLOCK
();
void
CyObject_UNLOCK
();
...
@@ -125,6 +126,10 @@
...
@@ -125,6 +126,10 @@
op
->
CyObject_INCREF
();
op
->
CyObject_INCREF
();
}
}
static
inline
int
_Cy_GETREF
(
CyObject
*
op
)
{
return
op
->
CyObject_GETREF
();
}
static
inline
void
_Cy_RLOCK
(
CyObject
*
op
)
{
static
inline
void
_Cy_RLOCK
(
CyObject
*
op
)
{
if
(
op
!=
NULL
)
{
if
(
op
!=
NULL
)
{
op
->
CyObject_RLOCK
();
op
->
CyObject_RLOCK
();
...
@@ -227,6 +232,7 @@
...
@@ -227,6 +232,7 @@
#define Cy_INCREF(op) do {if (op != NULL) {_Cy_INCREF(_CyObject_CAST(op));}} while(0)
#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_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_XDECREF(op) do {if (op != NULL) {Cy_DECREF(op);}} while(0)
#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)
#define Cy_GIVEREF(op)
#define Cy_GIVEREF(op)
...
@@ -469,6 +475,11 @@ int CyObject::CyObject_DECREF()
...
@@ -469,6 +475,11 @@ int CyObject::CyObject_DECREF()
return
0
;
return
0
;
}
}
int
CyObject
::
CyObject_GETREF
()
{
return
this
->
nogil_ob_refcnt
;
}
void
CyObject
::
CyObject_RLOCK
()
void
CyObject
::
CyObject_RLOCK
()
{
{
this
->
ob_lock
.
rlock
();
this
->
ob_lock
.
rlock
();
...
...
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