PyS2OPC does not compile on some platforms
Description
Compilation warnings such as:
-
pycparser.plyparser.ParseError: src/ClientServer/frontend/pys2opc/s2opc_headers.h:42:18: before: SOPC_StatusCode
-
pycparser.plyparser.ParseError: /usr/include/arm-linux-gnueabihf/bits/types.h:47:1: before: __extension__
-
cffi.FFIError: :32: unsupported expression: expected a simple numeric constant
may arise when building PyS2OPC on some platform/architectures that differ from linux/x86_64.
Analysis
The first two errors are due to the inclusion of <stdint.h>
(with or without defining __extension__
beforehand) by pycffi which may somehow change how pycffi sees standard types such as uint32_t
(hence the error on typedef uint32_t SOPC_StatusCode
.
The latter is due to the fact that some enums in S2OPC use the INT32_MAX
constant to force their size,
but pycffi does not know this constant, nor is able to tell where the error happened.
This leads to the following:
- we should not include
<stdint.h>
(or include files that include it) when using pycffi, - however we should include it so that
zINTxx_yy
constants are defined.
Proposed solution
- split "expansion time" (when produces
s2opc_expanded.h
used inffi.cdef()
to define S2OPC types) and "compilation time" (when pycffi calls gcc to compile the_pys2opc.c
it generated) so thatzINTxx_yy
constants are not redefined when including the real<stdint.h>
, - prevent
sopc_xxx_cffi.h
headers from including<stdint.h>
.
The latter could be done by manually copying headers such as sopc_buffer.h
which depends on <stdint.h>
.
A simpler solution is to define _STDINT_H
so that <stdint.h>
is not included.
This solution is known to be less robust, as it depends on private members, but it should require less maintenance overall.