Skip to content

Commit 3399605

Browse files
committed
fix: resolve 32-bit pointer truncation warnings on armv7l/i686
dispatcher.c: add missing #include <sys/time.h> in POSIX branch so struct timeval is defined on musl/Alpine (glibc pulls it in transitively but musl does not), fixing compilation of try_daemon_cli on armv7l musllinux. atomic_ops.c: replace long long buffer_addr with uintptr_t (stdint.h) for all three ops on both MSVC and GCC/Clang paths. uintptr_t is pointer-width on every target — 32-bit on armv7l/i686, 64-bit elsewhere — eliminating the -Wint-to-pointer-cast warnings that fire when casting a 64-bit integer to a 32-bit pointer. PyArg_ParseTuple format updated from "L" to "k" for the address argument to match; expected/desired remain "L"/long long as they are values, not addresses.
1 parent eaf4660 commit 3399605

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

src/omnipkg/dispatcher.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ static void winsock_init(void) {
189189
# include <dlfcn.h>
190190
# include <fcntl.h>
191191
# include <glob.h>
192+
# include <sys/time.h> /* struct timeval */
192193
# define PATH_SEPARATOR ":"
193194
# define sock_read(s,b,n) read(s,b,n)
194195
# define sock_write(s,b,n) write(s,b,n)

src/omnipkg/isolation/atomic_ops.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <Python.h>
2+
#include <stdint.h> /* uintptr_t — pointer-sized integer, safe on 32-bit and 64-bit */
23

34
#ifdef _MSC_VER
45
#include <intrin.h>
@@ -7,22 +8,24 @@
78
#pragma intrinsic(_InterlockedExchange64)
89

910
static PyObject* atomic_cas64(PyObject* self, PyObject* args) {
10-
long long buffer_addr, expected, desired;
11-
if (!PyArg_ParseTuple(args, "LLL", &buffer_addr, &expected, &desired)) return NULL;
11+
uintptr_t buffer_addr;
12+
long long expected, desired;
13+
if (!PyArg_ParseTuple(args, "kLL", &buffer_addr, &expected, &desired)) return NULL;
1214
volatile long long* ptr = (volatile long long*)buffer_addr;
1315
long long prev = _InterlockedCompareExchange64(ptr, desired, expected);
1416
return PyBool_FromLong(prev == expected);
1517
}
1618
static PyObject* atomic_store64(PyObject* self, PyObject* args) {
17-
long long buffer_addr, value;
18-
if (!PyArg_ParseTuple(args, "LL", &buffer_addr, &value)) return NULL;
19+
uintptr_t buffer_addr;
20+
long long value;
21+
if (!PyArg_ParseTuple(args, "kL", &buffer_addr, &value)) return NULL;
1922
volatile long long* ptr = (volatile long long*)buffer_addr;
2023
_InterlockedExchange64(ptr, value);
2124
Py_RETURN_NONE;
2225
}
2326
static PyObject* atomic_load64(PyObject* self, PyObject* args) {
24-
long long buffer_addr;
25-
if (!PyArg_ParseTuple(args, "L", &buffer_addr)) return NULL;
27+
uintptr_t buffer_addr;
28+
if (!PyArg_ParseTuple(args, "k", &buffer_addr)) return NULL;
2629
volatile long long* ptr = (volatile long long*)buffer_addr;
2730
long long val = _InterlockedExchangeAdd64((volatile long long*)ptr, 0);
2831
return PyLong_FromLongLong(val);
@@ -31,22 +34,24 @@ static PyObject* atomic_load64(PyObject* self, PyObject* args) {
3134
#else
3235
/* GCC/Clang path */
3336
static PyObject* atomic_cas64(PyObject* self, PyObject* args) {
34-
long long buffer_addr, expected, desired;
35-
if (!PyArg_ParseTuple(args, "LLL", &buffer_addr, &expected, &desired)) return NULL;
37+
uintptr_t buffer_addr;
38+
long long expected, desired;
39+
if (!PyArg_ParseTuple(args, "kLL", &buffer_addr, &expected, &desired)) return NULL;
3640
volatile long long* ptr = (volatile long long*)buffer_addr;
3741
int success = __sync_bool_compare_and_swap(ptr, expected, desired);
3842
return PyBool_FromLong(success);
3943
}
4044
static PyObject* atomic_store64(PyObject* self, PyObject* args) {
41-
long long buffer_addr, value;
42-
if (!PyArg_ParseTuple(args, "LL", &buffer_addr, &value)) return NULL;
45+
uintptr_t buffer_addr;
46+
long long value;
47+
if (!PyArg_ParseTuple(args, "kL", &buffer_addr, &value)) return NULL;
4348
volatile long long* ptr = (volatile long long*)buffer_addr;
4449
__atomic_store_n(ptr, value, __ATOMIC_RELEASE);
4550
Py_RETURN_NONE;
4651
}
4752
static PyObject* atomic_load64(PyObject* self, PyObject* args) {
48-
long long buffer_addr;
49-
if (!PyArg_ParseTuple(args, "L", &buffer_addr)) return NULL;
53+
uintptr_t buffer_addr;
54+
if (!PyArg_ParseTuple(args, "k", &buffer_addr)) return NULL;
5055
volatile long long* ptr = (volatile long long*)buffer_addr;
5156
long long val = __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
5257
return PyLong_FromLongLong(val);
@@ -64,4 +69,4 @@ static struct PyModuleDef atomicmodule = {
6469
};
6570
PyMODINIT_FUNC PyInit_omnipkg_atomic(void) {
6671
return PyModule_Create(&atomicmodule);
67-
}
72+
}

0 commit comments

Comments
 (0)