This supports three build modes:
No additional -D options, default legacy mode
-DSUPPORT_DIRECT_MALLOC, magic will use direct calls to libc malloc/free
and will leave in place the symbols now renamed as mallocMagicLegacy()
freeMagicLegacy() and callocMagicLegacy().
-DSUPPORT_DIRECT_MALLOC -DSUPPORT_REMOVE_MALLOC_LEGACY as above but will
remove the three legacy functions from the binary to provide assurance
they can not be used.
The system malloc is thread-safe the legacy magic malloc has a global
deferred free pointer and the mmap() allocate has a free-list that is
not thread-safe making use of free not thread-safe.
This could of course be improved with the use of
atomic_compare_and_exchange operations but for what gain ?
Then there is the additional function call overhead (of the indirection)
and a few tests/branches inserted into a commonly used code paths around
memory allocation, it hides the call site of the malloc/free usage from
the compiler which maybe have special optimization cases.
The existing malloc/free makes static code analysis around memory
allocation more problematic, also use of runtime analysers will operate
better with a fail-fast to bad memory usage.
Example build issue using SunOS Solaris solaris 5.11 11.4.42.111.0 i86pc i386
with gcc version 5.5.0 (GCC).
It turns out the definition is not used by the magic codebase. So only the
macro name is changed by this commit.
This platform also has a definition for FREAD but the MacOS patch can be used
to rename that.
In file included from DBio.c:51:0:
../utils/magic.h:141:0: warning: "FOPEN" redefined
#define FOPEN gzopen
^
In file included from DBio.c:30:0:
/usr/include/sys/file.h:74:0: note: this is the location of the previous definition
#define FOPEN 0xffffffff
^
In file included from DBio.c:51:0:
../utils/magic.h:144:0: warning: "FREAD" redefined
#define FREAD(a,b,c,d) gzread(d,a,b*c)
^
In file included from DBio.c:30:0:
/usr/include/sys/file.h:75:0: note: this is the location of the previous definition
#define FREAD 0x01 /* <sys/aiocb.h> LIO_READ must be identical */
^
This is a low level thing that other lowlevel API (platform shims for
strlen_s() and ctime_r() want to make use of, without any application
global pollution).
Copyright date(s) taken from git blame information for moved lines.
FUN2CD() on a function pointer still raises -Wpedantic warning due to the
officially undefined behaviour as defined by C standards.
So added FUN2CD() and CD2FUN() to at least mark the call-sites to help
with identification and ignoring -Wpedantic based on the source file
context given in the compiler output.
This did not work as expected. Maybe that indicate this should have
a slighlt restructure so the tcl.h definition is always given a chance
to provide type.
Or maybe autoconf should detect the type and provide in config.h ?
Now a (void *) but previously an integer.
These macros resolve the codebase allowing it to be built against both
tcl8 (8.5, 8.6) and tcl9 (9.0).
tar -zxvf tcl9.0.0-src.tar.gz
cd tcl9.0.0/unix
./configure --enable-symbols --prefix=/opt/tktcl9
make install
tar -zxvf tk9.0.0-src.tar.gz
cd tk9.0.0/unix
./configure --enable-symbols --prefix=/opt/tktcl9 --with-tcl=/opt/tktcl9/lib
make install
cd magic
./configure --with-tk=/opt/tktcl9/lib --with-tcl=/opt/tktcl9/lib
Example build issue using MacOS 12 (Xcode 14.2 from MacOSX.platform).
In file included from grTk1.c:23:
In file included from ../utils/main.h:26:
In file included from ../windows/windows.h:26:
../utils/magic.h:143:13: warning: 'FREAD' macro redefined [-Wmacro-redefined]
#define FREAD(a,b,c,d) gzread(d,a,b*c)
^
/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/fcntl.h:110:9: note: previous definition is here
#define FREAD 0x00000001
It is usual for a pointer to require the largest width, while some
platforms might have an 'int' that is smaller than a pointer width.
This reverses the detection order to find.
Note since C99 there is <stdint.h> with type 'intmax_t' which
serves a similar purpose.
SonarCloud reports a concern with this on many lines where used.
"An integral type is too small to hold a pointer value."
https://sonarcloud.io/project/issues?open=AZJB17ZoNGfDNup0RkY_&id=dlmiles_magic
supported). Fixed the long-standing issue in which DRC does not
get stopped by the "drc off" command (the behavior for interrupting
the DRC was dependent on the DRC being turned on, and the "drc off"
command was turning it off before breaking, causing the interrupt
to be ignored).