Skip to content

Commit 6913c51

Browse files
JBendaharryr0se
andauthored
Fix/135 cpp bindings in clib (#143)
Make the STD library compilation optional and guard STD usage more vigorously. fixes: #135 --------- Co-authored-by: Harry Rose <harryrose@protonmail.com>
1 parent d4f5207 commit 6913c51

File tree

22 files changed

+540
-399
lines changed

22 files changed

+540
-399
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ set(INKCPP_INKLECATE
6767
set_property(CACHE INKCPP_INKLECATE PROPERTY STRINGS "NONE" "OS" "ALL")
6868
option(INKCPP_NO_RTTI
6969
"Disable real time type information depended code. Used to build without RTTI." OFF)
70-
option(INKCPP_NO_EXCEPTIONS
71-
"Used to build without support for exceptions, disables try/catch blocks and throws" OFF)
7270
option(INKCPP_NO_STD "Disables the use of C(++) std libs." OFF)
7371

7472
if(INKCPP_NO_RTTI)

inkcpp/CMakeLists.txt

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,89 @@
11
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
22

3-
list(APPEND SOURCES
4-
array.h
5-
choice.cpp
6-
functional.cpp
7-
functions.h functions.cpp
8-
globals_impl.h globals_impl.cpp
9-
output.h output.cpp
10-
platform.h
11-
runner_impl.h runner_impl.cpp
12-
simple_restorable_stack.h stack.h stack.cpp
13-
story_impl.h story_impl.cpp
14-
snapshot_impl.h snapshot_impl.cpp snapshot_interface.h
15-
story_ptr.cpp
16-
system.cpp
17-
value.h value.cpp
3+
list(
4+
APPEND
5+
SOURCES
6+
array.h
7+
choice.cpp
8+
functional.cpp
9+
functions.h
10+
functions.cpp
11+
globals_impl.h
12+
globals_impl.cpp
13+
output.h
14+
output.cpp
15+
platform.h
16+
runner_impl.h
17+
runner_impl.cpp
18+
simple_restorable_stack.h
19+
stack.h
20+
stack.cpp
21+
story_impl.h
22+
story_impl.cpp
23+
snapshot_impl.h
24+
snapshot_impl.cpp
25+
snapshot_interface.h
26+
story_ptr.cpp
27+
system.cpp
28+
value.h
29+
value.cpp
1830
tuple.hpp
19-
string_table.h string_table.cpp
20-
list_table.h list_table.cpp
21-
list_impl.h list_impl.cpp
22-
operations.h operation_bases.h
23-
list_operations.h list_operations.cpp
24-
container_operations.h container_operations.cpp
25-
numeric_operations.h numeric_operations.cpp
26-
string_operations.h string_operations.cpp
31+
string_table.h
32+
string_table.cpp
33+
list_table.h
34+
list_table.cpp
35+
list_impl.h
36+
list_impl.cpp
37+
operations.h
38+
operation_bases.h
39+
list_operations.h
40+
list_operations.cpp
41+
container_operations.h
42+
container_operations.cpp
43+
numeric_operations.h
44+
numeric_operations.cpp
45+
string_operations.h
46+
string_operations.cpp
2747
string_operations.cpp
2848
numeric_operations.cpp
2949
casting.h
3050
executioner.h
3151
string_utils.h
3252
header.cpp
33-
random.h
34-
)
35-
list(APPEND COLLECTION_SOURCES
36-
collections/restorable.h
37-
collections/restorable.cpp
38-
)
39-
FILE(GLOB PUBLIC_HEADERS "include/*")
53+
random.h)
54+
list(APPEND COLLECTION_SOURCES collections/restorable.h collections/restorable.cpp)
55+
file(GLOB PUBLIC_HEADERS "include/*")
4056

4157
source_group(Collections REGULAR_EXPRESSION collections/.*)
4258
add_library(inkcpp_o OBJECT ${SOURCES} ${COLLECTION_SOURCES})
43-
target_include_directories(inkcpp_o PUBLIC
44-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
45-
$<INSTALL_INTERFACE:include>
46-
)
47-
add_library(inkcpp $<TARGET_OBJECTS:inkcpp_o>)
48-
target_include_directories(inkcpp PUBLIC
49-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
50-
$<INSTALL_INTERFACE:include>
51-
)
59+
target_include_directories(inkcpp_o PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
60+
$<INSTALL_INTERFACE:include>)
61+
target_compile_definitions(inkcpp_o PRIVATE INKCPP_BUILD_CLIB INKCPP_NO_EXCEPTIONS INKCPP_NO_RTTI)
62+
add_library(inkcpp ${SOURCES} ${COLLECTION_SOURCES})
63+
target_include_directories(inkcpp PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
64+
$<INSTALL_INTERFACE:include>)
5265
set_target_properties(inkcpp PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
5366

54-
# Make sure the include directory is included
67+
# Make sure the include directory is included
5568
target_link_libraries(inkcpp_o PUBLIC inkcpp_shared)
5669
target_link_libraries(inkcpp PUBLIC inkcpp_shared)
5770
# Make sure this project and all dependencies use the C++17 standard
5871
target_compile_features(inkcpp PUBLIC cxx_std_17)
5972

60-
6173
# Unreal installation
6274
list(REMOVE_ITEM SOURCES "avl_array.h")
63-
configure_file("avl_array.h" "${CMAKE_BINARY_DIR}/unreal/inkcpp/Source/ThirdParty/Private/avl_array.h" COPYONLY)
64-
foreach(FILE IN LISTS SOURCES)
65-
configure_file("${FILE}" "${CMAKE_BINARY_DIR}/unreal/inkcpp/Source/inkcpp/Private/ink/${FILE}" COPYONLY)
75+
configure_file("avl_array.h"
76+
"${CMAKE_BINARY_DIR}/unreal/inkcpp/Source/ThirdParty/Private/avl_array.h" COPYONLY)
77+
foreach(file IN LISTS SOURCES)
78+
configure_file("${file}" "${CMAKE_BINARY_DIR}/unreal/inkcpp/Source/inkcpp/Private/ink/${file}"
79+
COPYONLY)
6680
endforeach()
67-
foreach(FILE IN LISTS PUBLIC_HEADERS)
68-
get_filename_component(FILE "${FILE}" NAME)
69-
configure_file("include/${FILE}" "${CMAKE_BINARY_DIR}/unreal/inkcpp/Source/inkcpp/Public/ink/${FILE}" COPYONLY)
81+
foreach(file IN LISTS PUBLIC_HEADERS)
82+
get_filename_component(file "${file}" NAME)
83+
configure_file("include/${file}"
84+
"${CMAKE_BINARY_DIR}/unreal/inkcpp/Source/inkcpp/Public/ink/${FILE}" COPYONLY)
7085
endforeach()
71-
foreach(FILE IN LISTS COLLECTION_SOURCES)
72-
configure_file("${FILE}" "${CMAKE_BINARY_DIR}/unreal/inkcpp/Source/inkcpp/Private/ink/${FILE}" COPYONLY)
86+
foreach(file IN LISTS COLLECTION_SOURCES)
87+
configure_file("${file}" "${CMAKE_BINARY_DIR}/unreal/inkcpp/Source/inkcpp/Private/ink/${file}"
88+
COPYONLY)
7389
endforeach()

inkcpp/avl_array.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ class avl_array
6565

6666
// node storage, due to possible structure packing effects, single arrays are used instead of a
6767
// 'node' structure
68-
ink::runtime::internal::if_t<dynamic, Key*, Key[Size]> key_;
69-
ink::runtime::internal::if_t<dynamic, T*, T[Size]> val_;
70-
ink::runtime::internal::if_t<dynamic, std::int8_t*, std::int8_t[Size]> balance_;
71-
ink::runtime::internal::if_t<dynamic, child_type*, child_type[Size]> child_;
72-
size_type size_; // actual size
73-
size_type _capacity;
74-
size_type root_; // root node
68+
ink::runtime::internal::if_t<dynamic, Key*, Key[Size]> key_;
69+
ink::runtime::internal::if_t<dynamic, T*, T[Size]> val_;
70+
ink::runtime::internal::if_t<dynamic, char*, char[Size]> balance_;
71+
ink::runtime::internal::if_t<dynamic, child_type*, child_type[Size]> child_;
72+
size_type size_; // actual size
73+
size_type _capacity;
74+
size_type root_; // root node
7575
ink::runtime::internal::if_t<dynamic, size_type*, size_type[Fast ? Size : 1]> parent_;
7676

7777
// invalid index (like 'nullptr' in a pointer implementation)
@@ -197,7 +197,7 @@ class avl_array
197197
if constexpr (dynamic) {
198198
key_ = new Key[Size];
199199
val_ = new T[Size];
200-
balance_ = new std::int8_t[Size];
200+
balance_ = new char[Size];
201201
child_ = new child_type[Size];
202202
if constexpr (Fast) {
203203
parent_ = new size_type[Size];
@@ -285,7 +285,7 @@ class avl_array
285285
val_ = new_data;
286286
}
287287
{
288-
std::int8_t* new_data = new std::int8_t[new_size];
288+
char* new_data = new char[new_size];
289289
for (size_type i = 0; i < _capacity; ++i) {
290290
new_data[i] = balance_[i];
291291
}
@@ -660,7 +660,7 @@ class avl_array
660660
set_parent(target, get_parent(source));
661661
}
662662

663-
void insert_balance(size_type node, std::int8_t balance)
663+
void insert_balance(size_type node, char balance)
664664
{
665665
while (node != INVALID_IDX) {
666666
balance = (balance_[node] += balance);
@@ -691,7 +691,7 @@ class avl_array
691691
}
692692
}
693693

694-
void delete_balance(size_type node, std::int8_t balance)
694+
void delete_balance(size_type node, char balance)
695695
{
696696
while (node != INVALID_IDX) {
697697
balance = (balance_[node] += balance);

inkcpp/functional.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ int32_t function_base::pop<int32_t>(basic_eval_stack* stack, list_table&)
3333
}
3434

3535
template<>
36-
uint32_t function_base::pop<uint32_t>(basic_eval_stack* stack, list_table& lists)
36+
uint32_t function_base::pop<uint32_t>(basic_eval_stack* stack, list_table&)
3737
{
3838
value val = stack->pop();
3939
return casting::numeric_cast<value_type::uint32>(val);
4040
}
4141

4242
template<>
43-
bool function_base::pop<bool>(basic_eval_stack* stack, list_table& lists)
43+
bool function_base::pop<bool>(basic_eval_stack* stack, list_table&)
4444
{
4545
value val = stack->pop();
4646
return casting::numeric_cast<value_type::int32>(val) != 0;
4747
}
4848

4949
template<>
50-
float function_base::pop<float>(basic_eval_stack* stack, list_table& lists)
50+
float function_base::pop<float>(basic_eval_stack* stack, list_table&)
5151
{
5252
value val = stack->pop();
5353
return casting::numeric_cast<value_type::float32>(val);

inkcpp/include/list.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# include <ostream>
1313
#endif
1414

15-
#ifdef INK_BUILD_CLIB
15+
#ifdef INKCPP_BUILD_CLIB
1616
struct InkListIter;
1717
struct HInkList;
1818
int ink_list_flags(const HInkList*, InkListIter*);
@@ -61,7 +61,7 @@ class list_interface
6161
int _i;
6262
bool _one_list_iterator; ///< iterates only though values of one list
6363
friend list_interface;
64-
#ifdef INK_BUILD_CLIB
64+
#ifdef INKCPP_BUILD_CLIB
6565
friend int ::ink_list_flags(const HInkList*, InkListIter*);
6666
friend int ::ink_list_flags_from(const HInkList*, const char*, InkListIter*);
6767
friend int ::ink_list_iter_next(InkListIter* self);

inkcpp/include/runner.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class runner_interface
8383
*/
8484
virtual snapshot* create_snapshot() const = 0;
8585

86-
#ifdef INK_ENABLE_CSTD
8786
/**
8887
* Continue execution until the next newline, then allocate a c-style
8988
* string with the output. This allocated string is managed by the runtime
@@ -93,7 +92,6 @@ class runner_interface
9392
* @return allocated c-style string with the output of a single line of execution
9493
*/
9594
virtual const char* getline_alloc() = 0;
96-
#endif
9795

9896
#if defined(INK_ENABLE_STL) || defined(INK_ENABLE_UNREAL)
9997
/**

0 commit comments

Comments
 (0)