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
959c9d89
Commit
959c9d89
authored
Mar 07, 2019
by
gsamain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C++ CyObject utility code
parent
38211af1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
46 deletions
+42
-46
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+31
-14
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+11
-32
No files found.
Cython/Utility/ModuleSetupCode.c
View file @
959c9d89
...
...
@@ -1532,20 +1532,37 @@ static void __Pyx_FastGilFuncInit(void) {
#endif
/* Has GCC */
#ifdef __cplusplus
#include <atomic>
using
namespace
std
;
#define CyObject_ATOMIC_REFCOUNT_TYPE atomic_int
#else
#include <stdatomic.h>
#define CyObject_ATOMIC_REFCOUNT_TYPE int
#endif
/* __cplusplus */
#if __cplusplus >= 201103L
#include <atomic>
using
namespace
std
;
#define CyObject_ATOMIC_REFCOUNT_TYPE atomic_int
class
CyObject
{
private:
CyObject_ATOMIC_REFCOUNT_TYPE
ob_refcnt
;
public:
CyObject
()
:
ob_refcnt
(
1
)
{}
virtual
~
CyObject
()
{}
void
CyObject_INCREF
();
int
CyObject_DECREF
();
};
static
inline
int
_Cy_DECREF
(
CyObject
*
op
)
{
return
op
->
CyObject_DECREF
();
}
/* CyObject_HEAD defines the initial segment of every CyObject. */
#define CyObject_HEAD \
CyObject_ATOMIC_REFCOUNT_TYPE ob_refcnt; \
void (*cdealloc)(void* self);
static
inline
void
_Cy_INCREF
(
CyObject
*
op
)
{
op
->
CyObject_INCREF
();
}
struct
CyObject
{
CyObject_HEAD
};
/* Cast argument to CyObject* type. */
#define _CyObject_CAST(op) op
#define Cy_INCREF(op) _Cy_INCREF(_CyObject_CAST(op))
#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_GOTREF(op)
#define Cy_XGOTREF(op)
#define Cy_GIVEREF(op)
#define Cy_XGIVEREF(op)
#endif
#endif
Cython/Utility/ObjectHandling.c
View file @
959c9d89
...
...
@@ -1589,44 +1589,23 @@ try_unpack:
// atomic is already included in ModuleSetupCode
// #include <atomic>
#else
#include <stdlib.h>
#include <stddef.h>
// #include <stdatomic.h>
#error C++ needed for cython+ nogil classes
#endif
/* __cplusplus */
// Defined in ModuleSetupCode.c
/* CyObject_HEAD defines the initial segment of every CyObject. */
//#define CyObject_HEAD \
// int ob_refcnt; \
// void (*cdealloc)(void * self);
/* Cast argument to PyObject* type. */
#define _CyObject_CAST(op) ((struct CyObject*)(op))
static
inline
void
_Cy_DECREF
(
struct
CyObject
*
op
)
{
// int f = open("log_nogil", O_WRONLY|O_APPEND);
// dprintf(f, "DECREF ob_refcnt (before decref) = %d\n", op->ob_refcnt);
if
(
atomic_fetch_sub
(
&
(
op
->
ob_refcnt
),
1
)
==
1
)
{
//op->cdealloc(op);
// DEBUG
// dprintf(f, "Freeing memory\n");
free
(
op
);
}
// close(f);
void
CyObject
::
CyObject_INCREF
()
{
atomic_fetch_add
(
&
(
this
->
ob_refcnt
),
1
);
}
static
inline
void
_Cy_INCREF
(
struct
CyObject
*
op
)
{
atomic_fetch_add
(
&
(
op
->
ob_refcnt
),
1
);
int
CyObject
::
CyObject_DECREF
()
{
if
(
atomic_fetch_sub
(
&
(
this
->
ob_refcnt
),
1
)
==
1
)
{
delete
this
;
return
1
;
}
return
0
;
}
#define Cy_INCREF(op) _Cy_INCREF(_CyObject_CAST(op))
#define Cy_DECREF(op) _Cy_DECREF(_CyObject_CAST(op))
#define Cy_XDECREF(op) do {if (op != NULL) {Cy_DECREF(op);}} while(0)
#define Cy_GOTREF(op)
#define Cy_XGOTREF(op)
#define Cy_GIVEREF(op)
#define Cy_XGIVEREF(op)
/////////////// UnpackUnboundCMethod.proto ///////////////
typedef
struct
{
...
...
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