-
Notifications
You must be signed in to change notification settings - Fork 9
CFFI
The CFFI Layer is the innermost wrapper in PyMEOS architecture, and it is generated by the CFFI Library.
It is located inside the pymeos_cffi
package, and the files used to build it are the following:
-
builder/meos.h
C header file that is going to be wrapped by CFFI. It is a slightly modified version of themeos.h
file provided by the MEOS Library, and contains some extra type/functions definitions needed in PyMEOS that are defined inliblwgeom.h
or other parts of MEOS. -
builder/build_header.py
Generates the modifiedmeos.h
header file mention right above. It takes the header file provided by the MEOS Library and adds the extra definitions needed. -
builder/build_helpers.py
Contains the additional definitions needed for the C Header file -
builder/build_pymeos.py
Reads the modified C Header file and wraps it with using the CFFI library to create a C Extension Module that can be imported from python.
If the MEOS library has an API update (e.g. addition, modification or deletion of a function/type), the custom header file has to be updated before generating the wrapper. To do so, run the build_header.py
script from the pymeos_cffi
directory:
foo@bar:~/PyMEOS/pymeos_cffi$ python3 ./pymeos_cffi/builder/build_header.py <path-to-header-file>
For easier copying:
python3 ./pymeos_cffi/builder/build_header.py <path-to-header-file>
If the path to the header file it's not provided, it defaults to /usr/local/include/meos.h
Before building the extension module, make sure these extra header files are available in the same location as the meos.h
header file provided by MEOS:
- postgis_revision.h
- postgis_config.h
- lwinline.h
- liblwgeom.h (an include has to be modified from
#include "../postgis_config.h"
to#include "postgis_config.h"
These file are available in the MEOS source code after running CMake.
To do this easily, you can run the following script:
copy_headers() {
p="$1"
sudo cp "$p/postgis/postgis_revision.h" /usr/local/include/
sudo cp "$p/postgis/postgis_config.h" /usr/local/include/
sudo cp "$p/postgis/liblwgeom/lwinline.h" /usr/local/include/
sudo cp "$p/postgis/liblwgeom/liblwgeom.h" /usr/local/include/
sudo sed -i 's/\.\.\/postgis/postgis/' /usr/local/include/liblwgeom.h
}
copy_headers <path-to-meos-source-code>
To test that the wrapper generation works properly before going on with the next wrapper layer (CFFI Wrapper), you can generate with it by running the build_pymeos.py
script from the pymeos_cffi
directory:
foo@bar:~/PyMEOS/pymeos_cffi$ python3 ./pymeos_cffi/builder/build_pymeos.py
For easier copying:
python3 ./pymeos_cffi/builder/build_pymeos.py
If it was successful, three files should have been generated in the current folder:
-
_meos_cffi.c
: Containing all the C code generated by CFFI -
_meos_cffi.o
: Resulting from the compilation of the previous file -
_meos_cffi.**.(so|dll|dylib)
: Shared library that can be loaded in python to call MEOS functions (the name and extension will vary depending on the system)