Skip to content

Commit e78ff04

Browse files
fangerertimfel
authored andcommitted
re-apply memoryview patches
1 parent cb0565b commit e78ff04

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -297,33 +297,36 @@ extern PyGC_Head *_PyGC_generation0;
297297

298298
/* Tell the GC to track this object. NB: While the object is tracked the
299299
* collector it must be safe to call the ob_traverse method. */
300-
#define _PyObject_GC_TRACK(o) do { \
301-
PyGC_Head *g = _Py_AS_GC(o); \
302-
if (_PyGCHead_REFS(g) != _PyGC_REFS_UNTRACKED) \
303-
Py_FatalError("GC object already tracked"); \
304-
_PyGCHead_SET_REFS(g, _PyGC_REFS_REACHABLE); \
305-
g->gc.gc_next = _PyGC_generation0; \
306-
g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \
307-
g->gc.gc_prev->gc.gc_next = g; \
308-
_PyGC_generation0->gc.gc_prev = g; \
309-
} while (0);
300+
//#define _PyObject_GC_TRACK(o) do { \
301+
// PyGC_Head *g = _Py_AS_GC(o); \
302+
// if (_PyGCHead_REFS(g) != _PyGC_REFS_UNTRACKED) \
303+
// Py_FatalError("GC object already tracked"); \
304+
// _PyGCHead_SET_REFS(g, _PyGC_REFS_REACHABLE); \
305+
// g->gc.gc_next = _PyGC_generation0; \
306+
// g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \
307+
// g->gc.gc_prev->gc.gc_next = g; \
308+
// _PyGC_generation0->gc.gc_prev = g; \
309+
// } while (0);
310+
#define _PyObject_GC_TRACK(o)
310311

311312
/* Tell the GC to stop tracking this object.
312313
* gc_next doesn't need to be set to NULL, but doing so is a good
313314
* way to provoke memory errors if calling code is confused.
314315
*/
315-
#define _PyObject_GC_UNTRACK(o) do { \
316-
PyGC_Head *g = _Py_AS_GC(o); \
317-
assert(_PyGCHead_REFS(g) != _PyGC_REFS_UNTRACKED); \
318-
_PyGCHead_SET_REFS(g, _PyGC_REFS_UNTRACKED); \
319-
g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \
320-
g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \
321-
g->gc.gc_next = NULL; \
322-
} while (0);
316+
#define _PyObject_GC_UNTRACK(o)
317+
//#define _PyObject_GC_UNTRACK(o) do { \
318+
// PyGC_Head *g = _Py_AS_GC(o); \
319+
// assert(_PyGCHead_REFS(g) != _PyGC_REFS_UNTRACKED); \
320+
// _PyGCHead_SET_REFS(g, _PyGC_REFS_UNTRACKED); \
321+
// g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \
322+
// g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \
323+
// g->gc.gc_next = NULL; \
324+
// } while (0);
323325

324326
/* True if the object is currently tracked by the GC. */
325-
#define _PyObject_GC_IS_TRACKED(o) \
326-
(_PyGC_REFS(o) != _PyGC_REFS_UNTRACKED)
327+
#define _PyObject_GC_IS_TRACKED(o) 0
328+
//#define _PyObject_GC_IS_TRACKED(o) \
329+
// (_PyGC_REFS(o) != _PyGC_REFS_UNTRACKED)
327330

328331
/* True if the object may be tracked by the GC in the future, or already is.
329332
This can be useful to implement some optimizations. */

graalpython/com.oracle.graal.python.cext/modules/_memoryview.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
releasebufferprocs must NOT decrement view.obj.
5858
*/
5959

60+
PyTypeObject PyNativeMemoryView_Type;
6061

6162
#define CHECK_MBUF_RELEASED(mbuf) \
6263
if (((_PyManagedBufferObject *)mbuf)->flags&_Py_MANAGED_BUFFER_RELEASED) { \
@@ -72,7 +73,7 @@ mbuf_alloc(void)
7273
_PyManagedBufferObject *mbuf;
7374

7475
mbuf = (_PyManagedBufferObject *)
75-
PyObject_GC_New(_PyManagedBufferObject, &_PyManagedBuffer_Type);
76+
PyObject_New(_PyManagedBufferObject, &_PyManagedBuffer_Type);
7677
if (mbuf == NULL)
7778
return NULL;
7879
mbuf->flags = 0;
@@ -630,7 +631,7 @@ memory_alloc(int ndim)
630631
PyMemoryViewObject *mv;
631632

632633
mv = (PyMemoryViewObject *)
633-
PyObject_GC_NewVar(PyMemoryViewObject, &PyMemoryView_Type, 3*ndim);
634+
PyObject_NewVar(PyMemoryViewObject, &PyNativeMemoryView_Type, 3*ndim);
634635
if (mv == NULL)
635636
return NULL;
636637

@@ -802,13 +803,9 @@ PyMemoryView_FromObject(PyObject *v)
802803
return ret;
803804
}
804805

805-
// TODO: remove me once PyErr_XXX functions are supported
806-
printf("memoryview: a bytes-like object is required, not '%.200s'", Py_TYPE(v)->tp_name);
807-
PyErr_SetString(PyExc_TypeError, Py_TYPE(v)->tp_name);
808-
809-
// PyErr_Format(PyExc_TypeError,
810-
// "memoryview: a bytes-like object is required, not '%.200s'",
811-
// Py_TYPE(v)->tp_name);
806+
PyErr_Format(PyExc_TypeError,
807+
"memoryview: a bytes-like object is required, not '%.200s'",
808+
Py_TYPE(v)->tp_name);
812809
return NULL;
813810
}
814811

@@ -3087,9 +3084,9 @@ static PyMethodDef memory_methods[] = {
30873084
};
30883085

30893086

3090-
PyTypeObject PyMemoryView_Type = {
3087+
PyTypeObject PyNativeMemoryView_Type = {
30913088
PyVarObject_HEAD_INIT(&PyType_Type, 0)
3092-
"memoryview", /* tp_name */
3089+
"nativememoryview", /* tp_name */
30933090
offsetof(PyMemoryViewObject, ob_array), /* tp_basicsize */
30943091
sizeof(Py_ssize_t), /* tp_itemsize */
30953092
(destructor)memory_dealloc, /* tp_dealloc */
@@ -3149,17 +3146,17 @@ PyInit__memoryview(void)
31493146
if (m == NULL)
31503147
return NULL;
31513148

3152-
if (PyType_Ready(&PyMemoryView_Type) < 0)
3149+
if (PyType_Ready(&PyNativeMemoryView_Type) < 0)
31533150
return NULL;
31543151

31553152
if (PyType_Ready(&_PyManagedBuffer_Type) < 0)
31563153
return NULL;
31573154

3158-
Py_INCREF((PyObject*)&PyMemoryView_Type);
3159-
PyModule_AddObject(m, "memoryview", (PyObject*)&PyMemoryView_Type);
3155+
Py_INCREF((PyObject*)&PyNativeMemoryView_Type);
3156+
PyModule_AddObject(m, "nativememoryview",(PyObject*) &PyNativeMemoryView_Type);
31603157

31613158
Py_INCREF((PyObject*)&_PyManagedBuffer_Type);
3162-
PyModule_AddObject(m, "managedbuffer", (PyObject*)&_PyManagedBuffer_Type);
3159+
PyModule_AddObject(m, "managedbuffer", (PyObject*) &_PyManagedBuffer_Type);
31633160

31643161
return m;
31653162
}

0 commit comments

Comments
 (0)