flightaware / speedtables

Speed tables is a high-performance memory-resident database. The speed table compiler reads a table definition and generates a set of C access routines to create, manipulate and search tables containing millions of rows. Currently oriented towards Tcl.
https://flightaware.github.io/speedtables/
BSD 3-Clause "New" or "Revised" License
65 stars 15 forks source link

ckalloc no longer returns char* in tcl8.6 #44

Closed zeroschism closed 9 years ago

zeroschism commented 9 years ago

when trying to build a ctable on freebsd 10.1-RELEASE with the latest tcl8.6.3, I get make errors related to conversion from void* to char* when using ckalloc. My guess is that a number of things changed in 8.6 that will need to be accounted for.

From a similar bug in VTK (http://www.paraview.org/Bug/view.php?id=13449):

In tcl8.6:

 # define ckalloc(x) \ 
    ((VOID *) Tcl_Alloc((unsigned)(x))

while tcl8.5 had

 # define ckalloc(x) Tcl_Alloc(x)

Example error output:

In file included from stobj/include/ctable.h:38:0,
                 from stobj/birdseye/birdseye-1.0.cpp:27:
stobj/include/shared.c: In function 'shm_t* map_file(const char*, char*, size_t, int, int)':
stobj/include/shared.c:159:17: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
     p->filename = ckalloc(strlen(file)+1);
                 ^
stobj/include/shared.c: In function 'int doCreateOrAttach(Tcl_Interp*, const char*, const char*, size_t, int, shm_t**)':
stobj/include/shared.c:783:21: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
         share->name = ckalloc(strlen(sharename)+1);
                     ^
In file included from stobj/birdseye/birdseye-1.0.cpp:88:0:
stobj/include/ctable_io.c: In function 'int ctable_quoteString(const char**, int*, int, const char*)':
stobj/include/ctable_io.c:53:17: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
          newptr = ckalloc(maxExpansion * length + 1);
                 ^
In file included from stobj/include/ctable_search.c:22:0,
                 from stobj/birdseye/birdseye-1.0.cpp:89:
stobj/include/speedtableHash.c: In function 'ctable_HashEntry* ctable_InitOrStoreHashEntry(ctable_HashTable*, const char*, ctable_HashEntry*, int, int*)':
stobj/include/speedtableHash.c:181:19: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
         hPtr->key = ckalloc (strlen (key) + 1);
                   ^
bovine commented 9 years ago

fixed by pull #45

gahr commented 9 years ago

IMHO, this fix is not the right approach. These are C files, so the cast is not needed per se. But they are included by .cpp files (either directly or via headers) and therefore end up in a C++ translation unit, so even the c-style cast is discouraged. Well, malloc and free are discouraged in C++ anyway.

Why not take this opportunity to finally make these files first class C++ citizens by converting the remaining C-isms?