diff --git a/.github/workflows/haiku-test.yml b/.github/workflows/haiku-test.yml new file mode 100644 index 0000000000..fecca5c98b --- /dev/null +++ b/.github/workflows/haiku-test.yml @@ -0,0 +1,61 @@ +name: Haiku Test + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + - develop + tags: + - v*.*.* + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Haiku Test + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + build: [debug, relwithdebinfo, release] + arch: [x86-64] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run Haiku VM + uses: cross-platform-actions/action@v1.2.0 + with: + operating_system: haiku + version: r1beta5 + architecture: ${{ matrix.arch }} + shell: sh + run: | + mkdir -p /boot/home/config/settings/system/debug_server + printf 'default_action report\n' > /boot/home/config/settings/system/debug_server/settings + + sh ./tools/metacall-environment.sh base + + mkdir -p build && cd build + sh ../tools/metacall-configure.sh ${{ matrix.build }} scripts tests + + sh ../tools/metacall-build.sh ${{ matrix.build }} + + echo "===== HAIKU DESKTOP FILES =====" + ctest -j2 --timeout 120 --output-on-failure -C ${{ matrix.build }} || res=$? + ls -la /boot/home/Desktop/ 2>/dev/null || true + + echo "===== HAIKU CRASH REPORTS =====" + cat /boot/home/Desktop/*report* 2>/dev/null || true + + echo "===== HAIKU SYSLOG TAIL =====" + tail -n 200 /boot/system/var/log/syslog 2>/dev/null || true + + exit ${res:-0} diff --git a/cmake/CompileOptions.cmake b/cmake/CompileOptions.cmake index 3aec5ac4bf..dde8741310 100644 --- a/cmake/CompileOptions.cmake +++ b/cmake/CompileOptions.cmake @@ -381,7 +381,7 @@ if(WIN32 AND MSVC) endif() -if (PROJECT_OS_FAMILY MATCHES "unix" OR PROJECT_OS_FAMILY MATCHES "macos") +if (PROJECT_OS_FAMILY MATCHES "unix" OR PROJECT_OS_FAMILY MATCHES "macos" OR PROJECT_OS_FAMILY MATCHES "beos") if(PROJECT_OS_FAMILY MATCHES "macos") # We cannot enable "stack-protector-strong" On OS X due to a bug in clang compiler (current version 7.0.2) diff --git a/cmake/Portability.cmake b/cmake/Portability.cmake index d7861dfcb9..8df7437a6e 100644 --- a/cmake/Portability.cmake +++ b/cmake/Portability.cmake @@ -79,18 +79,6 @@ if(PROJECT_OS_HAIKU) set(PROJECT_OS_NAME "Haiku") set(PROJECT_OS_FAMILY beos) add_compile_definitions(__HAIKU__) - - # Workaround to enable Haiku with export headers - # This can be removed once export headers support Haiku - if(PROJECT_OS_HAIKU) - # As the function is already patched, repatch it again - function(_GENERATE_EXPORT_HEADER) - set(WIN32 1) - # When the function is redefined, the old function can be accessed through underscore - __GENERATE_EXPORT_HEADER(${ARGN}) - unset(WIN32) - endfunction() - endif() endif() # Check Windows diff --git a/source/dynlink/CMakeLists.txt b/source/dynlink/CMakeLists.txt index 8a9d6aed61..e8171db4a0 100644 --- a/source/dynlink/CMakeLists.txt +++ b/source/dynlink/CMakeLists.txt @@ -39,8 +39,12 @@ set(generated_source_path "${CMAKE_CURRENT_BINARY_DIR}/source") if(APPLE AND PROJECT_OS_VERSION GREATER 8) # From macOS 10.5 (version 9), dlopen compatible library is available set(DYNLINK_IMPL_INTERFACE_NAME unix) +elseif(PROJECT_OS_HAIKU) + # Haiku can use dlopen although it's BeOS family + set(DYNLINK_IMPL_INTERFACE_NAME haiku) else() set(DYNLINK_IMPL_INTERFACE_NAME ${PROJECT_OS_FAMILY}) + endif() set(headers diff --git a/source/dynlink/include/dynlink/dynlink_impl_haiku.h b/source/dynlink/include/dynlink/dynlink_impl_haiku.h new file mode 100644 index 0000000000..77484b29cc --- /dev/null +++ b/source/dynlink/include/dynlink/dynlink_impl_haiku.h @@ -0,0 +1,55 @@ +/* + * Dynamic Link Library by Parra Studios + * A library for dynamic loading and linking shared objects at run-time. + * + * Copyright (C) 2016 - 2026 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef DYNLINK_IMPL_HAIKU_H +#define DYNLINK_IMPL_HAIKU_H 1 + +/* -- Headers -- */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* -- Forward declarations -- */ + +struct dynlink_impl_interface_type; + +/* -- Type definitions -- */ + +typedef struct dynlink_impl_interface_type *dynlink_impl_interface; + +/* -- Methods -- */ + +/** +* @brief +* Haiku image add-on object implementation singleton +* +* @return +* A pointer to the Haiku image add-on object implementation singleton +*/ +DYNLINK_API dynlink_impl_interface dynlink_impl_interface_singleton(void); + +#ifdef __cplusplus +} +#endif + +#endif /* DYNLINK_IMPL_HAIKU_H */ diff --git a/source/dynlink/source/dynlink_impl_haiku.c b/source/dynlink/source/dynlink_impl_haiku.c new file mode 100644 index 0000000000..ad4f4e178b --- /dev/null +++ b/source/dynlink/source/dynlink_impl_haiku.c @@ -0,0 +1,171 @@ +/* + * Dynamic Link Library by Parra Studios + * A library for dynamic loading and linking shared objects at run-time. + * + * Copyright (C) 2016 - 2026 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#if defined(__HAIKU__) + +/* -- Headers -- */ + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +/* -- Methods -- */ + +const char *dynlink_impl_interface_prefix_haiku(void) +{ + static const char prefix_haiku[] = "lib"; + + return prefix_haiku; +} + +const char *dynlink_impl_interface_extension_haiku(void) +{ + static const char extension_haiku[] = "so"; + + return extension_haiku; +} + +dynlink_impl dynlink_impl_interface_load_haiku(dynlink handle) +{ + dynlink_flags flags = dynlink_get_flags(handle); + image_id impl = 0; + + if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_SELF)) + { + int mode; + void *self_impl; + + DYNLINK_FLAGS_SET(mode, 0); + + if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_NOW)) + { + DYNLINK_FLAGS_ADD(mode, RTLD_NOW); + } + + if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_LAZY)) + { + DYNLINK_FLAGS_ADD(mode, RTLD_LAZY); + } + + if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_LOCAL)) + { + DYNLINK_FLAGS_ADD(mode, RTLD_LOCAL); + } + + if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_GLOBAL)) + { + DYNLINK_FLAGS_ADD(mode, RTLD_GLOBAL); + } + + self_impl = dlopen(NULL, mode); + + if (self_impl == NULL) + { + log_write("metacall", LOG_LEVEL_ERROR, "DynLink error: %s", dlerror()); + return NULL; + } + + return self_impl; + } + + impl = load_add_on(dynlink_get_path(handle)); + + if (impl < B_NO_ERROR) + { + log_write("metacall", LOG_LEVEL_ERROR, "DynLink error: failed to load BeOS/Haiku image add-on with error code %d", (int)impl); + return NULL; + } + + return (dynlink_impl)(intptr_t)impl; +} + +int dynlink_impl_interface_symbol_haiku(dynlink handle, dynlink_impl impl, const char *name, dynlink_symbol_addr *addr) +{ + void *symbol = NULL; + + if (DYNLINK_FLAGS_CHECK(dynlink_get_flags(handle), DYNLINK_FLAGS_BIND_SELF)) + { + symbol = dlsym(impl, name); + } + else + { + int err = get_image_symbol((image_id)(intptr_t)impl, name, B_SYMBOL_TYPE_ANY, &symbol); + + if (err != B_OK) + { + log_write("metacall", LOG_LEVEL_ERROR, "DynLink error: failed to load BeOS/Haiku symbol %s", name); + return 1; + } + } + + dynlink_symbol_cast(void *, symbol, *addr); + + return (*addr == NULL); +} + +int dynlink_impl_interface_unload_haiku(dynlink handle, dynlink_impl impl) +{ + dynlink_flags flags = dynlink_get_flags(handle); + + (void)handle; + + /* Skip unlink when using global handle for loading symbols of the current process */ + if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_SELF)) + { + return 0; + } + +#if defined(__MEMORYCHECK__) || defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__) + /* Disable dlclose when running with address sanitizer in order to maintain stacktraces */ + (void)impl; + return 0; +#else + return ((image_id)(intptr_t)impl > 0) && (unload_add_on((image_id)(intptr_t)impl) < B_NO_ERROR); + // (void)impl; + // return 0; +#endif +} + +dynlink_impl_interface dynlink_impl_interface_singleton(void) +{ + static struct dynlink_impl_interface_type impl_interface_haiku = { + &dynlink_impl_interface_prefix_haiku, + &dynlink_impl_interface_extension_haiku, + &dynlink_impl_interface_load_haiku, + &dynlink_impl_interface_symbol_haiku, + &dynlink_impl_interface_unload_haiku, + }; + + return &impl_interface_haiku; +} + +#elif defined(__BEOS__) +#include "dynlink_impl_beos.c" +#endif diff --git a/source/format/include/format/format_specifier.h b/source/format/include/format/format_specifier.h index 80d1c84b9b..124e175878 100644 --- a/source/format/include/format/format_specifier.h +++ b/source/format/include/format/format_specifier.h @@ -38,7 +38,7 @@ extern "C" { (defined(unix) || defined(__unix__) || defined(__unix) || \ defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__CYGWIN__) || defined(__CYGWIN32__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__)) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__)) || defined(__HAIKU__) || defined(__BEOS__) #include @@ -97,7 +97,7 @@ extern "C" { #elif defined(FORMAT_32BIT) || \ (defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1900)) || \ defined(_BSD_SOURCE) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500) || \ - defined(_ISOC99_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) + defined(_ISOC99_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || defined(__HAIKU__) || defined(__BEOS__) #define FORMAT_PREFIX "z" #elif defined(FORMAT_64BIT) #if (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) diff --git a/source/log/source/log_policy_stream_syslog.c b/source/log/source/log_policy_stream_syslog.c index 9783fc3e78..57b752186a 100644 --- a/source/log/source/log_policy_stream_syslog.c +++ b/source/log/source/log_policy_stream_syslog.c @@ -27,7 +27,7 @@ #endif #elif defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__FreeBSD__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) || defined(__HAIKU__) || defined(__BEOS__) #include #endif @@ -56,7 +56,7 @@ struct log_policy_stream_syslog_data_type HANDLE handle; #elif defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__FreeBSD__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) || defined(__HAIKU__) || defined(__BEOS__) /* ... */ #endif }; @@ -106,7 +106,7 @@ static int log_policy_stream_syslog_create(log_policy policy, const log_policy_c syslog_data->handle = RegisterEventSource(NULL, syslog_data->name); #elif defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__FreeBSD__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) || defined(__HAIKU__) || defined(__BEOS__) openlog(syslog_data->name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER); #endif @@ -134,7 +134,7 @@ static int log_policy_stream_syslog_write(log_policy policy, const void *buffer, NULL, 1, 0, (LPTSTR *)lpt_str, NULL); #elif defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__FreeBSD__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) || defined(__HAIKU__) || defined(__BEOS__) (void)syslog_data; syslog(LOG_INFO, "%s", (const char *)buffer); @@ -163,7 +163,7 @@ static int log_policy_stream_syslog_destroy(log_policy policy) } #elif defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__FreeBSD__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) || defined(__HAIKU__) || defined(__BEOS__) closelog(); #endif diff --git a/source/metacall/CMakeLists.txt b/source/metacall/CMakeLists.txt index 898ed16a57..22a08ad356 100644 --- a/source/metacall/CMakeLists.txt +++ b/source/metacall/CMakeLists.txt @@ -213,6 +213,7 @@ target_link_libraries(${target} ${DEFAULT_LIBRARIES} $<$:${CMAKE_DL_LIBS}> # Native dynamic load library + $<$:bsd> # Fix issues with atomics in armv6 and armv7 $<$:-latomic> diff --git a/source/metacall/include/metacall/metacall_fork.h b/source/metacall/include/metacall/metacall_fork.h index 24d5f599c3..74527334a1 100644 --- a/source/metacall/include/metacall/metacall_fork.h +++ b/source/metacall/include/metacall/metacall_fork.h @@ -44,7 +44,7 @@ typedef int metacall_pid; #elif defined(unix) || defined(__unix__) || defined(__unix) || \ defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__CYGWIN__) || defined(__CYGWIN32__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) || defined(__HAIKU__) || defined(__BEOS__) /* -- Headers -- */ diff --git a/source/metacall/source/metacall_fork.c b/source/metacall/source/metacall_fork.c index 9a9a5340ea..bd265e37ec 100644 --- a/source/metacall/source/metacall_fork.c +++ b/source/metacall/source/metacall_fork.c @@ -96,7 +96,7 @@ NTSTATUS NTAPI metacall_fork_hook(ULONG ProcessFlags, #elif defined(unix) || defined(__unix__) || defined(__unix) || \ defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__CYGWIN__) || defined(__CYGWIN32__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) || defined(__HAIKU__) || defined(__BEOS__) /* -- Methods -- */ @@ -196,7 +196,7 @@ NTSTATUS NTAPI metacall_fork_hook(ULONG ProcessFlags, #elif defined(unix) || defined(__unix__) || defined(__unix) || \ defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__CYGWIN__) || defined(__CYGWIN32__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) || defined(__HAIKU__) || defined(__BEOS__) typedef pid_t (*metacall_fork_trampoline_type)(void); diff --git a/source/metacall/source/metacall_link.c b/source/metacall/source/metacall_link.c index 620ce8ad7f..883309b591 100644 --- a/source/metacall/source/metacall_link.c +++ b/source/metacall/source/metacall_link.c @@ -84,7 +84,7 @@ FARPROC metacall_link_hook(HMODULE handle, LPCSTR symbol) #elif defined(unix) || defined(__unix__) || defined(__unix) || \ defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ defined(__CYGWIN__) || defined(__CYGWIN32__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) + (defined(__APPLE__) && defined(__MACH__)) || defined(__MACOSX__) || defined(__HAIKU__) || defined(__BEOS__) #include diff --git a/source/portability/CMakeLists.txt b/source/portability/CMakeLists.txt index 1855258d28..095027c242 100644 --- a/source/portability/CMakeLists.txt +++ b/source/portability/CMakeLists.txt @@ -119,6 +119,7 @@ target_link_libraries(${target} PRIVATE ${META_PROJECT_NAME}::version ${META_PROJECT_NAME}::preprocessor + $<$:bsd> PUBLIC ${DEFAULT_LIBRARIES} diff --git a/source/portability/include/portability/portability_executable_path.h b/source/portability/include/portability/portability_executable_path.h index 1513b63d33..4bafde083e 100644 --- a/source/portability/include/portability/portability_executable_path.h +++ b/source/portability/include/portability/portability_executable_path.h @@ -45,6 +45,8 @@ typedef ssize_t portability_executable_path_length; typedef uint32_t portability_executable_path_length; #elif defined(sun) || defined(__sun) typedef size_t portability_executable_path_length; +#elif defined(__HAIKU__) || defined(__BEOS__) +typedef size_t portability_executable_path_length; #else #error "Unimplemented platform, please add support to it" #endif diff --git a/source/portability/include/portability/portability_path.h b/source/portability/include/portability/portability_path.h index 1856d3b662..a2614cc015 100644 --- a/source/portability/include/portability/portability_path.h +++ b/source/portability/include/portability/portability_path.h @@ -71,6 +71,13 @@ #include #include + #define PORTABILITY_PATH_SIZE PATH_MAX +#elif defined(__HAIKU__) || defined(__BEOS__) + #include + #include + #include + #include + #define PORTABILITY_PATH_SIZE PATH_MAX #else #error "Unimplemented platform, please add support to it" diff --git a/source/portability/source/portability_executable_path.c b/source/portability/source/portability_executable_path.c index f9632d33ec..5cdf8b8399 100644 --- a/source/portability/source/portability_executable_path.c +++ b/source/portability/source/portability_executable_path.c @@ -26,6 +26,8 @@ #include #elif defined(__FreeBSD__) #include +#elif defined(__HAIKU__) + #include #endif int portability_executable_path(portability_executable_path_str path, portability_executable_path_length *length) @@ -46,6 +48,20 @@ int portability_executable_path(portability_executable_path_str path, portabilit { return 1; } +#elif defined(__HAIKU__) + image_info info; + int32 cookie = 0; + *length = 0; + while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) + { + if (info.type == B_APP_IMAGE) + { + strncpy(path, info.name, path_max_length); + *length = strnlen(path, path_max_length); + break; + } + } + #elif defined(unix) || defined(__unix__) || defined(__unix) || \ defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) *length = readlink("/proc/self/exe", path, path_max_length); diff --git a/source/portability/source/portability_library_path.c b/source/portability/source/portability_library_path.c index bfe51363cf..b949e56052 100644 --- a/source/portability/source/portability_library_path.c +++ b/source/portability/source/portability_library_path.c @@ -27,7 +27,7 @@ static int portability_library_path_ends_with(const char path[], const char name #if defined(unix) || defined(__unix__) || defined(__unix) || \ defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ - defined(__FreeBSD__) + defined(__FreeBSD__) || defined(__HAIKU__) #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -69,7 +69,7 @@ int portability_library_path_ends_with(const char path[], const char name[]) #if defined(unix) || defined(__unix__) || defined(__unix) || \ defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ - defined(__FreeBSD__) + defined(__FreeBSD__) || defined(__HAIKU__) /* -- Type Definitions -- */ @@ -126,7 +126,7 @@ int portability_library_path_find(const char name[], portability_library_path_st { #if defined(unix) || defined(__unix__) || defined(__unix) || \ defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ - defined(__FreeBSD__) + defined(__FreeBSD__) || defined(__HAIKU__) struct portability_library_path_find_phdr_type data = { name, @@ -232,7 +232,7 @@ int portability_library_path_list(portability_library_path_list_cb callback, voi } #if defined(linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux) || \ - defined(__FreeBSD__) + defined(__FreeBSD__) || defined(__HAIKU__) { struct portability_library_path_list_phdr_type list_phdr = { callback, diff --git a/source/serials/rapid_json_serial/source/rapid_json_serial_impl.cpp b/source/serials/rapid_json_serial/source/rapid_json_serial_impl.cpp index 6271ca7433..dd793a1cdf 100644 --- a/source/serials/rapid_json_serial/source/rapid_json_serial_impl.cpp +++ b/source/serials/rapid_json_serial/source/rapid_json_serial_impl.cpp @@ -42,23 +42,20 @@ typedef struct rapid_json_document_type { + rapidjson::MemoryPoolAllocator<> json_allocator; rapidjson::Document impl; memory_allocator allocator; -} * rapid_json_document; +} *rapid_json_document; /* -- Private Methods -- */ -static void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v); +static void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v, rapidjson::MemoryPoolAllocator<> &rapid_json_allocator); static char *rapid_json_serial_impl_document_stringify(rapid_json_document document, size_t *size); static value rapid_json_serial_impl_deserialize_value(const rapidjson::Value *v); -/* -- Classes -- */ - -static thread_local rapidjson::MemoryPoolAllocator<> rapid_json_allocator; - /* -- Methods -- */ const char *rapid_json_serial_impl_extension() @@ -76,13 +73,12 @@ serial_handle rapid_json_serial_impl_initialize(memory_allocator allocator) { return NULL; } - document->allocator = allocator; return (serial_handle)document; } -void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v) +void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v, rapidjson::MemoryPoolAllocator<> &rapid_json_allocator) { type_id id = value_type_id(v); @@ -197,7 +193,7 @@ void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v) rapidjson::Value json_inner_value; - rapid_json_serial_impl_serialize_value(current_value, &json_inner_value); + rapid_json_serial_impl_serialize_value(current_value, &json_inner_value, rapid_json_allocator); json_array.PushBack(json_inner_value, rapid_json_allocator); } @@ -218,9 +214,9 @@ void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v) rapidjson::Value json_member, json_inner_value; - rapid_json_serial_impl_serialize_value(tupla_array[0], &json_member); + rapid_json_serial_impl_serialize_value(tupla_array[0], &json_member, rapid_json_allocator); - rapid_json_serial_impl_serialize_value(tupla_array[1], &json_inner_value); + rapid_json_serial_impl_serialize_value(tupla_array[1], &json_inner_value, rapid_json_allocator); json_map.AddMember(json_member, json_inner_value, rapid_json_allocator); } @@ -319,7 +315,7 @@ void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v) json_member.SetString(str, length); - rapid_json_serial_impl_serialize_value(throwable_value(th), &json_inner_value); + rapid_json_serial_impl_serialize_value(throwable_value(th), &json_inner_value, rapid_json_allocator); json_map.AddMember(json_member, json_inner_value, rapid_json_allocator); } @@ -374,7 +370,9 @@ char *rapid_json_serial_impl_serialize(serial_handle handle, value v, size_t *si return NULL; } - rapid_json_serial_impl_serialize_value(v, &document->impl); + // thread_local rapidjson::MemoryPoolAllocator<> rapid_json_allocator; + + rapid_json_serial_impl_serialize_value(v, &document->impl, document->json_allocator); return rapid_json_serial_impl_document_stringify(document, size); } diff --git a/source/tests/serial_test/source/serial_test.cpp b/source/tests/serial_test/source/serial_test.cpp index b2bc74ffb9..671eda5158 100644 --- a/source/tests/serial_test/source/serial_test.cpp +++ b/source/tests/serial_test/source/serial_test.cpp @@ -350,7 +350,7 @@ TEST_F(serial_test, DefaultConstructor) #else "0x000A7EF2", #endif -#elif defined(__linux) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) +#elif defined(__linux) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__HAIKU__) "0xa7ef2", #else "", diff --git a/source/threading/include/threading/threading_mutex.h b/source/threading/include/threading/threading_mutex.h index bb6c4bb2f0..1e60733a83 100644 --- a/source/threading/include/threading/threading_mutex.h +++ b/source/threading/include/threading/threading_mutex.h @@ -42,6 +42,7 @@ typedef CRITICAL_SECTION threading_mutex_impl_type; defined(__FreeBSD__) || \ defined(__NetBSD__) || \ defined(__OpenBSD__) || \ + defined(__HAIKU__) || \ (defined(bsdi) || defined(__bsdi__)) || \ defined(__DragonFly__) #include diff --git a/source/threading/source/threading_thread_id.c b/source/threading/source/threading_thread_id.c index 6a32298a39..c2b9e8319a 100644 --- a/source/threading/source/threading_thread_id.c +++ b/source/threading/source/threading_thread_id.c @@ -55,7 +55,7 @@ #elif defined(__FreeBSD__) #include #elif defined(__HAIKU__) || defined(__BEOS__) - #include + #include #else #error "Unsupported platform thread id" #endif @@ -89,7 +89,7 @@ uint64_t thread_id_get_current(void) return (thread_id < 0) ? 0 : (uint64_t)thread_id; #elif defined(__HAIKU__) || defined(__BEOS__) - return (uint64_t)thread_get_current_thread_id(); + return (uint64_t)find_thread(NULL); #else return THREAD_ID_INVALID; #endif diff --git a/tools/metacall-configure.sh b/tools/metacall-configure.sh index 960f1dbe2e..9c60e4a5b3 100755 --- a/tools/metacall-configure.sh +++ b/tools/metacall-configure.sh @@ -63,6 +63,7 @@ case "$(uname -s)" in CYGWIN*) OPERATIVE_SYSTEM=Cygwin;; MINGW*) OPERATIVE_SYSTEM=MinGW;; FreeBSD*) OPERATIVE_SYSTEM=FreeBSD;; + Haiku*) OPERATIVE_SYSTEM=Haiku;; *) OPERATIVE_SYSTEM="Unknown" esac diff --git a/tools/metacall-environment.sh b/tools/metacall-environment.sh index 56a04d772a..79c123c02a 100755 --- a/tools/metacall-environment.sh +++ b/tools/metacall-environment.sh @@ -74,6 +74,7 @@ case "$(uname -s)" in CYGWIN*) OPERATIVE_SYSTEM=Cygwin;; MINGW*) OPERATIVE_SYSTEM=MinGW;; FreeBSD*) OPERATIVE_SYSTEM=FreeBSD;; + Haiku*) OPERATIVE_SYSTEM=Haiku;; *) OPERATIVE_SYSTEM="Unknown" esac @@ -163,6 +164,8 @@ sub_base(){ brew install llvm cmake git wget gnupg ca-certificates elif [ "${OPERATIVE_SYSTEM}" = "FreeBSD" ]; then $SUDO_CMD pkg install -y cmake git gmake wget gnupg ca_root_nss + elif [ "${OPERATIVE_SYSTEM}" = "Haiku" ]; then + pkgman install -y cmake git make wget getconf gcc_syslibs_devel fi }