Skip to content

Commit b6145c8

Browse files
committed
haiku clean branch
1 parent e739f9e commit b6145c8

5 files changed

Lines changed: 300 additions & 13 deletions

File tree

.github/workflows/haiku-test.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Haiku Test
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
- develop
10+
tags:
11+
- v*.*.*
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
name: Haiku Test
20+
runs-on: ubuntu-latest
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
build: [debug, relwithdebinfo, release]
25+
arch: [x86-64]
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Run Haiku VM
34+
uses: cross-platform-actions/action@v1.2.0
35+
with:
36+
operating_system: haiku
37+
version: r1beta5
38+
architecture: ${{ matrix.arch }}
39+
shell: sh
40+
run: |
41+
mkdir -p /boot/home/config/settings/system/debug_server
42+
printf 'default_action report\n' > /boot/home/config/settings/system/debug_server/settings
43+
44+
sh ./tools/metacall-environment.sh base
45+
46+
mkdir -p build && cd build
47+
sh ../tools/metacall-configure.sh ${{ matrix.build }} scripts tests
48+
49+
sh ../tools/metacall-build.sh ${{ matrix.build }}
50+
51+
echo "===== HAIKU DESKTOP FILES ====="
52+
ctest -j2 --timeout 120 --output-on-failure -C ${{ matrix.build }} || res=$?
53+
ls -la /boot/home/Desktop/ 2>/dev/null || true
54+
55+
echo "===== HAIKU CRASH REPORTS ====="
56+
cat /boot/home/Desktop/*report* 2>/dev/null || true
57+
58+
echo "===== HAIKU SYSLOG TAIL ====="
59+
tail -n 200 /boot/system/var/log/syslog 2>/dev/null || true
60+
61+
exit ${res:-0}

source/dynlink/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ set(generated_source_path "${CMAKE_CURRENT_BINARY_DIR}/source")
3939
if(APPLE AND PROJECT_OS_VERSION GREATER 8)
4040
# From macOS 10.5 (version 9), dlopen compatible library is available
4141
set(DYNLINK_IMPL_INTERFACE_NAME unix)
42+
elseif(PROJECT_OS_HAIKU)
43+
# Haiku can use dlopen although it's BeOS family
44+
set(DYNLINK_IMPL_INTERFACE_NAME haiku)
4245
else()
4346
set(DYNLINK_IMPL_INTERFACE_NAME ${PROJECT_OS_FAMILY})
47+
4448
endif()
4549

4650
set(headers
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Dynamic Link Library by Parra Studios
3+
* A library for dynamic loading and linking shared objects at run-time.
4+
*
5+
* Copyright (C) 2016 - 2026 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#ifndef DYNLINK_IMPL_HAIKU_H
22+
#define DYNLINK_IMPL_HAIKU_H 1
23+
24+
/* -- Headers -- */
25+
26+
#include <dynlink/dynlink_api.h>
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
/* -- Forward declarations -- */
33+
34+
struct dynlink_impl_interface_type;
35+
36+
/* -- Type definitions -- */
37+
38+
typedef struct dynlink_impl_interface_type *dynlink_impl_interface;
39+
40+
/* -- Methods -- */
41+
42+
/**
43+
* @brief
44+
* Haiku image add-on object implementation singleton
45+
*
46+
* @return
47+
* A pointer to the Haiku image add-on object implementation singleton
48+
*/
49+
DYNLINK_API dynlink_impl_interface dynlink_impl_interface_singleton(void);
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
#endif /* DYNLINK_IMPL_HAIKU_H */
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* Dynamic Link Library by Parra Studios
3+
* A library for dynamic loading and linking shared objects at run-time.
4+
*
5+
* Copyright (C) 2016 - 2026 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#if defined(__HAIKU__)
22+
23+
/* -- Headers -- */
24+
25+
#include <dynlink/dynlink.h>
26+
27+
#include <dynlink/dynlink_impl.h>
28+
29+
#include <log/log.h>
30+
31+
#include <string.h>
32+
33+
#include <stdint.h>
34+
35+
#include <dlfcn.h>
36+
37+
#include <be/kernel/image.h>
38+
39+
/* -- Methods -- */
40+
41+
const char *dynlink_impl_interface_prefix_haiku(void)
42+
{
43+
static const char prefix_haiku[] = "lib";
44+
45+
return prefix_haiku;
46+
}
47+
48+
const char *dynlink_impl_interface_extension_haiku(void)
49+
{
50+
static const char extension_haiku[] = "so";
51+
52+
return extension_haiku;
53+
}
54+
55+
dynlink_impl dynlink_impl_interface_load_haiku(dynlink handle)
56+
{
57+
dynlink_flags flags = dynlink_get_flags(handle);
58+
image_id impl = 0;
59+
60+
if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_SELF))
61+
{
62+
int mode;
63+
void *self_impl;
64+
65+
DYNLINK_FLAGS_SET(mode, 0);
66+
67+
if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_NOW))
68+
{
69+
DYNLINK_FLAGS_ADD(mode, RTLD_NOW);
70+
}
71+
72+
if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_LAZY))
73+
{
74+
DYNLINK_FLAGS_ADD(mode, RTLD_LAZY);
75+
}
76+
77+
if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_LOCAL))
78+
{
79+
DYNLINK_FLAGS_ADD(mode, RTLD_LOCAL);
80+
}
81+
82+
if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_GLOBAL))
83+
{
84+
DYNLINK_FLAGS_ADD(mode, RTLD_GLOBAL);
85+
}
86+
87+
self_impl = dlopen(NULL, mode);
88+
89+
if (self_impl == NULL)
90+
{
91+
log_write("metacall", LOG_LEVEL_ERROR, "DynLink error: %s", dlerror());
92+
return NULL;
93+
}
94+
95+
return self_impl;
96+
}
97+
98+
impl = load_add_on(dynlink_get_path(handle));
99+
100+
if (impl < B_NO_ERROR)
101+
{
102+
log_write("metacall", LOG_LEVEL_ERROR, "DynLink error: failed to load BeOS/Haiku image add-on with error code %d", (int)impl);
103+
return NULL;
104+
}
105+
106+
return (dynlink_impl)(intptr_t)impl;
107+
}
108+
109+
int dynlink_impl_interface_symbol_haiku(dynlink handle, dynlink_impl impl, const char *name, dynlink_symbol_addr *addr)
110+
{
111+
void *symbol = NULL;
112+
113+
if (DYNLINK_FLAGS_CHECK(dynlink_get_flags(handle), DYNLINK_FLAGS_BIND_SELF))
114+
{
115+
symbol = dlsym(impl, name);
116+
}
117+
else
118+
{
119+
int err = get_image_symbol((image_id)(intptr_t)impl, name, B_SYMBOL_TYPE_ANY, &symbol);
120+
121+
if (err != B_OK)
122+
{
123+
log_write("metacall", LOG_LEVEL_ERROR, "DynLink error: failed to load BeOS/Haiku symbol %s", name);
124+
return 1;
125+
}
126+
}
127+
128+
dynlink_symbol_cast(void *, symbol, *addr);
129+
130+
return (*addr == NULL);
131+
}
132+
133+
int dynlink_impl_interface_unload_haiku(dynlink handle, dynlink_impl impl)
134+
{
135+
dynlink_flags flags = dynlink_get_flags(handle);
136+
137+
(void)handle;
138+
139+
/* Skip unlink when using global handle for loading symbols of the current process */
140+
if (DYNLINK_FLAGS_CHECK(flags, DYNLINK_FLAGS_BIND_SELF))
141+
{
142+
return 0;
143+
}
144+
145+
#if defined(__MEMORYCHECK__) || defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__)
146+
/* Disable dlclose when running with address sanitizer in order to maintain stacktraces */
147+
(void)impl;
148+
return 0;
149+
#else
150+
return ((image_id)(intptr_t)impl > 0) && (unload_add_on((image_id)(intptr_t)impl) < B_NO_ERROR);
151+
// (void)impl;
152+
// return 0;
153+
#endif
154+
}
155+
156+
dynlink_impl_interface dynlink_impl_interface_singleton(void)
157+
{
158+
static struct dynlink_impl_interface_type impl_interface_haiku = {
159+
&dynlink_impl_interface_prefix_haiku,
160+
&dynlink_impl_interface_extension_haiku,
161+
&dynlink_impl_interface_load_haiku,
162+
&dynlink_impl_interface_symbol_haiku,
163+
&dynlink_impl_interface_unload_haiku,
164+
};
165+
166+
return &impl_interface_haiku;
167+
}
168+
169+
#elif defined(__BEOS__)
170+
#include "dynlink_impl_beos.c"
171+
#endif

