12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- from cffi import FFI
- ffibuilder = FFI()
- import pathlib
- this_dir = pathlib.Path().absolute()
- # cdef() expects a single string declaring the C types, functions and
- # globals needed to use the shared object. It must be in valid C syntax.
- ffibuilder.cdef("""
- typedef struct {
- FILE* HdrFile_PS; /* File handle for .JHR file */
- FILE* TxtFile_PS; /* File handle for .JDT file */
- FILE* IdxFile_PS; /* File handle for .JDX file */
- FILE* LrdFile_PS; /* File handle for .JLR file */
- int Errno_I; /* last i/o error */
- int Locked_I; /* is area locked? */
- uint32_t LastUserPos_I; /* last position of lastread record */
- uint32_t LastUserId_I; /* userid for the last read lastread record */
- } s_JamBase;
- int JAM_OpenMB ( char* Basename_PC, s_JamBase** NewArea_PPS );
- int JAM_CloseMB ( s_JamBase* Area_PS );
- """)
- # int JAM_CloseMB ( s_JamBase* Area_PS );
- #
- # """)
- # set_source() gives the name of the python extension module to
- # produce, and some C source code as a string. This C code needs
- # to make the declarated functions, types and globals available,
- # so it is often just the "#include".
- ffibuilder.set_source("_pi_cffi",
- """
- #include "jam.h" // the C header of the library
- """,
- # libraries=['jamlib.a'],
- # library_dirs=[this_dir.as_posix()],
- # extra_link_args=["-Wl,-rpath,."],
- extra_link_args=["jamlib.a"],
- ) # library name, for the linker
- if __name__ == "__main__":
- ffibuilder.compile(verbose=True)
|