Skip to content

Commit bef234d

Browse files
committed
[GR-40247] New Implementation of C API that allows native execution.
PullRequest: graalpython/2614
2 parents 48692eb + cdbb353 commit bef234d

File tree

317 files changed

+36595
-20201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

317 files changed

+36595
-20201
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "47faab4012b93d0636f07508400d8ef7ed55479b" }
1+
{ "overlay": "f43588af9b5811c0c72177d07093606797b2e34e" }

graalpython/com.oracle.graal.python.cext/CAPIFunctions.txt

Lines changed: 1289 additions & 0 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python.cext/hpy/hpy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ POLYGLOT_DECLARE_TYPE(wchar_t)
8080
POLYGLOT_DECLARE_TYPE(HPyType_Spec)
8181
POLYGLOT_DECLARE_TYPE(HPyType_SpecParam)
8282

83-
int graal_hpy_init(HPyContext *context, void *initObject) {
83+
int Py_EXPORTED_SYMBOL graal_hpy_init(HPyContext *context, void *initObject) {
8484
// save context in global for NFI upcalls
8585
g_universal_ctx = context;
8686

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
/* Include nearly all Python header files */
1111

1212
#include "patchlevel.h"
13+
14+
// can be used to bulk-rename fields, e.g., by concatenating "_internal"
15+
#define Py_HIDE_IMPL_FIELD(name) name
16+
1317
#include "pyconfig.h"
1418

1519
#include <limits.h>
@@ -141,4 +145,7 @@
141145
#include "cpython/pyfpe.h"
142146
#include "tracemalloc.h"
143147

148+
// helper macro for quick printf debugging
149+
#define __PD {printf("%i \t%s\n", __LINE__, __func__); }
150+
144151
#endif /* !Py_PYTHON_H */

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,11 @@ PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
729729
#define PySequence_Fast_GET_ITEM(o, i)\
730730
(PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
731731

732+
PyAPI_FUNC(PyObject **) _PySequence_Fast_ITEMS(PyObject *o);
733+
732734
/* Return a pointer to the underlying item array for
733735
an object returned by PySequence_Fast */
734-
#define PySequence_Fast_ITEMS(sf) \
735-
(PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
736-
: ((PyTupleObject *)(sf))->ob_item)
736+
#define PySequence_Fast_ITEMS(sf) _PySequence_Fast_ITEMS(sf)
737737

738738
/* Return the number of occurrences on value on 'o', that is, return
739739
the number of keys for which o[key] == value.
@@ -866,6 +866,12 @@ PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
866866
/* issubclass(object, typeorclass) */
867867
PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
868868

869+
870+
/* GraalPy-specific API */
871+
PyAPI_FUNC(const char*) PyObject_GetDoc(PyObject* object);
872+
873+
PyAPI_FUNC(int) PyObject_SetDoc(PyObject* object, const char* doc);
874+
869875
#ifndef Py_LIMITED_API
870876
# define Py_CPYTHON_ABSTRACTOBJECT_H
871877
# include "cpython/abstract.h"

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
3333

3434
/* Macros for direct access to these values. Type checks are *not*
3535
done, so use with care. */
36-
#define PyMethod_GET_FUNCTION(meth) \
37-
(((PyMethodObject *)meth) -> im_func)
38-
#define PyMethod_GET_SELF(meth) \
39-
(((PyMethodObject *)meth) -> im_self)
36+
#define PyMethod_GET_FUNCTION(meth) PyMethod_Function((PyObject*)(meth))
37+
#define PyMethod_GET_SELF(meth) PyMethod_Self((PyObject*)(meth))
4038

4139
typedef struct {
4240
PyObject_HEAD
@@ -52,8 +50,7 @@ PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
5250

5351
/* Macros for direct access to these values. Type checks are *not*
5452
done, so use with care. */
55-
#define PyInstanceMethod_GET_FUNCTION(meth) \
56-
(((PyInstanceMethodObject *)meth) -> func)
53+
#define PyInstanceMethod_GET_FUNCTION(meth) PyInstanceMethod_Function((PyObject*)(meth))
5754

5855
#ifdef __cplusplus
5956
}

graalpython/com.oracle.graal.python.cext/include/cpython/abstract.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
/* Copyright (c) 2020, 2023, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2020 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -331,10 +331,11 @@ PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);
331331

332332
/* === Sequence protocol ================================================ */
333333

334+
PyAPI_FUNC(PyObject*) _PySequence_ITEM(PyObject* obj, Py_ssize_t index);
335+
334336
/* Assume tp_as_sequence and sq_item exist and that 'i' does not
335337
need to be corrected for a negative index. */
336-
#define PySequence_ITEM(o, i)\
337-
( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )
338+
#define PySequence_ITEM(o, i) _PySequence_ITEM((o), (i))
338339

339340
#define PY_ITERSEARCH_COUNT 1
340341
#define PY_ITERSEARCH_INDEX 2

graalpython/com.oracle.graal.python.cext/include/cpython/bytearrayobject.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2022, Oracle and/or its affiliates.
1+
/* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2022 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -16,10 +16,12 @@ typedef struct {
1616
Py_ssize_t ob_exports; /* How many buffer exports */
1717
} PyByteArrayObject;
1818

19+
PyAPI_FUNC(char*) _PyByteArray_Start(PyObject*);
20+
1921
/* Macros, trading safety for speed */
2022
#define PyByteArray_AS_STRING(self) \
2123
(assert(PyByteArray_Check(self)), \
22-
Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_start : _PyByteArray_empty_string)
24+
Py_SIZE(self) ? _PyByteArray_Start((PyObject *)self) : _PyByteArray_empty_string)
2325
#define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)), Py_SIZE(self))
2426

2527
PyAPI_DATA(char) _PyByteArray_empty_string[];

graalpython/com.oracle.graal.python.cext/include/cpython/bytesobject.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
typedef struct {
4646
PyObject_VAR_HEAD
4747
Py_hash_t ob_shash;
48-
// Truffle change: char ob_sval[1] doesn't work for us in Sulong
49-
char *ob_sval;
48+
char Py_HIDE_IMPL_FIELD(ob_sval)[1];
5049

5150
/* Invariants:
5251
* ob_sval contains space for 'ob_size+1' elements.
@@ -70,8 +69,7 @@ PyAPI_FUNC(PyObject *) _PyBytes_DecodeEscape(const char *, Py_ssize_t,
7069
const char *, const char **);
7170

7271
/* Macro, trading safety for speed */
73-
#define PyBytes_AS_STRING(op) (assert(PyBytes_Check(op)), \
74-
(((PyBytesObject *)(op))->ob_sval))
72+
#define PyBytes_AS_STRING(op) (PyBytes_AsString((PyObject*) (op)))
7573
#define PyBytes_GET_SIZE(op) (assert(PyBytes_Check(op)),Py_SIZE(op))
7674

7775
/* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*,

graalpython/com.oracle.graal.python.cext/include/cpython/dictobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ PyAPI_FUNC(int) _PyDict_Next(
5050
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
5151

5252
/* Get the number of items of a dictionary. */
53-
#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used)
53+
#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),PyObject_Size((PyObject*) mp))
5454
PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
5555
PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, struct _Py_Identifier *);
5656
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);

0 commit comments

Comments
 (0)