This is an automated email from the ASF dual-hosted git repository.
jdanek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
The following commit(s) were added to refs/heads/main by this push:
new 906b931 DISPATCH-2270 Use PyLong_FromVoidPtr to reliably pass void*
values into Python regardless of platform type sizes (#1409)
906b931 is described below
commit 906b9314fc5e1d4f3286cc7de81a97cd18c56198
Author: Jiri Daněk <[email protected]>
AuthorDate: Sat Nov 20 23:11:00 2021 +0100
DISPATCH-2270 Use PyLong_FromVoidPtr to reliably pass void* values into
Python regardless of platform type sizes (#1409)
---
src/dispatch.c | 8 +++-----
src/entity_cache.c | 2 +-
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/dispatch.c b/src/dispatch.c
index a219183..b042379 100644
--- a/src/dispatch.c
+++ b/src/dispatch.c
@@ -116,10 +116,6 @@ qd_dispatch_t *qd_dispatch(const char *python_pkgdir, bool
test_hooks)
return qd;
}
-
-// We pass pointers as longs via the python interface, make sure this is safe.
-STATIC_ASSERT(sizeof(long) >= sizeof(void*), pointer_is_bigger_than_long);
-
qd_error_t qd_dispatch_load_config(qd_dispatch_t *qd, const char *config_path)
{
// `dlopen(NULL, ...)` opens the current executable; qdrouterd used to
dlopen libqpid-dispatch.so here before
@@ -131,7 +127,9 @@ qd_error_t qd_dispatch_load_config(qd_dispatch_t *qd, const
char *config_path)
PyObject *module =
PyImport_ImportModule("qpid_dispatch_internal.management.config");
PyObject *configure_dispatch = module ? PyObject_GetAttrString(module,
"configure_dispatch") : NULL;
Py_XDECREF(module);
- PyObject *result = configure_dispatch ?
PyObject_CallFunction(configure_dispatch, "(lls)", (long)qd, qd->dl_handle,
config_path) : NULL;
+ PyObject *result = configure_dispatch ?
PyObject_CallFunction(configure_dispatch, "(NNs)", PyLong_FromVoidPtr(qd),
+
PyLong_FromVoidPtr(qd->dl_handle), config_path)
+ : NULL;
Py_XDECREF(configure_dispatch);
if (!result) qd_error_py();
Py_XDECREF(result);
diff --git a/src/entity_cache.c b/src/entity_cache.c
index 41c4435..48e2fdb 100644
--- a/src/entity_cache.c
+++ b/src/entity_cache.c
@@ -89,7 +89,7 @@ qd_error_t qd_entity_refresh_begin(PyObject *list) {
sys_mutex_lock(event_lock);
entity_event_t *event = DEQ_HEAD(event_list);
while (event) {
- PyObject *tuple = Py_BuildValue("(isl)", (int)event->action,
event->type, (long)event->object);
+ PyObject *tuple = Py_BuildValue("(isN)", (int)event->action,
event->type, PyLong_FromVoidPtr(event->object));
if (!tuple) { qd_error_py(); break; }
int err = PyList_Append(list, tuple);
Py_DECREF(tuple);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]