-
Notifications
You must be signed in to change notification settings - Fork 9
Fix infinite loop when setting record's own value from on_update callback #202
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
Open
AlexanderWells-diamond
wants to merge
1
commit into
master
Choose a base branch
from
reimplement_db_put_field
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+227
−21
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,16 +93,17 @@ static PyObject *get_field_offsets(PyObject *self, PyObject *args) | |
| } | ||
|
|
||
|
|
||
| /* Updates PV field with integrated db lookup. Safer to do this in C as we need | ||
| * an intermediate copy of the dbAddr structure, which changes size between | ||
| * EPICS releases. */ | ||
| static PyObject *db_put_field(PyObject *self, PyObject *args) | ||
| /* This is our own re-implementation of EPICS's dbPutField function. | ||
| We do this to allow us to control when dbProcess is called. We use the | ||
| same logicical flow as the original function. */ | ||
| static PyObject *db_put_field_process(PyObject *self, PyObject *args) | ||
| { | ||
| const char *name; | ||
| short dbrType; | ||
| PyObject *buffer_ptr; | ||
| long length; | ||
| if (!PyArg_ParseTuple(args, "shOl", &name, &dbrType, &buffer_ptr, &length)) | ||
| short process; | ||
| if (!PyArg_ParseTuple(args, "shOlh", &name, &dbrType, &buffer_ptr, &length, &process)) | ||
| return NULL; | ||
| void *pbuffer = PyLong_AsVoidPtr(buffer_ptr); | ||
| if (!pbuffer) | ||
|
|
@@ -113,6 +114,8 @@ static PyObject *db_put_field(PyObject *self, PyObject *args) | |
| return PyErr_Format( | ||
| PyExc_RuntimeError, "dbNameToAddr failed for %s", name); | ||
|
|
||
| struct dbCommon *precord = dbAddr.precord; | ||
|
|
||
| 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 | ||
|
|
@@ -125,7 +128,22 @@ static PyObject *db_put_field(PyObject *self, PyObject *args) | |
| * EPICS call, to avoid potential deadlocks. | ||
| * See https://github.com/DiamondLightSource/pythonSoftIOC/issues/119. */ | ||
| Py_BEGIN_ALLOW_THREADS | ||
| put_result = dbPutField(&dbAddr, dbrType, pbuffer, length); | ||
| dbScanLock(precord); | ||
| put_result = dbPut(&dbAddr, dbrType, pbuffer, length); | ||
|
|
||
| if (put_result == 0 && process) | ||
| { | ||
| if (precord->pact) | ||
| { | ||
| precord->rpro = TRUE; | ||
| } | ||
| else | ||
| { | ||
| dbProcess(precord); | ||
| } | ||
| } | ||
|
Comment on lines
+135
to
+144
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be consistent with the rest of the code and drop the unnecessary braces here. I'll let you keep the outer pair: if (put_result == 0 && process)
{
if (precord->pact)
precord->rpro = TRUE;
else
dbProcess(precord);
} |
||
|
|
||
| dbScanUnlock(precord); | ||
| Py_END_ALLOW_THREADS | ||
| if (put_result) | ||
| return PyErr_Format( | ||
|
|
@@ -314,7 +332,7 @@ static struct PyMethodDef softioc_methods[] = { | |
| "Get a map of DBF names to values"}, | ||
| {"get_field_offsets", get_field_offsets, METH_VARARGS, | ||
| "Get offset, size and type for each record field"}, | ||
| {"db_put_field", db_put_field, METH_VARARGS, | ||
| {"db_put_field_process", db_put_field_process, METH_VARARGS, | ||
| "Put a database field to a value"}, | ||
| {"db_get_field", db_get_field, METH_VARARGS, | ||
| "Get a database field's value"}, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting style appears to have changed...
Put the leading
*characters back to match the rest of the file.