ckalloc no longer returns char* in tcl8.6
zeroschism opened this issue · comments
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);
^
fixed by pull #45
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?