Skip to content

Commit f9960ce

Browse files
committed
Tidy up C extension code layout
1 parent 877a89c commit f9960ce

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

softioc/extension.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include <asDbLib.h>
1616

1717

18+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
19+
/* Field access helper functions. */
20+
1821
/* Reference stealing version of PyDict_SetItemString */
1922
static void set_dict_item_steal(
2023
PyObject *dict, const char *name, PyObject *py_value)
@@ -112,15 +115,15 @@ static PyObject *db_put_field(PyObject *self, PyObject *args)
112115

113116

114117
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
115-
/* IOC PV put logging */
116-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
118+
/* IOC PV put logging */
117119

118120
struct formatted
119121
{
120122
long length;
121123
epicsOldString values[];
122124
};
123125

126+
124127
static struct formatted * FormatValue(struct dbAddr *dbaddr)
125128
{
126129
struct formatted *formatted =
@@ -156,6 +159,7 @@ static struct formatted * FormatValue(struct dbAddr *dbaddr)
156159
return formatted;
157160
}
158161

162+
159163
static void PrintValue(struct formatted *formatted)
160164
{
161165
if (formatted->length == 1)
@@ -172,6 +176,7 @@ static void PrintValue(struct formatted *formatted)
172176
}
173177
}
174178

179+
175180
void EpicsPvPutHook(struct asTrapWriteMessage *pmessage, int after)
176181
{
177182
struct dbChannel *pchan = pmessage->serverSpecific;
@@ -211,6 +216,10 @@ static PyObject *install_pv_logging(PyObject *self, PyObject *args)
211216
Py_RETURN_NONE;
212217
}
213218

219+
220+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
221+
/* Process callback support. */
222+
214223
#define CAPSULE_NAME "ProcessDeviceSupportOut.callback"
215224

216225
static void capsule_destructor(PyObject *obj)
@@ -225,32 +234,31 @@ static PyObject *create_callback_capsule(PyObject *self, PyObject *args)
225234
return PyCapsule_New(callback, CAPSULE_NAME, &capsule_destructor);
226235
}
227236

237+
228238
static PyObject *signal_processing_complete(PyObject *self, PyObject *args)
229239
{
230240
int priority;
231241
dbCommon *record;
232242
PyObject *callback_capsule;
233-
234243
if (!PyArg_ParseTuple(args, "inO", &priority, &record, &callback_capsule))
235-
{
236244
return NULL;
237-
}
238245

239246
if (!PyCapsule_IsValid(callback_capsule, CAPSULE_NAME))
240-
{
241247
return PyErr_Format(
242248
PyExc_TypeError,
243249
"Given object was not a capsule with name \"%s\"",
244250
CAPSULE_NAME);
245-
}
246251

247252
CALLBACK *callback = PyCapsule_GetPointer(callback_capsule, CAPSULE_NAME);
248-
249253
callbackRequestProcessCallback(callback, priority, record);
250254

251255
Py_RETURN_NONE;
252256
}
253257

258+
259+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
260+
/* Initialisation. */
261+
254262
static struct PyMethodDef softioc_methods[] = {
255263
{"get_DBF_values", get_DBF_values, METH_VARARGS,
256264
"Get a map of DBF names to values"},
@@ -262,7 +270,7 @@ static struct PyMethodDef softioc_methods[] = {
262270
"Install caput logging to stdout"},
263271
{"signal_processing_complete", signal_processing_complete, METH_VARARGS,
264272
"Inform EPICS that asynchronous record processing has completed"},
265-
{"create_callback_capsule", create_callback_capsule, METH_VARARGS,
273+
{"create_callback_capsule", create_callback_capsule, METH_VARARGS,
266274
"Create a CALLBACK structure inside a PyCapsule"},
267275
{NULL, NULL, 0, NULL} /* Sentinel */
268276
};
@@ -276,6 +284,7 @@ static struct PyModuleDef softioc_module = {
276284
softioc_methods,
277285
};
278286

287+
279288
PyObject *PyInit__extension(void)
280289
{
281290
return PyModule_Create(&softioc_module);

0 commit comments

Comments
 (0)