[fpc-pascal] How can a project determine if it's using cmem?
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Wed Jul 4 11:32:03 CEST 2012
When building a shared library, I'm putting a (function that returns a)
magic number into both the library and the calling program. This returns
an integer, and allows the program and library to check their exposed
APIs without risk.
How can code in the library test whether it is using cmem, so that it
can tell the caller that it's safe to call functions that move strings
and objects around? It's obviously trivial to rely on a compile-time
conditional, but can this be done in a way that doesn't rely on this?
If I define USE_CMEM in the project and then in the main unit have
uses
{$ifdef USE_CMEM }
cmem, {$ifdef USE_HEAPTRC } HeapTrc, {$endif } ...
{$endif }
then this always errors
{$if not defined(cmem) }
{$error Not using cmem }
{$endif }
and this fails to compile saying the . is illegal
{$if not defined(cmem.malloc) }
{$error Not using cmem }
{$endif }
--
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