Skip to content
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

[Python 3.11] Fix Segfault #304

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion lingua-franca-ref.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
single-threaded
master
2 changes: 1 addition & 1 deletion python/lib/modal_models/impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ PyObject* convert_C_mode_to_py(
) {
// Create the mode struct in Python
mode_capsule_struct_t* cap =
(mode_capsule_struct_t*)PyObject_GC_New(mode_capsule_struct_t, &mode_capsule_t);
(mode_capsule_struct_t*)PyObject_New(mode_capsule_struct_t, &mode_capsule_t);
if (cap == NULL) {
lf_print_error_and_exit("Failed to convert mode.");
}
Expand Down
2 changes: 1 addition & 1 deletion python/lib/python_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ PyTypeObject PyTagType = {
* @return PyObject* The tag in Python.
*/
py_tag_t* convert_C_tag_to_py(tag_t c_tag) {
py_tag_t* py_tag = PyObject_GC_New(py_tag_t, &PyTagType);
py_tag_t* py_tag = PyObject_New(py_tag_t, &PyTagType);
if (py_tag == NULL) {
lf_print_error_and_exit("Failed to convert tag from C to Python.");
}
Expand Down
15 changes: 12 additions & 3 deletions python/lib/pythontarget.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void destroy_action_capsule(PyObject* capsule) {
PyObject* convert_C_port_to_py(void* port, int width) {
// Create the port struct in Python
PyObject* cap =
(PyObject*)PyObject_GC_New(generic_port_capsule_struct, &py_port_capsule_t);
(PyObject*)PyObject_New(generic_port_capsule_struct, &py_port_capsule_t);
if (cap == NULL) {
lf_print_error_and_exit("Failed to convert port.");
}
Expand Down Expand Up @@ -506,7 +506,7 @@ PyObject* convert_C_action_to_py(void* action) {
trigger_t* trigger = ((lf_action_base_t*)action)->trigger;

// Create the action struct in Python
PyObject* cap = (PyObject*)PyObject_GC_New(generic_action_capsule_struct, &py_action_capsule_t);
PyObject* cap = (PyObject*)PyObject_New(generic_action_capsule_struct, &py_action_capsule_t);
if (cap == NULL) {
lf_print_error_and_exit("Failed to convert action.");
}
Expand Down Expand Up @@ -597,7 +597,16 @@ get_python_function(string module, string class, int instance_id, string func) {

mbstowcs(wcwd, cwd, PATH_MAX);

Py_SetPath(wcwd);
// Deprecated: Py_SetPath(wcwd)
// Set Python's sys.path
PyObject* sys_path, * path;
sys_path = PySys_GetObject("path");
// New reference
path = PyUnicode_FromWideChar(wcwd, wcslen(wcwd));
if (sys_path != NULL && path != NULL) {
PyList_Insert(sys_path, 0, path);
}
Py_XDECREF(path);

LF_PRINT_DEBUG("Loading module %s in %s.", module, cwd);

Expand Down