Skip to content

Commit

Permalink
Solve issues Python 3.13.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Jan 30, 2025
1 parent 3f53257 commit 911e7a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 7 additions & 4 deletions source/loaders/py_loader/source/py_loader_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ int py_class_interface_static_set(klass cls, class_impl impl, struct accessor_ty
(void)cls;

loader_impl_py_class py_class = (loader_impl_py_class)impl;
PyObject *pyobject_class = py_class->cls;
char *attr_name = attribute_name(accessor->data.attr);

if (attr_name == NULL)
Expand All @@ -695,15 +694,15 @@ int py_class_interface_static_set(klass cls, class_impl impl, struct accessor_ty

py_loader_thread_acquire();

PyObject *pyvalue = py_loader_impl_value_to_capi(py_class->impl, value_type_id(v), v);
PyObject *py_value = py_loader_impl_value_to_capi(py_class->impl, value_type_id(v), v);
PyObject *key_py_str = PyUnicode_FromString(attr_name);
int retval = PyObject_GenericSetAttr(pyobject_class, key_py_str, pyvalue);
int result = PyObject_SetAttr(py_class->cls, key_py_str, py_value);

Py_DECREF(key_py_str);

py_loader_thread_release();

return retval;
return result;
}

value py_class_interface_static_invoke(klass cls, class_impl impl, method m, class_args args, size_t argc)
Expand Down Expand Up @@ -2640,7 +2639,11 @@ loader_impl_data py_loader_impl_initialize(loader_impl impl, configuration confi
/* Hook the deallocation of PyCFunction */
py_loader_impl_pycfunction_dealloc = PyCFunction_Type.tp_dealloc;
PyCFunction_Type.tp_dealloc = PyCFunction_dealloc;

/* TODO: This does not work after 3.13, is it really needed for this hook? */
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 13
PyType_Modified(&PyCFunction_Type);
#endif

if (py_loader_impl_initialize_sys_executable(py_impl) != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,24 @@ TEST_F(metacall_python_class_test, DefaultConstructor)
ASSERT_EQ((enum metacall_value_id)METACALL_STRING, (enum metacall_value_id)metacall_value_id(ret_value));
metacall_value_destroy(static_method_args[0]);
metacall_value_destroy(ret_value);

// Get and Set
void *param2 = metacall_class_static_get(myclass, "b");
ASSERT_EQ((enum metacall_value_id)METACALL_LONG, (enum metacall_value_id)metacall_value_id(param2));
ASSERT_EQ((long)44444L, (long)metacall_value_to_long(param2));

metacall_value_destroy(param2);

void *long_value = metacall_value_create_long(5555L);
int retcode = metacall_class_static_set(myclass, "b", long_value);
metacall_value_destroy(long_value);
ASSERT_EQ((int)0, int(retcode));

param2 = metacall_class_static_get(myclass, "b");
ASSERT_EQ((enum metacall_value_id)METACALL_LONG, (enum metacall_value_id)metacall_value_id(param2));
ASSERT_EQ((long)5555L, (long)metacall_value_to_long(param2));

metacall_value_destroy(param2);
}

{
Expand Down

0 comments on commit 911e7a3

Please sign in to comment.