source/serials/rapid_json_serial/source/rapid_json_serial_impl.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,20 @@
4242

4343
typedef struct rapid_json_document_type
4444
{
45+
rapidjson::MemoryPoolAllocator<> json_allocator;
4546
rapidjson::Document impl;
4647
memory_allocator allocator;
4748

48-
} * rapid_json_document;
49+
} *rapid_json_document;
4950

5051
/* -- Private Methods -- */
5152

52-
static void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v);
53+
static void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v, rapidjson::MemoryPoolAllocator<> &rapid_json_allocator);
5354

5455
static char *rapid_json_serial_impl_document_stringify(rapid_json_document document, size_t *size);
5556

5657
static value rapid_json_serial_impl_deserialize_value(const rapidjson::Value *v);
5758

58-
/* -- Classes -- */
59-
60-
static thread_local rapidjson::MemoryPoolAllocator<> rapid_json_allocator;
61-
6259
/* -- Methods -- */
6360

6461
const char *rapid_json_serial_impl_extension()
@@ -76,13 +73,12 @@ serial_handle rapid_json_serial_impl_initialize(memory_allocator allocator)
7673
{
7774
return NULL;
7875
}
79-
8076
document->allocator = allocator;
8177

8278
return (serial_handle)document;
8379
}
8480

