From b36044b796ae5affc6a7c4c2bb7988b8e7036824 Mon Sep 17 00:00:00 2001 From: Byeonggil Jun Date: Thu, 5 Feb 2026 12:54:20 -0700 Subject: [PATCH 1/7] Add function `update_deadline` in Python target --- lib/schedule.c | 1 + python/include/pythontarget.h | 17 +++++++++++++++++ python/lib/pythontarget.c | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/lib/schedule.c b/lib/schedule.c index 9c37213de..e7e78b9f7 100644 --- a/lib/schedule.c +++ b/lib/schedule.c @@ -91,6 +91,7 @@ bool lf_check_deadline(void* self, bool invoke_deadline_handler) { } void lf_update_deadline(void* self, interval_t updated_deadline) { + LF_PRINT_DEBUG("lf_update_deadline: update deadline to %lld.", updated_deadline); reaction_t* reaction = ((self_base_t*)self)->executing_reaction; if (reaction != NULL) { reaction->deadline = updated_deadline; diff --git a/python/include/pythontarget.h b/python/include/pythontarget.h index 8afd744a9..e8475b9ca 100644 --- a/python/include/pythontarget.h +++ b/python/include/pythontarget.h @@ -102,6 +102,23 @@ PyObject* py_package_directory(PyObject* self, PyObject* args); */ PyObject* py_check_deadline(PyObject* self, PyObject* args); +/** + * @brief Update the deadline of the currently executing reaction. + * + * Updating the deadline with this function does not affect + * the deadline check that has been performed (at the beginning + * of the caller reaction or check_deadline called before). + * Therefore, you need to invoke check_deadline after + * update the deadline through this function to confirm + * whether the newly updated deadline has been violated. + * + * @param self The Python object of the reactor. + * @param args contains: + * - updated_deadline: The updated deadline. + * @return Py_None + */ +PyObject* py_update_deadline(PyObject* self, PyObject* args); + ////////////////////////////////////////////////////////////// ///////////// Main function callable from Python code diff --git a/python/lib/pythontarget.c b/python/lib/pythontarget.c index 2787d9088..7a3e25a2e 100644 --- a/python/lib/pythontarget.c +++ b/python/lib/pythontarget.c @@ -240,6 +240,21 @@ PyObject* py_check_deadline(PyObject* self, PyObject* args) { return PyBool_FromLong(result); } +PyObject* py_update_deadline(PyObject* self, PyObject* args) { + PyObject* py_self; + int64_t updated_deadline = 0; // Default to 0 + + if (!PyArg_ParseTuple(args, "O|L", &py_self, &updated_deadline)) { + return NULL; + } + void* self_ptr = get_lf_self_pointer(py_self); + if (self_ptr == NULL) { + return NULL; + } + lf_update_deadline(self_ptr, updated_deadline); + return Py_None; +} + ////////////////////////////////////////////////////////////// ///////////// Main function callable from Python code @@ -293,6 +308,8 @@ static PyMethodDef GEN_NAME(MODULE_NAME, _methods)[] = { {"package_directory", py_package_directory, METH_NOARGS, "Root package directory path"}, {"check_deadline", (PyCFunction)py_check_deadline, METH_VARARGS, "Check whether the deadline of the currently executing reaction has passed"}, + {"update_deadline", (PyCFunction)py_update_deadline, METH_VARARGS, + "Update the deadline of the currently executing reaction"}, {NULL, NULL, 0, NULL}}; /** From 7955c34623472d3ac89e17bedd0a30845274977c Mon Sep 17 00:00:00 2001 From: Byeonggil Jun Date: Thu, 5 Feb 2026 13:02:40 -0700 Subject: [PATCH 2/7] Minor update --- lib/schedule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/schedule.c b/lib/schedule.c index e7e78b9f7..c8aa6fb06 100644 --- a/lib/schedule.c +++ b/lib/schedule.c @@ -91,7 +91,7 @@ bool lf_check_deadline(void* self, bool invoke_deadline_handler) { } void lf_update_deadline(void* self, interval_t updated_deadline) { - LF_PRINT_DEBUG("lf_update_deadline: update deadline to %lld.", updated_deadline); + LF_PRINT_DEBUG("lf_update_deadline: update deadline to %ld.", updated_deadline); reaction_t* reaction = ((self_base_t*)self)->executing_reaction; if (reaction != NULL) { reaction->deadline = updated_deadline; From 96c53bfc6b98249f0367ed20ee335c9b877e059a Mon Sep 17 00:00:00 2001 From: Byeonggil Jun Date: Thu, 5 Feb 2026 13:08:50 -0700 Subject: [PATCH 3/7] Apply formatter --- python/include/pythontarget.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/include/pythontarget.h b/python/include/pythontarget.h index e8475b9ca..47ae981c7 100644 --- a/python/include/pythontarget.h +++ b/python/include/pythontarget.h @@ -105,11 +105,11 @@ PyObject* py_check_deadline(PyObject* self, PyObject* args); /** * @brief Update the deadline of the currently executing reaction. * - * Updating the deadline with this function does not affect + * Updating the deadline with this function does not affect * the deadline check that has been performed (at the beginning * of the caller reaction or check_deadline called before). - * Therefore, you need to invoke check_deadline after - * update the deadline through this function to confirm + * Therefore, you need to invoke check_deadline after + * update the deadline through this function to confirm * whether the newly updated deadline has been violated. * * @param self The Python object of the reactor. From 6efb7a8125b207304ef4bab9fed5e4f5017383a6 Mon Sep 17 00:00:00 2001 From: Byeonggil Jun Date: Thu, 5 Feb 2026 13:14:28 -0700 Subject: [PATCH 4/7] Point to python-update-deadline branch (Revert me) --- lingua-franca-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index 1f7391f92..01d44e951 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -master +python-update-deadline From 3e9e32a14916cd1aad0ec15cf1af0938ce58ee7e Mon Sep 17 00:00:00 2001 From: Byeonggil Jun Date: Thu, 5 Feb 2026 15:12:59 -0700 Subject: [PATCH 5/7] Minor fix --- lib/schedule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/schedule.c b/lib/schedule.c index c8aa6fb06..dde40cc62 100644 --- a/lib/schedule.c +++ b/lib/schedule.c @@ -91,7 +91,7 @@ bool lf_check_deadline(void* self, bool invoke_deadline_handler) { } void lf_update_deadline(void* self, interval_t updated_deadline) { - LF_PRINT_DEBUG("lf_update_deadline: update deadline to %ld.", updated_deadline); + LF_PRINT_DEBUG("lf_update_deadline: update deadline to " PRINTF_TIME ".", updated_deadline); reaction_t* reaction = ((self_base_t*)self)->executing_reaction; if (reaction != NULL) { reaction->deadline = updated_deadline; From 841dbcdc6c1b57c91ac7495a74e0e4040b574478 Mon Sep 17 00:00:00 2001 From: Byeonggil Jun Date: Thu, 5 Feb 2026 16:52:12 -0700 Subject: [PATCH 6/7] Enable handling floating-point deadline values --- python/lib/pythontarget.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/python/lib/pythontarget.c b/python/lib/pythontarget.c index 7a3e25a2e..236a4f4ca 100644 --- a/python/lib/pythontarget.c +++ b/python/lib/pythontarget.c @@ -243,10 +243,22 @@ PyObject* py_check_deadline(PyObject* self, PyObject* args) { PyObject* py_update_deadline(PyObject* self, PyObject* args) { PyObject* py_self; int64_t updated_deadline = 0; // Default to 0 + double updated_deadline_in_double = + 0.0; // Deadline may be passed as a floating-point value in nanoseconds, e.g., SEC(0.5) → 0.5 * 1e9. - if (!PyArg_ParseTuple(args, "O|L", &py_self, &updated_deadline)) { + if (!PyArg_ParseTuple(args, "O|d", &py_self, &updated_deadline_in_double)) { return NULL; } + + // Check overflow before converting a double to int64_t (interval_t). + if (updated_deadline_in_double > (double)INT64_MAX || updated_deadline_in_double < (double)INT64_MIN) { + PyErr_SetString(PyExc_OverflowError, "The updated deadline value is out of int64 range"); + return NULL; + } + + // Convert double to int64_t + updated_deadline = (int64_t)updated_deadline_in_double; + void* self_ptr = get_lf_self_pointer(py_self); if (self_ptr == NULL) { return NULL; From 3f9182b0a371086a15b4061f140ef703ecce079b Mon Sep 17 00:00:00 2001 From: Byeonggil Jun <78055940+byeonggiljun@users.noreply.github.com> Date: Fri, 27 Mar 2026 15:25:12 -0700 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Edward A. Lee --- python/include/pythontarget.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/include/pythontarget.h b/python/include/pythontarget.h index 47ae981c7..dd1da1ce5 100644 --- a/python/include/pythontarget.h +++ b/python/include/pythontarget.h @@ -108,14 +108,14 @@ PyObject* py_check_deadline(PyObject* self, PyObject* args); * Updating the deadline with this function does not affect * the deadline check that has been performed (at the beginning * of the caller reaction or check_deadline called before). - * Therefore, you need to invoke check_deadline after - * update the deadline through this function to confirm + * Therefore, you may want to invoke check_deadline after + * updating the deadline through this function to confirm * whether the newly updated deadline has been violated. * * @param self The Python object of the reactor. * @param args contains: * - updated_deadline: The updated deadline. - * @return Py_None + * @return Py_None or NULL if an error occurs. */ PyObject* py_update_deadline(PyObject* self, PyObject* args);