Python Forum
interfacing C with Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
interfacing C with Python
#2
I'm not an expert in interfacing Python and C but I think the default API already works the way you described above. Extension modules use Python-aware C functions that get arguments in the form Python works with and parse them with the C macro PyArg_ParseTuple. When they return Python values they use the macro Py_BuildValue to create them. The problem with this API is that it forces you to write a lot of hybrid code, take care of reference counts, etc, so it is a slow process.

Before you jump into this, it would be a good idea to review existing tools that already interface Python and C as it is an old problem and many solutions have been developped, starting with the ctypes module, the Cython language, the Swig module. In my bookmarks, there are 3 modern modules that try to minimize the amount of boilerplate code and could be worth exploring, cffi, cppyy and pybind11.
Reply


Messages In This Thread
interfacing C with Python - by Skaperen - Aug-09-2021, 12:25 AM
RE: interfacing C with Python - by Gribouillis - Aug-09-2021, 08:50 AM
RE: interfacing C with Python - by Skaperen - Aug-10-2021, 12:52 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020