Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -754,6 +754,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
17 changes: 14 additions & 3 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,19 @@
return _PyStatus_OK();
}


static PyInterpreterState *
alloc_interpreter(void)
{
return PyMem_RawCalloc(1, sizeof(PyInterpreterState));
size_t alignment = _Alignof(PyInterpreterState);
size_t allocsize = sizeof(PyInterpreterState) + alignment - 1;
void *mem = PyMem_RawCalloc(1, allocsize);
if (mem == NULL) {
return NULL;
}
PyInterpreterState *interp = _Py_ALIGN_UP(mem, alignment);
assert(_Py_IS_ALIGNED(interp, alignment));
interp->_malloced = (uintptr_t)mem;

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

assignment to ‘void *’ from ‘long unsigned int’ makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

assignment to ‘void *’ from ‘long unsigned int’ makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Cross build Linux

assignment to ‘void *’ from ‘long unsigned int’ makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (x64)

'=': 'void *' differs in levels of indirection from 'uintptr_t' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (x64)

'=': 'void *' differs in levels of indirection from 'uintptr_t' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'=': 'void *' differs in levels of indirection from 'uintptr_t' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'=': 'void *' differs in levels of indirection from 'uintptr_t' [C:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (arm64)

'=': 'void *' differs in levels of indirection from 'uintptr_t' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (arm64)

'=': 'void *' differs in levels of indirection from 'uintptr_t' [C:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'=': 'void *' differs in levels of indirection from 'uintptr_t' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'=': 'void *' differs in levels of indirection from 'uintptr_t' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

assignment to ‘void *’ from ‘long unsigned int’ makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04-arm)

assignment to ‘void *’ from ‘long unsigned int’ makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

assignment to ‘void *’ from ‘long unsigned int’ makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

assignment to ‘void *’ from ‘long unsigned int’ makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 583 in Python/pystate.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

assignment to ‘void *’ from ‘long unsigned int’ makes pointer from integer without a cast [-Wint-conversion]
return interp;
}

static void
Expand All @@ -587,12 +595,15 @@
PyMem_RawFree(interp->obmalloc);
interp->obmalloc = NULL;
}
PyMem_RawFree(interp);
assert(_Py_IS_ALIGNED(interp, _Alignof(PyInterpreterState)));
PyMem_RawFree((void *)interp->_malloced);
}
}

#ifndef NDEBUG
static inline int check_interpreter_whence(long);
#endif

/* Get the interpreter state to a minimal consistent state.
Further init happens in pylifecycle.c before it can be used.
All fields not initialized here are expected to be zeroed out,
Expand Down
Loading