From b10478268c1363a44b23005bb46e846e4f388268 Mon Sep 17 00:00:00 2001 From: Matt Page Date: Tue, 17 Sep 2024 15:32:59 -0700 Subject: [PATCH] Fix warnings on windows --- Include/cpython/code.h | 2 +- Include/internal/pycore_code.h | 4 +++- Objects/codeobject.c | 11 ++++++----- Python/ceval.c | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Include/cpython/code.h b/Include/cpython/code.h index 0b354c38b2c398..741bc062a846ae 100644 --- a/Include/cpython/code.h +++ b/Include/cpython/code.h @@ -77,7 +77,7 @@ typedef struct { */ typedef struct { Py_ssize_t size; - char *entries[]; + char *entries[1]; } _PyCodeArray; #define _PyCode_DEF_THREAD_LOCAL_BYTECODE() \ diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h index 2df170e2b25ab9..5514991d29fa5d 100644 --- a/Include/internal/pycore_code.h +++ b/Include/internal/pycore_code.h @@ -653,7 +653,9 @@ extern _Py_CODEUNIT *_PyCode_GetTLBC(PyCodeObject *co); // Reserve an index for the current thread into thread-local bytecode // arrays -extern int _Py_ReserveTLBCIndex(PyInterpreterState *interp); +// +// Returns the reserved index or -1 on error. +extern Py_ssize_t _Py_ReserveTLBCIndex(PyInterpreterState *interp); // Release the current thread's index into thread-local bytecode arrays extern void _Py_ClearTLBCIndex(_PyThreadStateImpl *tstate); diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 82f8ce1f1d250f..2b051e221489eb 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -2700,7 +2700,7 @@ _PyCode_Fini(PyInterpreterState *interp) // interpreter and instrumentation use atomics, with specialization taking care // not to overwrite an instruction that was instrumented concurrently. -int +Py_ssize_t _Py_ReserveTLBCIndex(PyInterpreterState *interp) { return _PyIndexPool_AllocIndex(&interp->tlbc_indices); @@ -2716,8 +2716,8 @@ _Py_ClearTLBCIndex(_PyThreadStateImpl *tstate) static _PyCodeArray * _PyCodeArray_New(Py_ssize_t size) { - _PyCodeArray *arr = - PyMem_Calloc(1, sizeof(_PyCodeArray) + sizeof(void *) * size); + _PyCodeArray *arr = PyMem_Calloc( + 1, offsetof(_PyCodeArray, entries) + sizeof(void *) * size); if (arr == NULL) { PyErr_NoMemory(); return NULL; @@ -2729,8 +2729,9 @@ _PyCodeArray_New(Py_ssize_t size) static void copy_code(_Py_CODEUNIT *dst, PyCodeObject *co) { - int code_len = Py_SIZE(co); - for (int i = 0; i < code_len; i += _PyInstruction_GetLength(co, i)) { + Py_ssize_t code_len = Py_SIZE(co); + for (Py_ssize_t i = 0; i < code_len; + i += _PyInstruction_GetLength(co, i)) { dst[i] = _Py_GetBaseCodeUnit(co, i); } _PyCode_Quicken(dst, code_len); diff --git a/Python/ceval.c b/Python/ceval.c index b9495b5312b4de..469dfee07ca601 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -816,7 +816,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int goto error; } if (frame->bytecode != bytecode) { - int off = frame->instr_ptr - frame->bytecode; + ptrdiff_t off = frame->instr_ptr - frame->bytecode; frame->bytecode = bytecode; frame->instr_ptr = frame->bytecode + off; }