Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion of ctypes pointers passed to C extension #154

Merged
merged 3 commits into from
Mar 12, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Versioning <https://semver.org/spec/v2.0.0.html>`_.
Unreleased_
-----------

Fixed:

- `Fix conversion of ctypes pointers passed to C extension <../../pull/154>`_

4.5.0_ - 2023-12-04
-------------------

Expand Down
24 changes: 15 additions & 9 deletions softioc/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ static PyObject *db_put_field(PyObject *self, PyObject *args)
{
const char *name;
short dbrType;
void *pbuffer;
PyObject *buffer_ptr;
long length;
if (!PyArg_ParseTuple(args, "shnl", &name, &dbrType, &pbuffer, &length))
if (!PyArg_ParseTuple(args, "shOl", &name, &dbrType, &buffer_ptr, &length))
return NULL;
void *pbuffer = PyLong_AsVoidPtr(buffer_ptr);
if (!pbuffer)
return NULL;

struct dbAddr dbAddr;
Expand All @@ -110,11 +113,11 @@ static PyObject *db_put_field(PyObject *self, PyObject *args)

long put_result;
/* There are two important locks to consider at this point: The Global
* Interpreter Lock (GIL) and the EPICS record lock. A deadlock is possible if
* this thread holds the GIL and wants the record lock (which happens inside
* dbPutField), and there exists another EPICS thread that has the record lock
* and wants to call Python (which requires the GIL).
* This can occur if this code is called as part of an asynchronous on_update
* Interpreter Lock (GIL) and the EPICS record lock. A deadlock is possible
* if this thread holds the GIL and wants the record lock (which happens
* inside dbPutField), and there exists another EPICS thread that has the
* record lock and wants to call Python (which requires the GIL). This can
* occur if this code is called as part of an asynchronous on_update
* callback.
* Therefore, we must ensure we relinquish the GIL while we perform this
* EPICS call, to avoid potential deadlocks.
Expand All @@ -133,9 +136,12 @@ static PyObject *db_get_field(PyObject *self, PyObject *args)
{
const char *name;
short dbrType;
void *pbuffer;
PyObject *buffer_ptr;
long length;
if (!PyArg_ParseTuple(args, "shnl", &name, &dbrType, &pbuffer, &length))
if (!PyArg_ParseTuple(args, "shOl", &name, &dbrType, &buffer_ptr, &length))
return NULL;
void *pbuffer = PyLong_AsVoidPtr(buffer_ptr);
if (!pbuffer)
return NULL;

struct dbAddr dbAddr;
Expand Down
Loading