[fpc-pascal] Re: Automatically exporting C++ API using SWIG??

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Thu Aug 1 15:51:00 CEST 2013

Sven Barth wrote:

>>> We have three windows platforms with MSVC and I don't know how many
>>> platforms where GCC or LLVM is the main compiler. I'm not going for
>>> popularity here, just for the majority of platforms.
>> Looking at the options
>> 1 use swig architecture to parse the C++ source code/headers and extract
>> Pascal bindings - either by a rewrite or adapting the current effort
>> 2 accommodate (and maintain) various compiler idiosyncracies
>> from a distance... I'd say option 1 would be the easiest and best
>> maintainable?
>> - SWIG already provides infrastructure to parse the source files
>> - People using Delphi would probably also be interested in
>> fixing/patching bugs
>> - On top of the previous point: changes in C/C++ standards/formats would
>> not be our concern so much because those will be dealt with by the wider
>> SWIG community
>> - Of course, if swig is ever extended to support more languages, we get
>> that for free
>> Of course I understand it's very attractive to have everything in house
>> and native in FPC, but I suspect the effort needed to develop/maintain
>> it may outweigh that...
> Important point for variant 2: less overhead. Using swig you first 
> flatten the API and then unflatten it again into Object Pascal classes. 
> For callbacks you have also wrappers (which are hidden from you). In 
> case of cppclass you don't have all this, because code will be called 
> directly.

However, I'm reminded of the flurry of activity when SCADA malware was 
found in the wild a couple of years ago: it was decided fairly early 
that it had probably been compiled with MS tools, but inspection of the 
calling convention suggested that it was non-standard and it took a lot 
of head scratching before people decided which compiler/linker and what 
pragmata had been used.

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

More information about the fpc-pascal mailing list