Skip to content

Commit

Permalink
improve NetBSD-specific code
Browse files Browse the repository at this point in the history
NetBSD doesn't put packages in /usr/local like /CMakeLists.txt thought.
The `#ifdef __NetBSD__` around iconv was actually breaking compilation
on NetBSD when using the system libiconv (there's also a GNU iconv
package)
A C program included from C++ source broke on NetBSD specifically, work
around it.

This doesn't fix compilation on NetBSD, which is currently broken, but
is closer to correct.
  • Loading branch information
guijan committed May 3, 2024
1 parent 5817be7 commit f3fd452
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ endif()
# All commands and submodule commands also need to see these
# changes, so just setting them in the project scope via
# include_directories and link_directories is not sufficient
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD|NetBSD")
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr/local")
set(CMAKE_REQUIRED_INCLUDES "/usr/local/include")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
Expand Down
8 changes: 0 additions & 8 deletions Source/Core/Common/StringUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
constexpr u32 CODEPAGE_SHIFT_JIS = 932;
constexpr u32 CODEPAGE_WINDOWS_1252 = 1252;
#else
#if defined(__NetBSD__)
#define LIBICONV_PLUG
#endif
#include <errno.h>
#include <iconv.h>
#include <locale.h>
Expand Down Expand Up @@ -528,13 +525,8 @@ std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_v
while (src_bytes != 0)
{
size_t const iconv_result =
#if defined(__NetBSD__)
iconv(conv_desc, reinterpret_cast<const char**>(&src_buffer), &src_bytes, &dst_buffer,
&dst_bytes);
#else
iconv(conv_desc, const_cast<char**>(reinterpret_cast<const char**>(&src_buffer)),
&src_bytes, &dst_buffer, &dst_bytes);
#endif
if ((size_t)-1 == iconv_result)
{
if (EILSEQ == errno || EINVAL == errno)
Expand Down
10 changes: 10 additions & 0 deletions Source/Core/Core/PowerPC/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
#include <string_view>
#include <utility>

// https://github.com/zserge/expr/ is a C program and sorta valid C++.
// When included in a C++ program, it's treated as a C++ code, and it may cause
// issues: <cmath> may already be included, if so, including <math.h> may
// not do anything. <math.h> is obligated to put its functions in the global
// namespace, while <cmath> may or may not. The C code we're interpreting as
// C++ won't call functions by their qualified names. The code may work anyway
// if <cmath> puts its functions in the global namespace, or if the functions
// are actually macros that expand inline, both of which are common.
// NetBSD 10.0 i386 is an exception, and we need `using` there.
using std::isnan; using std::isinf;
#include <expr.h>

#include "Common/BitUtils.h"
Expand Down

0 comments on commit f3fd452

Please sign in to comment.