85-
void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v)
81+
void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v, rapidjson::MemoryPoolAllocator<> &rapid_json_allocator)
8682
{
8783
type_id id = value_type_id(v);
8884

@@ -197,7 +193,7 @@ void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v)
197193

198194
rapidjson::Value json_inner_value;
199195

200-
rapid_json_serial_impl_serialize_value(current_value, &json_inner_value);
196+
rapid_json_serial_impl_serialize_value(current_value, &json_inner_value, rapid_json_allocator);
201197

202198
json_array.PushBack(json_inner_value, rapid_json_allocator);
203199
}
@@ -218,9 +214,9 @@ void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v)
218214

219215
rapidjson::Value json_member, json_inner_value;
220216

221-
rapid_json_serial_impl_serialize_value(tupla_array[0], &json_member);
217+
rapid_json_serial_impl_serialize_value(tupla_array[0], &json_member, rapid_json_allocator);
222218

223-
rapid_json_serial_impl_serialize_value(tupla_array[1], &json_inner_value);
219+
rapid_json_serial_impl_serialize_value(tupla_array[1], &json_inner_value, rapid_json_allocator);
224220

225221
json_map.AddMember(json_member, json_inner_value, rapid_json_allocator);
226222
}
@@ -319,7 +315,7 @@ void rapid_json_serial_impl_serialize_value(value v, rapidjson::Value *json_v)
319315

320316
json_member.SetString(str, length);
321317

322-
rapid_json_serial_impl_serialize_value(throwable_value(th), &json_inner_value);
318+
rapid_json_serial_impl_serialize_value(throwable_value(th), &json_inner_value, rapid_json_allocator);
323319

324320
json_map.AddMember(json_member, json_inner_value, rapid_json_allocator);
325321
}
@@ -374,7 +370,7 @@ char *rapid_json_serial_impl_serialize(serial_handle handle, value v, size_t *si
374370
return NULL;
375371
}
376372

377-
rapid_json_serial_impl_serialize_value(v, &document->impl);
373+
rapid_json_serial_impl_serialize_value(v, &document->impl, document->json_allocator);
378374

379375
return rapid_json_serial_impl_document_stringify(document, size);
380376
}

0 commit comments

Comments
 (0)