Skip to content

Commit e7d5e76

Browse files
committed
Fix up merge
1 parent d040422 commit e7d5e76

12 files changed

+817
-848
lines changed

Include/internal/pycore_freelist.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ static inline void *
106106
_PyFreeList_PopMem(struct _Py_freelist *fl)
107107
{
108108
void *op = _PyFreeList_PopNoStats(fl);
109-
if (op != NULL) {
110-
OBJECT_STAT_INC(from_freelist);
111-
}
109+
OBJECT_STAT_INC_COND(from_freelist, op != NULL);
112110
return op;
113111
}
114112

Include/internal/pycore_freelist_state.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ struct _Py_freelist {
4040
uint32_t available;
4141
// The maximum number of items this freelist is allowed to hold
4242
uint32_t capacity;
43-
struct _Py_freelist ranges;
44-
struct _Py_freelist range_iters;
45-
struct _Py_freelist pycfunctionobject;
46-
struct _Py_freelist pycmethodobject;
4743
};
4844

4945
#ifdef __cplusplus

Include/internal/pycore_gc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ extern void _PyGC_VisitObjectsWorldStopped(PyInterpreterState *interp,
357357
gcvisitobjects_t callback, void *arg);
358358
#endif
359359

360+
PyAPI_FUNC(void) PyObject_GC_DelTstate(PyThreadState *tstate, PyObject *op, size_t presize, size_t size);
361+
360362
#ifdef __cplusplus
361363
}
362364
#endif

Include/internal/pycore_interp.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ extern "C" {
1313

1414
/* interpreter state */
1515

16-
typedef PyObject *(*alloc_func)(PyTypeObject *tp, size_t presize, size_t size);
17-
typedef PyObject *(*free_func)(PyObject *);
18-
19-
alloc_func alloc;
20-
free_func free;
2116
#define _PyInterpreterState_WHENCE_NOTSET -1
2217
#define _PyInterpreterState_WHENCE_UNKNOWN 0
2318
#define _PyInterpreterState_WHENCE_RUNTIME 1

Include/internal/pycore_interp_structs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ extern "C" {
1515
#include "pycore_tstate.h" // _PyThreadStateImpl
1616
#include "pycore_typedefs.h" // _PyRuntimeState
1717

18+
typedef PyObject *(*py_alloc_func)(PyTypeObject *tp, size_t presize, size_t size);
19+
typedef void (*py_free_func)(PyObject *obj, size_t presize);
20+
1821

1922
#define CODE_MAX_WATCHERS 8
2023
#define CONTEXT_MAX_WATCHERS 8
@@ -890,6 +893,8 @@ struct _is {
890893
// that allocated memory is gone. See free_obmalloc_arenas() for
891894
// more comments.
892895
struct _obmalloc_state *obmalloc;
896+
py_alloc_func alloc;
897+
py_free_func free;
893898

894899
PyObject *audit_hooks;
895900
PyType_WatchCallback type_watchers[TYPE_MAX_WATCHERS];

Include/internal/pycore_object_alloc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ _PyObject_NewTstate(PyThreadState *ts, PyTypeObject *tp, size_t presize, size_t
7474
if (size <= SMALL_REQUEST_THRESHOLD) {
7575
int size_cls = (size - 1) >> ALIGNMENT_SHIFT;
7676
struct _Py_freelist *fl = &ts->interp->object_state.freelists.by_size[size_cls];
77-
char *mem = _PyFreeList_Pop(fl);
78-
PyObject *op = (PyObject *)
77+
char *mem = _PyFreeList_PopMem(fl);
7978
if (mem != NULL) {
8079
PyObject *op = (PyObject *)(mem + presize);
8180
Py_SET_TYPE(op, tp);
@@ -108,7 +107,6 @@ _PyMem_FreeTstate(PyThreadState *ts, PyObject *obj, size_t presize, size_t size)
108107
}
109108
OBJECT_STAT_INC(frees);
110109
ts->interp->free(obj, presize);
111-
_PyRuntime.allocators.standard.obj.free(_PyRuntime.allocators.standard.obj.ctx, mem);
112110
}
113111

114112
static inline void

Include/internal/pycore_object_state.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ struct _Py_freelists {
4545
struct _Py_freelist object_stack_chunks;
4646
struct _Py_freelist unicode_writers;
4747
struct _Py_freelist pymethodobjects;
48+
struct _Py_freelist pycfunctionobject;
49+
struct _Py_freelist pycmethodobject;
50+
struct _Py_freelist ranges;
51+
struct _Py_freelist range_iters;
4852
};
4953

5054
struct _py_object_state {

Objects/floatobject.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,19 @@ PyFloat_FromDoubleTstate(PyThreadState *ts, double fval)
132132
return op;
133133
}
134134

135+
PyObject *
136+
PyFloat_FromDouble(double fval)
135137
{
136138
return PyFloat_FromDoubleTstate(PyThreadState_GET(), fval);
137139
}
138140

141+
_PyStackRef _PyFloat_FromDouble_ConsumeInputs(PyThreadState *ts, _PyStackRef left, _PyStackRef right, double value)
142+
{
143+
PyStackRef_CLOSE_SPECIALIZED_TSTATE(ts, left, _PyFloat_ExactDealloc);
144+
PyStackRef_CLOSE_SPECIALIZED_TSTATE(ts, right, _PyFloat_ExactDealloc);
145+
return PyStackRef_FromPyObjectSteal(PyFloat_FromDoubleTstate(ts, value));
146+
}
147+
139148
static PyObject *
140149
float_from_string_inner(const char *s, Py_ssize_t len, void *obj)
141150
{

Objects/listobject.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ list_dealloc(PyObject *self)
564564
op->ob_item = NULL;
565565
}
566566
if (PyList_CheckExact(op)) {
567+
size_t presize = sizeof(PyGC_Head);
568+
assert(presize == _PyType_PreHeaderSize(Py_TYPE(op)));
567569
PyObject_GC_DelTstate(tstate, self, sizeof(PyGC_Head), sizeof(PyListObject));
568570
}
569571
else {

Python/gc.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,21 +2378,7 @@ void
23782378
PyObject_GC_DelTstate(PyThreadState *tstate, PyObject *op, size_t presize, size_t size)
23792379
{
23802380
PyGC_Head *g = AS_GC(op);
2381-
if (_PyObject_GC_IS_TRACKED(op)) {
2382-
gc_list_remove(g);
2383-
#ifdef Py_DEBUG
2384-
PyObject *exc = PyErr_GetRaisedException();
2385-
if (PyErr_WarnExplicitFormat(PyExc_ResourceWarning, "gc", 0,
2386-
"gc", NULL,
2387-
"Object of type %s is not untracked "
2388-
"before destruction",
2389-
Py_TYPE(op)->tp_name))
2390-
{
2391-
PyErr_FormatUnraisable("Exception ignored on object deallocation");
2392-
}
2393-
PyErr_SetRaisedException(exc);
2394-
#endif
2395-
}
2381+
assert(!_PyObject_GC_IS_TRACKED(op));
23962382
GCState *gcstate = &tstate->interp->gc;
23972383
if (gcstate->young.count > 0) {
23982384
gcstate->young.count--;

0 commit comments

Comments
 (0)