Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,12 @@ struct _is {
* and should be placed at the beginning. */
struct _ceval_state ceval;

/* This structure is carefully allocated so that it's correctly aligned
* to avoid undefined behaviors during LOAD and STORE. The '_malloced'
* field stores the allocated pointer address that will later be freed.
*/
void *_malloced;

PyInterpreterState *next;

int64_t id;
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,14 +1469,14 @@ bytearray_removesuffix_impl(PyByteArrayObject *self, Py_buffer *suffix)
/*[clinic input]
bytearray.resize
size: Py_ssize_t
New size to resize to..
New size to resize to.
/
Resize the internal buffer of bytearray to len.
[clinic start generated code]*/

static PyObject *
bytearray_resize_impl(PyByteArrayObject *self, Py_ssize_t size)
/*[clinic end generated code: output=f73524922990b2d9 input=75fd4d17c4aa47d3]*/
/*[clinic end generated code: output=f73524922990b2d9 input=6c9a260ca7f72071]*/
{
Py_ssize_t start_size = PyByteArray_GET_SIZE(self);
int result = PyByteArray_Resize((PyObject *)self, size);
Expand Down
4 changes: 2 additions & 2 deletions Objects/clinic/bytearrayobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class object "PyObject *" "&PyBaseObject_Type"

#define END_TYPE_DICT_LOCK() Py_END_CRITICAL_SECTION2()

#ifdef Py_DEBUG
#ifndef NDEBUG
// Return true if the world is currently stopped.
static bool
types_world_is_stopped(void)
Expand Down
15 changes: 6 additions & 9 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,19 +457,16 @@ _PyInterpreterState_Enable(_PyRuntimeState *runtime)
static PyInterpreterState *
alloc_interpreter(void)
{
// Aligned allocation for PyInterpreterState.
// the first word of the memory block is used to store
// the original pointer to be used later to free the memory.
size_t alignment = _Alignof(PyInterpreterState);
size_t allocsize = sizeof(PyInterpreterState) + sizeof(void *) + alignment - 1;
size_t allocsize = sizeof(PyInterpreterState) + alignment - 1;
void *mem = PyMem_RawCalloc(1, allocsize);
if (mem == NULL) {
return NULL;
}
void *ptr = _Py_ALIGN_UP((char *)mem + sizeof(void *), alignment);
((void **)ptr)[-1] = mem;
assert(_Py_IS_ALIGNED(ptr, alignment));
return ptr;
PyInterpreterState *interp = _Py_ALIGN_UP(mem, alignment);
assert(_Py_IS_ALIGNED(interp, alignment));
interp->_malloced = mem;
return interp;
}

static void
Expand All @@ -484,7 +481,7 @@ free_interpreter(PyInterpreterState *interp)
interp->obmalloc = NULL;
}
assert(_Py_IS_ALIGNED(interp, _Alignof(PyInterpreterState)));
PyMem_RawFree(((void **)interp)[-1]);
PyMem_RawFree(interp->_malloced);
}
}

Expand Down
Loading