Skip to content

Commit 09f206b

Browse files
author
Franziska Geiger
committed
[GR-15897] Adding missing C libraries for tensorflow compilation
PullRequest: graalpython/528
2 parents e196ef0 + eeabfee commit 09f206b

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed

graalpython/com.oracle.graal.python.cext/include/Python.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121
#include "iterobject.h"
122122
#include "datetime.h"
123123
#include "typeslots.h"
124+
#include "weakrefobject.h"
125+
#include "sysmodule.h"
124126

125127
// TODO: we must extend the refcounting behavior to support handles to managed objects
126128
#undef Py_DECREF
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* Copyright (c) 2019, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2017 Python Software Foundation
3+
*
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
*/
6+
/* System module interface */
7+
8+
#ifndef Py_SYSMODULE_H
9+
#define Py_SYSMODULE_H
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
PyAPI_FUNC(PyObject *) PySys_GetObject(const char *);
15+
PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);
16+
#ifndef Py_LIMITED_API
17+
PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key);
18+
PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *);
19+
#endif
20+
21+
PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
22+
PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int);
23+
PyAPI_FUNC(void) PySys_SetPath(const wchar_t *);
24+
25+
PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
26+
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
27+
PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
28+
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
29+
PyAPI_FUNC(void) PySys_FormatStdout(const char *format, ...);
30+
PyAPI_FUNC(void) PySys_FormatStderr(const char *format, ...);
31+
32+
PyAPI_FUNC(void) PySys_ResetWarnOptions(void);
33+
PyAPI_FUNC(void) PySys_AddWarnOption(const wchar_t *);
34+
PyAPI_FUNC(void) PySys_AddWarnOptionUnicode(PyObject *);
35+
PyAPI_FUNC(int) PySys_HasWarnOptions(void);
36+
37+
PyAPI_FUNC(void) PySys_AddXOption(const wchar_t *);
38+
PyAPI_FUNC(PyObject *) PySys_GetXOptions(void);
39+
40+
#ifndef Py_LIMITED_API
41+
PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *);
42+
#endif
43+
44+
#ifdef __cplusplus
45+
}
46+
#endif
47+
#endif /* !Py_SYSMODULE_H */
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/* Copyright (c) 2019, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2017 Python Software Foundation
3+
*
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
*/
6+
/* Weak references objects for Python. */
7+
8+
#ifndef Py_WEAKREFOBJECT_H
9+
#define Py_WEAKREFOBJECT_H
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
15+
typedef struct _PyWeakReference PyWeakReference;
16+
17+
/* PyWeakReference is the base struct for the Python ReferenceType, ProxyType,
18+
* and CallableProxyType.
19+
*/
20+
#ifndef Py_LIMITED_API
21+
struct _PyWeakReference {
22+
PyObject_HEAD
23+
24+
/* The object to which this is a weak reference, or Py_None if none.
25+
* Note that this is a stealth reference: wr_object's refcount is
26+
* not incremented to reflect this pointer.
27+
*/
28+
PyObject *wr_object;
29+
30+
/* A callable to invoke when wr_object dies, or NULL if none. */
31+
PyObject *wr_callback;
32+
33+
/* A cache for wr_object's hash code. As usual for hashes, this is -1
34+
* if the hash code isn't known yet.
35+
*/
36+
Py_hash_t hash;
37+
38+
/* If wr_object is weakly referenced, wr_object has a doubly-linked NULL-
39+
* terminated list of weak references to it. These are the list pointers.
40+
* If wr_object goes away, wr_object is set to Py_None, and these pointers
41+
* have no meaning then.
42+
*/
43+
PyWeakReference *wr_prev;
44+
PyWeakReference *wr_next;
45+
};
46+
#endif
47+
48+
PyAPI_DATA(PyTypeObject) _PyWeakref_RefType;
49+
PyAPI_DATA(PyTypeObject) _PyWeakref_ProxyType;
50+
PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType;
51+
52+
#define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType)
53+
#define PyWeakref_CheckRefExact(op) \
54+
(Py_TYPE(op) == &_PyWeakref_RefType)
55+
#define PyWeakref_CheckProxy(op) \
56+
((Py_TYPE(op) == &_PyWeakref_ProxyType) || \
57+
(Py_TYPE(op) == &_PyWeakref_CallableProxyType))
58+
59+
#define PyWeakref_Check(op) \
60+
(PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op))
61+
62+
63+
PyAPI_FUNC(PyObject *) PyWeakref_NewRef(PyObject *ob,
64+
PyObject *callback);
65+
PyAPI_FUNC(PyObject *) PyWeakref_NewProxy(PyObject *ob,
66+
PyObject *callback);
67+
PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref);
68+
69+
#ifndef Py_LIMITED_API
70+
PyAPI_FUNC(Py_ssize_t) _PyWeakref_GetWeakrefCount(PyWeakReference *head);
71+
72+
PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
73+
#endif
74+
75+
/* Explanation for the Py_REFCNT() check: when a weakref's target is part
76+
of a long chain of deallocations which triggers the trashcan mechanism,
77+
clearing the weakrefs can be delayed long after the target's refcount
78+
has dropped to zero. In the meantime, code accessing the weakref will
79+
be able to "see" the target object even though it is supposed to be
80+
unreachable. See issue #16602. */
81+
82+
#define PyWeakref_GET_OBJECT(ref) \
83+
(Py_REFCNT(((PyWeakReference *)(ref))->wr_object) > 0 \
84+
? ((PyWeakReference *)(ref))->wr_object \
85+
: Py_None)
86+
87+
88+
#ifdef __cplusplus
89+
}
90+
#endif
91+
#endif /* !Py_WEAKREFOBJECT_H */

mx.graalpython/copyrights/overrides

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ graalpython/com.oracle.graal.python.cext/include/setobject.h,python.copyright
9797
graalpython/com.oracle.graal.python.cext/include/sliceobject.h,python.copyright
9898
graalpython/com.oracle.graal.python.cext/include/structmember.h,python.copyright
9999
graalpython/com.oracle.graal.python.cext/include/structseq.h,python.copyright
100+
graalpython/com.oracle.graal.python.cext/include/sysmodule.h,python.copyright
100101
graalpython/com.oracle.graal.python.cext/include/traceback.h,python.copyright
101102
graalpython/com.oracle.graal.python.cext/include/truffle.h,no.copyright
102103
graalpython/com.oracle.graal.python.cext/include/tupleobject.h,python.copyright
103104
graalpython/com.oracle.graal.python.cext/include/typeslots.h,python.copyright
104105
graalpython/com.oracle.graal.python.cext/include/ucnhash.h,python.copyright
105106
graalpython/com.oracle.graal.python.cext/include/unicodeobject.h,python.copyright
106107
graalpython/com.oracle.graal.python.cext/include/warnings.h,python.copyright
108+
graalpython/com.oracle.graal.python.cext/include/weakrefobject.h,python.copyright
107109
graalpython/com.oracle.graal.python.cext/modules/clinic/_bz2module.c.h,python.copyright
108110
graalpython/com.oracle.graal.python.cext/modules/clinic/_sre.c.h,python.copyright
109111
graalpython/com.oracle.graal.python.cext/modules/clinic/_struct.c.h,python.copyright

0 commit comments

Comments
 (0)