The Windows implementation of inet_ntop incorrectly omits the `const`
qualifier on the input address. This broke the Windows build, since
Rebirth passes a const-qualified input address, as permitted by POSIX.
Some Windows cross-compilers, such as mingw32, lack a definition of
inet_ntop entirely. For such environments, fall back to inet_ntoa and
disallow building with IPv6.
Rework the formatting and add a Windows-specific test for whether
inet_ntop is available. As inet_ntop is specified by POSIX, assume all
modern non-Windows platforms support it.
x86_64-w64-mingw32-g++ -Wformat handling misparses the std::size_t
format string, causing a spurious error.
common/main/valptridx.tcc: In function 'void untyped_index_mismatch_exception::prepare_report(const char*, unsigned int, const void*, long int, const void*, const void*, char (&)[229], std::size_t)':
common/main/valptridx.tcc:36:182: error: format '%u' expects argument of type 'unsigned int', but argument 7 has type 'std::size_t {aka long long unsigned int}' [-Werror=format=]
This occurs even though the processed text uses %I64u (which is correct
for a `long long unsigned int`), not %u as shown in the error message.
static void prepare_report(const char *const filename, const unsigned lineno, const void *const array_base, const long supplied_index, const void *const expected_pointer, const void *const actual_pointer, char (&buf)[report_buffer_size], const std::size_t array_size)
{
snprintf(buf, sizeof(buf), "%s:%u: " "pointer/index mismatch:" " base=%p size=%" "I64u" " index=%li expected=%p actual=%p", filename, lineno, array_base, array_size, supplied_index, expected_pointer, actual_pointer);
}
In practice, all such sizes will fit in `unsigned int` because they are
the dimension of an array of large structures. Switch all platforms to
use `unsigned long`, which works everywhere and is at least as big as
`unsigned int`. Using `unsigned long` produces the same size as
`std::size_t` on all platforms other than Win64, where `unsigned long`
is only 32 bits due to the strange LLP64 model Microsoft picked.
Commit b32298df5a ("Rewrite powerup cap
code to centralize logic") centralized powerup cap code in the
powerup_cap_state class.
Commit 901a554e96 ("New powerup management
code: Addeed functions and packet type to ...") removed all use of
powerup_cap_state, but left the dead implementation present.
Commit 479f5ed584 ("Fix 'format specifies
type 'unsigned short' but the argument has type 'unsigned char''
warning") switched the already dead (but still compiled) code from %hu
to %hhu to fix a warning on OS X. Although the commit was written by
Chris, it was my suggestion to use %hhu. I neglected to test Windows
before suggesting it, so the change went in even though Windows does not
accept %hhu; this broke the Windows build. Fortunately, the code had
been dead for 11 months when the change was made, so the fix for Windows
is to remove the long dead code.
SConstruct prefers to refer to linker flags for the main executable as
LINKFLAGS, not LDFLAGS. Rename the internal storage to eliminate a
special case in accessing it. Continue to use the environment variable
$LDFLAGS as an initial value, since many tools expect to pass linker
flags through $LDFLAGS.
Visual Studio 2013 support was experimental and never worked due to
missing C++11 support in the compiler and various compiler bugs that
caused it to crash on some of the more complicated files. Microsoft
never issued sufficient patches to get Visual Studio 2013 to compile
Rebirth successfully.
Remove the Visual Studio 2013 files and add files to build Rebirth with
Visual Studio 2017. Visual Studio 2017 support is also experimental and
is also currently broken. Among the known problems:
- Visual Studio 2017's C99 preprocessor support, like those of predecessor versions, is deficient regarding variadic macros, causing it to reject valid constructs with confusing error messages.
common\include\window.h(170): error C2672: 'con_puts_literal': no matching overloaded function found
common\include\window.h(170): error C2780: 'void con_puts_literal(const con_priority,const char (&)[len])': expects 2 arguments - 1 provided
common\include\console.h(44): note: see declaration of 'con_puts_literal'
common\include\window.h(170): error C2664: 'void con_printf(con_priority,const char *,...)': cannot convert argument 1 from 'const char [54]' to 'con_priority'
Visual Studio 2017's preprocessor expanded this line to:
( ((void)(("%s:%u: sending event %s to window of dimensions %dx%d"))), (sizeof("file, line, e, c.cv_bitmap.bm_w, c.cv_bitmap.bm_h") == 1) ? (con_puts_literal(("%s:%u: sending event %s to window of dimensions %dx%d"))) : (con_printf(("%s:%u: sending event %s to window of dimensions %dx%d") ,file, line, e, c.cv_bitmap.bm_w, c.cv_bitmap.bm_h)) );
gcc-5.4.0's preprocessor expanded this line to:
( ((void)(("%s:%u: sending event %s to window of dimensions %dx%d"))), (sizeof("file, line, e, c.cv_bitmap.bm_w, c.cv_bitmap.bm_h") == 1) ? (con_puts_literal(CON_DEBUG ,("%s:%u: sending event %s to window of dimensions %dx%d"))) : (con_printf(CON_DEBUG ,("%s:%u: sending event %s to window of dimensions %dx%d") , file, line, e, c.cv_bitmap.bm_w, c.cv_bitmap.bm_h)) );
Note the absence of the leading "CON_DEBUG," in the Visual Studio
version.
- Visual Studio 2017 sometimes disallows inner classes access to private typedef symbols in the containing class. Both gcc and clang permit this and the standard says this should work. This is shown mixed in as part of the next error.
- Visual Studio 2017's cl.exe crashes processing some files. Including "segment.h" is sufficient to crash cl.exe. Before crashing it prints:
common\include\fwd-valptridx.h(200): error C2833: 'operator integral_type' is not a recognized operator or type
common\include\fwd-valptridx.h(201): note: see reference to class template instantiation 'valptridx<managed_type>::magic_constant<constant>' being compiled
common\include\fwd-valptridx.h(202): note: see reference to class template instantiation 'valptridx<managed_type>' being compiled
common\main\fwd-segment.h(19): note: see reference to class template instantiation 'std::integral_constant<::size_t,9000>' being compiled
common\include\fwd-valptridx.h(200): error C2059: syntax error: 'newline'
common\include\fwd-valptridx.h(200): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
common\main\fwd-segment.h(48): error C2248: 'valptridx<d2x::segment>::specialized_types': cannot access private typedef declared in class 'valptridx<d2x::segment>'
common\include\fwd-valptridx.h(87): note: see declaration of 'valptridx<d2x::segment>::specialized_types'
common\main\fwd-segment.h(46): note: see declaration of 'valptridx<d2x::segment>'
common\main\fwd-segment.h(48): note: see reference to class template instantiation 'valptridx<d2x::segment>::magic_constant<65534>' being compiled
common\main\fwd-segment.h(48): fatal error C1903: unable to recover from previous error(s); stopping compilation
This list is not exhaustive. The project was abandoned upon
encountering a compiler crash suspiciously similar to the one seen when
using Visual Studio 2013 to compile this code. No one should expect
Visual Studio 2017 version 15.0.0+26228.9 to successfully compile
Rebirth, but these files are published in the hope that future patches
fix the problems in Visual Studio 2017.