← Back to team overview

kicad-developers team mailing list archive

Re: strtok_r not detected properly

 

On 03/12/2014 12:01 PM, Tomasz Wlostowski wrote:
> On 03/12/2014 05:57 PM, Dick Hollenbeck wrote:
>> On 03/12/2014 11:28 AM, David Novak wrote:
>>> When building Pcbnew, I get an error message indicating that strtok_r is
>>> being redefined. The offending code is in kicad_string.h.
>>>
>>> #ifndef HAVE_STRTOKR
>>> // common/strtok_r.c optionally:
>>> extern "C" char* strtok_r( char* str, const char* delim, char** nextp );
>>> #endif
>>>
>>> I tracked HAVE_STRTOKR to an auto detection inside
>>> PerformFeatureChecks.cmake.
>>>
>>> check_symbol_exists( strtok_r "string.h" HAVE_STRTOKR )
>>>
>>> Fore some reason, this check is failing even though strtok_r is defined.
>>> Presumably, the check is looking in the wrong file. I tried adjusting
>>> this line, but without success.
>>>
>>> As a quick fix I added
>>>
>>> #define HAVE_STRTOKR
>>>
>>> just prior to the check in kicad_string.h.
>>>
>>> I'm on Windows using TDM-GCC 4.8.1-3.
>>>
>>> What is the correct check_symbol_exists() line to fix this problem?
>>
>>
>> We concluded there's an edit needed in one of your TDC-GCC compiler headers.
> 
> Hi Dick,
> 
> Wouldn't it be a better idea to simply replace strtok_r (used only in 
> legacy_plugin.cpp AFAIK) and have a UTF8 or std::string token splitting 
> function, that is more in line with object oriented languages like C++?
> 
> Cheers,
> Tom
> 



strtok_r() is POSIX.  It belongs in <strings.h>.  It is a well defined function that is
expected to be cross platform.  And we pay for its memory in libc on all platforms but
Windows.  It's already in RAM in the libc*.so

What bug would we be fixing, what enhancement would be adding?

At some point you simply delete the LEGACY_PLUGIN, because the KICAD plugin supersedes it.
 Say 4 years from now.


strtok_r() is fast and it works.  It would be difficult to match its speed.  I wouldn't
advocate its use elsewhere, but this is a lot of talk about a bug introduced by someone
with 5 minutes of software experience into the TDM header.

We need to put blame where it belongs.

Besides, the version I brought into the project for Windows is public domain, the guy with
5 minutes experience can easily add that version to the TDM compiler and then honor the
posix behaviour.  Somebody just needs to send it to him.






Follow ups

References