MantisBT - Doomseeker
View Issue Details
0003905Doomseeker[All Projects] Cleanuppublic2021-09-24 15:402021-09-28 23:29
WubTheCaptain 
 
lowminorhave not tried
confirmedopen 
1.3.2 
 
0003905: zandronumbinaries.cpp OS-dependent macro hell is quite ugly (and broken)
This macro hell was too cumbersome to read for me:
Quote from src/plugins/zandronum/zandronumbinaries.cpp
#ifdef Q_OS_WIN32
#define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "windows.zip"
#define ZANDRONUM_BINARY_NAME "zandronum.exe"
#define SCRIPT_FILE_EXTENSION ".bat"
#else

#ifndef __x86_64__
#define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86.tar.bz2"
#else
#define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86_64.tar.bz2"
#endif

#ifndef Q_OS_DARWIN
#define ZANDRONUM_BINARY_NAME "zandronum"
#else
#define ZANDRONUM_BINARY_NAME "Zandronum.app"
#define ZANDRONUM_APP_BUNDLE_BIN "/Contents/MacOS/zandronum"
#endif
#define SCRIPT_FILE_EXTENSION ".sh"
#endif

The first Q_OS_WIN32 seems fine. Then the latter confused me.

I forgot it's not possible to re-define a macro without undefining it first in C++. This initially led me to believe 64-bit Windows would download GNU/Linux binaries, and use a binary named zandronum instead of zandronum.exe.
After copying the code to my text editor and adding spaces, I figured the first Q_OS_WIN32 block doesn't even end in #endif and changed my understanding of the code entirely.

With spaces and newlines, the above code is the same as:
#ifdef Q_OS_WIN32
    #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "windows.zip"
    #define ZANDRONUM_BINARY_NAME "zandronum.exe"
    #define SCRIPT_FILE_EXTENSION ".bat"
#else
    #ifndef __x86_64__
        #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86.tar.bz2"
    #else
        #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86_64.tar.bz2"
    #endif

    #ifndef Q_OS_DARWIN
        #define ZANDRONUM_BINARY_NAME "zandronum"
    #else
        #define ZANDRONUM_BINARY_NAME "Zandronum.app"
        #define ZANDRONUM_APP_BUNDLE_BIN "/Contents/MacOS/zandronum"
    #endif

    #define SCRIPT_FILE_EXTENSION ".sh"
#endif

Suddenly more understandable (thanks, spaces!), yet still ugly (and broken in some ways).

