Skip to content

Commit 5fcfbb5

Browse files
committed
[GR-12699] [GR-13338] [GR-12554] [GR-13724] Remove mirroring of native classes.
PullRequest: graalpython/392
2 parents c7d2200 + 228df7f commit 5fcfbb5

File tree

113 files changed

+4103
-1910
lines changed

Some content is hidden

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

113 files changed

+4103
-1910
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.c

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,8 @@ void* native_long_to_java(uint64_t val) {
233233
return Py_None;
234234
} else if (!truffle_cannot_be_handle(obj)) {
235235
return resolve_handle(cache, (uint64_t)obj);
236-
} else {
237-
void* refcnt = obj->ob_refcnt;
238-
if (!truffle_cannot_be_handle(refcnt)) {
239-
return resolve_handle(cache, refcnt);
240-
} else if (IS_POINTER(refcnt)) {
241-
return refcnt;
242-
}
243-
return obj;
244236
}
237+
return obj;
245238
}
246239

247240
__attribute__((always_inline))
@@ -259,25 +252,51 @@ PyObject* to_sulong(void *o) {
259252

260253
/** to be used from Java code only; reads native 'ob_type' field */
261254
void* get_ob_type(PyObject* obj) {
262-
PyTypeObject* type = obj->ob_type;
255+
PyTypeObject* type = obj->ob_type;
263256
if (!truffle_cannot_be_handle(type)) {
264257
return resolve_handle(cache, (uint64_t)type);
265-
} else {
266-
PyObject* cast_type = ((PyObject*)type);
267-
if (!polyglot_is_value(cast_type)) {
268-
// we have stored a handle to the Java class in ob_refcnt
269-
void* handle = (void*)(cast_type->ob_refcnt);
270-
if (!truffle_cannot_be_handle(handle)) {
271-
return resolve_handle(cache, (uint64_t)handle);
272-
} else {
273-
// assume handle is a TruffleObject
274-
return handle;
275-
}
276-
} else {
277-
// the type is already the right value (e.g. on sandboxed it's a managed pointer)
278-
return cast_type;
279-
}
280258
}
259+
return (void *)type;
260+
}
261+
262+
/** to be used from Java code only; reads native 'tp_dict' field */
263+
PyObject* get_tp_dict(PyTypeObject* obj) {
264+
return native_to_java(obj->tp_dict);
265+
}
266+
267+
/** to be used from Java code only; reads native 'tp_bases' field */
268+
PyObject* get_tp_bases(PyTypeObject* obj) {
269+
return native_to_java(obj->tp_bases);
270+
}
271+
272+
/** to be used from Java code only; reads native 'tp_name' field */
273+
PyObject* get_tp_name(PyTypeObject* obj) {
274+
return polyglot_from_string(obj->tp_name, SRC_CS);
275+
}
276+
277+
/** to be used from Java code only; reads native 'tp_mro' field */
278+
PyObject* get_tp_mro(PyTypeObject* obj) {
279+
return native_to_java(obj->tp_mro);
280+
}
281+
282+
/** to be used from Java code only; reads native 'tp_subclasses' field */
283+
PyObject* get_tp_subclasses(PyTypeObject* obj) {
284+
return native_to_java(obj->tp_subclasses);
285+
}
286+
287+
/** to be used from Java code only; reads native 'tp_dictoffset' field */
288+
Py_ssize_t get_tp_dictoffset(PyTypeObject* obj) {
289+
return obj->tp_dictoffset;
290+
}
291+
292+
/** to be used from Java code only; reads native 'tp_itemsize' field */
293+
Py_ssize_t get_tp_itemsize(PyTypeObject* obj) {
294+
return obj->tp_itemsize;
295+
}
296+
297+
/** to be used from Java code only; reads native 'tp_basicsize' field */
298+
Py_ssize_t get_tp_basicsize(PyTypeObject* obj) {
299+
return obj->tp_basicsize;
281300
}
282301

283302
/** to be used from Java code only; returns the type ID for a byte array */

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,16 @@ inline void* native_to_java(PyObject* obj) {
175175
return obj;
176176
} else if (!truffle_cannot_be_handle(obj)) {
177177
return resolve_handle(cache, (uint64_t)obj);
178-
} else {
179-
void* refcnt = obj->ob_refcnt;
180-
if (!truffle_cannot_be_handle(refcnt)) {
181-
return resolve_handle(cache, refcnt);
182-
} else if (IS_POINTER(refcnt)) {
183-
return refcnt;
184-
}
185-
return obj;
186178
}
179+
return obj;
187180
}
188181

189182
__attribute__((always_inline))
190183
inline void* native_type_to_java(PyTypeObject* type) {
191-
if (IS_POINTER(((PyObject*)type)->ob_refcnt)) {
192-
return (void*)((PyObject*)type)->ob_refcnt;
193-
} else if (!truffle_cannot_be_handle(((PyObject*)type)->ob_refcnt)) {
194-
return resolve_handle(cache, ((PyObject*)type)->ob_refcnt);
195-
}
196-
return (void*)type;
184+
if (!truffle_cannot_be_handle(type)) {
185+
return (void *)resolve_handle(cache, (uint64_t)type);
186+
}
187+
return (void *)type;
197188
}
198189

199190
extern void* to_java(PyObject* obj);

graalpython/com.oracle.graal.python.cext/src/moduleobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -53,6 +53,7 @@ int PyModule_AddFunctions(PyObject* mod, PyMethodDef* methods) {
5353
polyglot_invoke(PY_TRUFFLE_CEXT,
5454
"AddFunction",
5555
native_to_java(mod),
56+
NULL,
5657
polyglot_from_string((const char*)(def.ml_name), SRC_CS),
5758
def.ml_meth,
5859
get_method_flags_cwrapper(def.ml_flags),

graalpython/com.oracle.graal.python.cext/src/object.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -141,7 +141,6 @@ PyObject _Py_NotImplementedStruct = {
141141
PyObject* PyType_GenericAlloc(PyTypeObject* cls, Py_ssize_t nitems) {
142142
Py_ssize_t size = cls->tp_basicsize + cls->tp_itemsize * nitems;
143143
PyObject* newObj = (PyObject*)PyObject_Malloc(size);
144-
memset(newObj, 0, size);
145144
if(cls->tp_dictoffset) {
146145
*((PyObject **) ((char *)newObj + cls->tp_dictoffset)) = NULL;
147146
}

0 commit comments

Comments
 (0)