Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 " PRINTF_TIME ".", updated_deadline);
reaction_t* reaction = ((self_base_t*)self)->executing_reaction;
if (reaction != NULL) {
reaction->deadline = updated_deadline;
Expand Down
2 changes: 1 addition & 1 deletion lingua-franca-ref.txt
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed to master after the companion merge occurs.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
master
python-update-deadline
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lingua-franca-ref.txt is normally expected to point to master (per docs) so CI/system tests run against a stable lingua-franca revision. Pointing this to a feature branch (python-update-deadline) is likely to break CI once that branch name is unavailable; please revert to master (or a specific commit) before merging unless there’s a longer-term plan to keep this reference valid.

Suggested change
python-update-deadline
master

Copilot uses AI. Check for mistakes.
17 changes: 17 additions & 0 deletions python/include/pythontarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 or NULL if an error occurs.
*/
PyObject* py_update_deadline(PyObject* self, PyObject* args);

/**
* @brief Register a user trace event. Returns an opaque handle for use with
* tracepoint_user_event and tracepoint_user_value.
Expand Down
22 changes: 22 additions & 0 deletions python/lib/pythontarget.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,25 @@ 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
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|d", &py_self, &updated_deadline_in_double)) {
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyArg_ParseTuple(args, "O|d", ...) makes the deadline argument optional; calling update_deadline(self) would silently set the deadline to 0 via the default. If the deadline is required, use a non-optional format (e.g., require the second argument) and raise a TypeError when it’s missing.

Suggested change
if (!PyArg_ParseTuple(args, "O|d", &py_self, &updated_deadline_in_double)) {
if (!PyArg_ParseTuple(args, "Od", &py_self, &updated_deadline_in_double)) {

Copilot uses AI. Check for mistakes.
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;
Comment on lines +247 to +262
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says the deadline is converted to uint64_t, but the implementation uses int64_t/interval_t (and checks against INT64_{MIN,MAX}). Either update the description or align the implementation/type expectations so the API contract is unambiguous (especially for negative values like NEVER).

Copilot uses AI. Check for mistakes.

Comment on lines +245 to 263
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

py_update_deadline is incomplete: it never calls get_lf_self_pointer()/lf_update_deadline(), does not Py_INCREF(Py_None)/return Py_None, and the function body is missing its closing } (it currently falls through into the next comment/function). This will break compilation and the API won’t work as intended.

Copilot uses AI. Check for mistakes.
/**
* Register a user trace event. Returns an opaque handle (as a Python int)
* that must be passed to tracepoint_user_event and tracepoint_user_value.
Expand All @@ -258,6 +277,7 @@ PyObject* py_register_user_trace_event(PyObject* self, PyObject* args) {
if (self_ptr == NULL) {
return NULL;
}
lf_update_deadline(self_ptr, updated_deadline);
size_t len = strlen(description) + 1;
/* Allocate on the reactor's allocation record so it is freed when the reactor is deallocated. */
char* desc_copy = (char*)lf_allocate(len, 1, &((self_base_t*)self_ptr)->allocations);
Expand Down Expand Up @@ -386,6 +406,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"},
{"register_user_trace_event", (PyCFunction)py_register_user_trace_event, METH_VARARGS,
"Register a user trace event; returns a handle for use with tracepoint_user_event and tracepoint_user_value"},
{"tracepoint_user_event", (PyCFunction)py_tracepoint_user_event, METH_VARARGS,
Expand Down
Loading