Skip to content

Commit

Permalink
Merge 96693a0 into 7ba6073
Browse files Browse the repository at this point in the history
  • Loading branch information
rtobar committed Apr 13, 2022
2 parents 7ba6073 + 96693a0 commit fc4e031
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ matrix:
env: NO_DLG_RUNTIME=1
- python: "3.8"
env: NO_DLG_TRANSLATOR=1
- python: "3.9"
# NOTE: The OpenAPI code still needs to be removed
# - python: "3.8"
# env: TEST_OPENAPI=1
Expand Down
55 changes: 40 additions & 15 deletions daliuge-engine/test/apps/dynlib_example2.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ unsigned long usecs(struct timeval *start, struct timeval *end)

PyObject* build_error(PyObject* exception_type, const char* message)
{
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyObject *exception = PyObject_CallFunctionObjArgs(exception_type, PyUnicode_FromString(message), NULL);
PyGILState_Release(gstate);
return exception;
return PyObject_CallFunctionObjArgs(exception_type, PyUnicode_FromString(message), NULL);
}

PyObject* init2(dlg_app_info *app, PyObject* pyObject)
Expand All @@ -71,10 +67,16 @@ PyObject* init2(dlg_app_info *app, PyObject* pyObject)
unsigned int sleep_seconds = 0;
PyObject *key;
PyObject *value;
PyObject *error;
Py_ssize_t pos = 0;

PyGILState_STATE gstate;
gstate = PyGILState_Ensure();

if (!PyDict_Check(pyObject)) {
return build_error(PyExc_TypeError, "pyObject should be dictionary");
error = build_error(PyExc_TypeError, "pyObject should be dictionary");
PyGILState_Release(gstate);
return error;
}

while (PyDict_Next(pyObject, &pos, &key, &value)) {
Expand Down Expand Up @@ -104,7 +106,9 @@ PyObject* init2(dlg_app_info *app, PyObject* pyObject)
}
#endif
else {
return build_error(PyExc_TypeError, "print_stats should be a Boolean or Int");
error = build_error(PyExc_TypeError, "print_stats should be a Boolean or Int");
PyGILState_Release(gstate);
return error;
}
}

Expand All @@ -121,7 +125,9 @@ PyObject* init2(dlg_app_info *app, PyObject* pyObject)
}
#endif
else {
return build_error(PyExc_TypeError, "crash_and_burn should be a Boolean or Int");
error = build_error(PyExc_TypeError, "crash_and_burn should be a Boolean or Int");
PyGILState_Release(gstate);
return error;
}
}

Expand All @@ -135,7 +141,9 @@ PyObject* init2(dlg_app_info *app, PyObject* pyObject)
}
#endif
else {
return build_error(PyExc_TypeError, "bufsize should be an Int");
error = build_error(PyExc_TypeError, "bufsize should be an Int");
PyGILState_Release(gstate);
return error;
}
}

Expand All @@ -149,26 +157,35 @@ PyObject* init2(dlg_app_info *app, PyObject* pyObject)
}
#endif
else {
return build_error(PyExc_TypeError, "sleep_seconds should be an Int");
error = build_error(PyExc_TypeError, "sleep_seconds should be an Int");
PyGILState_Release(gstate);
return error;
}
}
Py_DECREF(s);
}
else {
return build_error(PyExc_TypeError, "One of the keys was not a string");
error = build_error(PyExc_TypeError, "One of the keys was not a string");
PyGILState_Release(gstate);
return error;
}
}

app->data = malloc(sizeof(struct app_data));
if (!app->data) {
return build_error(PyExc_MemoryError, "Allocating space for the app_data");
error = build_error(PyExc_MemoryError, "Allocating space for the app_data");
PyGILState_Release(gstate);
return error;
}
to_app_data(app)->print_stats = print_stats;
to_app_data(app)->crash_and_burn = crash_and_burn;
to_app_data(app)->sleep_seconds = sleep_seconds;
to_app_data(app)->total = 0;
to_app_data(app)->write_duration = 0;
to_app_data(app)->bufsize = bufsize;
return PyLong_FromLong(0);
PyObject *result = PyLong_FromLong(0);
PyGILState_Release(gstate);
return result;
}

void data_written(dlg_app_info *app, const char *uid, const char *data, size_t n)
Expand Down Expand Up @@ -225,7 +242,11 @@ PyObject* run2(dlg_app_info *app)
buf = (char *)malloc(bufsize);
if (!buf) {
fprintf(stderr, "Couldn't allocate memory for read/write buffer\n");
return build_error(PyExc_MemoryError, "Couldn't allocate memory for read/write buffer");
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyObject *error = build_error(PyExc_MemoryError, "Couldn't allocate memory for read/write buffer");
PyGILState_Release(gstate);
return error;
}

for (i = 0; i < app->n_inputs; i++) {
Expand Down Expand Up @@ -261,5 +282,9 @@ PyObject* run2(dlg_app_info *app)
printf("Copied %.3f [MB] of data at %.3f [MB/s]\n", total_mb, total_mb / duration);
}

return PyLong_FromLong(0);
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyObject *result = PyLong_FromLong(0);
PyGILState_Release(gstate);
return result;
}

0 comments on commit fc4e031

Please sign in to comment.