Other issues here, some which may be seperate issues:
  • __x86_64__ probably isn't portable. Qt handily has Q_PROCESSOR_X86_64 (at compile-time), which I found to be slightly more portable (and not mostly specific to GCC).
  • Anything non-Windows (except Q_OS_DARWIN, which has a special case later) will still download GNU/Linux binaries (because of the current state of the Zandronum downloads web directory). Hello OpenBSD.
  • Zandronum 3.1 (210919-1948) switched its downloadable 64-bit binary distribution filenames to linux-x64.tgz.
  • Q_OS_DARWIN includes iOS and stuff, so perhaps Q_OS_MACOS would be more appropriate (based on the comment).
  • I understand the current state allows the user to configure the exact file for Zandronum stable binaries, yet testing binaries allow the user to configure the testing directory (where we've hard-coded Zandronum testing binary filenames for scripts to be created). I would sort of like this split abstraction to cease existing for code maintainability to reduce the amount of preprocessor macros and inflexibility, although it would likely mean losing support for multiple testing versions of Zandronum without user configuration. (I have thought of alternative solutions to the problem: symlinks or a "firefox.real" approach taken by Debian.)
src/plugins/zandronumq/zandronumqbinaries.cpp does not have the __x64_64__ macro, no support for GNU/Linux with that plugin I assume.
No tags attached.
related to 0003906confirmed  Doomseeker on OpenBSD may download Zandronum's GNU/Linux testing binaries 
related to 0003908acknowledged  zandronumbinaries.cpp does not make sure the downloaded Zandronum testing binaries are supported by the CPU architecture 
Issue History
2021-09-24 15:40WubTheCaptainNew Issue
2021-09-24 15:46WubTheCaptainNote Added: 0021761
2021-09-24 15:59WubTheCaptainNote Added: 0021762
2021-09-24 15:59WubTheCaptainNote Edited: 0021762bug_revision_view_page.php?rev_id=13353
2021-09-24 16:00WubTheCaptainNote Deleted: 0021762
2021-09-24 16:28WubTheCaptainNote Added: 0021765
2021-09-24 16:28WubTheCaptainRelationship addedrelated to 0003906
2021-09-24 17:12WubTheCaptainNote Added: 0021769
2021-09-24 17:12WubTheCaptainNote Edited: 0021769bug_revision_view_page.php?bugnote_id=21769#r13362
2021-09-24 17:14WubTheCaptainNote Edited: 0021769bug_revision_view_page.php?bugnote_id=21769#r13363
2021-09-24 17:35WubTheCaptainNote Added: 0021772
2021-09-24 17:35WubTheCaptainNote Deleted: 0021772
2021-09-24 17:36WubTheCaptainRelationship addedrelated to 0003908
2021-09-24 17:54WubTheCaptainNote Edited: 0021761bug_revision_view_page.php?bugnote_id=21761#r13370
2021-09-24 18:06WubTheCaptainDescription Updatedbug_revision_view_page.php?rev_id=13372#r13372
2021-09-28 23:29Pol MNote Added: 0021779
2021-09-28 23:29Pol MStatusnew => confirmed

Notes
(0021761)
WubTheCaptain   
2021-09-24 15:46   
(edited on: 2021-09-24 17:54)
Nevermind I did not do the "if Windows" / "if not Windows" split here, for each OS the first part could look like:

#ifdef Q_OS_LINUX
    #ifndef Q_PROCESSOR_X86_64
        #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86.tar.bz2"
    #else
        #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "linux-x86_64.tar.bz2"
    #endif

    #define ZANDRONUM_BINARY_NAME "zandronum"
    #define SCRIPT_FILE_EXTENSION ".sh"
#endif

#ifdef Q_OS_MACOS
    #define ZANDRONUM_BINARY_NAME "Zandronum.app"
    #define ZANDRONUM_APP_BUNDLE_BIN "/Contents/MacOS/zandronum"
    #define SCRIPT_FILE_EXTENSION ".sh"
#endif

#ifdef Q_OS_WIN32
    #ifndef Q_OS_WIN64
        #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "windows.zip"
    #else
        #define TESTING_BINARY_URL TESTING_BINARY_URL_BASE "windows-x64.7z"
    #endif

    #define ZANDRONUM_BINARY_NAME "zandronum.exe"
    #define SCRIPT_FILE_EXTENSION ".bat"
#endif


It's not as concise and duplicates SCRIPT_FILE_EXTENSION once (can be macroed again to "if Windows" / "if not Windows"), but it's immediately mostly sensible.

(0021765)
WubTheCaptain   
2021-09-24 16:28   
Quote from WubTheCaptain
  • Anything non-Windows (except Q_OS_DARWIN, which has a special case later) will still download GNU/Linux binaries (because of the current state of the Zandronum downloads web directory). Hello OpenBSD.

This is also issue 0003906.
(0021769)
WubTheCaptain   
2021-09-24 17:12   
(edited on: 2021-09-24 17:14)
Quote from WubTheCaptain
  • __x86_64__ probably isn't portable. Qt handily has Q_PROCESSOR_X86_64 (at compile-time), which I found to be slightly more portable (and not mostly specific to GCC).

I had deleted my earlier note here, but the imprecision also implied in OP and incorrectly in the above example is that GNU/Linux on non-x86 processors (e.g. ARM) will still download the x86 binaries, instead of refusing.

(0021779)
Pol M   
2021-09-28 23:29   
All the points are logical and make sense, seems good to me