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
Boxiang Sun
cython
Commits
4a45a84a
Commit
4a45a84a
authored
Dec 28, 2018
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pritimive memory management for nogil extension
parent
ca525fde
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
4 deletions
+51
-4
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-0
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+3
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+0
-3
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+45
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
4a45a84a
...
@@ -8775,7 +8775,10 @@ class DictNode(ExprNode):
...
@@ -8775,7 +8775,10 @@ class DictNode(ExprNode):
# Custom method used here because key-value
# Custom method used here because key-value
# pairs are evaluated and used one at a time.
# pairs are evaluated and used one at a time.
code
.
mark_pos
(
self
.
pos
)
code
.
mark_pos
(
self
.
pos
)
self
.
allocate_temp_result
(
code
)
self
.
allocate_temp_result
(
code
)
if
hasattr
(
self
.
type
,
'nogil'
)
and
self
.
type
.
nogil
:
code
.
putln
(
"%s = (struct %s *)malloc(sizeof(struct %s));"
%
(
self
.
result
(),
self
.
type
.
objstruct_cname
,
self
.
type
.
objstruct_cname
))
is_dict
=
self
.
type
.
is_pyobject
is_dict
=
self
.
type
.
is_pyobject
if
is_dict
:
if
is_dict
:
...
...
Cython/Compiler/ModuleNode.py
View file @
4a45a84a
...
@@ -1117,11 +1117,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1117,11 +1117,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
Naming
.
obj_base_cname
))
Naming
.
obj_base_cname
))
elif
nogil
:
elif
nogil
:
# Extension type with nogil keyword indicate it is a CPython-free struct
# Extension type with nogil keyword indicate it is a CPython-free struct
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"CythonReferenceCounting"
,
"ObjectHandling.c"
))
code
.
putln
(
code
.
putln
(
"// nogil"
"// nogil"
)
)
code
.
putln
(
code
.
putln
(
"
size_t ob_refcnt;"
"
int ob_refcnt;"
# "CyObject_HEAD;" Sometimes the CythonReferenceCounting was put after the nogil extension declaration, WTF!!!
)
)
else
:
else
:
code
.
putln
(
code
.
putln
(
...
...
Cython/Compiler/PyrexTypes.py
View file @
4a45a84a
...
@@ -1363,9 +1363,6 @@ class CythonExtensionType(CythonObjectType):
...
@@ -1363,9 +1363,6 @@ class CythonExtensionType(CythonObjectType):
entity_code
=
"*%s"
%
entity_code
entity_code
=
"*%s"
%
entity_code
return
self
.
base_declaration_code
(
base_code
,
entity_code
)
return
self
.
base_declaration_code
(
base_code
,
entity_code
)
def
literal_code
(
self
,
value
):
return
'(struct %s *)malloc(sizeof(struct %s))'
%
(
self
.
objstruct_cname
,
self
.
objstruct_cname
)
def
type_test_code
(
self
,
py_arg
,
notnone
=
False
):
def
type_test_code
(
self
,
py_arg
,
notnone
=
False
):
none_check
=
"((%s) == Py_None)"
%
py_arg
none_check
=
"((%s) == Py_None)"
%
py_arg
...
...
Cython/Utility/ObjectHandling.c
View file @
4a45a84a
...
@@ -1527,6 +1527,51 @@ try_unpack:
...
@@ -1527,6 +1527,51 @@ try_unpack:
return
0
;
return
0
;
}
}
/////////////// CythonReferenceCounting.proto ///////////////
#include <stdlib.h>
#include <stddef.h>
#if !defined(__GNUC__)
#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
/* Test for GCC > 4.9.0 */
#if GCC_VERSION < 40900
#error atomic.h works only with GCC newer than version 4.9
#endif
/* GNUC >= 4.9 */
#endif
/* Has GCC */
// #include <stdatomic.h>
/* CyObject_HEAD defines the initial segment of every CyObject. */
#define CyObject_HEAD \
int ob_refcnt; \
void (*cdealloc)();
struct
CyObject
{
CyObject_HEAD
};
/* Cast argument to PyObject* type. */
#define _CyObject_CAST(op) ((struct CyObject*)(op))
// XXX: Without scope analysis this is useless...
/*
static inline void _Cy_DECREF(struct CyObject *op) {
if (atomic_fetch_sub(&(op->ob_refcnt), 1) == 1) {
op->cdealloc(op);
}
}
static inline void _Cy_INCREF(struct CyObject *op) {
atomic_fetch_add(&(op->ob_refcnt), 1);
}
#define Cy_INCREF(op) _Cy_INCREF(_CyObject_CAST(op))
#define Cy_DECREF(op) _Cy_DECREF(_CyObject_CAST(op))
*/
/////////////// UnpackUnboundCMethod.proto ///////////////
/////////////// UnpackUnboundCMethod.proto ///////////////
...
...
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