aardappel / treesheets

TreeSheets : Free Form Data Organizer (see strlen.com/treesheets)
zlib License
2.49k stars 184 forks source link

lobster/tools.h: avoid conflicting define for ssize_t #671

Closed barracuda156 closed 3 weeks ago

barracuda156 commented 3 weeks ago

@aardappel As I understand, this should be inconsequential where redefining works? On macOS it may not, since there is a conflicting definition in string.h: https://github.com/phracker/MacOSX-SDKs/blob/041600eda65c6a668f66cb7d56b7d1da3e8bcc93/MacOSX10.6.sdk/usr/include/string.h#L70

P. S. If this is not inconsequential for other OS, we can make a fix conditional on Apple.

barracuda156 commented 3 weeks ago

The error without the patch looks like this:

[ 36%] Building CXX object CMakeFiles/lobster.dir/lobster/src/disasm.cpp.o
/opt/local/bin/g++-mp-13 -DWXUSINGDLL -D_FILE_OFFSET_BITS=64 -D__WXGTK__ -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/include -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src -I/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/external/libtcc -isystem /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxGTK/3.0-cxx11/lib/wx/include/gtk3-unicode-3.0 -isystem /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxGTK/3.0-cxx11/include/wx-3.0 -pipe -Os -DNDEBUG -I/opt/local/include -I/opt/local/libexec/dispatch/usr/include -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++17 -arch ppc -mmacosx-version-min=10.6 -MD -MT CMakeFiles/lobster.dir/lobster/src/disasm.cpp.o -MF CMakeFiles/lobster.dir/lobster/src/disasm.cpp.o.d -o CMakeFiles/lobster.dir/lobster/src/disasm.cpp.o -c /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src/disasm.cpp
In file included from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src/lobster/stdafx.h:80,
                 from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src/compiler.cpp:17:
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src/lobster/tools.h:30:19: error: conflicting declaration 'typedef ptrdiff_t ssize_t'
   30 | typedef ptrdiff_t ssize_t;
      |                   ^~~~~~~
In file included from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src/lobster/stdafx.h:34:
/usr/include/string.h:70:33: note: previous declaration as 'typedef __darwin_ssize_t ssize_t'
   70 | typedef __darwin_ssize_t        ssize_t;
      |                                 ^~~~~~~
In file included from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src/lobster/stdafx.h:80,
                 from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src/builtins.cpp:15:
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src/lobster/tools.h:30:19: error: conflicting declaration 'typedef ptrdiff_t ssize_t'
   30 | typedef ptrdiff_t ssize_t;
      |                   ^~~~~~~
In file included from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_editors_treesheets/treesheets/work/treesheets-3989467383/lobster/src/lobster/stdafx.h:34:
/usr/include/string.h:70:33: note: previous declaration as 'typedef __darwin_ssize_t ssize_t'
   70 | typedef __darwin_ssize_t        ssize_t;
      |                                 ^~~~~~~
make[2]: *** [CMakeFiles/lobster.dir/lobster/src/builtins.cpp.o] Error 1

It happens with every version tried including the latest tag.

aardappel commented 3 weeks ago

I'm fine with your fix, that seems generally useful.

Looking at the definition in the mac header, it is guarded by #if !defined(_POSIX_C_SOURCE), meaning they are aware that introducing ssize_t there is not strictly posix compliant. So another fix could be to just #define _POSIX_C_SOURCE 1 (in stdafx.h before includes).

That said your current fix is simpler and protects against other places introducing ssize_t so probably better.

aardappel commented 3 weeks ago

https://stackoverflow.com/questions/48460942/how-and-when-should-i-use-posix-c-source-in-c-programs

aardappel commented 3 weeks ago

The typedef needs to be outside of the #ifdef.

barracuda156 commented 3 weeks ago

So another fix could be to just #define _POSIX_C_SOURCE 1 (in stdafx.h before includes).

That may break other things on macOS, it is generally unsafe and hardly ever used, AFAIK.

The typedef needs to be outside of the #ifdef.

Thanks, I will move it out then.

barracuda156 commented 3 weeks ago

@aardappel I have moved typedef out of the ifdef macro now.