I have some Python code that uses a library that implements virtual file systems. For the drivers for those virtual file systems to work a bunch of C functions (like readdir(), opendir(), fseek()) need to be overridden/replaced - with the replacements defined in a .so/.cpp file. Usually this could be done by setting LD_PRELOAD to that .so file. However, I need to be able to override these functions at runtime, and ideally revert back to the non-overridden functions once the Python functions that use those overridden functions have executed. Is this possible?
Asked
Active
Viewed 757 times
1 Answers
2
I am guessing you want ctypes. Here is a discussion: https://docs.python.org/2/library/ctypes.html

jim mcnamara
- 16,005
- 2
- 34
- 51
-
This looks very promising, thank you. I'll mark it as the answer once I figure out how to make the functions in the os module in Python use the library I imported using ctypes! – false_azure Nov 20 '14 at 00:56
-
Usually these kinds of things are coded in C or C++. And linked into a shared library. – jim mcnamara Nov 20 '14 at 00:59
-
That makes sense, but I need to work with an existing Python code base. I have a .cpp/.so file with all the redefinitions that the Python os functions should use, which is part of a C++ library that has Python wrappers. – false_azure Nov 20 '14 at 01:02