Compare commits
8 Commits
a65eb5c161
...
7b42a023e4
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b42a023e4 | |||
| 7d78d7d314 | |||
| 4f40bfd9a0 | |||
| a339b6e01a | |||
| 604ddfcebf | |||
| c78ea4bfa6 | |||
| b951577f48 | |||
| 5d1b2aabbb |
+6
-6
@@ -56,8 +56,8 @@ AttributeMacros:
|
||||
ForEachMacros:
|
||||
- fx_btree_foreach
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
MacroBlockBegin: "FX_(TYPE|ASSEMBLY)_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_(TYPE|ASSEMBLY)_.*_END"
|
||||
---
|
||||
Language: ObjC
|
||||
DerivePointerAlignment: false
|
||||
@@ -114,8 +114,8 @@ AttributeMacros:
|
||||
ForEachMacros:
|
||||
- fx_btree_foreach
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
MacroBlockBegin: "FX_(TYPE|ASSEMBLY)_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_(TYPE|ASSEMBLY)_.*_END"
|
||||
---
|
||||
Language: Cpp
|
||||
DerivePointerAlignment: false
|
||||
@@ -172,5 +172,5 @@ AttributeMacros:
|
||||
ForEachMacros:
|
||||
- fx_btree_foreach
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
MacroBlockBegin: "FX_(TYPE|ASSEMBLY)_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_(TYPE|ASSEMBLY)_.*_END"
|
||||
|
||||
+17
-44
@@ -9,8 +9,12 @@ set(CMAKE_C_EXTENSIONS OFF)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
if (NOT DEFINED fx_modules)
|
||||
set(fx_modules core ds serial term cmd io compress)
|
||||
set(fx_all_assemblies
|
||||
fx.runtime
|
||||
fx.collections)
|
||||
|
||||
if (NOT DEFINED fx_assemblies)
|
||||
set(fx_assemblies ${fx_all_assemblies})
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED fx_enable_floating_point)
|
||||
@@ -32,50 +36,19 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
|
||||
foreach (module ${fx_modules})
|
||||
add_subdirectory(${module})
|
||||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module})
|
||||
message(STATUS "Building unit tests for module ${module}")
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates.cmake)
|
||||
|
||||
if (fx_enable_tests AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c)
|
||||
add_executable(fx-${module}-units
|
||||
test/${module}/${module}-units.c
|
||||
misc/AllTests.c
|
||||
misc/CuTest.c
|
||||
misc/CuTest.h)
|
||||
target_link_libraries(fx-${module}-units fx-${module})
|
||||
target_include_directories(fx-${module}-units PRIVATE misc/)
|
||||
set_target_properties(fx-${module}-units PROPERTIES FOLDER "Tests/${module}")
|
||||
if ("fx.runtime" IN_LIST fx_assemblies)
|
||||
add_fx_assembly(
|
||||
NAME fx.runtime
|
||||
NAMESPACES fx fx.reflection)
|
||||
endif ()
|
||||
|
||||
file(GLOB test_sources test/${module}/*.c)
|
||||
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c")
|
||||
|
||||
if (fx_enable_tests)
|
||||
foreach (test_file ${test_sources})
|
||||
get_filename_component(test_name ${test_file} NAME_WE)
|
||||
add_executable(fx-${module}-${test_name} ${test_file})
|
||||
|
||||
set_target_properties(fx-${module}-${test_name} PROPERTIES FOLDER "Tests/${module}")
|
||||
|
||||
target_link_libraries(fx-${module}-${test_name} fx-${module})
|
||||
endforeach (test_file)
|
||||
if ("fx.collections" IN_LIST fx_assemblies)
|
||||
add_fx_assembly(
|
||||
NAME fx.collections
|
||||
NAMESPACES fx.collections
|
||||
DEPENDENCIES fx.runtime)
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach (module)
|
||||
|
||||
if (fx_enable_tests)
|
||||
file(GLOB test_sources test/*.c)
|
||||
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/units.c")
|
||||
|
||||
foreach (test_file ${test_sources})
|
||||
get_filename_component(test_name ${test_file} NAME_WE)
|
||||
add_executable(fx-${test_name} ${test_file})
|
||||
|
||||
set_target_properties(fx-${test_name} PROPERTIES FOLDER "Tests")
|
||||
|
||||
foreach (module ${fx_modules})
|
||||
target_link_libraries(fx-${test_name} fx-${module})
|
||||
endforeach (module)
|
||||
endforeach (test_file)
|
||||
endif ()
|
||||
add_executable(dynamic-test test/dynamic-test.c)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <fx/macros.h>
|
||||
#include <fx/reflection/assembly.h>
|
||||
|
||||
FX_ASSEMBLY_BEGIN()
|
||||
FX_ASSEMBLY_NAME("fx.collections");
|
||||
FX_ASSEMBLY_VERSION(1, 0, 0, 0);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "array", fx_array);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "bitbuffer", fx_bitbuffer);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "bitmap", fx_bitmap);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "dict", fx_dict);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "hashmap", fx_hashmap);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "list", fx_list);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "tree", fx_tree);
|
||||
FX_ASSEMBLY_END()
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <fx/macros.h>
|
||||
#include <fx/reflection/assembly.h>
|
||||
|
||||
FX_ASSEMBLY_BEGIN()
|
||||
FX_ASSEMBLY_NAME("fx.runtime");
|
||||
FX_ASSEMBLY_VERSION(1, 0, 0, 0);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx", "stream", fx_stream);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx", "string", fx_string);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx", "stringstream", fx_stringstream);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx", "iterator", fx_iterator);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.reflection", "assembly", fx_assembly);
|
||||
FX_ASSEMBLY_END()
|
||||
+60
-69
@@ -1,109 +1,100 @@
|
||||
function(add_fx_module)
|
||||
function(add_fx_assembly)
|
||||
set(options)
|
||||
set(one_value_args NAME)
|
||||
set(multi_value_args
|
||||
NAMESPACES
|
||||
DEPENDENCIES
|
||||
SUBDIRS
|
||||
EXTRA_SOURCES
|
||||
LIBS
|
||||
INCLUDE_DIRS
|
||||
DEFINES)
|
||||
LIBS)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 arg
|
||||
"${options}"
|
||||
"${one_value_args}"
|
||||
"${multi_value_args}")
|
||||
|
||||
set(module_name ${arg_NAME})
|
||||
set(assembly_name ${arg_NAME})
|
||||
string(REPLACE "." "/" assembly_path ${assembly_name})
|
||||
set(assembly_target_name ${assembly_name})
|
||||
string(REPLACE "." "_" assembly_token ${assembly_name})
|
||||
string(TOUPPER ${assembly_token} assembly_token)
|
||||
|
||||
file(GLOB sources *.c *.h)
|
||||
set(assembly_include_paths "")
|
||||
set(assembly_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/assemblies/${assembly_name}.c)
|
||||
|
||||
foreach (dir ${arg_SUBDIRS})
|
||||
file(GLOB dir_sources ${dir}/*.c ${dir}/*.h)
|
||||
set(sources ${sources} ${dir_sources})
|
||||
foreach (dir ${arg_NAMESPACES})
|
||||
add_subdirectory(${dir})
|
||||
set(assembly_sources ${assembly_sources} ${namespace_sources})
|
||||
set(assembly_include_paths ${assembly_include_paths} ${namespace_include_paths})
|
||||
endforeach (dir)
|
||||
|
||||
file(GLOB sys_sources sys/${fx_system_name}/*.c sys/${fx_system_name}/*.h)
|
||||
set(root_header include/fx/${module_name}.h)
|
||||
file(GLOB headers include/fx/${module_name}/*.h)
|
||||
message(STATUS "Building assembly ${assembly_name}")
|
||||
add_library(${assembly_target_name} SHARED
|
||||
${assembly_sources})
|
||||
|
||||
string(REPLACE "-" "_" module_preproc_token ${module_name})
|
||||
string(TOUPPER ${module_preproc_token} module_preproc_token)
|
||||
set(module_preproc_token FX_${module_preproc_token})
|
||||
target_include_directories(${assembly_target_name} PUBLIC ${assembly_include_paths})
|
||||
|
||||
message(STATUS "Building module ${module_name} (shared)")
|
||||
add_library(fx-${module_name} SHARED
|
||||
${sources}
|
||||
${sys_sources}
|
||||
${root_header}
|
||||
${headers}
|
||||
${arg_EXTRA_SOURCES})
|
||||
message(STATUS "Building module ${module_name} (static)")
|
||||
add_library(fx-${module_name}-s STATIC
|
||||
${sources}
|
||||
${sys_sources}
|
||||
${root_header}
|
||||
${headers}
|
||||
${arg_EXTRA_SOURCES})
|
||||
|
||||
target_include_directories(fx-${module_name} PUBLIC include/)
|
||||
target_include_directories(fx-${module_name}-s PUBLIC include/)
|
||||
|
||||
target_compile_definitions(fx-${module_name} PUBLIC
|
||||
${module_preproc_token}
|
||||
target_compile_definitions(${assembly_target_name} PUBLIC
|
||||
FX_EXPORT=1
|
||||
FX_ENABLE_FLOATING_POINT=${fx_enable_floating_point})
|
||||
target_compile_definitions(fx-${module_name}-s PUBLIC
|
||||
${module_preproc_token}
|
||||
FX_EXPORT=1
|
||||
FX_STATIC=1
|
||||
FX_ENABLE_FLOATING_POINT=${fx_enable_floating_point})
|
||||
|
||||
set_target_properties(fx-${module_name}
|
||||
set_target_properties(${assembly_target_name}
|
||||
PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
foreach (dep ${arg_DEPENDENCIES})
|
||||
target_link_libraries(fx-${module_name} fx-${dep})
|
||||
target_link_libraries(fx-${module_name}-s fx-${dep}-s)
|
||||
target_link_libraries(${assembly_target_name} ${dep})
|
||||
endforeach (dep)
|
||||
|
||||
foreach (lib ${arg_LIBS})
|
||||
target_link_libraries(fx-${module_name} ${lib})
|
||||
target_link_libraries(fx-${module_name}-s ${lib})
|
||||
target_link_libraries(${assembly_target_name} ${lib})
|
||||
endforeach (lib)
|
||||
|
||||
foreach (dir ${arg_INCLUDE_DIRS})
|
||||
target_include_directories(fx-${module_name} PRIVATE
|
||||
${dir})
|
||||
target_include_directories(fx-${module_name}-s PRIVATE
|
||||
${dir})
|
||||
target_include_directories(${assembly_target_name} PRIVATE ${dir})
|
||||
endforeach (dir)
|
||||
|
||||
foreach (def ${arg_DEFINES})
|
||||
target_compile_definitions(fx-${module_name} PRIVATE
|
||||
${def})
|
||||
target_compile_definitions(fx-${module_name}-s PRIVATE
|
||||
${def})
|
||||
target_compile_definitions(${assembly_target_name} PRIVATE ${def})
|
||||
endforeach (def)
|
||||
|
||||
set_target_properties(fx-${module_name} PROPERTIES
|
||||
FOLDER "Shared/${module_name}")
|
||||
set_target_properties(fx-${module_name}-s PROPERTIES
|
||||
FOLDER "Static/${module_name}")
|
||||
set_target_properties(${assembly_target_name} PROPERTIES
|
||||
FOLDER "${assembly_name}")
|
||||
|
||||
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
|
||||
if(IS_BIG_ENDIAN)
|
||||
target_compile_definitions(fx-${module_name} PRIVATE
|
||||
BIG_ENDIAN)
|
||||
target_compile_definitions(fx-${module_name}-s PRIVATE
|
||||
target_compile_definitions(${assembly_target_name} PRIVATE
|
||||
BIG_ENDIAN)
|
||||
else()
|
||||
target_compile_definitions(fx-${module_name} PRIVATE
|
||||
LITTLE_ENDIAN)
|
||||
target_compile_definitions(fx-${module_name}-s PRIVATE
|
||||
target_compile_definitions(${assembly_target_name} PRIVATE
|
||||
LITTLE_ENDIAN)
|
||||
endif()
|
||||
|
||||
install(TARGETS fx-${module_name} fx-${module_name}-s)
|
||||
install(FILES ${root_header} DESTINATION include/fx)
|
||||
install(FILES ${headers} DESTINATION include/fx/${module_name})
|
||||
endfunction(add_fx_module)
|
||||
install(TARGETS ${assembly_target_name})
|
||||
install(FILES ${headers} DESTINATION include/${assembly_path})
|
||||
endfunction(add_fx_assembly)
|
||||
|
||||
macro(export_fx_namespace_details)
|
||||
set(options)
|
||||
set(one_value_args NAME)
|
||||
set(multi_value_args)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 arg
|
||||
"${options}"
|
||||
"${one_value_args}"
|
||||
"${multi_value_args}")
|
||||
|
||||
set(namespace_name ${arg_NAME})
|
||||
string(REPLACE "." "/" namespace_path ${namespace_name})
|
||||
set(namespace_target_name ${namespace_name})
|
||||
|
||||
set(namespace_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
|
||||
|
||||
file(GLOB namespace_sources
|
||||
*.c *.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/${namespace_path}/*.h)
|
||||
file(GLOB sys_sources sys/${fx_system_name}/*.c sys/${fx_system_name}/*.h)
|
||||
file(GLOB headers include/${namespace_path}/*.h)
|
||||
set(namespace_sources
|
||||
${namespace_sources}
|
||||
${sys_sources}
|
||||
${headers}
|
||||
PARENT_SCOPE)
|
||||
endmacro(export_fx_namespace_details)
|
||||
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
include(../cmake/Templates.cmake)
|
||||
|
||||
add_fx_module(NAME ds DEPENDENCIES core)
|
||||
export_fx_namespace_details(
|
||||
NAME fx.collections)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/array.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/stream.h>
|
||||
#include <fx/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <fx/ds/bitbuffer.h>
|
||||
#include <fx/collections/bitbuffer.h>
|
||||
|
||||
/*** PRIVATE DATA *************************************************************/
|
||||
|
||||
|
||||
+45
-15
@@ -1,6 +1,6 @@
|
||||
#include <fx/core/bitop.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/bitmap.h>
|
||||
#include <fx/bitop.h>
|
||||
#include <fx/collections/bitmap.h>
|
||||
#include <fx/stream.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BITS_PER_WORD (8 * sizeof(bitmap_word_t))
|
||||
@@ -36,11 +36,17 @@ static void bitmap_clear_bit(struct fx_bitmap_p *map, size_t bit)
|
||||
map->map_words[index] &= ~mask;
|
||||
}
|
||||
|
||||
static void bitmap_set_range(struct fx_bitmap_p *map, size_t first_bit, size_t nbits)
|
||||
static void bitmap_set_range(
|
||||
struct fx_bitmap_p *map,
|
||||
size_t first_bit,
|
||||
size_t nbits)
|
||||
{
|
||||
}
|
||||
|
||||
static void bitmap_clear_range(struct fx_bitmap_p *map, size_t first_bit, size_t nbits)
|
||||
static void bitmap_clear_range(
|
||||
struct fx_bitmap_p *map,
|
||||
size_t first_bit,
|
||||
size_t nbits)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -216,13 +222,21 @@ void fx_bitmap_clear_bit(fx_bitmap *map, size_t bit)
|
||||
void fx_bitmap_set_range(fx_bitmap *map, size_t first_bit, size_t nbits)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_TYPE_BITMAP, bitmap_set_range, map, first_bit, nbits);
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_set_range,
|
||||
map,
|
||||
first_bit,
|
||||
nbits);
|
||||
}
|
||||
|
||||
void fx_bitmap_clear_range(fx_bitmap *map, size_t first_bit, size_t nbits)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_TYPE_BITMAP, bitmap_clear_range, map, first_bit, nbits);
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_clear_range,
|
||||
map,
|
||||
first_bit,
|
||||
nbits);
|
||||
}
|
||||
|
||||
void fx_bitmap_set_all(fx_bitmap *map)
|
||||
@@ -247,7 +261,10 @@ size_t fx_bitmap_count_set_bits(const fx_bitmap *map)
|
||||
|
||||
size_t fx_bitmap_count_clear_bits(const fx_bitmap *map)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BITMAP, bitmap_count_clear_bits, map);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_count_clear_bits,
|
||||
map);
|
||||
}
|
||||
|
||||
size_t fx_bitmap_highest_set_bit(const fx_bitmap *map)
|
||||
@@ -257,7 +274,10 @@ size_t fx_bitmap_highest_set_bit(const fx_bitmap *map)
|
||||
|
||||
size_t fx_bitmap_highest_clear_bit(const fx_bitmap *map)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BITMAP, bitmap_highest_clear_bit, map);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_highest_clear_bit,
|
||||
map);
|
||||
}
|
||||
|
||||
size_t fx_bitmap_lowest_set_bit(const fx_bitmap *map)
|
||||
@@ -267,7 +287,10 @@ size_t fx_bitmap_lowest_set_bit(const fx_bitmap *map)
|
||||
|
||||
size_t fx_bitmap_lowest_clear_bit(const fx_bitmap *map)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BITMAP, bitmap_lowest_clear_bit, map);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_lowest_clear_bit,
|
||||
map);
|
||||
}
|
||||
|
||||
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
|
||||
@@ -285,7 +308,8 @@ static void bitmap_fini(fx_object *obj, void *priv)
|
||||
|
||||
static void bitmap_to_string(const fx_object *obj, fx_stream *out)
|
||||
{
|
||||
const struct fx_bitmap_p *map = fx_object_get_private(obj, FX_TYPE_BITMAP);
|
||||
const struct fx_bitmap_p *map
|
||||
= fx_object_get_private(obj, FX_TYPE_BITMAP);
|
||||
|
||||
unsigned char *bytes = (unsigned char *)map->map_words;
|
||||
size_t nr_bytes = map->map_nr_words * sizeof(bitmap_word_t);
|
||||
@@ -294,10 +318,16 @@ static void bitmap_to_string(const fx_object *obj, fx_stream *out)
|
||||
for (size_t i = 0; i < nr_bytes - 1; i++) {
|
||||
c = bytes[i];
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%c%c%c%c%c%c%c%c", c & 0x80 ? '1' : '0',
|
||||
c & 0x40 ? '1' : '0', c & 0x20 ? '1' : '0',
|
||||
c & 0x10 ? '1' : '0', c & 0x08 ? '1' : '0',
|
||||
c & 0x04 ? '1' : '0', c & 0x02 ? '1' : '0',
|
||||
out,
|
||||
NULL,
|
||||
"%c%c%c%c%c%c%c%c",
|
||||
c & 0x80 ? '1' : '0',
|
||||
c & 0x40 ? '1' : '0',
|
||||
c & 0x20 ? '1' : '0',
|
||||
c & 0x10 ? '1' : '0',
|
||||
c & 0x08 ? '1' : '0',
|
||||
c & 0x04 ? '1' : '0',
|
||||
c & 0x02 ? '1' : '0',
|
||||
c & 0x01 ? '1' : '0');
|
||||
}
|
||||
|
||||
|
||||
+53
-14
@@ -1,5 +1,5 @@
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/ds/buffer.h>
|
||||
#include <fx/collections/buffer.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -21,7 +21,8 @@ static fx_status resize_buffer(struct fx_buffer_p *buffer, size_t new_capacity)
|
||||
{
|
||||
if (buffer->buf_cap < new_capacity) {
|
||||
void *new_data = realloc(
|
||||
buffer->buf_data, new_capacity * buffer->buf_itemsz);
|
||||
buffer->buf_data,
|
||||
new_capacity * buffer->buf_itemsz);
|
||||
if (!new_data) {
|
||||
return FX_ERR_NO_MEMORY;
|
||||
}
|
||||
@@ -29,7 +30,8 @@ static fx_status resize_buffer(struct fx_buffer_p *buffer, size_t new_capacity)
|
||||
buffer->buf_data = new_data;
|
||||
} else {
|
||||
void *new_data = realloc(
|
||||
buffer->buf_data, new_capacity * buffer->buf_itemsz);
|
||||
buffer->buf_data,
|
||||
new_capacity * buffer->buf_itemsz);
|
||||
if (!new_data) {
|
||||
return FX_ERR_NO_MEMORY;
|
||||
}
|
||||
@@ -78,7 +80,10 @@ static enum fx_status buffer_resize(struct fx_buffer_p *buf, size_t length)
|
||||
}
|
||||
|
||||
static enum fx_status buffer_insert(
|
||||
struct fx_buffer_p *buffer, const void *p, size_t count, size_t at)
|
||||
struct fx_buffer_p *buffer,
|
||||
const void *p,
|
||||
size_t count,
|
||||
size_t at)
|
||||
{
|
||||
if (at == FX_NPOS) {
|
||||
at = buffer->buf_len;
|
||||
@@ -110,7 +115,10 @@ static enum fx_status buffer_insert(
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static enum fx_status buffer_remove(struct fx_buffer_p *buffer, size_t at, size_t count)
|
||||
static enum fx_status buffer_remove(
|
||||
struct fx_buffer_p *buffer,
|
||||
size_t at,
|
||||
size_t count)
|
||||
{
|
||||
if (at >= buffer->buf_len) {
|
||||
return FX_ERR_OUT_OF_BOUNDS;
|
||||
@@ -162,7 +170,9 @@ static enum fx_status buffer_clear(struct fx_buffer_p *buffer)
|
||||
}
|
||||
|
||||
static enum fx_status buffer_push_back(
|
||||
struct fx_buffer_p *buf, size_t count, void **p)
|
||||
struct fx_buffer_p *buf,
|
||||
size_t count,
|
||||
void **p)
|
||||
{
|
||||
enum fx_status status = FX_SUCCESS;
|
||||
|
||||
@@ -181,7 +191,9 @@ static enum fx_status buffer_push_back(
|
||||
}
|
||||
|
||||
static enum fx_status buffer_push_front(
|
||||
struct fx_buffer_p *buf, size_t count, void **p)
|
||||
struct fx_buffer_p *buf,
|
||||
size_t count,
|
||||
void **p)
|
||||
{
|
||||
enum fx_status status = FX_SUCCESS;
|
||||
|
||||
@@ -286,7 +298,10 @@ fx_buffer *fx_buffer_create_from_bytes(const void *buf, size_t len)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
fx_buffer *fx_buffer_create_from_array(const void *buf, size_t item_sz, size_t len)
|
||||
fx_buffer *fx_buffer_create_from_array(
|
||||
const void *buf,
|
||||
size_t item_sz,
|
||||
size_t len)
|
||||
{
|
||||
fx_buffer *buffer = fx_object_create(FX_TYPE_BUFFER);
|
||||
if (!buffer) {
|
||||
@@ -325,14 +340,28 @@ enum fx_status fx_buffer_resize(fx_buffer *buf, size_t length)
|
||||
}
|
||||
|
||||
enum fx_status fx_buffer_insert(
|
||||
fx_buffer *buffer, const void *p, size_t count, size_t at)
|
||||
fx_buffer *buffer,
|
||||
const void *p,
|
||||
size_t count,
|
||||
size_t at)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_insert, buffer, p, count, at);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_BUFFER,
|
||||
buffer_insert,
|
||||
buffer,
|
||||
p,
|
||||
count,
|
||||
at);
|
||||
}
|
||||
|
||||
enum fx_status fx_buffer_remove(fx_buffer *buffer, size_t at, size_t count)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_remove, buffer, at, count);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_BUFFER,
|
||||
buffer_remove,
|
||||
buffer,
|
||||
at,
|
||||
count);
|
||||
}
|
||||
|
||||
void *fx_buffer_ptr(const fx_buffer *buffer)
|
||||
@@ -362,12 +391,22 @@ enum fx_status fx_buffer_clear(fx_buffer *buffer)
|
||||
|
||||
enum fx_status fx_buffer_push_back(fx_buffer *buf, size_t count, void **p)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_push_back, buf, count, p);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_BUFFER,
|
||||
buffer_push_back,
|
||||
buf,
|
||||
count,
|
||||
p);
|
||||
}
|
||||
|
||||
enum fx_status fx_buffer_push_front(fx_buffer *buf, size_t count, void **p)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_push_front, buf, count, p);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_BUFFER,
|
||||
buffer_push_front,
|
||||
buf,
|
||||
count,
|
||||
p);
|
||||
}
|
||||
|
||||
enum fx_status fx_buffer_pop_back(fx_buffer *buf, size_t count)
|
||||
|
||||
+58
-19
@@ -1,6 +1,6 @@
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/datetime.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/collections/datetime.h>
|
||||
#include <fx/stream.h>
|
||||
#include <fx/string.h>
|
||||
|
||||
/*** PRIVATE DATA *************************************************************/
|
||||
|
||||
@@ -89,7 +89,8 @@ static bool is_zone_valid(const struct fx_datetime_p *dt)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(dt->dt_zone_offset_minute >= 0 && dt->dt_zone_offset_minute <= 59)) {
|
||||
if (!(dt->dt_zone_offset_minute >= 0
|
||||
&& dt->dt_zone_offset_minute <= 59)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -309,12 +310,18 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *out)
|
||||
static enum fx_status encode_rfc3339(
|
||||
const struct fx_datetime_p *dt,
|
||||
fx_stream *out)
|
||||
{
|
||||
if (dt->dt_has_date) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%04ld-%02ld-%02ld", dt->dt_year,
|
||||
dt->dt_month, dt->dt_day);
|
||||
out,
|
||||
NULL,
|
||||
"%04ld-%02ld-%02ld",
|
||||
dt->dt_year,
|
||||
dt->dt_month,
|
||||
dt->dt_day);
|
||||
}
|
||||
|
||||
if (dt->dt_has_date && dt->dt_has_time) {
|
||||
@@ -323,7 +330,11 @@ static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *
|
||||
|
||||
if (dt->dt_has_time) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%02ld:%02ld:%02ld", dt->dt_hour, dt->dt_min,
|
||||
out,
|
||||
NULL,
|
||||
"%02ld:%02ld:%02ld",
|
||||
dt->dt_hour,
|
||||
dt->dt_min,
|
||||
dt->dt_sec);
|
||||
|
||||
if (dt->dt_msec > 0) {
|
||||
@@ -336,7 +347,9 @@ static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *
|
||||
fx_stream_write_char(out, 'Z');
|
||||
} else {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%c%02ld:%02ld",
|
||||
out,
|
||||
NULL,
|
||||
"%c%02ld:%02ld",
|
||||
dt->dt_zone_offset_negative ? '-' : '+',
|
||||
dt->dt_zone_offset_hour,
|
||||
dt->dt_zone_offset_minute);
|
||||
@@ -348,7 +361,9 @@ static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *
|
||||
}
|
||||
|
||||
static void datetime_to_string(
|
||||
const struct fx_datetime_p *dt, fx_datetime_format format, fx_stream *dest)
|
||||
const struct fx_datetime_p *dt,
|
||||
fx_datetime_format format,
|
||||
fx_stream *dest)
|
||||
{
|
||||
switch (format) {
|
||||
case FX_DATETIME_FORMAT_RFC3339:
|
||||
@@ -453,10 +468,16 @@ fx_datetime *fx_datetime_parse(enum fx_datetime_format format, const char *s)
|
||||
}
|
||||
|
||||
void fx_datetime_to_string(
|
||||
const fx_datetime *dt, fx_datetime_format format, fx_stream *dest)
|
||||
const fx_datetime *dt,
|
||||
fx_datetime_format format,
|
||||
fx_stream *dest)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_DATETIME, datetime_to_string, dt, format, dest);
|
||||
FX_TYPE_DATETIME,
|
||||
datetime_to_string,
|
||||
dt,
|
||||
format,
|
||||
dest);
|
||||
}
|
||||
|
||||
bool fx_datetime_is_localtime(const fx_datetime *dt)
|
||||
@@ -512,17 +533,25 @@ long fx_datetime_subsecond(const fx_datetime *dt)
|
||||
bool fx_datetime_zone_offset_is_negative(const fx_datetime *dt)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_DATETIME, datetime_zone_offset_is_negative, dt);
|
||||
FX_TYPE_DATETIME,
|
||||
datetime_zone_offset_is_negative,
|
||||
dt);
|
||||
}
|
||||
|
||||
long fx_datetime_zone_offset_hour(const fx_datetime *dt)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DATETIME, datetime_zone_offset_hour, dt);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_DATETIME,
|
||||
datetime_zone_offset_hour,
|
||||
dt);
|
||||
}
|
||||
|
||||
long fx_datetime_zone_offset_minute(const fx_datetime *dt)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DATETIME, datetime_zone_offset_minute, dt);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_DATETIME,
|
||||
datetime_zone_offset_minute,
|
||||
dt);
|
||||
}
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
@@ -543,8 +572,12 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
if (dt->dt_has_date) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%04ld-%02ld-%02ld", dt->dt_year,
|
||||
dt->dt_month, dt->dt_day);
|
||||
out,
|
||||
NULL,
|
||||
"%04ld-%02ld-%02ld",
|
||||
dt->dt_year,
|
||||
dt->dt_month,
|
||||
dt->dt_day);
|
||||
}
|
||||
|
||||
if (dt->dt_has_date && dt->dt_has_time) {
|
||||
@@ -553,7 +586,11 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
if (dt->dt_has_time) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%02ld:%02ld:%02ld", dt->dt_hour, dt->dt_min,
|
||||
out,
|
||||
NULL,
|
||||
"%02ld:%02ld:%02ld",
|
||||
dt->dt_hour,
|
||||
dt->dt_min,
|
||||
dt->dt_sec);
|
||||
|
||||
if (dt->dt_msec > 0) {
|
||||
@@ -562,7 +599,9 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
if (!dt->dt_localtime) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, " %c%02ld:%02ld",
|
||||
out,
|
||||
NULL,
|
||||
" %c%02ld:%02ld",
|
||||
dt->dt_zone_offset_negative ? '-' : '+',
|
||||
dt->dt_zone_offset_hour,
|
||||
dt->dt_zone_offset_minute);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/dict.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/collections/dict.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/stream.h>
|
||||
#include <fx/string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
+92
-41
@@ -1,7 +1,7 @@
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/ds/hashmap.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/collections/hashmap.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -42,9 +42,16 @@ struct fx_hashmap_iterator_p {
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
static FX_BST_DEFINE_SIMPLE_GET(
|
||||
struct fx_hashmap_bucket, uint64_t, bk_node, bk_hash, get_bucket);
|
||||
struct fx_hashmap_bucket,
|
||||
uint64_t,
|
||||
bk_node,
|
||||
bk_hash,
|
||||
get_bucket);
|
||||
static FX_BST_DEFINE_SIMPLE_INSERT(
|
||||
struct fx_hashmap_bucket, bk_node, bk_hash, put_bucket);
|
||||
struct fx_hashmap_bucket,
|
||||
bk_node,
|
||||
bk_hash,
|
||||
put_bucket);
|
||||
|
||||
static uint64_t hash_data(const void *p, size_t size)
|
||||
{
|
||||
@@ -69,7 +76,8 @@ static uint64_t hash_key(const struct fx_hashmap_key *key)
|
||||
}
|
||||
|
||||
static bool compare_key(
|
||||
const struct fx_hashmap_key *a, const struct fx_hashmap_key *b)
|
||||
const struct fx_hashmap_key *a,
|
||||
const struct fx_hashmap_key *b)
|
||||
{
|
||||
const void *a_data = NULL, *fx_data = NULL;
|
||||
size_t a_len = 0, fx_len = 0;
|
||||
@@ -99,8 +107,10 @@ static bool compare_key(
|
||||
}
|
||||
|
||||
static bool get_next_node(
|
||||
struct fx_bst_node *cur_node, struct fx_queue_entry *cur_entry,
|
||||
struct fx_bst_node **out_next_node, struct fx_queue_entry **out_next_entry)
|
||||
struct fx_bst_node *cur_node,
|
||||
struct fx_queue_entry *cur_entry,
|
||||
struct fx_bst_node **out_next_node,
|
||||
struct fx_queue_entry **out_next_entry)
|
||||
{
|
||||
struct fx_hashmap_bucket *cur_bucket
|
||||
= fx_unbox(struct fx_hashmap_bucket, cur_node, bk_node);
|
||||
@@ -122,8 +132,10 @@ static bool get_next_node(
|
||||
return false;
|
||||
}
|
||||
|
||||
struct fx_hashmap_bucket *next_bucket
|
||||
= fx_unbox(struct fx_hashmap_bucket, next_node, bk_node);
|
||||
struct fx_hashmap_bucket *next_bucket = fx_unbox(
|
||||
struct fx_hashmap_bucket,
|
||||
next_node,
|
||||
bk_node);
|
||||
if (!next_bucket) {
|
||||
return false;
|
||||
}
|
||||
@@ -169,11 +181,13 @@ static struct fx_hashmap_bucket_item *create_bucket_item(void)
|
||||
}
|
||||
|
||||
static fx_status hashmap_put(
|
||||
struct fx_hashmap_p *hashmap, const fx_hashmap_key *key,
|
||||
struct fx_hashmap_p *hashmap,
|
||||
const fx_hashmap_key *key,
|
||||
const fx_hashmap_value *value)
|
||||
{
|
||||
uint64_t hash = hash_key(key);
|
||||
struct fx_hashmap_bucket *bucket = get_bucket(&hashmap->h_buckets, hash);
|
||||
struct fx_hashmap_bucket *bucket
|
||||
= get_bucket(&hashmap->h_buckets, hash);
|
||||
|
||||
if (!bucket) {
|
||||
bucket = create_bucket();
|
||||
@@ -187,8 +201,10 @@ static fx_status hashmap_put(
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||
while (entry) {
|
||||
struct fx_hashmap_bucket_item *item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, entry, bi_entry);
|
||||
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
|
||||
if (compare_key(&item->bi_key, key)) {
|
||||
memcpy(&item->bi_value, value, sizeof *value);
|
||||
@@ -213,19 +229,23 @@ static fx_status hashmap_put(
|
||||
}
|
||||
|
||||
static const struct fx_hashmap_value *hashmap_get(
|
||||
const struct fx_hashmap_p *hashmap, const struct fx_hashmap_key *key)
|
||||
const struct fx_hashmap_p *hashmap,
|
||||
const struct fx_hashmap_key *key)
|
||||
{
|
||||
uint64_t hash = hash_key(key);
|
||||
|
||||
struct fx_hashmap_bucket *bucket = get_bucket(&hashmap->h_buckets, hash);
|
||||
struct fx_hashmap_bucket *bucket
|
||||
= get_bucket(&hashmap->h_buckets, hash);
|
||||
if (!bucket) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||
while (entry) {
|
||||
struct fx_hashmap_bucket_item *item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, entry, bi_entry);
|
||||
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
|
||||
if (compare_key(&item->bi_key, key)) {
|
||||
return &item->bi_value;
|
||||
@@ -238,18 +258,22 @@ static const struct fx_hashmap_value *hashmap_get(
|
||||
}
|
||||
|
||||
static bool hashmap_has_key(
|
||||
const struct fx_hashmap_p *hashmap, const fx_hashmap_key *key)
|
||||
const struct fx_hashmap_p *hashmap,
|
||||
const fx_hashmap_key *key)
|
||||
{
|
||||
uint64_t hash = hash_key(key);
|
||||
struct fx_hashmap_bucket *bucket = get_bucket(&hashmap->h_buckets, hash);
|
||||
struct fx_hashmap_bucket *bucket
|
||||
= get_bucket(&hashmap->h_buckets, hash);
|
||||
if (!bucket) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||
while (entry) {
|
||||
struct fx_hashmap_bucket_item *item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, entry, bi_entry);
|
||||
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
|
||||
if (compare_key(&item->bi_key, key)) {
|
||||
return true;
|
||||
@@ -276,8 +300,10 @@ static bool hashmap_is_empty(const struct fx_hashmap_p *hashmap)
|
||||
}
|
||||
|
||||
fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
|
||||
struct fx_hashmap_bucket_item *first_item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, first_entry, bi_entry);
|
||||
struct fx_hashmap_bucket_item *first_item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
first_entry,
|
||||
bi_entry);
|
||||
if (!first_item) {
|
||||
return true;
|
||||
}
|
||||
@@ -286,7 +312,8 @@ static bool hashmap_is_empty(const struct fx_hashmap_p *hashmap)
|
||||
}
|
||||
|
||||
static fx_status delete_item(
|
||||
struct fx_hashmap_p *hashmap, struct fx_hashmap_bucket *bucket,
|
||||
struct fx_hashmap_p *hashmap,
|
||||
struct fx_hashmap_bucket *bucket,
|
||||
struct fx_hashmap_bucket_item *item)
|
||||
{
|
||||
fx_queue_delete(&bucket->bk_items, &item->bi_entry);
|
||||
@@ -313,7 +340,8 @@ static fx_status delete_item(
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
fx_hashmap *fx_hashmap_create(
|
||||
fx_hashmap_key_destructor key_dtor, fx_hashmap_value_destructor value_dtor)
|
||||
fx_hashmap_key_destructor key_dtor,
|
||||
fx_hashmap_value_destructor value_dtor)
|
||||
{
|
||||
fx_hashmap *hashmap = fx_object_create(FX_TYPE_HASHMAP);
|
||||
if (!hashmap) {
|
||||
@@ -330,9 +358,11 @@ fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_hashmap_p *p = fx_object_get_private(hashmap, FX_TYPE_HASHMAP);
|
||||
struct fx_hashmap_p *p
|
||||
= fx_object_get_private(hashmap, FX_TYPE_HASHMAP);
|
||||
|
||||
for (size_t i = 0; items[i].key.key_data && items[i].key.key_size; i++) {
|
||||
for (size_t i = 0; items[i].key.key_data && items[i].key.key_size;
|
||||
i++) {
|
||||
hashmap_put(p, &items[i].key, &items[i].value);
|
||||
}
|
||||
|
||||
@@ -340,20 +370,32 @@ fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items)
|
||||
}
|
||||
|
||||
fx_status fx_hashmap_put(
|
||||
fx_hashmap *hashmap, const fx_hashmap_key *key, const fx_hashmap_value *value)
|
||||
fx_hashmap *hashmap,
|
||||
const fx_hashmap_key *key,
|
||||
const fx_hashmap_value *value)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_put, hashmap, key, value);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_HASHMAP,
|
||||
hashmap_put,
|
||||
hashmap,
|
||||
key,
|
||||
value);
|
||||
}
|
||||
|
||||
const struct fx_hashmap_value *fx_hashmap_get(
|
||||
const fx_hashmap *hashmap, const struct fx_hashmap_key *key)
|
||||
const fx_hashmap *hashmap,
|
||||
const struct fx_hashmap_key *key)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_get, hashmap, key);
|
||||
}
|
||||
|
||||
bool fx_hashmap_has_key(const fx_hashmap *hashmap, const fx_hashmap_key *key)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_has_key, hashmap, key);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_HASHMAP,
|
||||
hashmap_has_key,
|
||||
hashmap,
|
||||
key);
|
||||
}
|
||||
|
||||
size_t fx_hashmap_get_size(const fx_hashmap *hashmap)
|
||||
@@ -368,7 +410,8 @@ bool fx_hashmap_is_empty(const fx_hashmap *hashmap)
|
||||
|
||||
fx_iterator *fx_hashmap_begin(fx_hashmap *hashmap)
|
||||
{
|
||||
fx_hashmap_iterator *it_obj = fx_object_create(FX_TYPE_HASHMAP_ITERATOR);
|
||||
fx_hashmap_iterator *it_obj
|
||||
= fx_object_create(FX_TYPE_HASHMAP_ITERATOR);
|
||||
struct fx_hashmap_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_HASHMAP_ITERATOR);
|
||||
|
||||
@@ -391,9 +434,12 @@ fx_iterator *fx_hashmap_begin(fx_hashmap *hashmap)
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
struct fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
|
||||
struct fx_hashmap_bucket_item *first_item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, first_entry, bi_entry);
|
||||
struct fx_queue_entry *first_entry
|
||||
= fx_queue_first(&first_bucket->bk_items);
|
||||
struct fx_hashmap_bucket_item *first_item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
first_entry,
|
||||
bi_entry);
|
||||
if (!first_item) {
|
||||
memset(&it->item, 0x0, sizeof it->item);
|
||||
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
|
||||
@@ -435,8 +481,11 @@ static void hashmap_fini(fx_object *obj, void *priv)
|
||||
struct fx_queue_entry *entry = fx_queue_first(&b->bk_items);
|
||||
while (entry) {
|
||||
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item, entry, bi_entry);
|
||||
struct fx_queue_entry *next_entry = fx_queue_next(entry);
|
||||
struct fx_hashmap_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
struct fx_queue_entry *next_entry
|
||||
= fx_queue_next(entry);
|
||||
fx_queue_delete(&b->bk_items, entry);
|
||||
|
||||
if (map->h_key_dtor) {
|
||||
@@ -444,7 +493,8 @@ static void hashmap_fini(fx_object *obj, void *priv)
|
||||
}
|
||||
|
||||
if (map->h_value_dtor) {
|
||||
map->h_value_dtor((void *)item->bi_value.value_data);
|
||||
map->h_value_dtor(
|
||||
(void *)item->bi_value.value_data);
|
||||
}
|
||||
|
||||
free(item);
|
||||
@@ -524,7 +574,8 @@ static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
|
||||
if (next_item) {
|
||||
memcpy(&it->item.key, &next_item->bi_key, sizeof it->item.key);
|
||||
memcpy(&it->item.value, &next_item->bi_value,
|
||||
memcpy(&it->item.value,
|
||||
&next_item->bi_value,
|
||||
sizeof it->item.value);
|
||||
|
||||
it->_cbn = next_node;
|
||||
|
||||
+17
-13
@@ -9,10 +9,10 @@
|
||||
#ifndef FX_DS_ARRAY_H_
|
||||
#define FX_DS_ARRAY_H_
|
||||
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -51,11 +51,13 @@ FX_TYPE_DEFAULT_CONSTRUCTOR(fx_array, FX_TYPE_ARRAY);
|
||||
* @return A pointer to the new fx_array, or NULL if an error occurred.
|
||||
*/
|
||||
FX_API fx_array *fx_array_create_with_values(
|
||||
fx_object *const *values, size_t nr_values);
|
||||
fx_object *const *values,
|
||||
size_t nr_values);
|
||||
|
||||
/**
|
||||
* Remove all object references from an fx_array, resetting the size of the array to zero.
|
||||
* The reference counts of all objects in the array will be decremented.
|
||||
* Remove all object references from an fx_array, resetting the size of the
|
||||
* array to zero. The reference counts of all objects in the array will be
|
||||
* decremented.
|
||||
*
|
||||
* @param array The fx_array to clear.
|
||||
*/
|
||||
@@ -116,11 +118,12 @@ FX_API fx_status fx_array_remove(fx_array *array, size_t at);
|
||||
|
||||
/**
|
||||
* Removes the object at the beginning of an fx_array. The reference count
|
||||
* of the removed object will be decremented. The remaining objects will be moved
|
||||
* to fill the empty space created by the object's removal.
|
||||
* of the removed object will be decremented. The remaining objects will be
|
||||
* moved to fill the empty space created by the object's removal.
|
||||
*
|
||||
* @param array The fx_array to remove the object from.
|
||||
* @return FX_SUCCESS if the object was removed, or a status code describing any error that occurred.
|
||||
* @return FX_SUCCESS if the object was removed, or a status code describing any
|
||||
* error that occurred.
|
||||
*/
|
||||
FX_API fx_status fx_array_remove_front(fx_array *array);
|
||||
|
||||
@@ -129,7 +132,8 @@ FX_API fx_status fx_array_remove_front(fx_array *array);
|
||||
* of the removed object will be decremented.
|
||||
*
|
||||
* @param array The fx_array to remove the object from.
|
||||
* @return FX_SUCCESS if the object was removed, or a status code describing any error that occurred.
|
||||
* @return FX_SUCCESS if the object was removed, or a status code describing any
|
||||
* error that occurred.
|
||||
*/
|
||||
FX_API fx_status fx_array_remove_back(fx_array *array);
|
||||
|
||||
@@ -162,8 +166,8 @@ FX_API fx_object *fx_array_pop(fx_array *array, size_t at);
|
||||
FX_API fx_object *fx_array_pop_front(fx_array *array);
|
||||
|
||||
/**
|
||||
* Removes the object at the end of an fx_array, and returns a pointer to it. The
|
||||
* reference count of the removed object will NOT be decremented. The caller
|
||||
* Removes the object at the end of an fx_array, and returns a pointer to it.
|
||||
* The reference count of the removed object will NOT be decremented. The caller
|
||||
* becomes the owner of the array's reference to the object.
|
||||
*
|
||||
* @param array The fx_array to remove the object from.
|
||||
+11
-5
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_DS_BITBUFFER_H_
|
||||
#define FX_DS_BITBUFFER_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/macros.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -13,12 +13,18 @@ FX_TYPE_CLASS_DECLARATION_END(fx_bitbuffer);
|
||||
|
||||
FX_API fx_status fx_bitbuffer_put_bit(fx_bitbuffer *buf, int bit);
|
||||
FX_API fx_status fx_bitbuffer_put_bool(fx_bitbuffer *buf, bool b);
|
||||
FX_API fx_status fx_bitbuffer_put_int(
|
||||
fx_bitbuffer *buf, uint64_t v, unsigned int nr_bits);
|
||||
FX_API fx_status
|
||||
fx_bitbuffer_put_int(fx_bitbuffer *buf, uint64_t v, unsigned int nr_bits);
|
||||
FX_API fx_status fx_bitbuffer_put_bytes(
|
||||
fx_bitbuffer *buf, const void *p, size_t len, size_t bits_per_byte);
|
||||
fx_bitbuffer *buf,
|
||||
const void *p,
|
||||
size_t len,
|
||||
size_t bits_per_byte);
|
||||
FX_API fx_status fx_bitbuffer_put_string(
|
||||
fx_bitbuffer *buf, const char *p, size_t len, size_t bits_per_char);
|
||||
fx_bitbuffer *buf,
|
||||
const char *p,
|
||||
size_t len,
|
||||
size_t bits_per_char);
|
||||
|
||||
FX_DECLS_END;
|
||||
|
||||
+6
-3
@@ -1,8 +1,8 @@
|
||||
#ifndef FX_DS_BITMAP_H_
|
||||
#define FX_DS_BITMAP_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -21,7 +21,10 @@ FX_API fx_bitmap *fx_bitmap_create(size_t nr_bits);
|
||||
FX_API void fx_bitmap_set_bit(fx_bitmap *map, size_t bit);
|
||||
FX_API void fx_bitmap_clear_bit(fx_bitmap *map, size_t bit);
|
||||
FX_API void fx_bitmap_set_range(fx_bitmap *map, size_t first_bit, size_t nbits);
|
||||
FX_API void fx_bitmap_clear_range(fx_bitmap *map, size_t first_bit, size_t nbits);
|
||||
FX_API void fx_bitmap_clear_range(
|
||||
fx_bitmap *map,
|
||||
size_t first_bit,
|
||||
size_t nbits);
|
||||
FX_API void fx_bitmap_set_all(fx_bitmap *map);
|
||||
FX_API void fx_bitmap_clear_all(fx_bitmap *map);
|
||||
|
||||
+8
-5
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_DS_BUFFER_H_
|
||||
#define FX_DS_BUFFER_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/macros.h>
|
||||
#include <stddef.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -18,16 +18,19 @@ FX_API fx_type fx_buffer_get_type(void);
|
||||
FX_API fx_buffer *fx_buffer_create(size_t item_sz);
|
||||
FX_API fx_buffer *fx_buffer_create_from_bytes(const void *p, size_t len);
|
||||
FX_API fx_buffer *fx_buffer_create_from_array(
|
||||
const void *p, size_t item_sz, size_t len);
|
||||
const void *p,
|
||||
size_t item_sz,
|
||||
size_t len);
|
||||
|
||||
FX_API void *fx_buffer_steal(fx_buffer *buf);
|
||||
FX_API fx_status fx_buffer_reserve(fx_buffer *buf, size_t capacity);
|
||||
FX_API fx_status fx_buffer_resize(fx_buffer *buf, size_t length);
|
||||
|
||||
FX_API fx_status fx_buffer_append(fx_buffer *dest, const void *p, size_t count);
|
||||
FX_API fx_status fx_buffer_prepend(fx_buffer *dest, const void *p, size_t count);
|
||||
FX_API fx_status fx_buffer_insert(
|
||||
fx_buffer *dest, const void *p, size_t count, size_t at);
|
||||
FX_API fx_status
|
||||
fx_buffer_prepend(fx_buffer *dest, const void *p, size_t count);
|
||||
FX_API fx_status
|
||||
fx_buffer_insert(fx_buffer *dest, const void *p, size_t count, size_t at);
|
||||
FX_API fx_status fx_buffer_remove(fx_buffer *dest, size_t at, size_t count);
|
||||
FX_API fx_status fx_buffer_clear(fx_buffer *buf);
|
||||
|
||||
+4
-3
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_DS_DATETIME_H_
|
||||
#define FX_DS_DATETIME_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <ctype.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -24,7 +24,8 @@ FX_TYPE_DEFAULT_CONSTRUCTOR(fx_datetime, FX_TYPE_DATETIME);
|
||||
|
||||
FX_API fx_datetime *fx_datetime_parse(fx_datetime_format format, const char *s);
|
||||
FX_API void fx_datetime_to_string(
|
||||
const fx_datetime *dt, fx_datetime_format format,
|
||||
const fx_datetime *dt,
|
||||
fx_datetime_format format,
|
||||
FX_TYPE_FWDREF(fx_stream) * dest);
|
||||
|
||||
FX_API bool fx_datetime_is_localtime(const fx_datetime *dt);
|
||||
@@ -1,12 +1,12 @@
|
||||
#ifndef FX_DS_DICT_H_
|
||||
#define FX_DS_DICT_H_
|
||||
|
||||
#include <fx/core/bst.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/bst.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/string.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -29,7 +29,8 @@ FX_TYPE_CLASS_DECLARATION_END(fx_dict_iterator)
|
||||
|
||||
#define fx_dict_foreach(it, dict) \
|
||||
for (int z__fx_unique_name() = fx_dict_iterator_begin(dict, it); \
|
||||
(it)->key != NULL; fx_dict_iterator_next(it))
|
||||
(it)->key != NULL; \
|
||||
fx_dict_iterator_next(it))
|
||||
|
||||
typedef struct fx_dict_item {
|
||||
const fx_string *key;
|
||||
@@ -46,7 +47,8 @@ FX_API fx_dict *fx_dict_create_with_items(const fx_dict_item *items);
|
||||
#endif
|
||||
|
||||
FX_API fx_status fx_dict_put(fx_dict *dict, const char *key, fx_object *value);
|
||||
FX_API fx_status fx_dict_put_sk(fx_dict *dict, const fx_string *key, fx_object *value);
|
||||
FX_API fx_status
|
||||
fx_dict_put_sk(fx_dict *dict, const fx_string *key, fx_object *value);
|
||||
FX_API fx_object *fx_dict_at(const fx_dict *dict, const char *key);
|
||||
FX_API fx_object *fx_dict_at_sk(const fx_dict *dict, const fx_string *key);
|
||||
FX_API fx_object *fx_dict_get(fx_dict *dict, const char *key);
|
||||
+17
-10
@@ -1,11 +1,11 @@
|
||||
#ifndef FX_DS_HASHMAP_H_
|
||||
#define FX_DS_HASHMAP_H_
|
||||
|
||||
#include <fx/core/bst.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/bst.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -34,7 +34,8 @@ FX_TYPE_CLASS_DECLARATION_END(fx_hashmap_iterator)
|
||||
|
||||
#define fx_hashmap_foreach(it, hashmap) \
|
||||
for (int z__fx_unique_name() = fx_hashmap_iterator_begin(hashmap, it); \
|
||||
(it)->key != NULL; fx_hashmap_iterator_next(it))
|
||||
(it)->key != NULL; \
|
||||
fx_hashmap_iterator_next(it))
|
||||
|
||||
typedef void (*fx_hashmap_key_destructor)(void *);
|
||||
typedef void (*fx_hashmap_value_destructor)(void *);
|
||||
@@ -63,15 +64,21 @@ FX_API fx_type fx_hashmap_get_type(void);
|
||||
FX_API fx_type fx_hashmap_iterator_get_type(void);
|
||||
|
||||
FX_API fx_hashmap *fx_hashmap_create(
|
||||
fx_hashmap_key_destructor key_dtor, fx_hashmap_value_destructor value_dtor);
|
||||
fx_hashmap_key_destructor key_dtor,
|
||||
fx_hashmap_value_destructor value_dtor);
|
||||
FX_API fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items);
|
||||
|
||||
FX_API fx_status fx_hashmap_put(
|
||||
fx_hashmap *hashmap, const fx_hashmap_key *key, const fx_hashmap_value *value);
|
||||
fx_hashmap *hashmap,
|
||||
const fx_hashmap_key *key,
|
||||
const fx_hashmap_value *value);
|
||||
FX_API const fx_hashmap_value *fx_hashmap_get(
|
||||
const fx_hashmap *hashmap, const fx_hashmap_key *key);
|
||||
const fx_hashmap *hashmap,
|
||||
const fx_hashmap_key *key);
|
||||
|
||||
FX_API bool fx_hashmap_has_key(const fx_hashmap *hashmap, const fx_hashmap_key *key);
|
||||
FX_API bool fx_hashmap_has_key(
|
||||
const fx_hashmap *hashmap,
|
||||
const fx_hashmap_key *key);
|
||||
FX_API size_t fx_hashmap_get_size(const fx_hashmap *hashmap);
|
||||
FX_API bool fx_hashmap_is_empty(const fx_hashmap *hashmap);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_DS_LIST_H_
|
||||
#define FX_DS_LIST_H_
|
||||
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -39,9 +39,13 @@ FX_API fx_list_entry *fx_list_prev(const fx_list_entry *entry);
|
||||
FX_API size_t fx_list_length(const fx_list *q);
|
||||
|
||||
FX_API fx_list_entry *fx_list_insert_before(
|
||||
fx_list *q, void *ptr, fx_list_entry *before);
|
||||
fx_list *q,
|
||||
void *ptr,
|
||||
fx_list_entry *before);
|
||||
FX_API fx_list_entry *fx_list_insert_after(
|
||||
fx_list *q, void *ptr, fx_list_entry *after);
|
||||
fx_list *q,
|
||||
void *ptr,
|
||||
fx_list_entry *after);
|
||||
|
||||
FX_API fx_list_entry *fx_list_push_front(fx_list *q, void *ptr);
|
||||
FX_API fx_list_entry *fx_list_push_back(fx_list *q, void *ptr);
|
||||
+4
-2
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_DS_NUMBER_H
|
||||
#define FX_DS_NUMBER_H
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/macros.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -133,7 +133,9 @@ static inline fx_number *fx_number_create_size_t(size_t value)
|
||||
|
||||
FX_API fx_number_type fx_number_get_number_type(const fx_number *number);
|
||||
FX_API int fx_number_get_value(
|
||||
const fx_number *number, fx_number_type type, void *value_ptr);
|
||||
const fx_number *number,
|
||||
fx_number_type type,
|
||||
void *value_ptr);
|
||||
|
||||
static inline int8_t fx_number_get_int8(const fx_number *number)
|
||||
{
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef FX_DS_TREE_H_
|
||||
#define FX_DS_TREE_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/string.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -50,7 +50,8 @@ FX_API fx_iterator *fx_tree_node_begin(fx_tree_node *node);
|
||||
FX_API const fx_iterator *fx_tree_node_cbegin(const fx_tree_node *node);
|
||||
|
||||
FX_API fx_iterator *fx_tree_node_begin_recursive(fx_tree_node *node);
|
||||
FX_API const fx_iterator *fx_tree_node_cbegin_recursive(const fx_tree_node *node);
|
||||
FX_API const fx_iterator *fx_tree_node_cbegin_recursive(
|
||||
const fx_tree_node *node);
|
||||
|
||||
FX_DECLS_END;
|
||||
|
||||
+26
-11
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_DS_UUID_H_
|
||||
#define FX_DS_UUID_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/string.h>
|
||||
|
||||
#define FX_UUID_NBYTES 16
|
||||
#define FX_UUID_STRING_MAX 37
|
||||
@@ -29,19 +29,34 @@ FX_API fx_type fx_uuid_get_type(void);
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_uuid, FX_TYPE_UUID);
|
||||
|
||||
FX_API fx_uuid *fx_uuid_create_from_bytes(
|
||||
unsigned char u00, unsigned char u01, unsigned char u02,
|
||||
unsigned char u03, unsigned char u04, unsigned char u05,
|
||||
unsigned char u06, unsigned char u07, unsigned char u08,
|
||||
unsigned char u09, unsigned char u10, unsigned char u11, unsigned char u12,
|
||||
unsigned char u13, unsigned char u14, unsigned char u15);
|
||||
FX_API fx_uuid *fx_uuid_create_from_bytev(const unsigned char bytes[FX_UUID_NBYTES]);
|
||||
unsigned char u00,
|
||||
unsigned char u01,
|
||||
unsigned char u02,
|
||||
unsigned char u03,
|
||||
unsigned char u04,
|
||||
unsigned char u05,
|
||||
unsigned char u06,
|
||||
unsigned char u07,
|
||||
unsigned char u08,
|
||||
unsigned char u09,
|
||||
unsigned char u10,
|
||||
unsigned char u11,
|
||||
unsigned char u12,
|
||||
unsigned char u13,
|
||||
unsigned char u14,
|
||||
unsigned char u15);
|
||||
FX_API fx_uuid *fx_uuid_create_from_bytev(
|
||||
const unsigned char bytes[FX_UUID_NBYTES]);
|
||||
FX_API fx_uuid *fx_uuid_create_from_uuid_bytes(const fx_uuid_bytes *bytes);
|
||||
FX_API fx_uuid *fx_uuid_create_from_string(const fx_string *string);
|
||||
FX_API fx_uuid *fx_uuid_create_from_cstr(const char *s);
|
||||
|
||||
FX_API fx_status fx_uuid_to_cstr(const fx_uuid *uuid, char out[FX_UUID_STRING_MAX]);
|
||||
FX_API fx_status fx_uuid_to_cstr(
|
||||
const fx_uuid *uuid,
|
||||
char out[FX_UUID_STRING_MAX]);
|
||||
FX_API void fx_uuid_get_bytes(
|
||||
const fx_uuid *uuid, unsigned char bytes[FX_UUID_NBYTES]);
|
||||
const fx_uuid *uuid,
|
||||
unsigned char bytes[FX_UUID_NBYTES]);
|
||||
FX_API void fx_uuid_get_uuid_bytes(const fx_uuid *uuid, fx_uuid_bytes *bytes);
|
||||
FX_API fx_uuid_bytes *fx_uuid_ptr(fx_uuid *uuid);
|
||||
|
||||
+30
-10
@@ -1,6 +1,6 @@
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/ds/list.h>
|
||||
#include <fx/collections/list.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/queue.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -109,7 +109,9 @@ static struct fx_list_entry *make_entry(void *item)
|
||||
}
|
||||
|
||||
static struct fx_list_entry *list_insert_before(
|
||||
struct fx_list_p *q, void *ptr, struct fx_list_entry *before)
|
||||
struct fx_list_p *q,
|
||||
void *ptr,
|
||||
struct fx_list_entry *before)
|
||||
{
|
||||
struct fx_list_entry *entry = make_entry(ptr);
|
||||
if (!entry) {
|
||||
@@ -122,7 +124,9 @@ static struct fx_list_entry *list_insert_before(
|
||||
}
|
||||
|
||||
static struct fx_list_entry *list_insert_after(
|
||||
struct fx_list_p *q, void *ptr, struct fx_list_entry *after)
|
||||
struct fx_list_p *q,
|
||||
void *ptr,
|
||||
struct fx_list_entry *after)
|
||||
{
|
||||
struct fx_list_entry *entry = make_entry(ptr);
|
||||
if (!entry) {
|
||||
@@ -226,7 +230,9 @@ static fx_status list_delete_item(struct fx_list_p *q, void *ptr)
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_status list_delete_entry(struct fx_list_p *q, struct fx_list_entry *entry)
|
||||
static fx_status list_delete_entry(
|
||||
struct fx_list_p *q,
|
||||
struct fx_list_entry *entry)
|
||||
{
|
||||
fx_queue_delete(&q->l_queue, &entry->e_entry);
|
||||
q->l_len--;
|
||||
@@ -314,15 +320,29 @@ size_t fx_list_length(const fx_list *q)
|
||||
}
|
||||
|
||||
struct fx_list_entry *fx_list_insert_before(
|
||||
fx_list *q, void *ptr, struct fx_list_entry *before)
|
||||
fx_list *q,
|
||||
void *ptr,
|
||||
struct fx_list_entry *before)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_LIST, list_insert_before, q, ptr, before);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_LIST,
|
||||
list_insert_before,
|
||||
q,
|
||||
ptr,
|
||||
before);
|
||||
}
|
||||
|
||||
struct fx_list_entry *fx_list_insert_after(
|
||||
fx_list *q, void *ptr, struct fx_list_entry *after)
|
||||
fx_list *q,
|
||||
void *ptr,
|
||||
struct fx_list_entry *after)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_LIST, list_insert_after, q, ptr, after);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_LIST,
|
||||
list_insert_after,
|
||||
q,
|
||||
ptr,
|
||||
after);
|
||||
}
|
||||
|
||||
struct fx_list_entry *fx_list_push_front(fx_list *q, void *ptr)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/number.h>
|
||||
#include <fx/collections/number.h>
|
||||
#include <fx/stream.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
+17
-7
@@ -1,4 +1,4 @@
|
||||
#include <fx/ds/tree.h>
|
||||
#include <fx/collections/tree.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -33,7 +33,9 @@ static void tree_set_root(struct fx_tree_p *tree, struct fx_tree_node *node)
|
||||
}
|
||||
|
||||
static const struct fx_tree_node *next_node(
|
||||
const struct fx_tree_node *node, bool recursive, int *depth_diff)
|
||||
const struct fx_tree_node *node,
|
||||
bool recursive,
|
||||
int *depth_diff)
|
||||
{
|
||||
if (!node) {
|
||||
return NULL;
|
||||
@@ -101,7 +103,8 @@ static void remove_node(struct fx_tree_node *node)
|
||||
}
|
||||
|
||||
static void reparent_children(
|
||||
struct fx_tree_node *old_parent, struct fx_tree_node *new_parent)
|
||||
struct fx_tree_node *old_parent,
|
||||
struct fx_tree_node *new_parent)
|
||||
{
|
||||
struct fx_tree_node *last = NODE_FIRST_CHILD(new_parent);
|
||||
while (last && NODE_NEXT_SIBLING(last)) {
|
||||
@@ -132,7 +135,9 @@ void fx_tree_set_root(fx_tree *tree, struct fx_tree_node *node)
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_TREE, tree_set_root, tree, node);
|
||||
}
|
||||
|
||||
void fx_tree_node_add_child(struct fx_tree_node *parent, struct fx_tree_node *child)
|
||||
void fx_tree_node_add_child(
|
||||
struct fx_tree_node *parent,
|
||||
struct fx_tree_node *child)
|
||||
{
|
||||
if (NODE_PARENT(child)) {
|
||||
return;
|
||||
@@ -152,7 +157,9 @@ void fx_tree_node_add_child(struct fx_tree_node *parent, struct fx_tree_node *ch
|
||||
NODE_NEXT_SIBLING(cur) = child;
|
||||
}
|
||||
|
||||
void fx_tree_node_add_sibling(struct fx_tree_node *node, struct fx_tree_node *to_add)
|
||||
void fx_tree_node_add_sibling(
|
||||
struct fx_tree_node *node,
|
||||
struct fx_tree_node *to_add)
|
||||
{
|
||||
if (NODE_PARENT(to_add) || !NODE_PARENT(node)) {
|
||||
return;
|
||||
@@ -161,7 +168,9 @@ void fx_tree_node_add_sibling(struct fx_tree_node *node, struct fx_tree_node *to
|
||||
fx_tree_node_add_child(NODE_PARENT(node), to_add);
|
||||
}
|
||||
|
||||
struct fx_tree_node *fx_tree_node_get_child(struct fx_tree_node *node, size_t at)
|
||||
struct fx_tree_node *fx_tree_node_get_child(
|
||||
struct fx_tree_node *node,
|
||||
size_t at)
|
||||
{
|
||||
size_t i = 0;
|
||||
struct fx_tree_node *cur = NODE_FIRST_CHILD(node);
|
||||
@@ -233,7 +242,8 @@ fx_iterator *fx_tree_node_begin_recursive(struct fx_tree_node *node)
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
const fx_iterator *fx_tree_node_cbegin_recursive(const struct fx_tree_node *node)
|
||||
const fx_iterator *fx_tree_node_cbegin_recursive(
|
||||
const struct fx_tree_node *node)
|
||||
{
|
||||
return fx_tree_node_begin_recursive((struct fx_tree_node *)node);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <ctype.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/ds/uuid.h>
|
||||
#include <fx/collections/uuid.h>
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
set(namespace_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
|
||||
|
||||
file(GLOB namespace_sources
|
||||
*.c *.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/fx/reflection/*.h)
|
||||
set(namespace_sources ${namespace_sources} PARENT_SCOPE)
|
||||
@@ -0,0 +1,264 @@
|
||||
#include <fx/bst.h>
|
||||
#include <fx/hash.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/reflection/assembly.h>
|
||||
|
||||
enum map_entry_type {
|
||||
MAP_ENTRY_NONE = 0,
|
||||
MAP_ENTRY_ITEM,
|
||||
MAP_ENTRY_BUCKET,
|
||||
};
|
||||
|
||||
struct map_entry {
|
||||
enum map_entry_type e_type;
|
||||
uint64_t e_hash;
|
||||
union {
|
||||
fx_queue_entry e_entry;
|
||||
fx_bst_node e_node;
|
||||
};
|
||||
};
|
||||
|
||||
struct map_bucket {
|
||||
struct map_entry b_entry;
|
||||
fx_queue b_items;
|
||||
};
|
||||
|
||||
struct map_item {
|
||||
struct map_entry i_entry;
|
||||
const char *i_name;
|
||||
};
|
||||
|
||||
struct map {
|
||||
fx_bst m_entries;
|
||||
};
|
||||
|
||||
struct type {
|
||||
struct map_item e_map_item;
|
||||
fx_type e_type;
|
||||
};
|
||||
|
||||
struct fx_assembly_p {
|
||||
const char *a_name;
|
||||
struct map a_types;
|
||||
|
||||
struct {
|
||||
long v_major;
|
||||
long v_minor;
|
||||
long v_build;
|
||||
long v_revision;
|
||||
} a_version;
|
||||
};
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
FX_BST_DEFINE_SIMPLE_GET(
|
||||
struct map_entry,
|
||||
uint64_t,
|
||||
e_node,
|
||||
e_hash,
|
||||
map_get_entry);
|
||||
FX_BST_DEFINE_SIMPLE_INSERT(struct map_entry, e_node, e_hash, map_put_entry);
|
||||
|
||||
static struct map_bucket *map_item_convert_to_bucket(
|
||||
struct map *map,
|
||||
struct map_item *item)
|
||||
{
|
||||
struct map_bucket *bucket = malloc(sizeof *bucket);
|
||||
|
||||
memset(bucket, 0x0, sizeof *bucket);
|
||||
|
||||
bucket->b_entry.e_hash = item->i_entry.e_hash;
|
||||
bucket->b_entry.e_type = MAP_ENTRY_BUCKET;
|
||||
|
||||
fx_bst_delete(&map->m_entries, &item->i_entry.e_node);
|
||||
fx_queue_push_back(&bucket->b_items, &item->i_entry.e_entry);
|
||||
map_put_entry(&map->m_entries, &bucket->b_entry);
|
||||
|
||||
return bucket;
|
||||
}
|
||||
|
||||
static void map_put(struct map *map, const char *name, struct map_item *item)
|
||||
{
|
||||
uint64_t hash = fx_hash_cstr(name);
|
||||
|
||||
item->i_entry.e_type = MAP_ENTRY_ITEM;
|
||||
item->i_entry.e_hash = hash;
|
||||
item->i_name = name;
|
||||
|
||||
struct map_entry *entry = map_get_entry(&map->m_entries, hash);
|
||||
if (!entry) {
|
||||
map_put_entry(&map->m_entries, &item->i_entry);
|
||||
return;
|
||||
}
|
||||
|
||||
struct map_item *existing_item = NULL;
|
||||
struct map_bucket *bucket = NULL;
|
||||
switch (entry->e_type) {
|
||||
case MAP_ENTRY_ITEM:
|
||||
existing_item = (struct map_item *)entry;
|
||||
bucket = map_item_convert_to_bucket(map, existing_item);
|
||||
fx_queue_push_back(&bucket->b_items, &item->i_entry.e_entry);
|
||||
break;
|
||||
case MAP_ENTRY_BUCKET:
|
||||
bucket = (struct map_bucket *)entry;
|
||||
fx_queue_push_back(&bucket->b_items, &item->i_entry.e_entry);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void assembly_set_name(struct fx_assembly_p *asm, const char *name)
|
||||
{
|
||||
asm->a_name = name;
|
||||
}
|
||||
|
||||
static void assembly_set_version(
|
||||
struct fx_assembly_p *asm,
|
||||
long major,
|
||||
long minor,
|
||||
long build,
|
||||
long revision)
|
||||
{
|
||||
asm->a_version.v_major = major;
|
||||
asm->a_version.v_minor = minor;
|
||||
asm->a_version.v_build = build;
|
||||
asm->a_version.v_revision = revision;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
static void assembly_add_type(
|
||||
struct fx_assembly_p *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id)
|
||||
{
|
||||
struct type *type = malloc(sizeof *type);
|
||||
memset(type, 0x0, sizeof *type);
|
||||
|
||||
map_put(&asm->a_types, full_name, &type->e_map_item);
|
||||
}
|
||||
|
||||
static void map_item_dump(struct map_item *item)
|
||||
{
|
||||
struct type *type = (struct type *)item;
|
||||
printf(" Type: %s\n", type->e_map_item.i_name);
|
||||
}
|
||||
|
||||
static void assembly_dump(struct fx_assembly_p *asm)
|
||||
{
|
||||
printf("Loaded assembly:\n");
|
||||
printf(" %s, Version=%ld.%ld.%ld.%ld\n",
|
||||
asm->a_name,
|
||||
asm->a_version.v_major,
|
||||
asm->a_version.v_minor,
|
||||
asm->a_version.v_build,
|
||||
asm->a_version.v_revision);
|
||||
|
||||
fx_bst_node *cur_node = fx_bst_first(&asm->a_types.m_entries);
|
||||
while (cur_node) {
|
||||
struct map_entry *entry
|
||||
= fx_unbox(struct map_entry, cur_node, e_node);
|
||||
switch (entry->e_type) {
|
||||
case MAP_ENTRY_ITEM: {
|
||||
struct map_item *item = (struct map_item *)entry;
|
||||
map_item_dump(item);
|
||||
break;
|
||||
}
|
||||
|
||||
case MAP_ENTRY_BUCKET: {
|
||||
struct map_bucket *bucket = (struct map_bucket *)entry;
|
||||
fx_queue_entry *cur_qentry
|
||||
= fx_queue_first(&bucket->b_items);
|
||||
while (cur_qentry) {
|
||||
struct map_item *item = fx_unbox(
|
||||
struct map_item,
|
||||
cur_qentry,
|
||||
i_entry.e_entry);
|
||||
map_item_dump(item);
|
||||
cur_qentry = fx_queue_next(cur_qentry);
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cur_node = fx_bst_next(cur_node);
|
||||
}
|
||||
}
|
||||
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
void fx_assembly_set_name(fx_assembly *asm, const char *name)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
assembly_set_name,
|
||||
asm,
|
||||
name);
|
||||
}
|
||||
|
||||
void fx_assembly_set_version(
|
||||
fx_assembly *asm,
|
||||
long major,
|
||||
long minor,
|
||||
long build,
|
||||
long revision)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
assembly_set_version,
|
||||
asm,
|
||||
major,
|
||||
minor,
|
||||
build,
|
||||
revision);
|
||||
}
|
||||
|
||||
void fx_assembly_add_type(
|
||||
fx_assembly *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
assembly_add_type,
|
||||
asm,
|
||||
full_name,
|
||||
type_id);
|
||||
}
|
||||
|
||||
void fx_assembly_dump(const fx_assembly *asm)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
assembly_dump,
|
||||
asm);
|
||||
}
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
|
||||
static void assembly_init(fx_object *obj, void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
static void assembly_fini(fx_object *obj, void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_string DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_assembly)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_assembly)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_assembly)
|
||||
FX_TYPE_ID(0xf6690c30, 0x6642, 0x42f0, 0xb79f, 0xe2baf3684b1b);
|
||||
FX_TYPE_CLASS(fx_assembly_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_assembly_p);
|
||||
FX_TYPE_INSTANCE_INIT(assembly_init);
|
||||
FX_TYPE_INSTANCE_FINI(assembly_fini);
|
||||
FX_TYPE_DEFINITION_END(fx_assembly)
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef FX_REFLECTION_ASSEMBLY_H_
|
||||
#define FX_REFLECTION_ASSEMBLY_H_
|
||||
|
||||
#include <fx/macros.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
#define FX_REFLECTION_TYPE_ASSEMBLY (fx_assembly_get_type())
|
||||
|
||||
FX_DECLARE_TYPE(fx_assembly);
|
||||
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_assembly)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_assembly)
|
||||
|
||||
FX_API fx_type fx_assembly_get_type();
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_assembly, FX_REFLECTION_TYPE_ASSEMBLY);
|
||||
|
||||
FX_API void fx_assembly_set_name(fx_assembly *asm, const char *name);
|
||||
FX_API void fx_assembly_set_version(
|
||||
fx_assembly *asm,
|
||||
long major,
|
||||
long minor,
|
||||
long build,
|
||||
long revision);
|
||||
|
||||
FX_API void fx_assembly_add_type(
|
||||
fx_assembly *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id);
|
||||
|
||||
FX_API void fx_assembly_dump(const fx_assembly *asm);
|
||||
|
||||
FX_DECLS_END
|
||||
;
|
||||
|
||||
#endif
|
||||
+6
-4
@@ -1,5 +1,7 @@
|
||||
include(../cmake/Templates.cmake)
|
||||
set(namespace_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
|
||||
|
||||
add_fx_module(
|
||||
NAME core
|
||||
SUBDIRS hash)
|
||||
file(GLOB namespace_sources
|
||||
*.c *.h
|
||||
hash/*.c hash/*.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/fx/*.h)
|
||||
set(namespace_sources ${namespace_sources} PARENT_SCOPE)
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
provide a comparator function.
|
||||
*/
|
||||
|
||||
#include <fx/core/bst.h>
|
||||
#include <fx/bst.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
@@ -419,7 +419,8 @@ void fx_bst_insert_fixup(struct fx_bst *tree, struct fx_bst_node *node)
|
||||
@param node the node to delete.
|
||||
*/
|
||||
static struct fx_bst_node *remove_node_with_no_children(
|
||||
struct fx_bst *tree, struct fx_bst_node *node)
|
||||
struct fx_bst *tree,
|
||||
struct fx_bst_node *node)
|
||||
{
|
||||
struct fx_bst_node *w = node->n_parent;
|
||||
struct fx_bst_node *p = node->n_parent;
|
||||
@@ -452,7 +453,8 @@ static struct fx_bst_node *remove_node_with_no_children(
|
||||
@param node the node to delete.
|
||||
*/
|
||||
static struct fx_bst_node *replace_node_with_one_subst(
|
||||
struct fx_bst *tree, struct fx_bst_node *node)
|
||||
struct fx_bst *tree,
|
||||
struct fx_bst_node *node)
|
||||
{
|
||||
struct fx_bst_node *p = node->n_parent;
|
||||
struct fx_bst_node *z = NULL;
|
||||
@@ -501,7 +503,8 @@ static struct fx_bst_node *replace_node_with_one_subst(
|
||||
@param z the node to delete.
|
||||
*/
|
||||
static struct fx_bst_node *replace_node_with_two_substs(
|
||||
struct fx_bst *tree, struct fx_bst_node *z)
|
||||
struct fx_bst *tree,
|
||||
struct fx_bst_node *z)
|
||||
{
|
||||
/* x will replace z */
|
||||
struct fx_bst_node *x = z->n_left;
|
||||
@@ -737,7 +740,9 @@ fx_bst_node *fx_bst_prev(const struct fx_bst_node *node)
|
||||
}
|
||||
|
||||
void fx_bst_move(
|
||||
struct fx_bst *tree, struct fx_bst_node *dest, struct fx_bst_node *src)
|
||||
struct fx_bst *tree,
|
||||
struct fx_bst_node *dest,
|
||||
struct fx_bst_node *src)
|
||||
{
|
||||
if (src->n_parent) {
|
||||
if (src->n_parent->n_left == src) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "printf.h"
|
||||
|
||||
#include <fx/core/bstr.h>
|
||||
#include <fx/core/rope.h>
|
||||
#include <fx/bstr.h>
|
||||
#include <fx/rope.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -153,7 +153,10 @@ static void bstr_fctprintf(char c, void *arg)
|
||||
}
|
||||
|
||||
static enum fx_status bstr_putcs(
|
||||
struct fx_bstr *str, const char *s, size_t len, size_t *nr_written)
|
||||
struct fx_bstr *str,
|
||||
const char *s,
|
||||
size_t len,
|
||||
size_t *nr_written)
|
||||
{
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
formatter_putchar(str, s[i]);
|
||||
@@ -166,7 +169,10 @@ static enum fx_status bstr_putcs(
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static enum fx_status bstr_puts(struct fx_bstr *str, const char *s, size_t *nr_written)
|
||||
static enum fx_status bstr_puts(
|
||||
struct fx_bstr *str,
|
||||
const char *s,
|
||||
size_t *nr_written)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; s[i]; i++) {
|
||||
@@ -222,18 +228,26 @@ enum fx_status fx_bstr_write_char(struct fx_bstr *str, char c)
|
||||
}
|
||||
|
||||
enum fx_status fx_bstr_write_chars(
|
||||
struct fx_bstr *str, const char *s, size_t len, size_t *nr_written)
|
||||
struct fx_bstr *str,
|
||||
const char *s,
|
||||
size_t len,
|
||||
size_t *nr_written)
|
||||
{
|
||||
return bstr_putcs(str, s, len, nr_written);
|
||||
}
|
||||
|
||||
enum fx_status fx_bstr_write_cstr(struct fx_bstr *str, const char *s, size_t *nr_written)
|
||||
enum fx_status fx_bstr_write_cstr(
|
||||
struct fx_bstr *str,
|
||||
const char *s,
|
||||
size_t *nr_written)
|
||||
{
|
||||
return bstr_puts(str, s, nr_written);
|
||||
}
|
||||
|
||||
enum fx_status fx_bstr_write_cstr_list(
|
||||
struct fx_bstr *str, const char **strs, size_t *nr_written)
|
||||
struct fx_bstr *str,
|
||||
const char **strs,
|
||||
size_t *nr_written)
|
||||
{
|
||||
size_t w = 0;
|
||||
enum fx_status status = FX_SUCCESS;
|
||||
@@ -256,7 +270,10 @@ enum fx_status fx_bstr_write_cstr_list(
|
||||
}
|
||||
|
||||
enum fx_status fx_bstr_write_cstr_array(
|
||||
struct fx_bstr *str, const char **strs, size_t count, size_t *nr_written)
|
||||
struct fx_bstr *str,
|
||||
const char **strs,
|
||||
size_t count,
|
||||
size_t *nr_written)
|
||||
{
|
||||
enum fx_status status = FX_SUCCESS;
|
||||
size_t w = 0;
|
||||
@@ -308,7 +325,9 @@ enum fx_status fx_bstr_add_many(struct fx_bstr *str, size_t *nr_written, ...)
|
||||
}
|
||||
|
||||
enum fx_status fx_bstr_write_rope(
|
||||
fx_bstr *strv, const struct fx_rope *rope, size_t *nr_written)
|
||||
fx_bstr *strv,
|
||||
const struct fx_rope *rope,
|
||||
size_t *nr_written)
|
||||
{
|
||||
size_t start = strv->bstr_len;
|
||||
enum fx_status status = fx_rope_to_bstr(rope, strv);
|
||||
@@ -322,18 +341,25 @@ enum fx_status fx_bstr_write_rope(
|
||||
}
|
||||
|
||||
enum fx_status fx_bstr_write_fmt(
|
||||
struct fx_bstr *str, size_t *nr_written, const char *format, ...)
|
||||
struct fx_bstr *str,
|
||||
size_t *nr_written,
|
||||
const char *format,
|
||||
...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
enum fx_status result = fx_bstr_write_vfmt(str, nr_written, format, arg);
|
||||
enum fx_status result
|
||||
= fx_bstr_write_vfmt(str, nr_written, format, arg);
|
||||
va_end(arg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
enum fx_status fx_bstr_write_vfmt(
|
||||
struct fx_bstr *str, size_t *nr_written, const char *format, va_list arg)
|
||||
struct fx_bstr *str,
|
||||
size_t *nr_written,
|
||||
const char *format,
|
||||
va_list arg)
|
||||
{
|
||||
size_t start = str->bstr_len;
|
||||
z__fx_fctprintf(bstr_fctprintf, str, format, arg);
|
||||
|
||||
+3
-2
@@ -3,7 +3,7 @@
|
||||
#include "type.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <fx/core/class.h>
|
||||
#include <fx/class.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -48,7 +48,8 @@ void *fx_class_get_interface(const struct _fx_class *c, const union fx_type *id)
|
||||
}
|
||||
|
||||
fx_result fx_class_instantiate(
|
||||
struct fx_type_registration *type, struct _fx_class **out_class)
|
||||
struct fx_type_registration *type,
|
||||
struct _fx_class **out_class)
|
||||
{
|
||||
struct _fx_class *out = malloc(type->r_class_size);
|
||||
if (!out) {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
#ifndef _CLASS_H_
|
||||
#define _CLASS_H_
|
||||
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct fx_type_registration;
|
||||
|
||||
+4
-2
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/encoding.h>
|
||||
#include <fx/encoding.h>
|
||||
#include <wctype.h>
|
||||
|
||||
bool fx_wchar_is_number(fx_wchar c)
|
||||
@@ -1364,7 +1364,9 @@ size_t fx_wchar_utf8_codepoint_count(const char *s, size_t nr_bytes)
|
||||
return nr_codepoints;
|
||||
}
|
||||
|
||||
size_t fx_wchar_utf8_string_encoded_size(const fx_wchar *s, size_t nr_codepoints)
|
||||
size_t fx_wchar_utf8_string_encoded_size(
|
||||
const fx_wchar *s,
|
||||
size_t nr_codepoints)
|
||||
{
|
||||
size_t len = 0;
|
||||
for (size_t i = 0; i < nr_codepoints; i++) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/endian.h>
|
||||
#include <fx/endian.h>
|
||||
|
||||
fx_i16 fx_i16_htob(uint16_t v)
|
||||
{
|
||||
|
||||
+191
-84
@@ -1,12 +1,13 @@
|
||||
#include "error.h"
|
||||
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void default_error_reporter(
|
||||
const struct fx_error *error, enum fx_error_report_flags flags);
|
||||
const struct fx_error *error,
|
||||
enum fx_error_report_flags flags);
|
||||
static void free_error(struct fx_error *error);
|
||||
static void do_free_error(struct fx_error *error);
|
||||
|
||||
@@ -16,13 +17,15 @@ static const struct fx_error_vendor builtin_vendor;
|
||||
static struct fx_queue free_errors = FX_QUEUE_INIT;
|
||||
static struct fx_queue allocated_errors = FX_QUEUE_INIT;
|
||||
static fx_error_report_function error_reporter = default_error_reporter;
|
||||
static enum fx_error_report_flags error_reporter_flags = FX_ERROR_REPORT_DEFAULT;
|
||||
static enum fx_error_report_flags error_reporter_flags
|
||||
= FX_ERROR_REPORT_DEFAULT;
|
||||
|
||||
static void error_cleanup(void)
|
||||
{
|
||||
struct fx_queue_entry *entry = fx_queue_pop_back(&allocated_errors);
|
||||
while (entry) {
|
||||
struct fx_error *error = fx_unbox(struct fx_error, entry, err_entry);
|
||||
struct fx_error *error
|
||||
= fx_unbox(struct fx_error, entry, err_entry);
|
||||
do_free_error(error);
|
||||
free(error);
|
||||
|
||||
@@ -31,7 +34,8 @@ static void error_cleanup(void)
|
||||
|
||||
entry = fx_queue_pop_back(&free_errors);
|
||||
while (entry) {
|
||||
struct fx_error *error = fx_unbox(struct fx_error, entry, err_entry);
|
||||
struct fx_error *error
|
||||
= fx_unbox(struct fx_error, entry, err_entry);
|
||||
free(error);
|
||||
|
||||
entry = fx_queue_pop_back(&free_errors);
|
||||
@@ -39,7 +43,9 @@ static void error_cleanup(void)
|
||||
}
|
||||
|
||||
bool fx_result_is(
|
||||
struct fx_error *err, const fx_error_vendor *vendor, fx_error_status_code code)
|
||||
struct fx_error *err,
|
||||
const fx_error_vendor *vendor,
|
||||
fx_error_status_code code)
|
||||
{
|
||||
if (!err) {
|
||||
return false;
|
||||
@@ -58,7 +64,8 @@ const struct fx_error_vendor *fx_error_vendor_get_builtin(void)
|
||||
}
|
||||
|
||||
const struct fx_error_definition *fx_error_vendor_get_error_definition(
|
||||
const struct fx_error_vendor *vendor, fx_error_status_code code)
|
||||
const struct fx_error_vendor *vendor,
|
||||
fx_error_status_code code)
|
||||
{
|
||||
const struct fx_error_definition *error_def = NULL;
|
||||
|
||||
@@ -70,7 +77,8 @@ const struct fx_error_definition *fx_error_vendor_get_error_definition(
|
||||
return error_def;
|
||||
}
|
||||
|
||||
size_t nr_errors = vendor->v_error_definitions_length / sizeof *error_def;
|
||||
size_t nr_errors
|
||||
= vendor->v_error_definitions_length / sizeof *error_def;
|
||||
if (code >= 0 && code < nr_errors) {
|
||||
error_def = &vendor->v_error_definitions[code];
|
||||
}
|
||||
@@ -83,7 +91,8 @@ const struct fx_error_definition *fx_error_vendor_get_error_definition(
|
||||
}
|
||||
|
||||
const char *fx_error_vendor_get_status_code_name(
|
||||
const struct fx_error_vendor *vendor, fx_error_status_code code)
|
||||
const struct fx_error_vendor *vendor,
|
||||
fx_error_status_code code)
|
||||
{
|
||||
const struct fx_error_definition *error_def
|
||||
= fx_error_vendor_get_error_definition(vendor, code);
|
||||
@@ -91,7 +100,8 @@ const char *fx_error_vendor_get_status_code_name(
|
||||
}
|
||||
|
||||
const char *fx_error_vendor_get_status_code_description(
|
||||
const struct fx_error_vendor *vendor, fx_error_status_code code)
|
||||
const struct fx_error_vendor *vendor,
|
||||
fx_error_status_code code)
|
||||
{
|
||||
const struct fx_error_definition *error_def
|
||||
= fx_error_vendor_get_error_definition(vendor, code);
|
||||
@@ -99,7 +109,8 @@ const char *fx_error_vendor_get_status_code_description(
|
||||
}
|
||||
|
||||
const struct fx_error_msg *fx_error_vendor_get_msg(
|
||||
const struct fx_error_vendor *vendor, fx_error_msg_id msg_id)
|
||||
const struct fx_error_vendor *vendor,
|
||||
fx_error_msg_id msg_id)
|
||||
{
|
||||
const struct fx_error_msg *msg = NULL;
|
||||
|
||||
@@ -131,7 +142,8 @@ static struct fx_error *allocate_error(void)
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_pop_back(&free_errors);
|
||||
if (entry) {
|
||||
struct fx_error *error = fx_unbox(struct fx_error, entry, err_entry);
|
||||
struct fx_error *error
|
||||
= fx_unbox(struct fx_error, entry, err_entry);
|
||||
memset(error, 0x0, sizeof *error);
|
||||
fx_queue_push_back(&allocated_errors, entry);
|
||||
return error;
|
||||
@@ -172,7 +184,8 @@ static void do_free_error(struct fx_error *error)
|
||||
entry = fx_queue_pop_back(&error->err_stack);
|
||||
}
|
||||
|
||||
size_t nr_param = sizeof error->err_params / sizeof error->err_params[0];
|
||||
size_t nr_param
|
||||
= sizeof error->err_params / sizeof error->err_params[0];
|
||||
for (size_t i = 0; i < nr_param; i++) {
|
||||
const struct fx_error_template_parameter_definition *param_def
|
||||
= error->err_params[i].__param_def;
|
||||
@@ -205,9 +218,14 @@ static void free_error(struct fx_error *error)
|
||||
}
|
||||
|
||||
struct fx_error *z__fx_error_create_string(
|
||||
const fx_error_vendor *vendor, fx_error_status_code code,
|
||||
struct fx_error *caused_by, const char *file, unsigned int line,
|
||||
const char *func, const char *description, va_list arg)
|
||||
const fx_error_vendor *vendor,
|
||||
fx_error_status_code code,
|
||||
struct fx_error *caused_by,
|
||||
const char *file,
|
||||
unsigned int line,
|
||||
const char *func,
|
||||
const char *description,
|
||||
va_list arg)
|
||||
{
|
||||
struct fx_error *error = allocate_error();
|
||||
if (!error) {
|
||||
@@ -229,21 +247,31 @@ struct fx_error *z__fx_error_create_string(
|
||||
}
|
||||
|
||||
struct fx_error *z__fx_error_create_msg(
|
||||
const struct fx_error_vendor *vendor, fx_error_status_code code,
|
||||
struct fx_error *caused_by, const char *file, unsigned int line,
|
||||
const char *func, fx_error_msg_id msg_id,
|
||||
const struct fx_error_vendor *vendor,
|
||||
fx_error_status_code code,
|
||||
struct fx_error *caused_by,
|
||||
const char *file,
|
||||
unsigned int line,
|
||||
const char *func,
|
||||
fx_error_msg_id msg_id,
|
||||
const fx_error_template_parameter params[])
|
||||
{
|
||||
const struct fx_error_definition *error_def
|
||||
= fx_error_vendor_get_error_definition(vendor, code);
|
||||
if (!error_def) {
|
||||
fprintf(stderr, "Undefined %s error %lu\n", vendor->v_name, code);
|
||||
fprintf(stderr,
|
||||
"Undefined %s error %lu\n",
|
||||
vendor->v_name,
|
||||
code);
|
||||
abort();
|
||||
}
|
||||
|
||||
const struct fx_error_msg *msg = fx_error_vendor_get_msg(vendor, msg_id);
|
||||
const struct fx_error_msg *msg
|
||||
= fx_error_vendor_get_msg(vendor, msg_id);
|
||||
if (!msg) {
|
||||
fprintf(stderr, "Undefined %s error msg %lu\n", vendor->v_name,
|
||||
fprintf(stderr,
|
||||
"Undefined %s error msg %lu\n",
|
||||
vendor->v_name,
|
||||
msg_id);
|
||||
abort();
|
||||
}
|
||||
@@ -262,7 +290,9 @@ struct fx_error *z__fx_error_create_msg(
|
||||
const struct fx_error_template_parameter *param = ¶ms[i];
|
||||
|
||||
const struct fx_error_template_parameter_definition *param_def
|
||||
= fx_error_msg_get_template_parameter(msg, param->param_name);
|
||||
= fx_error_msg_get_template_parameter(
|
||||
msg,
|
||||
param->param_name);
|
||||
if (!param_def) {
|
||||
continue;
|
||||
}
|
||||
@@ -270,8 +300,8 @@ struct fx_error *z__fx_error_create_msg(
|
||||
memcpy(&error->err_params[i], param, sizeof *param);
|
||||
error->err_params[i].__param_def = param_def;
|
||||
if (param_def->param_type == FX_ERROR_TEMPLATE_PARAM_STRING) {
|
||||
const char *s
|
||||
= (const char *)error->err_params[i].param_value;
|
||||
const char *s = (const char *)error->err_params[i]
|
||||
.param_value;
|
||||
size_t len = strlen(s);
|
||||
char *s2 = malloc(len + 1);
|
||||
if (!s2) {
|
||||
@@ -290,14 +320,21 @@ struct fx_error *z__fx_error_create_msg(
|
||||
}
|
||||
|
||||
struct fx_error *z__fx_error_create_template(
|
||||
const struct fx_error_vendor *vendor, fx_error_status_code code,
|
||||
struct fx_error *caused_by, const char *file, unsigned int line,
|
||||
const char *func, const fx_error_template_parameter params[])
|
||||
const struct fx_error_vendor *vendor,
|
||||
fx_error_status_code code,
|
||||
struct fx_error *caused_by,
|
||||
const char *file,
|
||||
unsigned int line,
|
||||
const char *func,
|
||||
const fx_error_template_parameter params[])
|
||||
{
|
||||
const struct fx_error_definition *error_def
|
||||
= fx_error_vendor_get_error_definition(vendor, code);
|
||||
if (!error_def) {
|
||||
fprintf(stderr, "Undefined %s error %lu\n", vendor->v_name, code);
|
||||
fprintf(stderr,
|
||||
"Undefined %s error %lu\n",
|
||||
vendor->v_name,
|
||||
code);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -315,7 +352,8 @@ struct fx_error *z__fx_error_create_template(
|
||||
|
||||
const struct fx_error_template_parameter_definition *param_def
|
||||
= fx_error_definition_get_template_parameter(
|
||||
error_def, param->param_name);
|
||||
error_def,
|
||||
param->param_name);
|
||||
if (!param_def) {
|
||||
continue;
|
||||
}
|
||||
@@ -323,8 +361,8 @@ struct fx_error *z__fx_error_create_template(
|
||||
memcpy(&error->err_params[i], param, sizeof *param);
|
||||
error->err_params[i].__param_def = param_def;
|
||||
if (param_def->param_type == FX_ERROR_TEMPLATE_PARAM_STRING) {
|
||||
const char *s
|
||||
= (const char *)error->err_params[i].param_value;
|
||||
const char *s = (const char *)error->err_params[i]
|
||||
.param_value;
|
||||
size_t len = strlen(s);
|
||||
char *s2 = malloc(len + 1);
|
||||
if (!s2) {
|
||||
@@ -343,7 +381,9 @@ struct fx_error *z__fx_error_create_template(
|
||||
}
|
||||
|
||||
struct fx_error *z__fx_error_propagate(
|
||||
struct fx_error *error, const char *file, unsigned int line,
|
||||
struct fx_error *error,
|
||||
const char *file,
|
||||
unsigned int line,
|
||||
const char *function)
|
||||
{
|
||||
if (!error) {
|
||||
@@ -368,22 +408,34 @@ struct fx_error *z__fx_error_propagate(
|
||||
return error;
|
||||
}
|
||||
|
||||
struct fx_error *z__fx_error_caused_by(struct fx_error *error, struct fx_error *caused_by)
|
||||
struct fx_error *z__fx_error_caused_by(
|
||||
struct fx_error *error,
|
||||
struct fx_error *caused_by)
|
||||
{
|
||||
error->err_caused_by = caused_by;
|
||||
return error;
|
||||
}
|
||||
|
||||
struct fx_error *z__fx_error_caused_by_fx_status(
|
||||
struct fx_error *error, enum fx_status status)
|
||||
struct fx_error *error,
|
||||
enum fx_status status)
|
||||
{
|
||||
error->err_caused_by = z__fx_error_create(
|
||||
&builtin_vendor, status, NULL, NULL, 0, NULL, NULL);
|
||||
&builtin_vendor,
|
||||
status,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL);
|
||||
return error;
|
||||
}
|
||||
|
||||
enum fx_status fx_error_add_submsg_string(
|
||||
struct fx_error *error, fx_error_submsg_type type, const char *msg, ...)
|
||||
struct fx_error *error,
|
||||
fx_error_submsg_type type,
|
||||
const char *msg,
|
||||
...)
|
||||
{
|
||||
struct fx_error_submsg *submsg = malloc(sizeof *submsg);
|
||||
if (!submsg) {
|
||||
@@ -419,14 +471,18 @@ enum fx_status fx_error_add_submsg_string(
|
||||
}
|
||||
|
||||
enum fx_status z__fx_error_add_submsg_template(
|
||||
struct fx_error *error, enum fx_error_submsg_type type,
|
||||
fx_error_msg_id msg_id, struct fx_error_template_parameter params[])
|
||||
struct fx_error *error,
|
||||
enum fx_error_submsg_type type,
|
||||
fx_error_msg_id msg_id,
|
||||
struct fx_error_template_parameter params[])
|
||||
{
|
||||
const struct fx_error_msg *msg
|
||||
= fx_error_vendor_get_msg(error->err_vendor, msg_id);
|
||||
if (!msg) {
|
||||
fprintf(stderr, "Undefined %s error message %lu\n",
|
||||
error->err_vendor->v_name, msg_id);
|
||||
fprintf(stderr,
|
||||
"Undefined %s error message %lu\n",
|
||||
error->err_vendor->v_name,
|
||||
msg_id);
|
||||
abort();
|
||||
}
|
||||
|
||||
@@ -442,7 +498,9 @@ enum fx_status z__fx_error_add_submsg_template(
|
||||
const struct fx_error_template_parameter *param = ¶ms[i];
|
||||
|
||||
const struct fx_error_template_parameter_definition *param_def
|
||||
= fx_error_msg_get_template_parameter(msg, param->param_name);
|
||||
= fx_error_msg_get_template_parameter(
|
||||
msg,
|
||||
param->param_name);
|
||||
if (!param_def) {
|
||||
continue;
|
||||
}
|
||||
@@ -450,8 +508,8 @@ enum fx_status z__fx_error_add_submsg_template(
|
||||
memcpy(&submsg->msg_params[i], param, sizeof *param);
|
||||
submsg->msg_params[i].__param_def = param_def;
|
||||
if (param_def->param_type == FX_ERROR_TEMPLATE_PARAM_STRING) {
|
||||
const char *s
|
||||
= (const char *)submsg->msg_params[i].param_value;
|
||||
const char *s = (const char *)submsg->msg_params[i]
|
||||
.param_value;
|
||||
size_t len = strlen(s);
|
||||
char *s2 = malloc(len + 1);
|
||||
if (!s2) {
|
||||
@@ -478,7 +536,10 @@ void fx_error_discard(struct fx_error *error)
|
||||
}
|
||||
|
||||
void z__fx_error_throw(
|
||||
struct fx_error *error, const char *file, unsigned int line, const char *func)
|
||||
struct fx_error *error,
|
||||
const char *file,
|
||||
unsigned int line,
|
||||
const char *func)
|
||||
{
|
||||
if (!error) {
|
||||
return;
|
||||
@@ -499,13 +560,15 @@ const struct fx_error_vendor *fx_error_get_vendor(const struct fx_error *error)
|
||||
return error->err_vendor;
|
||||
}
|
||||
|
||||
const struct fx_error_definition *fx_error_get_definition(const struct fx_error *error)
|
||||
const struct fx_error_definition *fx_error_get_definition(
|
||||
const struct fx_error *error)
|
||||
{
|
||||
return error->err_def;
|
||||
}
|
||||
|
||||
const struct fx_error_template_parameter *fx_error_get_template_parameter(
|
||||
const struct fx_error *error, const char *param_name)
|
||||
const struct fx_error *error,
|
||||
const char *param_name)
|
||||
{
|
||||
const size_t nr_params
|
||||
= sizeof error->err_params / sizeof error->err_params[0];
|
||||
@@ -538,7 +601,8 @@ const struct fx_error_msg *fx_error_get_msg(const fx_error *error)
|
||||
return error->err_msg;
|
||||
}
|
||||
|
||||
const struct fx_error_submsg *fx_error_get_first_submsg(const struct fx_error *error)
|
||||
const struct fx_error_submsg *fx_error_get_first_submsg(
|
||||
const struct fx_error *error)
|
||||
{
|
||||
struct fx_queue_entry *entry = fx_queue_first(&error->err_submsg);
|
||||
if (!entry) {
|
||||
@@ -549,7 +613,8 @@ const struct fx_error_submsg *fx_error_get_first_submsg(const struct fx_error *e
|
||||
}
|
||||
|
||||
const struct fx_error_submsg *fx_error_get_next_submsg(
|
||||
const struct fx_error *error, const struct fx_error_submsg *msg)
|
||||
const struct fx_error *error,
|
||||
const struct fx_error_submsg *msg)
|
||||
{
|
||||
struct fx_queue_entry *entry = fx_queue_next(&msg->msg_entry);
|
||||
if (!entry) {
|
||||
@@ -571,7 +636,8 @@ const struct fx_error_stack_frame *fx_error_get_first_stack_frame(
|
||||
}
|
||||
|
||||
const struct fx_error_stack_frame *fx_error_get_next_stack_frame(
|
||||
const struct fx_error *error, const struct fx_error_stack_frame *frame)
|
||||
const struct fx_error *error,
|
||||
const struct fx_error_stack_frame *frame)
|
||||
{
|
||||
struct fx_queue_entry *entry = fx_queue_next(&frame->f_entry);
|
||||
if (!entry) {
|
||||
@@ -586,7 +652,8 @@ const fx_error *fx_error_get_caused_by(const struct fx_error *error)
|
||||
return error->err_caused_by;
|
||||
}
|
||||
|
||||
enum fx_error_submsg_type fx_error_submsg_get_type(const struct fx_error_submsg *msg)
|
||||
enum fx_error_submsg_type fx_error_submsg_get_type(
|
||||
const struct fx_error_submsg *msg)
|
||||
{
|
||||
return msg->msg_type;
|
||||
}
|
||||
@@ -601,13 +668,14 @@ const struct fx_error_msg *fx_error_submsg_get_msg(const fx_error_submsg *msg)
|
||||
return msg->msg_msg;
|
||||
}
|
||||
|
||||
const struct fx_error_template_parameter *fx_error_submsg_get_template_parameters(
|
||||
const struct fx_error_submsg *msg)
|
||||
const struct fx_error_template_parameter *
|
||||
fx_error_submsg_get_template_parameters(const struct fx_error_submsg *msg)
|
||||
{
|
||||
return msg->msg_params;
|
||||
}
|
||||
|
||||
const char *fx_error_stack_frame_get_filepath(const struct fx_error_stack_frame *frame)
|
||||
const char *fx_error_stack_frame_get_filepath(
|
||||
const struct fx_error_stack_frame *frame)
|
||||
{
|
||||
return frame->f_file;
|
||||
}
|
||||
@@ -624,11 +692,13 @@ const char *fx_error_stack_frame_get_function_name(
|
||||
return frame->f_function;
|
||||
}
|
||||
|
||||
const struct fx_error_template_parameter_definition *fx_error_definition_get_template_parameter(
|
||||
const struct fx_error_definition *error_def, const char *param_name)
|
||||
const struct fx_error_template_parameter_definition *
|
||||
fx_error_definition_get_template_parameter(
|
||||
const struct fx_error_definition *error_def,
|
||||
const char *param_name)
|
||||
{
|
||||
size_t nr_param
|
||||
= sizeof error_def->err_params / sizeof error_def->err_params[0];
|
||||
size_t nr_param = sizeof error_def->err_params
|
||||
/ sizeof error_def->err_params[0];
|
||||
|
||||
for (size_t i = 0; i < nr_param; i++) {
|
||||
if (!error_def->err_params[i].param_name) {
|
||||
@@ -648,8 +718,10 @@ const char *fx_error_msg_get_content(const struct fx_error_msg *msg)
|
||||
return msg->msg_message;
|
||||
}
|
||||
|
||||
const struct fx_error_template_parameter_definition *fx_error_msg_get_template_parameter(
|
||||
const struct fx_error_msg *msg, const char *param_name)
|
||||
const struct fx_error_template_parameter_definition *
|
||||
fx_error_msg_get_template_parameter(
|
||||
const struct fx_error_msg *msg,
|
||||
const char *param_name)
|
||||
{
|
||||
size_t nr_param = sizeof msg->msg_params / sizeof msg->msg_params[0];
|
||||
|
||||
@@ -667,7 +739,8 @@ const struct fx_error_template_parameter_definition *fx_error_msg_get_template_p
|
||||
}
|
||||
|
||||
void fx_set_error_report_function(
|
||||
fx_error_report_function func, enum fx_error_report_flags flags)
|
||||
fx_error_report_function func,
|
||||
enum fx_error_report_flags flags)
|
||||
{
|
||||
if (!func) {
|
||||
func = default_error_reporter;
|
||||
@@ -685,51 +758,75 @@ static const struct fx_error_definition builtin_errors[] = {
|
||||
FX_ERROR_DEFINITION(FX_SUCCESS, "SUCCESS", "Success"),
|
||||
FX_ERROR_DEFINITION(FX_ERR_NO_MEMORY, "NO_MEMORY", "Out of memory"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_OUT_OF_BOUNDS, "OUT_OF_BOUNDS", "Argument out of bounds"),
|
||||
FX_ERR_OUT_OF_BOUNDS,
|
||||
"OUT_OF_BOUNDS",
|
||||
"Argument out of bounds"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_INVALID_ARGUMENT, "INVALID_ARGUMENT", "Invalid argument"),
|
||||
FX_ERR_INVALID_ARGUMENT,
|
||||
"INVALID_ARGUMENT",
|
||||
"Invalid argument"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_NAME_EXISTS, "NAME_EXISTS", "Name already exists"),
|
||||
FX_ERR_NAME_EXISTS,
|
||||
"NAME_EXISTS",
|
||||
"Name already exists"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_NOT_SUPPORTED, "NOT_SUPPORTED", "Operation not supported"),
|
||||
FX_ERR_NOT_SUPPORTED,
|
||||
"NOT_SUPPORTED",
|
||||
"Operation not supported"),
|
||||
FX_ERROR_DEFINITION(FX_ERR_BAD_STATE, "BAD_STATE", "Bad state"),
|
||||
FX_ERROR_DEFINITION(FX_ERR_NO_ENTRY, "NO_ENTRY", "Name does not exist"),
|
||||
FX_ERROR_DEFINITION(FX_ERR_NO_DATA, "NO_DATA", "No data available"),
|
||||
FX_ERROR_DEFINITION(FX_ERR_NO_SPACE, "NO_DATA", "No space available"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_UNKNOWN_FUNCTION, "UNKNOWN_FUNCTION", "Unknown function"),
|
||||
FX_ERR_UNKNOWN_FUNCTION,
|
||||
"UNKNOWN_FUNCTION",
|
||||
"Unknown function"),
|
||||
FX_ERROR_DEFINITION(FX_ERR_BAD_FORMAT, "BAD_FORMAT", "Bad format"),
|
||||
FX_ERROR_DEFINITION(FX_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_IS_DIRECTORY, "IS_DIRECTORY", "Item is a directory"),
|
||||
FX_ERR_IS_DIRECTORY,
|
||||
"IS_DIRECTORY",
|
||||
"Item is a directory"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_NOT_DIRECTORY, "NOT_DIRECTORY", "Item is not a directory"),
|
||||
FX_ERR_NOT_DIRECTORY,
|
||||
"NOT_DIRECTORY",
|
||||
"Item is not a directory"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_PERMISSION_DENIED, "PERMISSION_DENIED",
|
||||
FX_ERR_PERMISSION_DENIED,
|
||||
"PERMISSION_DENIED",
|
||||
"Permission denied"),
|
||||
FX_ERROR_DEFINITION(FX_ERR_BUSY, "BUSY", "Resource busy or locked"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_COMPRESSION_FAILURE, "COMPRESSION_FAILURE",
|
||||
FX_ERR_COMPRESSION_FAILURE,
|
||||
"COMPRESSION_FAILURE",
|
||||
"Compression failure"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_TYPE_REGISTRATION_FAILURE, "TYPE_REGISTRATION_FAILURE",
|
||||
FX_ERR_TYPE_REGISTRATION_FAILURE,
|
||||
"TYPE_REGISTRATION_FAILURE",
|
||||
"Type registration failure"),
|
||||
FX_ERROR_DEFINITION(
|
||||
FX_ERR_CLASS_INIT_FAILURE, "CLASS_INIT_FAILURE",
|
||||
FX_ERR_CLASS_INIT_FAILURE,
|
||||
"CLASS_INIT_FAILURE",
|
||||
"Class initialisation failure"),
|
||||
};
|
||||
|
||||
static const struct fx_error_msg builtin_msg[] = {
|
||||
FX_ERROR_MSG(FX_MSG_TYPE_REGISTRATION_FAILURE, "Type registration failed"),
|
||||
FX_ERROR_MSG(
|
||||
FX_MSG_TYPE_REGISTRATION_FAILURE,
|
||||
"Type registration failed"),
|
||||
FX_ERROR_MSG(FX_MSG_CLASS_INIT_FAILURE, "Class initialisation failed"),
|
||||
FX_ERROR_MSG_TEMPLATE(
|
||||
FX_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE,
|
||||
"Class @[class_name] specifies an implementation for interface "
|
||||
"@[interface_name] that it does not extend or inherit",
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"class_name", FX_ERROR_TEMPLATE_PARAM_STRING, "%s"),
|
||||
"class_name",
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
"%s"),
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"interface_name", FX_ERROR_TEMPLATE_PARAM_STRING, "%s")),
|
||||
"interface_name",
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
"%s")),
|
||||
};
|
||||
|
||||
static const struct fx_error_vendor builtin_vendor = {
|
||||
@@ -741,8 +838,10 @@ static const struct fx_error_vendor builtin_vendor = {
|
||||
};
|
||||
|
||||
static void get_error_id(
|
||||
const struct fx_error_vendor *vendor, const struct fx_error *error,
|
||||
char *out, size_t max)
|
||||
const struct fx_error_vendor *vendor,
|
||||
const struct fx_error *error,
|
||||
char *out,
|
||||
size_t max)
|
||||
{
|
||||
const char *vendor_name = NULL;
|
||||
const char *error_name = NULL;
|
||||
@@ -777,7 +876,8 @@ static void get_error_id(
|
||||
}
|
||||
|
||||
static void print_template_parameter(
|
||||
const struct fx_error_template_parameter *params, size_t nr_params,
|
||||
const struct fx_error_template_parameter *params,
|
||||
size_t nr_params,
|
||||
const char *param_name)
|
||||
{
|
||||
const struct fx_error_template_parameter *param = NULL;
|
||||
@@ -861,7 +961,8 @@ static void print_template_parameter(
|
||||
}
|
||||
|
||||
static void print_content(
|
||||
const struct fx_error_template_parameter *params, size_t nr_params,
|
||||
const struct fx_error_template_parameter *params,
|
||||
size_t nr_params,
|
||||
const char *s)
|
||||
{
|
||||
char modifier = 0;
|
||||
@@ -933,7 +1034,8 @@ static void print_content(
|
||||
|
||||
static void print_submsg(const struct fx_error *error)
|
||||
{
|
||||
const struct fx_error_definition *error_def = fx_error_get_definition(error);
|
||||
const struct fx_error_definition *error_def
|
||||
= fx_error_get_definition(error);
|
||||
const struct fx_error_submsg *msg = fx_error_get_first_submsg(error);
|
||||
|
||||
while (msg) {
|
||||
@@ -992,20 +1094,24 @@ static void print_stack_trace(const struct fx_error *error)
|
||||
}
|
||||
|
||||
static void report_error(
|
||||
const fx_error *error, fx_error_report_flags flags, bool caused_by)
|
||||
const fx_error *error,
|
||||
fx_error_report_flags flags,
|
||||
bool caused_by)
|
||||
{
|
||||
const fx_error_vendor *vendor = fx_error_get_vendor(error);
|
||||
|
||||
char error_id[128];
|
||||
get_error_id(vendor, error, error_id, sizeof error_id);
|
||||
|
||||
const struct fx_error_definition *error_def = fx_error_get_definition(error);
|
||||
const struct fx_error_definition *error_def
|
||||
= fx_error_get_definition(error);
|
||||
fx_error_status_code code = fx_error_get_status_code(error);
|
||||
const char *description = fx_error_get_description(error);
|
||||
|
||||
if (!description && vendor) {
|
||||
description = fx_error_vendor_get_status_code_description(
|
||||
vendor, code);
|
||||
vendor,
|
||||
code);
|
||||
}
|
||||
|
||||
if (caused_by) {
|
||||
@@ -1053,7 +1159,8 @@ static void report_error(
|
||||
}
|
||||
|
||||
static void default_error_reporter(
|
||||
const struct fx_error *error, enum fx_error_report_flags flags)
|
||||
const struct fx_error *error,
|
||||
enum fx_error_report_flags flags)
|
||||
{
|
||||
report_error(error, flags, false);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
#ifndef _FX_ERROR_H_
|
||||
#define _FX_ERROR_H_
|
||||
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/queue.h>
|
||||
|
||||
struct fx_error_stack_frame {
|
||||
fx_queue_entry f_entry;
|
||||
|
||||
+21
-8
@@ -1,7 +1,7 @@
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/core/rope.h>
|
||||
#include <fx/hash.h>
|
||||
#include <fx/rope.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -66,7 +66,9 @@ uint64_t fx_hash_cstr_ex(const char *s, size_t *len)
|
||||
return hash;
|
||||
}
|
||||
|
||||
enum fx_status fx_hash_ctx_init(struct fx_hash_ctx *ctx, enum fx_hash_function func)
|
||||
enum fx_status fx_hash_ctx_init(
|
||||
struct fx_hash_ctx *ctx,
|
||||
enum fx_hash_function func)
|
||||
{
|
||||
if (func < 0 || func >= nr_hash_functions) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -104,7 +106,10 @@ enum fx_status fx_hash_ctx_reset(struct fx_hash_ctx *ctx)
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
enum fx_status fx_hash_ctx_update(struct fx_hash_ctx *ctx, const void *p, size_t len)
|
||||
enum fx_status fx_hash_ctx_update(
|
||||
struct fx_hash_ctx *ctx,
|
||||
const void *p,
|
||||
size_t len)
|
||||
{
|
||||
if (!ctx->ctx_ops) {
|
||||
return FX_ERR_BAD_STATE;
|
||||
@@ -127,13 +132,18 @@ static void update_rope(const fx_rope *rope, void *arg)
|
||||
|
||||
switch (type) {
|
||||
case FX_ROPE_F_CHAR:
|
||||
fx_hash_ctx_update(ctx, &rope->r_v.v_char, sizeof rope->r_v.v_char);
|
||||
fx_hash_ctx_update(
|
||||
ctx,
|
||||
&rope->r_v.v_char,
|
||||
sizeof rope->r_v.v_char);
|
||||
break;
|
||||
case FX_ROPE_F_CSTR:
|
||||
case FX_ROPE_F_CSTR_BORROWED:
|
||||
case FX_ROPE_F_CSTR_STATIC:
|
||||
fx_hash_ctx_update(
|
||||
ctx, rope->r_v.v_cstr.s, strlen(rope->r_v.v_cstr.s));
|
||||
ctx,
|
||||
rope->r_v.v_cstr.s,
|
||||
strlen(rope->r_v.v_cstr.s));
|
||||
break;
|
||||
case FX_ROPE_F_INT:
|
||||
len = snprintf(tmp, sizeof tmp, "%" PRIdPTR, rope->r_v.v_int);
|
||||
@@ -149,14 +159,17 @@ static void update_rope(const fx_rope *rope, void *arg)
|
||||
}
|
||||
|
||||
enum fx_status fx_hash_ctx_update_rope(
|
||||
struct fx_hash_ctx *ctx, const struct fx_rope *rope)
|
||||
struct fx_hash_ctx *ctx,
|
||||
const struct fx_rope *rope)
|
||||
{
|
||||
fx_rope_iterate(rope, update_rope, ctx);
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
enum fx_status fx_hash_ctx_finish(
|
||||
struct fx_hash_ctx *ctx, void *out_digest, size_t out_max)
|
||||
struct fx_hash_ctx *ctx,
|
||||
void *out_digest,
|
||||
size_t out_max)
|
||||
{
|
||||
if (!ctx->ctx_ops) {
|
||||
return FX_ERR_BAD_STATE;
|
||||
|
||||
+5
-2
@@ -36,7 +36,7 @@
|
||||
*/
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/hash.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -88,7 +88,10 @@
|
||||
* This processes one or more 64-byte data blocks, but does NOT update the bit
|
||||
* counters. There are no alignment requirements.
|
||||
*/
|
||||
static const void *body(struct fx_hash_ctx *ctx, const void *data, unsigned long size)
|
||||
static const void *body(
|
||||
struct fx_hash_ctx *ctx,
|
||||
const void *data,
|
||||
unsigned long size)
|
||||
{
|
||||
const unsigned char *ptr;
|
||||
uint32_t a, b, c, d;
|
||||
|
||||
+16
-7
@@ -3,7 +3,7 @@
|
||||
* and is in the public domain. */
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/hash.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -30,7 +30,10 @@ void md5_init(struct fx_hash_ctx *ctx)
|
||||
ctx->ctx_state.md5.count[1] = 0;
|
||||
}
|
||||
|
||||
uint8_t *md5_transform(struct fx_hash_ctx *ctx, const void *data, uintmax_t size)
|
||||
uint8_t *md5_transform(
|
||||
struct fx_hash_ctx *ctx,
|
||||
const void *data,
|
||||
uintmax_t size)
|
||||
{
|
||||
uint8_t *ptr = (uint8_t *)data;
|
||||
uint32_t a, b, c, d, aa, bb, cc, dd;
|
||||
@@ -146,7 +149,8 @@ void md5_update(struct fx_hash_ctx *ctx, const void *buffer, size_t buffer_size)
|
||||
uint32_t used;
|
||||
uint32_t free;
|
||||
|
||||
if ((ctx->ctx_state.md5.count[0] = ((saved_low + buffer_size) & 0x1fffffff))
|
||||
if ((ctx->ctx_state.md5.count[0]
|
||||
= ((saved_low + buffer_size) & 0x1fffffff))
|
||||
< saved_low) {
|
||||
ctx->ctx_state.md5.count[1]++;
|
||||
}
|
||||
@@ -158,7 +162,8 @@ void md5_update(struct fx_hash_ctx *ctx, const void *buffer, size_t buffer_size)
|
||||
free = 64 - used;
|
||||
|
||||
if (buffer_size < free) {
|
||||
memcpy(&ctx->ctx_state.md5.input[used], buffer,
|
||||
memcpy(&ctx->ctx_state.md5.input[used],
|
||||
buffer,
|
||||
buffer_size);
|
||||
return;
|
||||
}
|
||||
@@ -171,7 +176,9 @@ void md5_update(struct fx_hash_ctx *ctx, const void *buffer, size_t buffer_size)
|
||||
|
||||
if (buffer_size >= 64) {
|
||||
buffer = md5_transform(
|
||||
ctx, buffer, buffer_size & ~(unsigned long)0x3f);
|
||||
ctx,
|
||||
buffer,
|
||||
buffer_size & ~(unsigned long)0x3f);
|
||||
buffer_size = buffer_size % 64;
|
||||
}
|
||||
|
||||
@@ -197,13 +204,15 @@ void md5_finish(struct fx_hash_ctx *ctx, void *out, size_t max)
|
||||
|
||||
ctx->ctx_state.md5.count[0] <<= 3;
|
||||
ctx->ctx_state.md5.input[56] = (uint8_t)(ctx->ctx_state.md5.count[0]);
|
||||
ctx->ctx_state.md5.input[57] = (uint8_t)(ctx->ctx_state.md5.count[0] >> 8);
|
||||
ctx->ctx_state.md5.input[57]
|
||||
= (uint8_t)(ctx->ctx_state.md5.count[0] >> 8);
|
||||
ctx->ctx_state.md5.input[58]
|
||||
= (uint8_t)(ctx->ctx_state.md5.count[0] >> 16);
|
||||
ctx->ctx_state.md5.input[59]
|
||||
= (uint8_t)(ctx->ctx_state.md5.count[0] >> 24);
|
||||
ctx->ctx_state.md5.input[60] = (uint8_t)(ctx->ctx_state.md5.count[1]);
|
||||
ctx->ctx_state.md5.input[61] = (uint8_t)(ctx->ctx_state.md5.count[1] >> 8);
|
||||
ctx->ctx_state.md5.input[61]
|
||||
= (uint8_t)(ctx->ctx_state.md5.count[1] >> 8);
|
||||
ctx->ctx_state.md5.input[62]
|
||||
= (uint8_t)(ctx->ctx_state.md5.count[1] >> 16);
|
||||
ctx->ctx_state.md5.input[63]
|
||||
|
||||
+5
-3
@@ -19,7 +19,7 @@ A million repetitions of "a"
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/hash.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -235,7 +235,8 @@ static void sha_finish(struct fx_hash_ctx *context, void *out, size_t max)
|
||||
unsigned char c;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
finalcount[i] = (unsigned char)((context->ctx_state.sha1
|
||||
finalcount[i]
|
||||
= (unsigned char)((context->ctx_state.sha1
|
||||
.count[(i >= 4 ? 0 : 1)]
|
||||
>> ((3 - (i & 3)) * 8))
|
||||
& 255); /* Endian independent */
|
||||
@@ -250,7 +251,8 @@ static void sha_finish(struct fx_hash_ctx *context, void *out, size_t max)
|
||||
}
|
||||
sha_update(context, finalcount, 8); /* Should cause a SHA1Transform() */
|
||||
for (i = 0; i < 20; i++) {
|
||||
digest[i] = (unsigned char)((context->ctx_state.sha1.state[i >> 2]
|
||||
digest[i]
|
||||
= (unsigned char)((context->ctx_state.sha1.state[i >> 2]
|
||||
>> ((3 - (i & 3)) * 8))
|
||||
& 255);
|
||||
}
|
||||
|
||||
+8
-3
@@ -1,12 +1,17 @@
|
||||
// SHA-224. Adapted from LibTomCrypt. This code is Public Domain
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/hash.h>
|
||||
#include <string.h>
|
||||
|
||||
extern void z__fx_sha2_256_update(
|
||||
struct fx_hash_ctx *md, const void *src, size_t inlen);
|
||||
extern void z__fx_sha2_256_finish(struct fx_hash_ctx *md, void *out, size_t max);
|
||||
struct fx_hash_ctx *md,
|
||||
const void *src,
|
||||
size_t inlen);
|
||||
extern void z__fx_sha2_256_finish(
|
||||
struct fx_hash_ctx *md,
|
||||
void *out,
|
||||
size_t max);
|
||||
|
||||
static void sha_init(struct fx_hash_ctx *md)
|
||||
{
|
||||
|
||||
+38
-12
@@ -1,7 +1,7 @@
|
||||
// SHA-256. Adapted from LibTomCrypt. This code is Public Domain
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/hash.h>
|
||||
#include <string.h>
|
||||
|
||||
static const uint32_t K[64] = {
|
||||
@@ -77,9 +77,18 @@ static uint32_t Gamma1(uint32_t x)
|
||||
}
|
||||
|
||||
static void RND(
|
||||
uint32_t *t0, uint32_t *t1, uint32_t W[], uint32_t a, uint32_t b,
|
||||
uint32_t c, uint32_t *d, uint32_t e, uint32_t f, uint32_t g,
|
||||
uint32_t *h, uint32_t i)
|
||||
uint32_t *t0,
|
||||
uint32_t *t1,
|
||||
uint32_t W[],
|
||||
uint32_t a,
|
||||
uint32_t b,
|
||||
uint32_t c,
|
||||
uint32_t *d,
|
||||
uint32_t e,
|
||||
uint32_t f,
|
||||
uint32_t g,
|
||||
uint32_t *h,
|
||||
uint32_t i)
|
||||
{
|
||||
(*t0) = *h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];
|
||||
(*t1) = Sigma0(a) + Maj(a, b, c);
|
||||
@@ -101,13 +110,24 @@ static void sha_compress(struct fx_hash_ctx *md, const unsigned char *buf)
|
||||
|
||||
// Fill W[16..63]
|
||||
for (int i = 16; i < 64; i++)
|
||||
W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
|
||||
W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15])
|
||||
+ W[i - 16];
|
||||
|
||||
// Compress
|
||||
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
RND(&t0, &t1, W, S[0], S[1], S[2], &S[3], S[4], S[5], S[6],
|
||||
&S[7], i);
|
||||
RND(&t0,
|
||||
&t1,
|
||||
W,
|
||||
S[0],
|
||||
S[1],
|
||||
S[2],
|
||||
&S[3],
|
||||
S[4],
|
||||
S[5],
|
||||
S[6],
|
||||
&S[7],
|
||||
i);
|
||||
t = S[7];
|
||||
S[7] = S[6];
|
||||
S[6] = S[5];
|
||||
@@ -141,7 +161,10 @@ static void sha_init(struct fx_hash_ctx *md)
|
||||
md->ctx_state.sha2_256.state[7] = 0x5BE0CD19UL;
|
||||
}
|
||||
|
||||
void z__fx_sha2_256_update(struct fx_hash_ctx *md, const void *src, size_t inlen)
|
||||
void z__fx_sha2_256_update(
|
||||
struct fx_hash_ctx *md,
|
||||
const void *src,
|
||||
size_t inlen)
|
||||
{
|
||||
const uint32_t block_size = sizeof md->ctx_state.sha2_256.buf;
|
||||
const unsigned char *in = (const unsigned char *)(src);
|
||||
@@ -158,7 +181,8 @@ void z__fx_sha2_256_update(struct fx_hash_ctx *md, const void *src, size_t inlen
|
||||
(block_size - md->ctx_state.sha2_256.curlen));
|
||||
memcpy(md->ctx_state.sha2_256.buf
|
||||
+ md->ctx_state.sha2_256.curlen,
|
||||
in, n);
|
||||
in,
|
||||
n);
|
||||
md->ctx_state.sha2_256.curlen += n;
|
||||
in += n;
|
||||
inlen -= n;
|
||||
@@ -180,11 +204,13 @@ void z__fx_sha2_256_finish(struct fx_hash_ctx *md, void *out, size_t max)
|
||||
md->ctx_state.sha2_256.buf[md->ctx_state.sha2_256.curlen++]
|
||||
= (unsigned char)(0x80);
|
||||
|
||||
// If the length is currently above 56 bytes we append zeros then compress.
|
||||
// Then we can fall back to padding zeros and length encoding like normal.
|
||||
// If the length is currently above 56 bytes we append zeros then
|
||||
// compress. Then we can fall back to padding zeros and length encoding
|
||||
// like normal.
|
||||
if (md->ctx_state.sha2_256.curlen > 56) {
|
||||
while (md->ctx_state.sha2_256.curlen < 64)
|
||||
md->ctx_state.sha2_256.buf[md->ctx_state.sha2_256.curlen++]
|
||||
md->ctx_state.sha2_256
|
||||
.buf[md->ctx_state.sha2_256.curlen++]
|
||||
= 0;
|
||||
sha_compress(md, md->ctx_state.sha2_256.buf);
|
||||
md->ctx_state.sha2_256.curlen = 0;
|
||||
|
||||
+8
-3
@@ -1,12 +1,17 @@
|
||||
// SHA-384. Adapted from LibTomCrypt. This code is Public Domain
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/hash.h>
|
||||
#include <string.h>
|
||||
|
||||
extern void z__fx_sha2_512_update(
|
||||
struct fx_hash_ctx *md, const void *src, size_t inlen);
|
||||
extern void z__fx_sha2_512_finish(struct fx_hash_ctx *md, void *out, size_t max);
|
||||
struct fx_hash_ctx *md,
|
||||
const void *src,
|
||||
size_t inlen);
|
||||
extern void z__fx_sha2_512_finish(
|
||||
struct fx_hash_ctx *md,
|
||||
void *out,
|
||||
size_t max);
|
||||
|
||||
void sha_init(struct fx_hash_ctx *md)
|
||||
{
|
||||
|
||||
+126
-28
@@ -1,7 +1,7 @@
|
||||
// SHA-512. Adapted from LibTomCrypt. This code is Public Domain
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/hash.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -86,9 +86,18 @@ static uint64_t Gamma1(uint64_t x)
|
||||
return Rot(x, 19) ^ Rot(x, 61) ^ Sh(x, 6);
|
||||
}
|
||||
static void RND(
|
||||
uint64_t W[], uint64_t *t0, uint64_t *t1, uint64_t a, uint64_t b,
|
||||
uint64_t c, uint64_t *d, uint64_t e, uint64_t f, uint64_t g,
|
||||
uint64_t *h, uint64_t i)
|
||||
uint64_t W[],
|
||||
uint64_t *t0,
|
||||
uint64_t *t1,
|
||||
uint64_t a,
|
||||
uint64_t b,
|
||||
uint64_t c,
|
||||
uint64_t *d,
|
||||
uint64_t e,
|
||||
uint64_t f,
|
||||
uint64_t g,
|
||||
uint64_t *h,
|
||||
uint64_t i)
|
||||
{
|
||||
*t0 = *h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];
|
||||
*t1 = Sigma0(a) + Maj(a, b, c);
|
||||
@@ -112,28 +121,109 @@ static void sha_compress(struct fx_hash_ctx *md, const unsigned char *buf)
|
||||
|
||||
// Fill W[16..79]
|
||||
for (int i = 16; i < 80; i++) {
|
||||
W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
|
||||
W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15])
|
||||
+ W[i - 16];
|
||||
}
|
||||
|
||||
// Compress
|
||||
|
||||
for (int i = 0; i < 80; i += 8) {
|
||||
RND(W, &t0, &t1, S[0], S[1], S[2], &S[3], S[4], S[5], S[6],
|
||||
&S[7], i + 0);
|
||||
RND(W, &t0, &t1, S[7], S[0], S[1], &S[2], S[3], S[4], S[5],
|
||||
&S[6], i + 1);
|
||||
RND(W, &t0, &t1, S[6], S[7], S[0], &S[1], S[2], S[3], S[4],
|
||||
&S[5], i + 2);
|
||||
RND(W, &t0, &t1, S[5], S[6], S[7], &S[0], S[1], S[2], S[3],
|
||||
&S[4], i + 3);
|
||||
RND(W, &t0, &t1, S[4], S[5], S[6], &S[7], S[0], S[1], S[2],
|
||||
&S[3], i + 4);
|
||||
RND(W, &t0, &t1, S[3], S[4], S[5], &S[6], S[7], S[0], S[1],
|
||||
&S[2], i + 5);
|
||||
RND(W, &t0, &t1, S[2], S[3], S[4], &S[5], S[6], S[7], S[0],
|
||||
&S[1], i + 6);
|
||||
RND(W, &t0, &t1, S[1], S[2], S[3], &S[4], S[5], S[6], S[7],
|
||||
&S[0], i + 7);
|
||||
RND(W,
|
||||
&t0,
|
||||
&t1,
|
||||
S[0],
|
||||
S[1],
|
||||
S[2],
|
||||
&S[3],
|
||||
S[4],
|
||||
S[5],
|
||||
S[6],
|
||||
&S[7],
|
||||
i + 0);
|
||||
RND(W,
|
||||
&t0,
|
||||
&t1,
|
||||
S[7],
|
||||
S[0],
|
||||
S[1],
|
||||
&S[2],
|
||||
S[3],
|
||||
S[4],
|
||||
S[5],
|
||||
&S[6],
|
||||
i + 1);
|
||||
RND(W,
|
||||
&t0,
|
||||
&t1,
|
||||
S[6],
|
||||
S[7],
|
||||
S[0],
|
||||
&S[1],
|
||||
S[2],
|
||||
S[3],
|
||||
S[4],
|
||||
&S[5],
|
||||
i + 2);
|
||||
RND(W,
|
||||
&t0,
|
||||
&t1,
|
||||
S[5],
|
||||
S[6],
|
||||
S[7],
|
||||
&S[0],
|
||||
S[1],
|
||||
S[2],
|
||||
S[3],
|
||||
&S[4],
|
||||
i + 3);
|
||||
RND(W,
|
||||
&t0,
|
||||
&t1,
|
||||
S[4],
|
||||
S[5],
|
||||
S[6],
|
||||
&S[7],
|
||||
S[0],
|
||||
S[1],
|
||||
S[2],
|
||||
&S[3],
|
||||
i + 4);
|
||||
RND(W,
|
||||
&t0,
|
||||
&t1,
|
||||
S[3],
|
||||
S[4],
|
||||
S[5],
|
||||
&S[6],
|
||||
S[7],
|
||||
S[0],
|
||||
S[1],
|
||||
&S[2],
|
||||
i + 5);
|
||||
RND(W,
|
||||
&t0,
|
||||
&t1,
|
||||
S[2],
|
||||
S[3],
|
||||
S[4],
|
||||
&S[5],
|
||||
S[6],
|
||||
S[7],
|
||||
S[0],
|
||||
&S[1],
|
||||
i + 6);
|
||||
RND(W,
|
||||
&t0,
|
||||
&t1,
|
||||
S[1],
|
||||
S[2],
|
||||
S[3],
|
||||
&S[4],
|
||||
S[5],
|
||||
S[6],
|
||||
S[7],
|
||||
&S[0],
|
||||
i + 7);
|
||||
}
|
||||
|
||||
// Feedback
|
||||
@@ -158,7 +248,10 @@ static void sha_init(struct fx_hash_ctx *md)
|
||||
md->ctx_state.sha2_512.state[7] = 0x5be0cd19137e2179ULL;
|
||||
}
|
||||
|
||||
void z__fx_sha2_512_update(struct fx_hash_ctx *md, const void *src, size_t inlen)
|
||||
void z__fx_sha2_512_update(
|
||||
struct fx_hash_ctx *md,
|
||||
const void *src,
|
||||
size_t inlen)
|
||||
{
|
||||
const uint32_t block_size = sizeof md->ctx_state.sha2_512.block;
|
||||
const unsigned char *in = (const unsigned char *)src;
|
||||
@@ -175,7 +268,8 @@ void z__fx_sha2_512_update(struct fx_hash_ctx *md, const void *src, size_t inlen
|
||||
(block_size - md->ctx_state.sha2_512.curlen));
|
||||
memcpy(md->ctx_state.sha2_512.block
|
||||
+ md->ctx_state.sha2_512.curlen,
|
||||
in, n);
|
||||
in,
|
||||
n);
|
||||
md->ctx_state.sha2_512.curlen += n;
|
||||
in += n;
|
||||
inlen -= n;
|
||||
@@ -197,11 +291,13 @@ void z__fx_sha2_512_finish(struct fx_hash_ctx *md, void *out, size_t max)
|
||||
// Append the '1' bit
|
||||
md->ctx_state.sha2_512.block[md->ctx_state.sha2_512.curlen++] = 0x80;
|
||||
|
||||
// If the length is currently above 112 bytes we append zeros then compress.
|
||||
// Then we can fall back to padding zeros and length encoding like normal.
|
||||
// If the length is currently above 112 bytes we append zeros then
|
||||
// compress. Then we can fall back to padding zeros and length encoding
|
||||
// like normal.
|
||||
if (md->ctx_state.sha2_512.curlen > 112) {
|
||||
while (md->ctx_state.sha2_512.curlen < 128)
|
||||
md->ctx_state.sha2_512.block[md->ctx_state.sha2_512.curlen++]
|
||||
md->ctx_state.sha2_512
|
||||
.block[md->ctx_state.sha2_512.curlen++]
|
||||
= 0;
|
||||
sha_compress(md, md->ctx_state.sha2_512.block);
|
||||
md->ctx_state.sha2_512.curlen = 0;
|
||||
@@ -211,11 +307,13 @@ void z__fx_sha2_512_finish(struct fx_hash_ctx *md, void *out, size_t max)
|
||||
// note: that from 112 to 120 is the 64 MSB of the length. We assume
|
||||
// that you won't hash 2^64 bits of data... :-)
|
||||
while (md->ctx_state.sha2_512.curlen < 120) {
|
||||
md->ctx_state.sha2_512.block[md->ctx_state.sha2_512.curlen++] = 0;
|
||||
md->ctx_state.sha2_512.block[md->ctx_state.sha2_512.curlen++]
|
||||
= 0;
|
||||
}
|
||||
|
||||
// Store length
|
||||
store64(md->ctx_state.sha2_512.length, md->ctx_state.sha2_512.block + 120);
|
||||
store64(md->ctx_state.sha2_512.length,
|
||||
md->ctx_state.sha2_512.block + 120);
|
||||
sha_compress(md, md->ctx_state.sha2_512.block);
|
||||
|
||||
unsigned char digest[FX_DIGEST_LENGTH_SHA2_512];
|
||||
|
||||
+4
-3
@@ -30,8 +30,8 @@
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/hash.h>
|
||||
#include <fx/misc.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef KECCAKF_ROUNDS
|
||||
@@ -108,7 +108,8 @@ void sha3_keccakf(uint64_t st[25])
|
||||
for (i = 0; i < 5; i++)
|
||||
bc[i] = st[j + i];
|
||||
for (i = 0; i < 5; i++)
|
||||
st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];
|
||||
st[j + i]
|
||||
^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];
|
||||
}
|
||||
|
||||
// Iota
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_CORE_BITOP_H_
|
||||
#define FX_CORE_BITOP_H_
|
||||
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/misc.h>
|
||||
|
||||
FX_API int fx_popcountl(long v);
|
||||
FX_API int fx_ctzl(long v);
|
||||
@@ -10,7 +10,12 @@ FX_API int fx_clzl(long v);
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define fx_cmpxchg(v, expected_val, new_val) \
|
||||
__atomic_compare_exchange_n( \
|
||||
v, expected_val, new_val, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED)
|
||||
v, \
|
||||
expected_val, \
|
||||
new_val, \
|
||||
0, \
|
||||
__ATOMIC_RELAXED, \
|
||||
__ATOMIC_RELAXED)
|
||||
#elif defined(_MSC_VER)
|
||||
/* TODO add MSVC support */
|
||||
#error MSVC intrinsics not yet supported
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_CORE_BST_H_
|
||||
#define FX_CORE_BST_H_
|
||||
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -52,19 +52,26 @@ FX_TYPE_CLASS_DECLARATION_END(fx_bst_iterator)
|
||||
@param function_name the name of the function to generate.
|
||||
*/
|
||||
#define FX_BST_DEFINE_SIMPLE_INSERT( \
|
||||
node_type, container_node_member, container_key_member, function_name) \
|
||||
node_type, \
|
||||
container_node_member, \
|
||||
container_key_member, \
|
||||
function_name) \
|
||||
void function_name(fx_bst *tree, node_type *node) \
|
||||
{ \
|
||||
if (!tree->bst_root) { \
|
||||
tree->bst_root = &node->container_node_member; \
|
||||
fx_bst_insert_fixup(tree, &node->container_node_member); \
|
||||
fx_bst_insert_fixup( \
|
||||
tree, \
|
||||
&node->container_node_member); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
fx_bst_node *cur = tree->bst_root; \
|
||||
while (1) { \
|
||||
node_type *cur_node = fx_unbox( \
|
||||
node_type, cur, container_node_member); \
|
||||
node_type, \
|
||||
cur, \
|
||||
container_node_member); \
|
||||
fx_bst_node *next = NULL; \
|
||||
\
|
||||
if (node->container_key_member \
|
||||
@@ -140,20 +147,27 @@ FX_TYPE_CLASS_DECLARATION_END(fx_bst_iterator)
|
||||
conforms to the requirements listed above.
|
||||
*/
|
||||
#define FX_BST_DEFINE_INSERT( \
|
||||
node_type, container_node_member, container_key_member, function_name, \
|
||||
node_type, \
|
||||
container_node_member, \
|
||||
container_key_member, \
|
||||
function_name, \
|
||||
comparator) \
|
||||
void function_name(fx_bst *tree, node_type *node) \
|
||||
{ \
|
||||
if (!tree->bst_root) { \
|
||||
tree->bst_root = &node->container_node_member; \
|
||||
fx_bst_insert_fixup(tree, &node->container_node_member); \
|
||||
fx_bst_insert_fixup( \
|
||||
tree, \
|
||||
&node->container_node_member); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
fx_bst_node *cur = tree->bst_root; \
|
||||
while (1) { \
|
||||
node_type *cur_node = fx_unbox( \
|
||||
node_type, cur, container_node_member); \
|
||||
node_type, \
|
||||
cur, \
|
||||
container_node_member); \
|
||||
fx_bst_node *next = NULL; \
|
||||
int cmp = comparator(node, cur_node); \
|
||||
\
|
||||
@@ -218,14 +232,19 @@ FX_TYPE_CLASS_DECLARATION_END(fx_bst_iterator)
|
||||
@param function_name the name of the function to generate.
|
||||
*/
|
||||
#define FX_BST_DEFINE_SIMPLE_GET( \
|
||||
node_type, key_type, container_node_member, container_key_member, \
|
||||
node_type, \
|
||||
key_type, \
|
||||
container_node_member, \
|
||||
container_key_member, \
|
||||
function_name) \
|
||||
node_type *function_name(const fx_bst *tree, key_type key) \
|
||||
{ \
|
||||
fx_bst_node *cur = tree->bst_root; \
|
||||
while (cur) { \
|
||||
node_type *cur_node = fx_unbox( \
|
||||
node_type, cur, container_node_member); \
|
||||
node_type, \
|
||||
cur, \
|
||||
container_node_member); \
|
||||
if (key > cur_node->container_key_member) { \
|
||||
cur = fx_bst_right(cur); \
|
||||
} else if (key < cur_node->container_key_member) { \
|
||||
@@ -240,7 +259,8 @@ FX_TYPE_CLASS_DECLARATION_END(fx_bst_iterator)
|
||||
|
||||
#define fx_bst_foreach(it, bst) \
|
||||
for (int z__fx_unique_name() = fx_bst_iterator_begin(bst, it); \
|
||||
(it)->node != NULL; fx_bst_iterator_next(it))
|
||||
(it)->node != NULL; \
|
||||
fx_bst_iterator_next(it))
|
||||
|
||||
/* binary tree nodes. this *cannot* be used directly. you need to define a
|
||||
custom node type that contains a member variable of type fx_bst_node.
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef FX_CORE_BSTR_H_
|
||||
#define FX_CORE_BSTR_H_
|
||||
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -19,7 +19,8 @@ typedef struct fx_bstr {
|
||||
uint64_t bstr_magic;
|
||||
enum fx_bstr_flags bstr_flags;
|
||||
char *bstr_buf;
|
||||
/* total number of characters in bstr_buf, not including null terminator */
|
||||
/* total number of characters in bstr_buf, not including null terminator
|
||||
*/
|
||||
size_t bstr_len;
|
||||
/* number of bytes allocated for bstr_buf (includes space for the null
|
||||
* terminator) */
|
||||
@@ -49,20 +50,32 @@ FX_API fx_status fx_bstr_pop_indent(fx_bstr *strv);
|
||||
|
||||
FX_API fx_status fx_bstr_write_char(fx_bstr *strv, char c);
|
||||
FX_API fx_status fx_bstr_write_chars(
|
||||
fx_bstr *strv, const char *cs, size_t len, size_t *nr_written);
|
||||
FX_API fx_status fx_bstr_write_cstr(
|
||||
fx_bstr *strv, const char *str, size_t *nr_written);
|
||||
FX_API fx_status fx_bstr_write_cstr_list(
|
||||
fx_bstr *strv, const char **strs, size_t *nr_written);
|
||||
fx_bstr *strv,
|
||||
const char *cs,
|
||||
size_t len,
|
||||
size_t *nr_written);
|
||||
FX_API fx_status
|
||||
fx_bstr_write_cstr(fx_bstr *strv, const char *str, size_t *nr_written);
|
||||
FX_API fx_status
|
||||
fx_bstr_write_cstr_list(fx_bstr *strv, const char **strs, size_t *nr_written);
|
||||
FX_API fx_status fx_bstr_write_cstr_array(
|
||||
fx_bstr *strv, const char **strs, size_t count, size_t *nr_written);
|
||||
FX_API fx_status fx_bstr_write_cstr_varg(fx_bstr *strv, size_t *nr_written, ...);
|
||||
fx_bstr *strv,
|
||||
const char **strs,
|
||||
size_t count,
|
||||
size_t *nr_written);
|
||||
FX_API fx_status
|
||||
fx_bstr_write_cstr_varg(fx_bstr *strv, size_t *nr_written, ...);
|
||||
FX_API fx_status fx_bstr_write_rope(
|
||||
fx_bstr *strv, const struct fx_rope *rope, size_t *nr_written);
|
||||
FX_API fx_status fx_bstr_write_fmt(
|
||||
fx_bstr *strv, size_t *nr_written, const char *format, ...);
|
||||
fx_bstr *strv,
|
||||
const struct fx_rope *rope,
|
||||
size_t *nr_written);
|
||||
FX_API fx_status
|
||||
fx_bstr_write_fmt(fx_bstr *strv, size_t *nr_written, const char *format, ...);
|
||||
FX_API fx_status fx_bstr_write_vfmt(
|
||||
fx_bstr *strv, size_t *nr_written, const char *format, va_list arg);
|
||||
fx_bstr *strv,
|
||||
size_t *nr_written,
|
||||
const char *format,
|
||||
va_list arg);
|
||||
|
||||
FX_API char *fx_bstr_rope(const struct fx_rope *rope, size_t *nr_written);
|
||||
FX_API char *fx_bstr_fmt(size_t *nr_written, const char *format, ...);
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_OBJECT_CLASS_H_
|
||||
#define FX_OBJECT_CLASS_H_
|
||||
#ifndef FX_CLASS_H_
|
||||
#define FX_CLASS_H_
|
||||
|
||||
#include <fx/core/type.h>
|
||||
#include <fx/type.h>
|
||||
|
||||
#define FX_CLASS_MAGIC 0xDEADFACEDCAFEBEDULL
|
||||
#define FX_CLASS(p) ((fx_class *)(p))
|
||||
@@ -1,418 +0,0 @@
|
||||
#ifndef FX_CORE_ERROR_H_
|
||||
#define FX_CORE_ERROR_H_
|
||||
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FX_ERROR_TEMPLATE_PARAMETER_MAX 4
|
||||
#define FX_ERROR_MSG_ID_INVALID ((unsigned long)-1)
|
||||
|
||||
#define FX_CATCH(err, expr) ((err = (expr)) != NULL)
|
||||
|
||||
#define fx_result_is_error(result) ((result) != NULL)
|
||||
#define fx_result_is_success(result) ((result) == NULL)
|
||||
|
||||
#define FX_RESULT_SUCCESS ((fx_result)NULL)
|
||||
#define FX_RESULT_ERR(err_name) \
|
||||
fx_error_with_code(fx_error_vendor_get_builtin(), FX_ERR_##err_name)
|
||||
#define FX_RESULT_ERR_WITH_STRING(err_name, ...) \
|
||||
fx_error_with_string( \
|
||||
fx_error_vendor_get_builtin(), FX_ERR_##err_name, __VA_ARGS__)
|
||||
#define FX_RESULT_STATUS(code) \
|
||||
((code) == FX_SUCCESS \
|
||||
? FX_RESULT_SUCCESS \
|
||||
: (fx_error_with_code(fx_error_vendor_get_builtin(), code)))
|
||||
#define FX_RESULT_STATUS_WITH_STRING(code, ...) \
|
||||
((code) == FX_SUCCESS \
|
||||
? FX_RESULT_SUCCESS \
|
||||
: (fx_error_with_string( \
|
||||
fx_error_vendor_get_builtin(), code, __VA_ARGS__)))
|
||||
|
||||
#define FX_ERRORS_BUILTIN (fx_error_vendor_get_builtin())
|
||||
#define FX_ERRORS_ERRNO (fx_error_vendor_get_errno())
|
||||
|
||||
#define FX_ERROR_PARAM(name, value) \
|
||||
(fx_error_template_parameter) \
|
||||
{ \
|
||||
.param_name = (name), .param_value = (uintptr_t)(value), \
|
||||
}
|
||||
|
||||
#define FX_ERROR_TEMPLATE_PARAM(name, type, format) \
|
||||
(fx_error_template_parameter_definition) \
|
||||
{ \
|
||||
.param_name = (name), .param_type = (type), \
|
||||
.param_format = (format), \
|
||||
}
|
||||
#define FX_ERROR_DEFINITION(code, name, msg) \
|
||||
[code] = (fx_error_definition) \
|
||||
{ \
|
||||
.err_name = (name), .err_message = (msg), \
|
||||
}
|
||||
#define FX_ERROR_DEFINITION_TEMPLATE(code, name, msg, ...) \
|
||||
[code] = (fx_error_definition) \
|
||||
{ \
|
||||
.err_name = (name), .err_message = (msg), \
|
||||
.err_params = __VA_ARGS__, \
|
||||
}
|
||||
|
||||
#define FX_ERROR_MSG(id, content) \
|
||||
[id] = (fx_error_msg) \
|
||||
{ \
|
||||
.msg_message = (content), \
|
||||
}
|
||||
#define FX_ERROR_MSG_TEMPLATE(id, content, ...) \
|
||||
[id] = (fx_error_msg) \
|
||||
{ \
|
||||
.msg_message = (content), .msg_params = __VA_ARGS__, \
|
||||
}
|
||||
|
||||
#define z__fx_error_create_status(status_code) \
|
||||
(z__fx_error_create( \
|
||||
fx_error_vendor_get_builtin(), status_code, NULL, NULL, 0, \
|
||||
NULL, NULL))
|
||||
|
||||
/* Error creation macros */
|
||||
#define fx_error_with_code(vendor, code) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define fx_error_caused_by_error(vendor, code, cause_error) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define fx_error_caused_by_status(vendor, code, cause_status) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define fx_error_caused_by_code(vendor, code, cause_vendor, cause_code) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, fx_error_with_code(cause_vendor, cause_code), \
|
||||
__FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define fx_error_with_string(vendor, code, ...) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__))
|
||||
#define fx_error_with_string_caused_by_error(vendor, code, cause_error, ...) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
__VA_ARGS__))
|
||||
#define fx_error_with_string_caused_by_status(vendor, code, cause_status, ...) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__))
|
||||
#define fx_error_with_msg(vendor, code, msg_id) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_with_msg_caused_by_error(vendor, code, cause_error, msg_id) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
msg_id, (fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_with_msg_caused_by_status(vendor, code, cause_status, msg_id) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_with_msg_template(vendor, code, msg_id, ...) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_msg_template_caused_by_error( \
|
||||
vendor, code, cause_error, msg_id, ...) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
msg_id, (fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_msg_template_caused_by_status( \
|
||||
vendor, code, cause_status, msg_id, ...) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_template(vendor, code, ...) \
|
||||
(z__fx_error_create_template( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_template_caused_by_error(vendor, code, cause_error, ...) \
|
||||
(z__fx_error_create_template( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_template_caused_by_status(vendor, code, cause_status, ...) \
|
||||
(z__fx_error_create_template( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
|
||||
/* Error propagation macros */
|
||||
#define fx_result_propagate(err) \
|
||||
(z__fx_error_propagate(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
#define fx_error_caused_by(err, caused_by) (z__fx_error_caused_by(err, caused_by))
|
||||
#define fx_error_caused_by_fx_status(err, status) \
|
||||
(z__fx_error_caused_by_fx_status(err, status))
|
||||
#define fx_error_replace(err, caused_by) \
|
||||
(z__fx_error_propagate(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
|
||||
/* Error throw macros */
|
||||
#define z__fx_throw(err) (z__fx_error_throw(err, NULL, 0, NULL))
|
||||
#define fx_throw(err) (z__fx_error_throw(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
#define fx_throw_status(status) \
|
||||
(z__fx_error_throw( \
|
||||
z__fx_error_create( \
|
||||
fx_error_vendor_get_builtin(), status, NULL, NULL, 0, \
|
||||
NULL, NULL), \
|
||||
__FILE__, __LINE__, __FUNCTION__))
|
||||
|
||||
#define fx_throw_status_string(status, ...) \
|
||||
(z__fx_error_throw( \
|
||||
z__fx_error_create( \
|
||||
fx_error_vendor_get_builtin(), status, NULL, NULL, 0, \
|
||||
NULL, __VA_ARGS__), \
|
||||
__FILE__, __LINE__, __FUNCTION__))
|
||||
#define fx_throw_error_code(vendor, code) \
|
||||
z__fx_throw(fx_error_with_code(vendor, code))
|
||||
#define fx_throw_error_caused_by_error(vendor, code, cause) \
|
||||
z__fx_throw(fx_error_caused_by_error(vendor, code, cause))
|
||||
#define fx_throw_error_caused_by_status(vendor, code, cause) \
|
||||
z__fx_throw(fx_error_caused_by_status(vendor, code, cause))
|
||||
#define fx_throw_error_with_string(vendor, code, ...) \
|
||||
z__fx_throw(fx_error_with_string(vendor, code, __VA_ARGS__))
|
||||
#define fx_throw_error_with_string_caused_by_error(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_string_caused_by_error( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
#define fx_throw_error_with_string_caused_by_status(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_string_caused_by_status( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
|
||||
#define fx_throw_error_with_msg(vendor, code, msg_id) \
|
||||
z__fx_throw(fx_error_with_msg(vendor, code, msg_id))
|
||||
#define fx_throw_error_with_msg_caused_by_error(vendor, code, cause, msg_id) \
|
||||
z__fx_throw(fx_error_with_msg_caused_by_error(vendor, code, cause, msg_id))
|
||||
#define fx_throw_error_with_msg_caused_by_status(vendor, code, cause, msg_id) \
|
||||
z__fx_throw(fx_error_with_msg_caused_by_status(vendor, code, cause, msg_id))
|
||||
|
||||
#define fx_throw_error_with_msg_template(vendor, code, msg_id, ...) \
|
||||
z__fx_throw(fx_error_with_msg_template(vendor, code, msg_id, __VA_ARGS__))
|
||||
#define fx_throw_error_with_msg_template_caused_by_error( \
|
||||
vendor, code, cause, msg_id, ...) \
|
||||
z__fx_throw(fx_error_with_msg_template_caused_by_error( \
|
||||
vendor, code, cause, msg_id, __VA_ARGS__))
|
||||
#define fx_throw_error_with_msg_template_caused_by_status( \
|
||||
vendor, code, cause, msg_id, ...) \
|
||||
z__fx_throw(fx_error_with_msg_template_caused_by_status( \
|
||||
vendor, code, cause, msg_id, __VA_ARGS__))
|
||||
|
||||
#define fx_throw_error_with_template(vendor, code, ...) \
|
||||
z__fx_throw(fx_error_with_template(vendor, code, __VA_ARGS__))
|
||||
#define fx_throw_error_with_template_caused_by_error(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_template_caused_by_error( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
#define fx_throw_error_with_template_caused_by_status(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_template_caused_by_status( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
|
||||
#define FX_ERR_MSG(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_ERROR, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define FX_ERR_MSG_WARN(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_WARN, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define FX_ERR_MSG_INFO(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_INFO, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define FX_ERR_MSG_END(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_NONE, \
|
||||
.msg_content = NULL, \
|
||||
}
|
||||
|
||||
typedef enum fx_error_submsg_type {
|
||||
FX_ERROR_SUBMSG_NONE = 0,
|
||||
FX_ERROR_SUBMSG_ERROR,
|
||||
FX_ERROR_SUBMSG_WARNING,
|
||||
FX_ERROR_SUBMSG_INFO,
|
||||
} fx_error_submsg_type;
|
||||
|
||||
typedef enum fx_error_report_flags {
|
||||
FX_ERROR_REPORT_NONE = 0,
|
||||
FX_ERROR_REPORT_STATUS = 0x01u,
|
||||
FX_ERROR_REPORT_DESCRIPTION = 0x02u,
|
||||
FX_ERROR_REPORT_SUBMSG = 0x04u,
|
||||
FX_ERROR_REPORT_STACK_TRACE = 0x08u,
|
||||
FX_ERROR_REPORT_CAUSE = 0x10u,
|
||||
|
||||
FX_ERROR_REPORT_MINIMAL = FX_ERROR_REPORT_STATUS | FX_ERROR_REPORT_DESCRIPTION,
|
||||
FX_ERROR_REPORT_DEFAULT = FX_ERROR_REPORT_MINIMAL | FX_ERROR_REPORT_SUBMSG
|
||||
| FX_ERROR_REPORT_CAUSE,
|
||||
FX_ERROR_REPORT_ALL = FX_ERROR_REPORT_DEFAULT | FX_ERROR_REPORT_STACK_TRACE,
|
||||
} fx_error_report_flags;
|
||||
|
||||
typedef enum fx_error_template_parameter_type {
|
||||
FX_ERROR_TEMPLATE_PARAM_NONE = 0,
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
FX_ERROR_TEMPLATE_PARAM_CHAR,
|
||||
FX_ERROR_TEMPLATE_PARAM_INT,
|
||||
FX_ERROR_TEMPLATE_PARAM_UINT,
|
||||
FX_ERROR_TEMPLATE_PARAM_LONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_ULONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_LONGLONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_ULONGLONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_SIZE_T,
|
||||
FX_ERROR_TEMPLATE_PARAM_INTPTR,
|
||||
FX_ERROR_TEMPLATE_PARAM_UINTPTR,
|
||||
FX_ERROR_TEMPLATE_PARAM_PTR,
|
||||
} fx_error_template_parameter_type;
|
||||
|
||||
typedef struct fx_error_template_parameter_definition {
|
||||
const char *param_name;
|
||||
fx_error_template_parameter_type param_type;
|
||||
const char *param_format;
|
||||
} fx_error_template_parameter_definition;
|
||||
|
||||
typedef struct fx_error_template_parameter {
|
||||
const char *param_name;
|
||||
uintptr_t param_value;
|
||||
const struct fx_error_template_parameter_definition *__param_def;
|
||||
} fx_error_template_parameter;
|
||||
|
||||
struct fx_error_vendor;
|
||||
|
||||
typedef struct fx_error fx_error;
|
||||
typedef struct fx_error *fx_result;
|
||||
typedef struct fx_error_submsg fx_error_submsg;
|
||||
typedef struct fx_error_stack_frame fx_error_stack_frame;
|
||||
typedef long fx_error_status_code;
|
||||
typedef unsigned long fx_error_msg_id;
|
||||
|
||||
typedef struct fx_error_definition {
|
||||
const char *err_name;
|
||||
const char *err_message;
|
||||
const fx_error_template_parameter_definition err_params[FX_ERROR_TEMPLATE_PARAMETER_MAX];
|
||||
} fx_error_definition;
|
||||
|
||||
typedef struct fx_error_msg {
|
||||
const char *msg_message;
|
||||
const fx_error_template_parameter_definition msg_params[FX_ERROR_TEMPLATE_PARAMETER_MAX];
|
||||
} fx_error_msg;
|
||||
|
||||
typedef const fx_error_definition *(*fx_error_status_code_get_definition)(
|
||||
const struct fx_error_vendor *, fx_error_status_code);
|
||||
typedef const fx_error_msg *(*fx_error_msg_get_definition)(
|
||||
const struct fx_error_vendor *, fx_error_msg_id);
|
||||
typedef void (*fx_error_report_function)(
|
||||
const struct fx_error *, fx_error_report_flags);
|
||||
|
||||
typedef struct fx_error_vendor {
|
||||
const char *v_name;
|
||||
|
||||
fx_error_status_code_get_definition v_status_get_definition;
|
||||
fx_error_msg_get_definition v_msg_get_definition;
|
||||
|
||||
const fx_error_definition *v_error_definitions;
|
||||
size_t v_error_definitions_length;
|
||||
|
||||
const fx_error_msg *v_msg;
|
||||
size_t v_msg_length;
|
||||
} fx_error_vendor;
|
||||
|
||||
FX_API fx_error *z__fx_error_create_template(
|
||||
const fx_error_vendor *, fx_error_status_code, fx_error *, const char *,
|
||||
unsigned int, const char *, const fx_error_template_parameter[]);
|
||||
FX_API fx_error *z__fx_error_create_string(
|
||||
const fx_error_vendor *, fx_error_status_code, fx_error *, const char *,
|
||||
unsigned int, const char *, const char *, va_list);
|
||||
FX_API fx_error *z__fx_error_create_msg(
|
||||
const fx_error_vendor *, fx_error_status_code, fx_error *, const char *,
|
||||
unsigned int, const char *, fx_error_msg_id,
|
||||
const fx_error_template_parameter[]);
|
||||
FX_API fx_error *z__fx_error_propagate(
|
||||
fx_error *, const char *, unsigned int, const char *);
|
||||
FX_API fx_error *z__fx_error_caused_by(fx_error *, fx_error *);
|
||||
FX_API fx_error *z__fx_error_caused_by_fx_status(fx_error *, fx_status);
|
||||
FX_API void z__fx_error_throw(fx_error *, const char *, unsigned int, const char *);
|
||||
|
||||
FX_API bool fx_result_is(
|
||||
fx_result result, const fx_error_vendor *vendor, fx_error_status_code code);
|
||||
|
||||
FX_API const fx_error_vendor *fx_error_vendor_get_builtin(void);
|
||||
FX_API const fx_error_vendor *fx_error_vendor_get_errno(void);
|
||||
FX_API const fx_error_definition *fx_error_vendor_get_error_definition(
|
||||
const fx_error_vendor *vendor, fx_error_status_code code);
|
||||
FX_API const char *fx_error_vendor_get_status_code_name(
|
||||
const fx_error_vendor *vendor, fx_error_status_code code);
|
||||
FX_API const char *fx_error_vendor_get_status_code_description(
|
||||
const fx_error_vendor *vendor, fx_error_status_code code);
|
||||
FX_API const fx_error_msg *fx_error_vendor_get_msg(
|
||||
const fx_error_vendor *vendor, fx_error_msg_id msg_id);
|
||||
|
||||
static inline fx_error *z__fx_error_create(
|
||||
const fx_error_vendor *v, fx_error_status_code c, fx_error *c2,
|
||||
const char *f0, unsigned int l, const char *f1, const char *d, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, d);
|
||||
fx_error *err = z__fx_error_create_string(v, c, c2, f0, l, f1, d, arg);
|
||||
va_end(arg);
|
||||
return err;
|
||||
}
|
||||
|
||||
FX_API enum fx_status fx_error_add_submsg_string(
|
||||
fx_error *error, fx_error_submsg_type type, const char *msg, ...);
|
||||
FX_API enum fx_status z__fx_error_add_submsg_template(
|
||||
fx_error *error, fx_error_submsg_type type, fx_error_msg_id msg_id,
|
||||
fx_error_template_parameter param[]);
|
||||
#define fx_error_add_submsg(error, type, msg_id) \
|
||||
(z__fx_error_add_submsg_template( \
|
||||
error, type, msg_id, (fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_add_submsg_template(error, type, msg_id, ...) \
|
||||
(z__fx_error_add_submsg_template( \
|
||||
error, type, msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
|
||||
FX_API void fx_error_discard(fx_error *error);
|
||||
|
||||
FX_API fx_error_status_code fx_error_get_status_code(const fx_error *error);
|
||||
FX_API const fx_error_vendor *fx_error_get_vendor(const fx_error *error);
|
||||
FX_API const fx_error_definition *fx_error_get_definition(const fx_error *error);
|
||||
FX_API const fx_error_template_parameter *fx_error_get_template_parameter(
|
||||
const fx_error *error, const char *param_name);
|
||||
FX_API const fx_error_template_parameter *fx_error_get_template_parameters(
|
||||
const fx_error *error);
|
||||
FX_API const char *fx_error_get_description(const fx_error *error);
|
||||
FX_API const fx_error_msg *fx_error_get_msg(const fx_error *error);
|
||||
FX_API const fx_error_submsg *fx_error_get_first_submsg(const fx_error *error);
|
||||
FX_API const fx_error_submsg *fx_error_get_next_submsg(
|
||||
const fx_error *error, const fx_error_submsg *msg);
|
||||
FX_API const fx_error_stack_frame *fx_error_get_first_stack_frame(
|
||||
const fx_error *error);
|
||||
FX_API const fx_error_stack_frame *fx_error_get_next_stack_frame(
|
||||
const fx_error *error, const fx_error_stack_frame *frame);
|
||||
FX_API const fx_error *fx_error_get_caused_by(const fx_error *error);
|
||||
|
||||
FX_API fx_error_submsg_type fx_error_submsg_get_type(const fx_error_submsg *msg);
|
||||
FX_API const char *fx_error_submsg_get_content(const fx_error_submsg *msg);
|
||||
FX_API const fx_error_msg *fx_error_submsg_get_msg(const fx_error_submsg *msg);
|
||||
FX_API const fx_error_template_parameter *fx_error_submsg_get_template_parameters(
|
||||
const fx_error_submsg *msg);
|
||||
|
||||
FX_API const char *fx_error_stack_frame_get_filepath(
|
||||
const fx_error_stack_frame *frame);
|
||||
FX_API unsigned int fx_error_stack_frame_get_line_number(
|
||||
const fx_error_stack_frame *frame);
|
||||
FX_API const char *fx_error_stack_frame_get_function_name(
|
||||
const fx_error_stack_frame *frame);
|
||||
|
||||
FX_API const fx_error_template_parameter_definition *fx_error_definition_get_template_parameter(
|
||||
const fx_error_definition *error_def, const char *param_name);
|
||||
|
||||
FX_API const char *fx_error_msg_get_content(const fx_error_msg *msg);
|
||||
FX_API const fx_error_template_parameter_definition *fx_error_msg_get_template_parameter(
|
||||
const fx_error_msg *msg, const char *param_name);
|
||||
|
||||
FX_API void fx_set_error_report_function(
|
||||
fx_error_report_function func, fx_error_report_flags flags);
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_CORE_ENCODING_H_
|
||||
#define FX_CORE_ENCODING_H_
|
||||
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -36,6 +36,7 @@ FX_API unsigned int fx_wchar_utf8_codepoint_encode(fx_wchar c, char s[4]);
|
||||
FX_API unsigned int fx_wchar_utf8_codepoint_stride(const char *s);
|
||||
FX_API size_t fx_wchar_utf8_codepoint_count(const char *s, size_t nr_bytes);
|
||||
FX_API size_t fx_wchar_utf8_string_encoded_size(
|
||||
const fx_wchar *s, size_t nr_codepoints);
|
||||
const fx_wchar *s,
|
||||
size_t nr_codepoints);
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_CORE_ENDIAN_H_
|
||||
#define FX_CORE_ENDIAN_H_
|
||||
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
@@ -0,0 +1,643 @@
|
||||
#ifndef FX_CORE_ERROR_H_
|
||||
#define FX_CORE_ERROR_H_
|
||||
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FX_ERROR_TEMPLATE_PARAMETER_MAX 4
|
||||
#define FX_ERROR_MSG_ID_INVALID ((unsigned long)-1)
|
||||
|
||||
#define FX_CATCH(err, expr) ((err = (expr)) != NULL)
|
||||
|
||||
#define fx_result_is_error(result) ((result) != NULL)
|
||||
#define fx_result_is_success(result) ((result) == NULL)
|
||||
|
||||
#define FX_RESULT_SUCCESS ((fx_result)NULL)
|
||||
#define FX_RESULT_ERR(err_name) \
|
||||
fx_error_with_code(fx_error_vendor_get_builtin(), FX_ERR_##err_name)
|
||||
#define FX_RESULT_ERR_WITH_STRING(err_name, ...) \
|
||||
fx_error_with_string( \
|
||||
fx_error_vendor_get_builtin(), \
|
||||
FX_ERR_##err_name, \
|
||||
__VA_ARGS__)
|
||||
#define FX_RESULT_STATUS(code) \
|
||||
((code) == FX_SUCCESS \
|
||||
? FX_RESULT_SUCCESS \
|
||||
: (fx_error_with_code(fx_error_vendor_get_builtin(), code)))
|
||||
#define FX_RESULT_STATUS_WITH_STRING(code, ...) \
|
||||
((code) == FX_SUCCESS ? FX_RESULT_SUCCESS \
|
||||
: (fx_error_with_string( \
|
||||
fx_error_vendor_get_builtin(), \
|
||||
code, \
|
||||
__VA_ARGS__)))
|
||||
|
||||
#define FX_ERRORS_BUILTIN (fx_error_vendor_get_builtin())
|
||||
#define FX_ERRORS_ERRNO (fx_error_vendor_get_errno())
|
||||
|
||||
#define FX_ERROR_PARAM(name, value) \
|
||||
(fx_error_template_parameter) \
|
||||
{ \
|
||||
.param_name = (name), .param_value = (uintptr_t)(value), \
|
||||
}
|
||||
|
||||
#define FX_ERROR_TEMPLATE_PARAM(name, type, format) \
|
||||
(fx_error_template_parameter_definition) \
|
||||
{ \
|
||||
.param_name = (name), .param_type = (type), \
|
||||
.param_format = (format), \
|
||||
}
|
||||
#define FX_ERROR_DEFINITION(code, name, msg) \
|
||||
[code] = (fx_error_definition) \
|
||||
{ \
|
||||
.err_name = (name), .err_message = (msg), \
|
||||
}
|
||||
#define FX_ERROR_DEFINITION_TEMPLATE(code, name, msg, ...) \
|
||||
[code] = (fx_error_definition) \
|
||||
{ \
|
||||
.err_name = (name), .err_message = (msg), \
|
||||
.err_params = __VA_ARGS__, \
|
||||
}
|
||||
|
||||
#define FX_ERROR_MSG(id, content) \
|
||||
[id] = (fx_error_msg) \
|
||||
{ \
|
||||
.msg_message = (content), \
|
||||
}
|
||||
#define FX_ERROR_MSG_TEMPLATE(id, content, ...) \
|
||||
[id] = (fx_error_msg) \
|
||||
{ \
|
||||
.msg_message = (content), .msg_params = __VA_ARGS__, \
|
||||
}
|
||||
|
||||
#define z__fx_error_create_status(status_code) \
|
||||
(z__fx_error_create( \
|
||||
fx_error_vendor_get_builtin(), \
|
||||
status_code, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
0, \
|
||||
NULL, \
|
||||
NULL))
|
||||
|
||||
/* Error creation macros */
|
||||
#define fx_error_with_code(vendor, code) \
|
||||
(z__fx_error_create( \
|
||||
vendor, \
|
||||
code, \
|
||||
NULL, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
NULL))
|
||||
#define fx_error_caused_by_error(vendor, code, cause_error) \
|
||||
(z__fx_error_create( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause_error, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
NULL))
|
||||
#define fx_error_caused_by_status(vendor, code, cause_status) \
|
||||
(z__fx_error_create( \
|
||||
vendor, \
|
||||
code, \
|
||||
z__fx_error_create_status(cause_status), \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
NULL))
|
||||
#define fx_error_caused_by_code(vendor, code, cause_vendor, cause_code) \
|
||||
(z__fx_error_create( \
|
||||
vendor, \
|
||||
code, \
|
||||
fx_error_with_code(cause_vendor, cause_code), \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
NULL))
|
||||
#define fx_error_with_string(vendor, code, ...) \
|
||||
(z__fx_error_create( \
|
||||
vendor, \
|
||||
code, \
|
||||
NULL, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
__VA_ARGS__))
|
||||
#define fx_error_with_string_caused_by_error(vendor, code, cause_error, ...) \
|
||||
(z__fx_error_create( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause_error, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
__VA_ARGS__))
|
||||
#define fx_error_with_string_caused_by_status(vendor, code, cause_status, ...) \
|
||||
(z__fx_error_create( \
|
||||
vendor, \
|
||||
code, \
|
||||
z__fx_error_create_status(cause_status), \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
__VA_ARGS__))
|
||||
#define fx_error_with_msg(vendor, code, msg_id) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, \
|
||||
code, \
|
||||
NULL, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
msg_id, \
|
||||
(fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_with_msg_caused_by_error(vendor, code, cause_error, msg_id) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause_error, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
msg_id, \
|
||||
(fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_with_msg_caused_by_status(vendor, code, cause_status, msg_id) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, \
|
||||
code, \
|
||||
z__fx_error_create_status(cause_status), \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
msg_id, \
|
||||
(fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_with_msg_template(vendor, code, msg_id, ...) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, \
|
||||
code, \
|
||||
NULL, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_msg_template_caused_by_error( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause_error, \
|
||||
msg_id, \
|
||||
...) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause_error, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_msg_template_caused_by_status( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause_status, \
|
||||
msg_id, \
|
||||
...) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, \
|
||||
code, \
|
||||
z__fx_error_create_status(cause_status), \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_template(vendor, code, ...) \
|
||||
(z__fx_error_create_template( \
|
||||
vendor, \
|
||||
code, \
|
||||
NULL, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_template_caused_by_error(vendor, code, cause_error, ...) \
|
||||
(z__fx_error_create_template( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause_error, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_template_caused_by_status( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause_status, \
|
||||
...) \
|
||||
(z__fx_error_create_template( \
|
||||
vendor, \
|
||||
code, \
|
||||
z__fx_error_create_status(cause_status), \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
|
||||
/* Error propagation macros */
|
||||
#define fx_result_propagate(err) \
|
||||
(z__fx_error_propagate(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
#define fx_error_caused_by(err, caused_by) \
|
||||
(z__fx_error_caused_by(err, caused_by))
|
||||
#define fx_error_caused_by_fx_status(err, status) \
|
||||
(z__fx_error_caused_by_fx_status(err, status))
|
||||
#define fx_error_replace(err, caused_by) \
|
||||
(z__fx_error_propagate(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
|
||||
/* Error throw macros */
|
||||
#define z__fx_throw(err) (z__fx_error_throw(err, NULL, 0, NULL))
|
||||
#define fx_throw(err) (z__fx_error_throw(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
#define fx_throw_status(status) \
|
||||
(z__fx_error_throw( \
|
||||
z__fx_error_create( \
|
||||
fx_error_vendor_get_builtin(), \
|
||||
status, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
0, \
|
||||
NULL, \
|
||||
NULL), \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__))
|
||||
|
||||
#define fx_throw_status_string(status, ...) \
|
||||
(z__fx_error_throw( \
|
||||
z__fx_error_create( \
|
||||
fx_error_vendor_get_builtin(), \
|
||||
status, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
0, \
|
||||
NULL, \
|
||||
__VA_ARGS__), \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__FUNCTION__))
|
||||
#define fx_throw_error_code(vendor, code) \
|
||||
z__fx_throw(fx_error_with_code(vendor, code))
|
||||
#define fx_throw_error_caused_by_error(vendor, code, cause) \
|
||||
z__fx_throw(fx_error_caused_by_error(vendor, code, cause))
|
||||
#define fx_throw_error_caused_by_status(vendor, code, cause) \
|
||||
z__fx_throw(fx_error_caused_by_status(vendor, code, cause))
|
||||
#define fx_throw_error_with_string(vendor, code, ...) \
|
||||
z__fx_throw(fx_error_with_string(vendor, code, __VA_ARGS__))
|
||||
#define fx_throw_error_with_string_caused_by_error(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_string_caused_by_error( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
__VA_ARGS__))
|
||||
#define fx_throw_error_with_string_caused_by_status(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_string_caused_by_status( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
__VA_ARGS__))
|
||||
|
||||
#define fx_throw_error_with_msg(vendor, code, msg_id) \
|
||||
z__fx_throw(fx_error_with_msg(vendor, code, msg_id))
|
||||
#define fx_throw_error_with_msg_caused_by_error(vendor, code, cause, msg_id) \
|
||||
z__fx_throw(fx_error_with_msg_caused_by_error( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
msg_id))
|
||||
#define fx_throw_error_with_msg_caused_by_status(vendor, code, cause, msg_id) \
|
||||
z__fx_throw(fx_error_with_msg_caused_by_status( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
msg_id))
|
||||
|
||||
#define fx_throw_error_with_msg_template(vendor, code, msg_id, ...) \
|
||||
z__fx_throw( \
|
||||
fx_error_with_msg_template(vendor, code, msg_id, __VA_ARGS__))
|
||||
#define fx_throw_error_with_msg_template_caused_by_error( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
msg_id, \
|
||||
...) \
|
||||
z__fx_throw(fx_error_with_msg_template_caused_by_error( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
msg_id, \
|
||||
__VA_ARGS__))
|
||||
#define fx_throw_error_with_msg_template_caused_by_status( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
msg_id, \
|
||||
...) \
|
||||
z__fx_throw(fx_error_with_msg_template_caused_by_status( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
msg_id, \
|
||||
__VA_ARGS__))
|
||||
|
||||
#define fx_throw_error_with_template(vendor, code, ...) \
|
||||
z__fx_throw(fx_error_with_template(vendor, code, __VA_ARGS__))
|
||||
#define fx_throw_error_with_template_caused_by_error(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_template_caused_by_error( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
__VA_ARGS__))
|
||||
#define fx_throw_error_with_template_caused_by_status( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
...) \
|
||||
z__fx_throw(fx_error_with_template_caused_by_status( \
|
||||
vendor, \
|
||||
code, \
|
||||
cause, \
|
||||
__VA_ARGS__))
|
||||
|
||||
#define FX_ERR_MSG(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_ERROR, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define FX_ERR_MSG_WARN(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_WARN, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define FX_ERR_MSG_INFO(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_INFO, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define FX_ERR_MSG_END(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_NONE, \
|
||||
.msg_content = NULL, \
|
||||
}
|
||||
|
||||
typedef enum fx_error_submsg_type {
|
||||
FX_ERROR_SUBMSG_NONE = 0,
|
||||
FX_ERROR_SUBMSG_ERROR,
|
||||
FX_ERROR_SUBMSG_WARNING,
|
||||
FX_ERROR_SUBMSG_INFO,
|
||||
} fx_error_submsg_type;
|
||||
|
||||
typedef enum fx_error_report_flags {
|
||||
FX_ERROR_REPORT_NONE = 0,
|
||||
FX_ERROR_REPORT_STATUS = 0x01u,
|
||||
FX_ERROR_REPORT_DESCRIPTION = 0x02u,
|
||||
FX_ERROR_REPORT_SUBMSG = 0x04u,
|
||||
FX_ERROR_REPORT_STACK_TRACE = 0x08u,
|
||||
FX_ERROR_REPORT_CAUSE = 0x10u,
|
||||
|
||||
FX_ERROR_REPORT_MINIMAL
|
||||
= FX_ERROR_REPORT_STATUS | FX_ERROR_REPORT_DESCRIPTION,
|
||||
FX_ERROR_REPORT_DEFAULT = FX_ERROR_REPORT_MINIMAL
|
||||
| FX_ERROR_REPORT_SUBMSG
|
||||
| FX_ERROR_REPORT_CAUSE,
|
||||
FX_ERROR_REPORT_ALL
|
||||
= FX_ERROR_REPORT_DEFAULT | FX_ERROR_REPORT_STACK_TRACE,
|
||||
} fx_error_report_flags;
|
||||
|
||||
typedef enum fx_error_template_parameter_type {
|
||||
FX_ERROR_TEMPLATE_PARAM_NONE = 0,
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
FX_ERROR_TEMPLATE_PARAM_CHAR,
|
||||
FX_ERROR_TEMPLATE_PARAM_INT,
|
||||
FX_ERROR_TEMPLATE_PARAM_UINT,
|
||||
FX_ERROR_TEMPLATE_PARAM_LONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_ULONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_LONGLONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_ULONGLONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_SIZE_T,
|
||||
FX_ERROR_TEMPLATE_PARAM_INTPTR,
|
||||
FX_ERROR_TEMPLATE_PARAM_UINTPTR,
|
||||
FX_ERROR_TEMPLATE_PARAM_PTR,
|
||||
} fx_error_template_parameter_type;
|
||||
|
||||
typedef struct fx_error_template_parameter_definition {
|
||||
const char *param_name;
|
||||
fx_error_template_parameter_type param_type;
|
||||
const char *param_format;
|
||||
} fx_error_template_parameter_definition;
|
||||
|
||||
typedef struct fx_error_template_parameter {
|
||||
const char *param_name;
|
||||
uintptr_t param_value;
|
||||
const struct fx_error_template_parameter_definition *__param_def;
|
||||
} fx_error_template_parameter;
|
||||
|
||||
struct fx_error_vendor;
|
||||
|
||||
typedef struct fx_error fx_error;
|
||||
typedef struct fx_error *fx_result;
|
||||
typedef struct fx_error_submsg fx_error_submsg;
|
||||
typedef struct fx_error_stack_frame fx_error_stack_frame;
|
||||
typedef long fx_error_status_code;
|
||||
typedef unsigned long fx_error_msg_id;
|
||||
|
||||
typedef struct fx_error_definition {
|
||||
const char *err_name;
|
||||
const char *err_message;
|
||||
const fx_error_template_parameter_definition
|
||||
err_params[FX_ERROR_TEMPLATE_PARAMETER_MAX];
|
||||
} fx_error_definition;
|
||||
|
||||
typedef struct fx_error_msg {
|
||||
const char *msg_message;
|
||||
const fx_error_template_parameter_definition
|
||||
msg_params[FX_ERROR_TEMPLATE_PARAMETER_MAX];
|
||||
} fx_error_msg;
|
||||
|
||||
typedef const fx_error_definition *(*fx_error_status_code_get_definition)(
|
||||
const struct fx_error_vendor *,
|
||||
fx_error_status_code);
|
||||
typedef const fx_error_msg *(*fx_error_msg_get_definition)(
|
||||
const struct fx_error_vendor *,
|
||||
fx_error_msg_id);
|
||||
typedef void (*fx_error_report_function)(
|
||||
const struct fx_error *,
|
||||
fx_error_report_flags);
|
||||
|
||||
typedef struct fx_error_vendor {
|
||||
const char *v_name;
|
||||
|
||||
fx_error_status_code_get_definition v_status_get_definition;
|
||||
fx_error_msg_get_definition v_msg_get_definition;
|
||||
|
||||
const fx_error_definition *v_error_definitions;
|
||||
size_t v_error_definitions_length;
|
||||
|
||||
const fx_error_msg *v_msg;
|
||||
size_t v_msg_length;
|
||||
} fx_error_vendor;
|
||||
|
||||
FX_API fx_error *z__fx_error_create_template(
|
||||
const fx_error_vendor *,
|
||||
fx_error_status_code,
|
||||
fx_error *,
|
||||
const char *,
|
||||
unsigned int,
|
||||
const char *,
|
||||
const fx_error_template_parameter[]);
|
||||
FX_API fx_error *z__fx_error_create_string(
|
||||
const fx_error_vendor *,
|
||||
fx_error_status_code,
|
||||
fx_error *,
|
||||
const char *,
|
||||
unsigned int,
|
||||
const char *,
|
||||
const char *,
|
||||
va_list);
|
||||
FX_API fx_error *z__fx_error_create_msg(
|
||||
const fx_error_vendor *,
|
||||
fx_error_status_code,
|
||||
fx_error *,
|
||||
const char *,
|
||||
unsigned int,
|
||||
const char *,
|
||||
fx_error_msg_id,
|
||||
const fx_error_template_parameter[]);
|
||||
FX_API fx_error *z__fx_error_propagate(
|
||||
fx_error *,
|
||||
const char *,
|
||||
unsigned int,
|
||||
const char *);
|
||||
FX_API fx_error *z__fx_error_caused_by(fx_error *, fx_error *);
|
||||
FX_API fx_error *z__fx_error_caused_by_fx_status(fx_error *, fx_status);
|
||||
FX_API void z__fx_error_throw(
|
||||
fx_error *,
|
||||
const char *,
|
||||
unsigned int,
|
||||
const char *);
|
||||
|
||||
FX_API bool fx_result_is(
|
||||
fx_result result,
|
||||
const fx_error_vendor *vendor,
|
||||
fx_error_status_code code);
|
||||
|
||||
FX_API const fx_error_vendor *fx_error_vendor_get_builtin(void);
|
||||
FX_API const fx_error_vendor *fx_error_vendor_get_errno(void);
|
||||
FX_API const fx_error_definition *fx_error_vendor_get_error_definition(
|
||||
const fx_error_vendor *vendor,
|
||||
fx_error_status_code code);
|
||||
FX_API const char *fx_error_vendor_get_status_code_name(
|
||||
const fx_error_vendor *vendor,
|
||||
fx_error_status_code code);
|
||||
FX_API const char *fx_error_vendor_get_status_code_description(
|
||||
const fx_error_vendor *vendor,
|
||||
fx_error_status_code code);
|
||||
FX_API const fx_error_msg *fx_error_vendor_get_msg(
|
||||
const fx_error_vendor *vendor,
|
||||
fx_error_msg_id msg_id);
|
||||
|
||||
static inline fx_error *z__fx_error_create(
|
||||
const fx_error_vendor *v,
|
||||
fx_error_status_code c,
|
||||
fx_error *c2,
|
||||
const char *f0,
|
||||
unsigned int l,
|
||||
const char *f1,
|
||||
const char *d,
|
||||
...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, d);
|
||||
fx_error *err = z__fx_error_create_string(v, c, c2, f0, l, f1, d, arg);
|
||||
va_end(arg);
|
||||
return err;
|
||||
}
|
||||
|
||||
FX_API enum fx_status fx_error_add_submsg_string(
|
||||
fx_error *error,
|
||||
fx_error_submsg_type type,
|
||||
const char *msg,
|
||||
...);
|
||||
FX_API enum fx_status z__fx_error_add_submsg_template(
|
||||
fx_error *error,
|
||||
fx_error_submsg_type type,
|
||||
fx_error_msg_id msg_id,
|
||||
fx_error_template_parameter param[]);
|
||||
#define fx_error_add_submsg(error, type, msg_id) \
|
||||
(z__fx_error_add_submsg_template( \
|
||||
error, \
|
||||
type, \
|
||||
msg_id, \
|
||||
(fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_add_submsg_template(error, type, msg_id, ...) \
|
||||
(z__fx_error_add_submsg_template( \
|
||||
error, \
|
||||
type, \
|
||||
msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
|
||||
FX_API void fx_error_discard(fx_error *error);
|
||||
|
||||
FX_API fx_error_status_code fx_error_get_status_code(const fx_error *error);
|
||||
FX_API const fx_error_vendor *fx_error_get_vendor(const fx_error *error);
|
||||
FX_API const fx_error_definition *fx_error_get_definition(
|
||||
const fx_error *error);
|
||||
FX_API const fx_error_template_parameter *fx_error_get_template_parameter(
|
||||
const fx_error *error,
|
||||
const char *param_name);
|
||||
FX_API const fx_error_template_parameter *fx_error_get_template_parameters(
|
||||
const fx_error *error);
|
||||
FX_API const char *fx_error_get_description(const fx_error *error);
|
||||
FX_API const fx_error_msg *fx_error_get_msg(const fx_error *error);
|
||||
FX_API const fx_error_submsg *fx_error_get_first_submsg(const fx_error *error);
|
||||
FX_API const fx_error_submsg *fx_error_get_next_submsg(
|
||||
const fx_error *error,
|
||||
const fx_error_submsg *msg);
|
||||
FX_API const fx_error_stack_frame *fx_error_get_first_stack_frame(
|
||||
const fx_error *error);
|
||||
FX_API const fx_error_stack_frame *fx_error_get_next_stack_frame(
|
||||
const fx_error *error,
|
||||
const fx_error_stack_frame *frame);
|
||||
FX_API const fx_error *fx_error_get_caused_by(const fx_error *error);
|
||||
|
||||
FX_API fx_error_submsg_type fx_error_submsg_get_type(
|
||||
const fx_error_submsg *msg);
|
||||
FX_API const char *fx_error_submsg_get_content(const fx_error_submsg *msg);
|
||||
FX_API const fx_error_msg *fx_error_submsg_get_msg(const fx_error_submsg *msg);
|
||||
FX_API const fx_error_template_parameter *
|
||||
fx_error_submsg_get_template_parameters(const fx_error_submsg *msg);
|
||||
|
||||
FX_API const char *fx_error_stack_frame_get_filepath(
|
||||
const fx_error_stack_frame *frame);
|
||||
FX_API unsigned int fx_error_stack_frame_get_line_number(
|
||||
const fx_error_stack_frame *frame);
|
||||
FX_API const char *fx_error_stack_frame_get_function_name(
|
||||
const fx_error_stack_frame *frame);
|
||||
|
||||
FX_API const fx_error_template_parameter_definition *
|
||||
fx_error_definition_get_template_parameter(
|
||||
const fx_error_definition *error_def,
|
||||
const char *param_name);
|
||||
|
||||
FX_API const char *fx_error_msg_get_content(const fx_error_msg *msg);
|
||||
FX_API const fx_error_template_parameter_definition *
|
||||
fx_error_msg_get_template_parameter(
|
||||
const fx_error_msg *msg,
|
||||
const char *param_name);
|
||||
|
||||
FX_API void fx_set_error_report_function(
|
||||
fx_error_report_function func,
|
||||
fx_error_report_flags flags);
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef FX_CORE_HASH_H_
|
||||
#define FX_CORE_HASH_H_
|
||||
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -103,9 +103,12 @@ FX_API uint64_t fx_hash_cstr_ex(const char *s, size_t *len);
|
||||
|
||||
FX_API fx_status fx_hash_ctx_init(fx_hash_ctx *ctx, fx_hash_function func);
|
||||
FX_API fx_status fx_hash_ctx_reset(fx_hash_ctx *ctx);
|
||||
FX_API fx_status fx_hash_ctx_update(fx_hash_ctx *ctx, const void *p, size_t len);
|
||||
FX_API fx_status fx_hash_ctx_update_rope(fx_hash_ctx *ctx, const struct fx_rope *rope);
|
||||
FX_API fx_status fx_hash_ctx_finish(
|
||||
fx_hash_ctx *ctx, void *out_digest, size_t out_max);
|
||||
FX_API fx_status
|
||||
fx_hash_ctx_update(fx_hash_ctx *ctx, const void *p, size_t len);
|
||||
FX_API fx_status fx_hash_ctx_update_rope(
|
||||
fx_hash_ctx *ctx,
|
||||
const struct fx_rope *rope);
|
||||
FX_API fx_status
|
||||
fx_hash_ctx_finish(fx_hash_ctx *ctx, void *out_digest, size_t out_max);
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_CORE_ITERATOR_H_
|
||||
#define FX_CORE_ITERATOR_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -77,7 +77,9 @@ FX_API fx_iterator *fx_iterator_begin(fx_iterable *it);
|
||||
FX_API const fx_iterator *fx_iterator_cbegin(const fx_iterable *it);
|
||||
|
||||
FX_API fx_status fx_iterator_get_status(const fx_iterator *it);
|
||||
FX_API fx_status fx_iterator_set_status(const fx_iterator *it, fx_status status);
|
||||
FX_API fx_status fx_iterator_set_status(
|
||||
const fx_iterator *it,
|
||||
fx_status status);
|
||||
|
||||
FX_API fx_status fx_iterator_move_next(const fx_iterator *it);
|
||||
FX_API fx_iterator_value fx_iterator_get_value(fx_iterator *it);
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef FX_CORE_MACROS_H_
|
||||
#define FX_CORE_MACROS_H_
|
||||
|
||||
#include <fx/core/class.h>
|
||||
#include <fx/core/object.h>
|
||||
#include <fx/core/thread.h>
|
||||
#include <fx/core/type.h>
|
||||
#include <fx/class.h>
|
||||
#include <fx/object.h>
|
||||
#include <fx/thread.h>
|
||||
#include <fx/type.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define __FX_IFACE_I0(p, x) p##x
|
||||
@@ -22,7 +22,8 @@
|
||||
= fx_class_get_interface(p, interface_id); \
|
||||
if (!__FX_IFACE_I1(iface, __LINE__)) { \
|
||||
fx_throw_error_with_msg_template( \
|
||||
FX_ERRORS_BUILTIN, FX_ERR_CLASS_INIT_FAILURE, \
|
||||
FX_ERRORS_BUILTIN, \
|
||||
FX_ERR_CLASS_INIT_FAILURE, \
|
||||
FX_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE, \
|
||||
FX_ERROR_PARAM("class_name", fx_class_get_name(p)), \
|
||||
FX_ERROR_PARAM("interface_name", #interface_name)); \
|
||||
@@ -45,7 +46,8 @@
|
||||
fx_result result = fx_type_register(type_info); \
|
||||
if (fx_result_is_error(result)) { \
|
||||
fx_throw_error_caused_by_error( \
|
||||
FX_ERRORS_BUILTIN, FX_ERR_TYPE_REGISTRATION_FAILURE, \
|
||||
FX_ERRORS_BUILTIN, \
|
||||
FX_ERR_TYPE_REGISTRATION_FAILURE, \
|
||||
result); \
|
||||
abort(); \
|
||||
} \
|
||||
@@ -61,7 +63,8 @@
|
||||
return &name##_type_info.t_id; \
|
||||
}
|
||||
|
||||
#define FX_TYPE_ID(a, b, c, d, e) fx_type_id_init(&type_info->t_id, a, b, c, d, e)
|
||||
#define FX_TYPE_ID(a, b, c, d, e) \
|
||||
fx_type_id_init(&type_info->t_id, a, b, c, d, e)
|
||||
#define FX_TYPE_EXTENDS(parent_id) \
|
||||
fx_type_id_copy(parent_id, &type_info->t_parent_id)
|
||||
#define FX_TYPE_IMPLEMENTS(interface_id) \
|
||||
@@ -80,7 +83,8 @@
|
||||
{ \
|
||||
vtable_struct *iface = &__FX_IFACE_I1(iface, __LINE__); \
|
||||
type_info->t_vtables[nr_vtables].v_vtable = iface; \
|
||||
type_info->t_vtables[nr_vtables].v_interface_id = interface_id; \
|
||||
type_info->t_vtables[nr_vtables].v_interface_id \
|
||||
= interface_id; \
|
||||
nr_vtables++;
|
||||
#define FX_TYPE_VTABLE_END(vtable_struct, interface_id) }
|
||||
#endif
|
||||
@@ -124,7 +128,12 @@
|
||||
/* Other macros */
|
||||
|
||||
#define FX_CLASS_DISPATCH_VIRTUAL( \
|
||||
type_name, type_id, default_value, func, object, ...) \
|
||||
type_name, \
|
||||
type_id, \
|
||||
default_value, \
|
||||
func, \
|
||||
object, \
|
||||
...) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= fx_object_get_interface(object, type_id); \
|
||||
@@ -134,7 +143,12 @@
|
||||
return default_value; \
|
||||
} \
|
||||
} while (0)
|
||||
#define FX_CLASS_DISPATCH_VIRTUAL_0(type_name, type_id, default_value, func, object) \
|
||||
#define FX_CLASS_DISPATCH_VIRTUAL_0( \
|
||||
type_name, \
|
||||
type_id, \
|
||||
default_value, \
|
||||
func, \
|
||||
object) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= fx_object_get_interface(object, type_id); \
|
||||
@@ -186,6 +200,28 @@
|
||||
func_name(priv); \
|
||||
} while (0)
|
||||
|
||||
#define FX_ASSEMBLY_BEGIN() \
|
||||
const fx_assembly *__fx_assembly_get(void) \
|
||||
{ \
|
||||
static fx_assembly *self = NULL; \
|
||||
if (self) { \
|
||||
return self; \
|
||||
} \
|
||||
self = fx_assembly_create();
|
||||
#define FX_ASSEMBLY_END() \
|
||||
fx_assembly_dump(self); \
|
||||
return self; \
|
||||
}
|
||||
#define FX_ASSEMBLY_NAME(name) fx_assembly_set_name(self, name)
|
||||
#define FX_ASSEMBLY_VERSION(major, minor, build, revision) \
|
||||
fx_assembly_set_version(self, major, minor, build, revision)
|
||||
#define FX_ASSEMBLY_EXPORT_TYPE(namespace_name, type_name, type_id) \
|
||||
extern fx_type type_id##_get_type(void); \
|
||||
fx_assembly_add_type( \
|
||||
self, \
|
||||
namespace_name "." type_name, \
|
||||
type_id##_get_type())
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define FX_DECLS_BEGIN extern "C" {
|
||||
#define FX_DECLS_END }
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef FX_CORE_OBJECT_H_
|
||||
#define FX_CORE_OBJECT_H_
|
||||
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/type.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/type.h>
|
||||
|
||||
#define FX_OBJECT_MAGIC 0xDECAFC0C0ABEEF13ULL
|
||||
|
||||
@@ -25,7 +25,10 @@ FX_API void *fx_object_get_private(const fx_object *object, fx_type type);
|
||||
FX_API void *fx_object_get_protected(const fx_object *object, fx_type type);
|
||||
FX_API void *fx_object_get_interface(const fx_object *object, fx_type type);
|
||||
FX_API fx_status fx_object_get_data(
|
||||
const fx_object *object, fx_type type, void **priv, void **prot,
|
||||
const fx_object *object,
|
||||
fx_type type,
|
||||
void **priv,
|
||||
void **prot,
|
||||
void **iface);
|
||||
|
||||
FX_API fx_object *fx_object_ref(fx_object *p);
|
||||
@@ -33,7 +36,9 @@ FX_API void fx_object_unref(fx_object *p);
|
||||
FX_API fx_object *fx_object_make_rvalue(fx_object *p);
|
||||
|
||||
FX_API fx_object *fx_object_create(fx_type type);
|
||||
FX_API void fx_object_to_string(const fx_object *p, FX_TYPE_FWDREF(fx_stream) * out);
|
||||
FX_API void fx_object_to_string(
|
||||
const fx_object *p,
|
||||
FX_TYPE_FWDREF(fx_stream) * out);
|
||||
FX_API bool fx_object_is_type(const fx_object *p, fx_type type);
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_CORE_QUEUE_H_
|
||||
#define FX_CORE_QUEUE_H_
|
||||
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -17,7 +17,8 @@ FX_TYPE_CLASS_DECLARATION_BEGIN(fx_queue_iterator)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_queue_iterator)
|
||||
|
||||
#define FX_QUEUE_INIT ((fx_queue) {.q_first = NULL, .q_last = NULL})
|
||||
#define FX_QUEUE_ENTRY_INIT ((fx_queue_entry) {.qe_next = NULL, .qe_prev = NULL})
|
||||
#define FX_QUEUE_ENTRY_INIT \
|
||||
((fx_queue_entry) {.qe_next = NULL, .qe_prev = NULL})
|
||||
|
||||
typedef struct fx_queue_entry {
|
||||
struct fx_queue_entry *qe_next;
|
||||
@@ -60,9 +61,13 @@ FX_API fx_type fx_queue_iterator_get_type(void);
|
||||
FX_API size_t fx_queue_length(const fx_queue *q);
|
||||
|
||||
FX_API void fx_queue_insert_before(
|
||||
fx_queue *q, fx_queue_entry *entry, fx_queue_entry *before);
|
||||
fx_queue *q,
|
||||
fx_queue_entry *entry,
|
||||
fx_queue_entry *before);
|
||||
FX_API void fx_queue_insert_after(
|
||||
fx_queue *q, fx_queue_entry *entry, fx_queue_entry *after);
|
||||
fx_queue *q,
|
||||
fx_queue_entry *entry,
|
||||
fx_queue_entry *after);
|
||||
|
||||
FX_API void fx_queue_push_front(fx_queue *q, fx_queue_entry *entry);
|
||||
FX_API void fx_queue_push_back(fx_queue *q, fx_queue_entry *entry);
|
||||
@@ -70,7 +75,10 @@ FX_API void fx_queue_push_back(fx_queue *q, fx_queue_entry *entry);
|
||||
FX_API fx_queue_entry *fx_queue_pop_front(fx_queue *q);
|
||||
FX_API fx_queue_entry *fx_queue_pop_back(fx_queue *q);
|
||||
|
||||
FX_API void fx_queue_move(fx_queue *q, fx_queue_entry *dest, fx_queue_entry *src);
|
||||
FX_API void fx_queue_move(
|
||||
fx_queue *q,
|
||||
fx_queue_entry *dest,
|
||||
fx_queue_entry *src);
|
||||
FX_API void fx_queue_delete(fx_queue *q, fx_queue_entry *entry);
|
||||
FX_API void fx_queue_delete_all(fx_queue *q);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_RANDOM_H_
|
||||
#define FX_RANDOM_H_
|
||||
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct fx_random_algorithm;
|
||||
@@ -32,6 +32,8 @@ FX_API fx_status fx_random_init(fx_random_ctx *ctx, fx_random_flags flags);
|
||||
FX_API unsigned long long fx_random_next_int64(fx_random_ctx *ctx);
|
||||
FX_API double fx_random_next_double(fx_random_ctx *ctx);
|
||||
FX_API void fx_random_next_bytes(
|
||||
fx_random_ctx *ctx, unsigned char *out, size_t nbytes);
|
||||
fx_random_ctx *ctx,
|
||||
unsigned char *out,
|
||||
size_t nbytes);
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_CORE_RINGBUFFER_H_
|
||||
#define FX_CORE_RINGBUFFER_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -17,14 +17,19 @@ FX_TYPE_CLASS_DECLARATION_END(fx_ringbuffer)
|
||||
FX_API fx_type fx_ringbuffer_get_type(void);
|
||||
|
||||
FX_API fx_ringbuffer *fx_ringbuffer_create(size_t capacity);
|
||||
FX_API fx_ringbuffer *fx_ringbuffer_create_with_buffer(void *ptr, size_t capacity);
|
||||
FX_API fx_ringbuffer *fx_ringbuffer_create_with_buffer(
|
||||
void *ptr,
|
||||
size_t capacity);
|
||||
|
||||
FX_API fx_status fx_ringbuffer_clear(fx_ringbuffer *buf);
|
||||
|
||||
FX_API fx_status fx_ringbuffer_read(
|
||||
fx_ringbuffer *buf, void *p, size_t count, size_t *nr_read);
|
||||
FX_API fx_status
|
||||
fx_ringbuffer_read(fx_ringbuffer *buf, void *p, size_t count, size_t *nr_read);
|
||||
FX_API fx_status fx_ringbuffer_write(
|
||||
fx_ringbuffer *buf, const void *p, size_t count, size_t *nr_written);
|
||||
fx_ringbuffer *buf,
|
||||
const void *p,
|
||||
size_t count,
|
||||
size_t *nr_written);
|
||||
|
||||
FX_API int fx_ringbuffer_getc(fx_ringbuffer *buf);
|
||||
FX_API fx_status fx_ringbuffer_putc(fx_ringbuffer *buf, int c);
|
||||
@@ -33,14 +38,22 @@ FX_API size_t fx_ringbuffer_write_capacity_remaining(const fx_ringbuffer *buf);
|
||||
FX_API size_t fx_ringbuffer_available_data_remaining(const fx_ringbuffer *buf);
|
||||
|
||||
FX_API fx_status fx_ringbuffer_open_read_buffer(
|
||||
fx_ringbuffer *buf, const void **ptr, size_t *length);
|
||||
fx_ringbuffer *buf,
|
||||
const void **ptr,
|
||||
size_t *length);
|
||||
FX_API fx_status fx_ringbuffer_close_read_buffer(
|
||||
fx_ringbuffer *buf, const void **ptr, size_t nr_read);
|
||||
fx_ringbuffer *buf,
|
||||
const void **ptr,
|
||||
size_t nr_read);
|
||||
|
||||
FX_API fx_status fx_ringbuffer_open_write_buffer(
|
||||
fx_ringbuffer *buf, void **ptr, size_t *capacity);
|
||||
fx_ringbuffer *buf,
|
||||
void **ptr,
|
||||
size_t *capacity);
|
||||
FX_API fx_status fx_ringbuffer_close_write_buffer(
|
||||
fx_ringbuffer *buf, void **ptr, size_t nr_written);
|
||||
fx_ringbuffer *buf,
|
||||
void **ptr,
|
||||
size_t nr_written);
|
||||
|
||||
FX_DECLS_END;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_CORE_ROPE_H_
|
||||
#define FX_CORE_ROPE_H_
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/hash.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/stream.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -97,10 +97,18 @@ FX_API void fx_rope_init_uint(fx_rope *rope, uintptr_t v);
|
||||
FX_API void fx_rope_destroy(fx_rope *rope);
|
||||
|
||||
FX_API void fx_rope_iterate(
|
||||
const fx_rope *rope, void (*func)(const fx_rope *, void *), void *arg);
|
||||
const fx_rope *rope,
|
||||
void (*func)(const fx_rope *, void *),
|
||||
void *arg);
|
||||
FX_API size_t fx_rope_get_size(const fx_rope *rope);
|
||||
FX_API void fx_rope_concat(fx_rope *result, const fx_rope *left, const fx_rope *right);
|
||||
FX_API void fx_rope_join(fx_rope *result, const fx_rope **ropes, size_t nr_ropes);
|
||||
FX_API void fx_rope_concat(
|
||||
fx_rope *result,
|
||||
const fx_rope *left,
|
||||
const fx_rope *right);
|
||||
FX_API void fx_rope_join(
|
||||
fx_rope *result,
|
||||
const fx_rope **ropes,
|
||||
size_t nr_ropes);
|
||||
|
||||
FX_API fx_status fx_rope_to_cstr(const fx_rope *rope, char *out, size_t max);
|
||||
FX_API fx_status fx_rope_to_bstr(const fx_rope *rope, struct fx_bstr *str);
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_CORE_STATUS_H_
|
||||
#define FX_CORE_STATUS_H_
|
||||
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/misc.h>
|
||||
|
||||
#define FX_OK(status) ((enum fx_status)((uintptr_t)(status)) == FX_SUCCESS)
|
||||
#define FX_ERR(status) ((status) != FX_SUCCESS)
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef FX_CORE_STREAM_H_
|
||||
#define FX_CORE_STREAM_H_
|
||||
|
||||
#include <fx/core/encoding.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/encoding.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -64,7 +64,9 @@ FX_API fx_stream *fx_stream_open_fp(FILE *fp);
|
||||
|
||||
FX_API fx_status fx_stream_reserve(fx_stream *stream, size_t len);
|
||||
FX_API fx_status fx_stream_seek(
|
||||
fx_stream *stream, long long offset, fx_stream_seek_origin origin);
|
||||
fx_stream *stream,
|
||||
long long offset,
|
||||
fx_stream_seek_origin origin);
|
||||
FX_API size_t fx_stream_cursor(const fx_stream *stream);
|
||||
|
||||
FX_API fx_status fx_stream_push_indent(fx_stream *stream, int indent);
|
||||
@@ -73,27 +75,45 @@ FX_API fx_status fx_stream_pop_indent(fx_stream *stream);
|
||||
FX_API fx_status fx_stream_read_char(fx_stream *stream, fx_wchar *c);
|
||||
|
||||
FX_API fx_status fx_stream_read_bytes(
|
||||
fx_stream *stream, void *buf, size_t count, size_t *nr_read);
|
||||
fx_stream *stream,
|
||||
void *buf,
|
||||
size_t count,
|
||||
size_t *nr_read);
|
||||
|
||||
FX_API fx_status fx_stream_read_line(fx_stream *stream, char *s, size_t max);
|
||||
FX_API fx_status fx_stream_read_line_s(fx_stream *src, fx_stream *dest);
|
||||
|
||||
FX_API fx_status fx_stream_read_all_bytes(
|
||||
fx_stream *stream, void *p, size_t max, size_t *nr_read);
|
||||
fx_stream *stream,
|
||||
void *p,
|
||||
size_t max,
|
||||
size_t *nr_read);
|
||||
FX_API fx_status fx_stream_read_all_bytes_s(
|
||||
fx_stream *src, fx_stream *dest, fx_stream_buffer *buffer, size_t *nr_read);
|
||||
fx_stream *src,
|
||||
fx_stream *dest,
|
||||
fx_stream_buffer *buffer,
|
||||
size_t *nr_read);
|
||||
|
||||
FX_API fx_status fx_stream_write_char(fx_stream *stream, fx_wchar c);
|
||||
FX_API fx_status fx_stream_write_cstr(
|
||||
fx_stream *stream, const char *s, size_t *nr_written);
|
||||
FX_API fx_status
|
||||
fx_stream_write_cstr(fx_stream *stream, const char *s, size_t *nr_written);
|
||||
|
||||
FX_API fx_status fx_stream_write_bytes(
|
||||
fx_stream *stream, const void *buf, size_t count, size_t *nr_written);
|
||||
fx_stream *stream,
|
||||
const void *buf,
|
||||
size_t count,
|
||||
size_t *nr_written);
|
||||
|
||||
FX_API fx_status fx_stream_write_fmt(
|
||||
fx_stream *stream, size_t *nr_written, const char *format, ...);
|
||||
fx_stream *stream,
|
||||
size_t *nr_written,
|
||||
const char *format,
|
||||
...);
|
||||
FX_API fx_status fx_stream_write_vfmt(
|
||||
fx_stream *stream, size_t *nr_written, const char *format, va_list arg);
|
||||
fx_stream *stream,
|
||||
size_t *nr_written,
|
||||
const char *format,
|
||||
va_list arg);
|
||||
|
||||
FX_DECLS_END;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#ifndef FX_DS_STRING_H_
|
||||
#define FX_DS_STRING_H_
|
||||
#ifndef FX_STRING_H_
|
||||
#define FX_STRING_H_
|
||||
|
||||
#include <ctype.h>
|
||||
#include <fx/core/encoding.h>
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/encoding.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/stringstream.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef FX_CORE_STRINGSTREAM_H_
|
||||
#define FX_CORE_STRINGSTREAM_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/stream.h>
|
||||
#include <stddef.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -19,11 +19,13 @@ FX_TYPE_CLASS_DECLARATION_END(fx_stringstream)
|
||||
FX_API fx_type fx_stringstream_get_type(void);
|
||||
|
||||
FX_API fx_stringstream *fx_stringstream_create(void);
|
||||
FX_API fx_stringstream *fx_stringstream_create_with_buffer(char *buf, size_t max);
|
||||
FX_API fx_stringstream *fx_stringstream_create_with_buffer(
|
||||
char *buf,
|
||||
size_t max);
|
||||
|
||||
FX_API fx_status fx_stringstream_reset(fx_stringstream *strv);
|
||||
FX_API fx_status fx_stringstream_reset_with_buffer(
|
||||
fx_stringstream *strv, char *buf, size_t max);
|
||||
FX_API fx_status
|
||||
fx_stringstream_reset_with_buffer(fx_stringstream *strv, char *buf, size_t max);
|
||||
|
||||
FX_API const char *fx_stringstream_ptr(const fx_stringstream *strv);
|
||||
FX_API char *fx_stringstream_steal(fx_stringstream *strv);
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef FX_CORE_THREAD_H_
|
||||
#define FX_CORE_THREAD_H_
|
||||
|
||||
#include <fx/core/bitop.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/bitop.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined(__APPLE__) || defined(__linux__) || defined(__rosetta__)
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef FX_CORE_TYPE_H_
|
||||
#define FX_CORE_TYPE_H_
|
||||
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@@ -44,7 +44,11 @@ typedef struct fx_type_info {
|
||||
} fx_type_info;
|
||||
|
||||
FX_API void fx_type_id_init(
|
||||
union fx_type *out, uint32_t a, uint16_t b, uint16_t c, uint16_t d,
|
||||
union fx_type *out,
|
||||
uint32_t a,
|
||||
uint16_t b,
|
||||
uint16_t c,
|
||||
uint16_t d,
|
||||
uint64_t e);
|
||||
static inline void fx_type_id_copy(fx_type src, union fx_type *dest)
|
||||
{
|
||||
+35
-11
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/iterator.h>
|
||||
|
||||
/*** PRIVATE DATA *************************************************************/
|
||||
|
||||
@@ -13,7 +13,9 @@ static enum fx_status iterator_get_status(const struct fx_iterator_p *it)
|
||||
return it->it_status;
|
||||
}
|
||||
|
||||
static enum fx_status iterator_set_status(struct fx_iterator_p *it, fx_status status)
|
||||
static enum fx_status iterator_set_status(
|
||||
struct fx_iterator_p *it,
|
||||
fx_status status)
|
||||
{
|
||||
it->it_status = status;
|
||||
return FX_SUCCESS;
|
||||
@@ -23,12 +25,22 @@ static enum fx_status iterator_set_status(struct fx_iterator_p *it, fx_status st
|
||||
|
||||
fx_iterator *fx_iterator_begin(fx_iterable *it)
|
||||
{
|
||||
FX_CLASS_DISPATCH_VIRTUAL_0(fx_iterable, FX_TYPE_ITERABLE, NULL, it_begin, it);
|
||||
FX_CLASS_DISPATCH_VIRTUAL_0(
|
||||
fx_iterable,
|
||||
FX_TYPE_ITERABLE,
|
||||
NULL,
|
||||
it_begin,
|
||||
it);
|
||||
}
|
||||
|
||||
const fx_iterator *fx_iterator_cbegin(const fx_iterable *it)
|
||||
{
|
||||
FX_CLASS_DISPATCH_VIRTUAL_0(fx_iterable, FX_TYPE_ITERABLE, NULL, it_cbegin, it);
|
||||
FX_CLASS_DISPATCH_VIRTUAL_0(
|
||||
fx_iterable,
|
||||
FX_TYPE_ITERABLE,
|
||||
NULL,
|
||||
it_cbegin,
|
||||
it);
|
||||
}
|
||||
|
||||
enum fx_status fx_iterator_get_status(const fx_iterator *it)
|
||||
@@ -38,14 +50,19 @@ enum fx_status fx_iterator_get_status(const fx_iterator *it)
|
||||
|
||||
enum fx_status fx_iterator_set_status(const fx_iterator *it, fx_status status)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_ITERATOR, iterator_set_status, it, status);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_ITERATOR,
|
||||
iterator_set_status,
|
||||
it,
|
||||
status);
|
||||
}
|
||||
|
||||
enum fx_status fx_iterator_move_next(const fx_iterator *it)
|
||||
{
|
||||
enum fx_status status = FX_ERR_NOT_SUPPORTED;
|
||||
|
||||
fx_iterator_class *iface = fx_object_get_interface(it, FX_TYPE_ITERATOR);
|
||||
fx_iterator_class *iface
|
||||
= fx_object_get_interface(it, FX_TYPE_ITERATOR);
|
||||
if (iface && iface->it_move_next) {
|
||||
status = iface->it_move_next(it);
|
||||
}
|
||||
@@ -59,22 +76,29 @@ enum fx_status fx_iterator_move_next(const fx_iterator *it)
|
||||
fx_iterator_value fx_iterator_get_value(fx_iterator *it)
|
||||
{
|
||||
FX_CLASS_DISPATCH_VIRTUAL_0(
|
||||
fx_iterator, FX_TYPE_ITERATOR, FX_ITERATOR_VALUE_NULL,
|
||||
it_get_value, it);
|
||||
fx_iterator,
|
||||
FX_TYPE_ITERATOR,
|
||||
FX_ITERATOR_VALUE_NULL,
|
||||
it_get_value,
|
||||
it);
|
||||
}
|
||||
|
||||
const fx_iterator_value fx_iterator_get_cvalue(const fx_iterator *it)
|
||||
{
|
||||
FX_CLASS_DISPATCH_VIRTUAL_0(
|
||||
fx_iterator, FX_TYPE_ITERATOR, FX_ITERATOR_VALUE_NULL,
|
||||
it_get_cvalue, it);
|
||||
fx_iterator,
|
||||
FX_TYPE_ITERATOR,
|
||||
FX_ITERATOR_VALUE_NULL,
|
||||
it_get_cvalue,
|
||||
it);
|
||||
}
|
||||
|
||||
fx_status fx_iterator_erase(fx_iterator *it)
|
||||
{
|
||||
enum fx_status status = FX_ERR_NOT_SUPPORTED;
|
||||
|
||||
fx_iterator_class *iface = fx_object_get_interface(it, FX_TYPE_ITERATOR);
|
||||
fx_iterator_class *iface
|
||||
= fx_object_get_interface(it, FX_TYPE_ITERATOR);
|
||||
if (iface && iface->it_erase) {
|
||||
status = iface->it_erase(it);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/misc.h>
|
||||
|
||||
#define LENGTH_RET(v, boundary, len) \
|
||||
if ((v) < (boundary)) \
|
||||
|
||||
+18
-10
@@ -29,8 +29,8 @@
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
#include "random.h"
|
||||
|
||||
#include <fx/core/random.h>
|
||||
#include <fx/random.h>
|
||||
|
||||
#define NN 312
|
||||
#define MM 156
|
||||
@@ -64,14 +64,17 @@
|
||||
#define LM 0x7FFFFFFFULL /* Least significant 31 bits */
|
||||
|
||||
/* initializes mt[NN] with a seed */
|
||||
static void init_genrand64(struct fx_random_ctx *context, unsigned long long seed)
|
||||
static void init_genrand64(
|
||||
struct fx_random_ctx *context,
|
||||
unsigned long long seed)
|
||||
{
|
||||
context->__mt19937.mt[0] = seed;
|
||||
for (context->__mt19937.mti = 1; context->__mt19937.mti < NN;
|
||||
context->__mt19937.mti++)
|
||||
context->__mt19937.mt[context->__mt19937.mti]
|
||||
= (6364136223846793005ULL
|
||||
* (context->__mt19937.mt[context->__mt19937.mti - 1]
|
||||
* (context->__mt19937
|
||||
.mt[context->__mt19937.mti - 1]
|
||||
^ (context->__mt19937
|
||||
.mt[context->__mt19937.mti - 1]
|
||||
>> 62))
|
||||
@@ -82,7 +85,8 @@ static void init_genrand64(struct fx_random_ctx *context, unsigned long long see
|
||||
/* init_key is the array for initializing keys */
|
||||
/* key_length is its length */
|
||||
static void init_by_array64(
|
||||
struct fx_random_ctx *context, unsigned long long init_key[],
|
||||
struct fx_random_ctx *context,
|
||||
unsigned long long init_key[],
|
||||
unsigned long long key_length)
|
||||
{
|
||||
unsigned long long i, j, k;
|
||||
@@ -100,7 +104,8 @@ static void init_by_array64(
|
||||
i++;
|
||||
j++;
|
||||
if (i >= NN) {
|
||||
context->__mt19937.mt[0] = context->__mt19937.mt[NN - 1];
|
||||
context->__mt19937.mt[0]
|
||||
= context->__mt19937.mt[NN - 1];
|
||||
i = 1;
|
||||
}
|
||||
if (j >= key_length)
|
||||
@@ -115,7 +120,8 @@ static void init_by_array64(
|
||||
- i; /* non linear */
|
||||
i++;
|
||||
if (i >= NN) {
|
||||
context->__mt19937.mt[0] = context->__mt19937.mt[NN - 1];
|
||||
context->__mt19937.mt[0]
|
||||
= context->__mt19937.mt[NN - 1];
|
||||
i = 1;
|
||||
}
|
||||
}
|
||||
@@ -185,12 +191,14 @@ static uint64_t genrand64_int64(struct fx_random_ctx *context)
|
||||
| (context->__mt19937.mt[i + 1] & LM);
|
||||
context->__mt19937.mt[i]
|
||||
= context->__mt19937.mt[i + mid] ^ (x >> 1)
|
||||
^ ((context->__mt19937.mt[i + 1] & 1) * MATRIX_A);
|
||||
^ ((context->__mt19937.mt[i + 1] & 1)
|
||||
* MATRIX_A);
|
||||
y = (context->__mt19937.mt[j] & UM)
|
||||
| (context->__mt19937.mt[j + 1] & LM);
|
||||
context->__mt19937.mt[j]
|
||||
= context->__mt19937.mt[j - mid] ^ (y >> 1)
|
||||
^ ((context->__mt19937.mt[j + 1] & 1) * MATRIX_A);
|
||||
^ ((context->__mt19937.mt[j + 1] & 1)
|
||||
* MATRIX_A);
|
||||
}
|
||||
x = (context->__mt19937.mt[mid - 1] & UM) | (stateMid & LM);
|
||||
context->__mt19937.mt[mid - 1] = context->__mt19937.mt[NN - 1]
|
||||
|
||||
+23
-9
@@ -3,11 +3,11 @@
|
||||
#include "type.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <fx/core/class.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/object.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/core/thread.h>
|
||||
#include <fx/class.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/object.h>
|
||||
#include <fx/stream.h>
|
||||
#include <fx/thread.h>
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_object)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
@@ -21,7 +21,8 @@ FX_TYPE_DEFINITION_BEGIN(fx_object)
|
||||
FX_TYPE_DEFINITION_END(fx_object)
|
||||
|
||||
fx_result fx_object_instantiate(
|
||||
struct fx_type_registration *type, struct _fx_object **out_object)
|
||||
struct fx_type_registration *type,
|
||||
struct _fx_object **out_object)
|
||||
{
|
||||
struct _fx_object *out = malloc(type->r_instance_size);
|
||||
if (!out) {
|
||||
@@ -77,8 +78,18 @@ struct _fx_object *fx_object_create(fx_type type)
|
||||
|
||||
void fx_object_to_string(const struct _fx_object *p, fx_stream *out)
|
||||
{
|
||||
FX_CLASS_DISPATCH_VIRTUAL_V(fx_object, FX_TYPE_OBJECT, to_string, p, out);
|
||||
fx_stream_write_fmt(out, NULL, "<%s@%p>", p->obj_type->r_info->t_name, p);
|
||||
FX_CLASS_DISPATCH_VIRTUAL_V(
|
||||
fx_object,
|
||||
FX_TYPE_OBJECT,
|
||||
to_string,
|
||||
p,
|
||||
out);
|
||||
fx_stream_write_fmt(
|
||||
out,
|
||||
NULL,
|
||||
"<%s@%p>",
|
||||
p->obj_type->r_info->t_name,
|
||||
p);
|
||||
}
|
||||
|
||||
bool fx_object_is_type(const struct _fx_object *p, fx_type type)
|
||||
@@ -143,7 +154,10 @@ void *fx_object_get_interface(const struct _fx_object *object, fx_type type)
|
||||
}
|
||||
|
||||
enum fx_status fx_object_get_data(
|
||||
const struct _fx_object *object, fx_type type, void **priv, void **prot,
|
||||
const struct _fx_object *object,
|
||||
fx_type type,
|
||||
void **priv,
|
||||
void **prot,
|
||||
void **iface)
|
||||
{
|
||||
if (!object) {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
#ifndef _OBJECT_H_
|
||||
#define _OBJECT_H_
|
||||
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct fx_type_registration;
|
||||
|
||||
+7
-3
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/queue.h>
|
||||
|
||||
struct fx_queue_iterator_p {
|
||||
size_t i;
|
||||
@@ -19,7 +19,9 @@ size_t fx_queue_length(const struct fx_queue *q)
|
||||
}
|
||||
|
||||
void fx_queue_insert_before(
|
||||
struct fx_queue *q, struct fx_queue_entry *entry, struct fx_queue_entry *before)
|
||||
struct fx_queue *q,
|
||||
struct fx_queue_entry *entry,
|
||||
struct fx_queue_entry *before)
|
||||
{
|
||||
struct fx_queue_entry *x = before->qe_prev;
|
||||
if (x) {
|
||||
@@ -35,7 +37,9 @@ void fx_queue_insert_before(
|
||||
}
|
||||
|
||||
void fx_queue_insert_after(
|
||||
struct fx_queue *q, struct fx_queue_entry *entry, struct fx_queue_entry *after)
|
||||
struct fx_queue *q,
|
||||
struct fx_queue_entry *entry,
|
||||
struct fx_queue_entry *after)
|
||||
{
|
||||
struct fx_queue_entry *x = after->qe_next;
|
||||
if (x) {
|
||||
|
||||
+4
-2
@@ -1,6 +1,6 @@
|
||||
#include "random.h"
|
||||
|
||||
#include <fx/core/random.h>
|
||||
#include <fx/random.h>
|
||||
|
||||
#define GET_ALGORITHM_ID(flags) ((flags) & 0xFF)
|
||||
|
||||
@@ -73,7 +73,9 @@ double fx_random_next_double(struct fx_random_ctx *ctx)
|
||||
#endif
|
||||
|
||||
void fx_random_next_bytes(
|
||||
struct fx_random_ctx *ctx, unsigned char *out, size_t nbytes)
|
||||
struct fx_random_ctx *ctx,
|
||||
unsigned char *out,
|
||||
size_t nbytes)
|
||||
{
|
||||
size_t n_qwords = 0;
|
||||
n_qwords = nbytes >> 3;
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
#ifndef _FX_RANDOM_H_
|
||||
#define _FX_RANDOM_H_
|
||||
|
||||
#include <fx/misc.h>
|
||||
#include <stdint.h>
|
||||
#include <fx/core/misc.h>
|
||||
|
||||
struct fx_random_ctx;
|
||||
|
||||
|
||||
+81
-23
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/ringbuffer.h>
|
||||
#include <fx/ringbuffer.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -34,7 +34,8 @@ static enum fx_status ringbuffer_clear(struct fx_ringbuffer_p *buf)
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static size_t ringbuffer_write_capacity_remaining(const struct fx_ringbuffer_p *buf)
|
||||
static size_t ringbuffer_write_capacity_remaining(
|
||||
const struct fx_ringbuffer_p *buf)
|
||||
{
|
||||
if (buf->r_read_ptr > buf->r_write_ptr) {
|
||||
return buf->r_read_ptr - buf->r_write_ptr - 1;
|
||||
@@ -43,7 +44,8 @@ static size_t ringbuffer_write_capacity_remaining(const struct fx_ringbuffer_p *
|
||||
}
|
||||
}
|
||||
|
||||
static size_t ringbuffer_available_data_remaining(const struct fx_ringbuffer_p *buf)
|
||||
static size_t ringbuffer_available_data_remaining(
|
||||
const struct fx_ringbuffer_p *buf)
|
||||
{
|
||||
if (buf->r_read_ptr < buf->r_write_ptr) {
|
||||
return buf->r_write_ptr - buf->r_read_ptr;
|
||||
@@ -55,7 +57,9 @@ static size_t ringbuffer_available_data_remaining(const struct fx_ringbuffer_p *
|
||||
}
|
||||
|
||||
static enum fx_status ringbuffer_open_read_buffer(
|
||||
struct fx_ringbuffer_p *buf, const void **ptr, size_t *length)
|
||||
struct fx_ringbuffer_p *buf,
|
||||
const void **ptr,
|
||||
size_t *length)
|
||||
{
|
||||
if (BUF_LOCKED(buf)) {
|
||||
return FX_ERR_BUSY;
|
||||
@@ -83,7 +87,9 @@ static enum fx_status ringbuffer_open_read_buffer(
|
||||
}
|
||||
|
||||
static enum fx_status ringbuffer_close_read_buffer(
|
||||
struct fx_ringbuffer_p *buf, const void **ptr, size_t nr_read)
|
||||
struct fx_ringbuffer_p *buf,
|
||||
const void **ptr,
|
||||
size_t nr_read)
|
||||
{
|
||||
if (!(buf->r_flags & RINGBUFFER_READ_LOCKED)) {
|
||||
return FX_ERR_BAD_STATE;
|
||||
@@ -118,7 +124,9 @@ static enum fx_status ringbuffer_close_read_buffer(
|
||||
}
|
||||
|
||||
static enum fx_status ringbuffer_open_write_buffer(
|
||||
struct fx_ringbuffer_p *buf, void **ptr, size_t *capacity)
|
||||
struct fx_ringbuffer_p *buf,
|
||||
void **ptr,
|
||||
size_t *capacity)
|
||||
{
|
||||
if (BUF_LOCKED(buf)) {
|
||||
return FX_ERR_BUSY;
|
||||
@@ -150,7 +158,9 @@ static enum fx_status ringbuffer_open_write_buffer(
|
||||
}
|
||||
|
||||
static enum fx_status ringbuffer_close_write_buffer(
|
||||
struct fx_ringbuffer_p *buf, void **ptr, size_t nr_written)
|
||||
struct fx_ringbuffer_p *buf,
|
||||
void **ptr,
|
||||
size_t nr_written)
|
||||
{
|
||||
if (!(buf->r_flags & RINGBUFFER_WRITE_LOCKED)) {
|
||||
return FX_ERR_BAD_STATE;
|
||||
@@ -177,7 +187,10 @@ static enum fx_status ringbuffer_close_write_buffer(
|
||||
}
|
||||
|
||||
static enum fx_status ringbuffer_read(
|
||||
struct fx_ringbuffer_p *buf, void *p, size_t count, size_t *nr_read)
|
||||
struct fx_ringbuffer_p *buf,
|
||||
void *p,
|
||||
size_t count,
|
||||
size_t *nr_read)
|
||||
{
|
||||
if (BUF_LOCKED(buf)) {
|
||||
return FX_ERR_BUSY;
|
||||
@@ -220,7 +233,10 @@ static enum fx_status ringbuffer_read(
|
||||
}
|
||||
|
||||
static enum fx_status ringbuffer_write(
|
||||
struct fx_ringbuffer_p *buf, const void *p, size_t count, size_t *nr_written)
|
||||
struct fx_ringbuffer_p *buf,
|
||||
const void *p,
|
||||
size_t count,
|
||||
size_t *nr_written)
|
||||
{
|
||||
if (BUF_LOCKED(buf)) {
|
||||
return FX_ERR_BUSY;
|
||||
@@ -344,17 +360,33 @@ enum fx_status fx_ringbuffer_clear(fx_ringbuffer *buf)
|
||||
}
|
||||
|
||||
enum fx_status fx_ringbuffer_read(
|
||||
fx_ringbuffer *buf, void *p, size_t count, size_t *nr_read)
|
||||
fx_ringbuffer *buf,
|
||||
void *p,
|
||||
size_t count,
|
||||
size_t *nr_read)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_RINGBUFFER, ringbuffer_read, buf, p, count, nr_read);
|
||||
FX_TYPE_RINGBUFFER,
|
||||
ringbuffer_read,
|
||||
buf,
|
||||
p,
|
||||
count,
|
||||
nr_read);
|
||||
}
|
||||
|
||||
enum fx_status fx_ringbuffer_write(
|
||||
fx_ringbuffer *buf, const void *p, size_t count, size_t *nr_written)
|
||||
fx_ringbuffer *buf,
|
||||
const void *p,
|
||||
size_t count,
|
||||
size_t *nr_written)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_RINGBUFFER, ringbuffer_write, buf, p, count, nr_written);
|
||||
FX_TYPE_RINGBUFFER,
|
||||
ringbuffer_write,
|
||||
buf,
|
||||
p,
|
||||
count,
|
||||
nr_written);
|
||||
}
|
||||
|
||||
int fx_ringbuffer_getc(fx_ringbuffer *buf)
|
||||
@@ -370,42 +402,68 @@ enum fx_status fx_ringbuffer_putc(fx_ringbuffer *buf, int c)
|
||||
size_t fx_ringbuffer_write_capacity_remaining(const fx_ringbuffer *buf)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_RINGBUFFER, ringbuffer_write_capacity_remaining, buf);
|
||||
FX_TYPE_RINGBUFFER,
|
||||
ringbuffer_write_capacity_remaining,
|
||||
buf);
|
||||
}
|
||||
|
||||
size_t fx_ringbuffer_available_data_remaining(const fx_ringbuffer *buf)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_RINGBUFFER, ringbuffer_available_data_remaining, buf);
|
||||
FX_TYPE_RINGBUFFER,
|
||||
ringbuffer_available_data_remaining,
|
||||
buf);
|
||||
}
|
||||
|
||||
enum fx_status fx_ringbuffer_open_read_buffer(
|
||||
fx_ringbuffer *buf, const void **ptr, size_t *length)
|
||||
fx_ringbuffer *buf,
|
||||
const void **ptr,
|
||||
size_t *length)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_RINGBUFFER, ringbuffer_open_read_buffer, buf, ptr, length);
|
||||
FX_TYPE_RINGBUFFER,
|
||||
ringbuffer_open_read_buffer,
|
||||
buf,
|
||||
ptr,
|
||||
length);
|
||||
}
|
||||
|
||||
enum fx_status fx_ringbuffer_close_read_buffer(
|
||||
fx_ringbuffer *buf, const void **ptr, size_t nr_read)
|
||||
fx_ringbuffer *buf,
|
||||
const void **ptr,
|
||||
size_t nr_read)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_RINGBUFFER, ringbuffer_close_read_buffer, buf, ptr, nr_read);
|
||||
FX_TYPE_RINGBUFFER,
|
||||
ringbuffer_close_read_buffer,
|
||||
buf,
|
||||
ptr,
|
||||
nr_read);
|
||||
}
|
||||
|
||||
enum fx_status fx_ringbuffer_open_write_buffer(
|
||||
fx_ringbuffer *buf, void **ptr, size_t *capacity)
|
||||
fx_ringbuffer *buf,
|
||||
void **ptr,
|
||||
size_t *capacity)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_RINGBUFFER, ringbuffer_open_write_buffer, buf, ptr,
|
||||
FX_TYPE_RINGBUFFER,
|
||||
ringbuffer_open_write_buffer,
|
||||
buf,
|
||||
ptr,
|
||||
capacity);
|
||||
}
|
||||
|
||||
enum fx_status fx_ringbuffer_close_write_buffer(
|
||||
fx_ringbuffer *buf, void **ptr, size_t nr_written)
|
||||
fx_ringbuffer *buf,
|
||||
void **ptr,
|
||||
size_t nr_written)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_RINGBUFFER, ringbuffer_close_write_buffer, buf, ptr,
|
||||
FX_TYPE_RINGBUFFER,
|
||||
ringbuffer_close_write_buffer,
|
||||
buf,
|
||||
ptr,
|
||||
nr_written);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <fx/core/bstr.h>
|
||||
#include <fx/core/rope.h>
|
||||
#include <fx/bstr.h>
|
||||
#include <fx/rope.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -76,7 +76,8 @@ void fx_rope_destroy(struct fx_rope *rope)
|
||||
break;
|
||||
case FX_ROPE_F_COMPOSITE:
|
||||
fx_rope_destroy((struct fx_rope *)rope->r_v.v_composite.r_left);
|
||||
fx_rope_destroy((struct fx_rope *)rope->r_v.v_composite.r_right);
|
||||
fx_rope_destroy(
|
||||
(struct fx_rope *)rope->r_v.v_composite.r_right);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -88,7 +89,9 @@ void fx_rope_destroy(struct fx_rope *rope)
|
||||
}
|
||||
|
||||
void fx_rope_iterate(
|
||||
const struct fx_rope *rope, void (*func)(const fx_rope *, void *), void *arg)
|
||||
const struct fx_rope *rope,
|
||||
void (*func)(const fx_rope *, void *),
|
||||
void *arg)
|
||||
{
|
||||
if (FX_ROPE_TYPE(rope->r_flags) != FX_ROPE_F_COMPOSITE) {
|
||||
func(rope, arg);
|
||||
@@ -110,7 +113,9 @@ size_t fx_rope_get_size(const struct fx_rope *rope)
|
||||
}
|
||||
|
||||
void fx_rope_concat(
|
||||
struct fx_rope *result, const struct fx_rope *left, const struct fx_rope *right)
|
||||
struct fx_rope *result,
|
||||
const struct fx_rope *left,
|
||||
const struct fx_rope *right)
|
||||
{
|
||||
memset(result, 0x0, sizeof *result);
|
||||
|
||||
@@ -177,7 +182,8 @@ void fx_rope_join(fx_rope *result, const fx_rope **ropes, size_t nr_ropes)
|
||||
|
||||
static void rope_iterate(
|
||||
const struct fx_rope *rope,
|
||||
void (*callback)(const struct fx_rope *, void *), void *arg)
|
||||
void (*callback)(const struct fx_rope *, void *),
|
||||
void *arg)
|
||||
{
|
||||
unsigned int type = FX_ROPE_TYPE(rope->r_flags);
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define ENUM_STR(s) \
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#include "printf.h"
|
||||
|
||||
#include <fx/core/bstr.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/bstr.h>
|
||||
#include <fx/stream.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <ctype.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/stream.h>
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
+38
-11
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -42,7 +42,10 @@ static enum fx_status __getc(struct fx_stringstream_p *ss, fx_wchar *out)
|
||||
}
|
||||
|
||||
static enum fx_status __gets(
|
||||
struct fx_stringstream_p *ss, char *s, size_t len, size_t *nr_read)
|
||||
struct fx_stringstream_p *ss,
|
||||
char *s,
|
||||
size_t len,
|
||||
size_t *nr_read)
|
||||
{
|
||||
size_t available = ss->ss_len - ss->ss_ptr;
|
||||
size_t to_copy = len;
|
||||
@@ -63,7 +66,10 @@ static enum fx_status __gets(
|
||||
}
|
||||
|
||||
static enum fx_status __puts(
|
||||
struct fx_stringstream_p *ss, const char *s, size_t len, size_t *nr_written)
|
||||
struct fx_stringstream_p *ss,
|
||||
const char *s,
|
||||
size_t len,
|
||||
size_t *nr_written)
|
||||
{
|
||||
size_t available = ss->ss_max - ss->ss_len;
|
||||
size_t to_copy = len;
|
||||
@@ -109,7 +115,9 @@ static enum fx_status stringstream_reset(struct fx_stringstream_p *ss)
|
||||
}
|
||||
|
||||
static enum fx_status stringstream_reset_with_buffer(
|
||||
struct fx_stringstream_p *ss, char *buf, size_t max)
|
||||
struct fx_stringstream_p *ss,
|
||||
char *buf,
|
||||
size_t max)
|
||||
{
|
||||
ss->ss_len = 0;
|
||||
|
||||
@@ -198,19 +206,29 @@ fx_stringstream *fx_stringstream_create(void)
|
||||
size_t fx_stringstream_get_length(const fx_stringstream *strv)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_STRINGSTREAM, stringstream_get_length, strv);
|
||||
FX_TYPE_STRINGSTREAM,
|
||||
stringstream_get_length,
|
||||
strv);
|
||||
}
|
||||
|
||||
enum fx_status fx_stringstream_reset(fx_stringstream *strv)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRINGSTREAM, stringstream_reset, strv);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_STRINGSTREAM,
|
||||
stringstream_reset,
|
||||
strv);
|
||||
}
|
||||
|
||||
enum fx_status fx_stringstream_reset_with_buffer(
|
||||
fx_stringstream *strv, char *buf, size_t max)
|
||||
fx_stringstream *strv,
|
||||
char *buf,
|
||||
size_t max)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRINGSTREAM, stringstream_reset_with_buffer, strv, buf,
|
||||
FX_TYPE_STRINGSTREAM,
|
||||
stringstream_reset_with_buffer,
|
||||
strv,
|
||||
buf,
|
||||
max);
|
||||
}
|
||||
|
||||
@@ -221,7 +239,10 @@ const char *fx_stringstream_ptr(const fx_stringstream *ss)
|
||||
|
||||
char *fx_stringstream_steal(fx_stringstream *ss)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRINGSTREAM, stringstream_steal, ss);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_STRINGSTREAM,
|
||||
stringstream_steal,
|
||||
ss);
|
||||
}
|
||||
|
||||
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
|
||||
@@ -252,7 +273,10 @@ enum fx_status stream_getc(fx_stream *stream, fx_wchar *c)
|
||||
}
|
||||
|
||||
enum fx_status stream_read(
|
||||
fx_stream *stream, void *buf, size_t count, size_t *nr_read)
|
||||
fx_stream *stream,
|
||||
void *buf,
|
||||
size_t count,
|
||||
size_t *nr_read)
|
||||
{
|
||||
struct fx_stringstream_p *s
|
||||
= fx_object_get_private(stream, FX_TYPE_STRINGSTREAM);
|
||||
@@ -263,7 +287,10 @@ enum fx_status stream_read(
|
||||
}
|
||||
|
||||
enum fx_status stream_write(
|
||||
fx_stream *stream, const void *buf, size_t count, size_t *nr_written)
|
||||
fx_stream *stream,
|
||||
const void *buf,
|
||||
size_t count,
|
||||
size_t *nr_written)
|
||||
{
|
||||
struct fx_stringstream_p *s
|
||||
= fx_object_get_private(stream, FX_TYPE_STRINGSTREAM);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/bitop.h>
|
||||
#include <fx/bitop.h>
|
||||
|
||||
int fx_popcountl(long v)
|
||||
{
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include "class.h"
|
||||
#include "object.h"
|
||||
|
||||
#include <fx/core/bst.h>
|
||||
#include <fx/core/endian.h>
|
||||
#include <fx/core/object.h>
|
||||
#include <fx/core/type.h>
|
||||
#include <fx/bst.h>
|
||||
#include <fx/endian.h>
|
||||
#include <fx/object.h>
|
||||
#include <fx/type.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -20,26 +20,37 @@ struct type_init_ctx {
|
||||
};
|
||||
|
||||
static inline int registration_compare(
|
||||
const struct fx_type_registration *a, const struct fx_type_registration *b)
|
||||
const struct fx_type_registration *a,
|
||||
const struct fx_type_registration *b)
|
||||
{
|
||||
return fx_type_id_compare(&a->r_info->t_id, &b->r_info->t_id);
|
||||
}
|
||||
|
||||
static inline int component_compare(
|
||||
const struct fx_type_component *a, const struct fx_type_component *b)
|
||||
const struct fx_type_component *a,
|
||||
const struct fx_type_component *b)
|
||||
{
|
||||
return fx_type_id_compare(&a->c_type->r_info->t_id, &b->c_type->r_info->t_id);
|
||||
return fx_type_id_compare(
|
||||
&a->c_type->r_info->t_id,
|
||||
&b->c_type->r_info->t_id);
|
||||
}
|
||||
|
||||
FX_BST_DEFINE_INSERT(
|
||||
struct fx_type_registration, r_node, r_info->r_id, put_type,
|
||||
struct fx_type_registration,
|
||||
r_node,
|
||||
r_info->r_id,
|
||||
put_type,
|
||||
registration_compare)
|
||||
FX_BST_DEFINE_INSERT(
|
||||
struct fx_type_component, c_node, &c_type->r_info->t_id,
|
||||
put_type_component, component_compare)
|
||||
struct fx_type_component,
|
||||
c_node,
|
||||
&c_type->r_info->t_id,
|
||||
put_type_component,
|
||||
component_compare)
|
||||
|
||||
static struct fx_type_registration *get_type(
|
||||
const fx_bst *tree, const union fx_type *key)
|
||||
const fx_bst *tree,
|
||||
const union fx_type *key)
|
||||
{
|
||||
fx_bst_node *cur = tree->bst_root;
|
||||
while (cur) {
|
||||
@@ -60,13 +71,16 @@ static struct fx_type_registration *get_type(
|
||||
}
|
||||
|
||||
struct fx_type_component *fx_type_get_component(
|
||||
const fx_bst *tree, const union fx_type *key)
|
||||
const fx_bst *tree,
|
||||
const union fx_type *key)
|
||||
{
|
||||
fx_bst_node *cur = tree->bst_root;
|
||||
while (cur) {
|
||||
struct fx_type_component *cur_node
|
||||
= fx_unbox(struct fx_type_component, cur, c_node);
|
||||
int cmp = fx_type_id_compare(key, &cur_node->c_type->r_info->t_id);
|
||||
int cmp = fx_type_id_compare(
|
||||
key,
|
||||
&cur_node->c_type->r_info->t_id);
|
||||
|
||||
if (cmp > 0) {
|
||||
cur = fx_bst_right(cur);
|
||||
@@ -96,7 +110,11 @@ static struct fx_type_component *create_type_component(
|
||||
}
|
||||
|
||||
void fx_type_id_init(
|
||||
union fx_type *out, uint32_t a, uint16_t b, uint16_t c, uint16_t d,
|
||||
union fx_type *out,
|
||||
uint32_t a,
|
||||
uint16_t b,
|
||||
uint16_t c,
|
||||
uint16_t d,
|
||||
uint64_t e)
|
||||
{
|
||||
fx_i32 x_a = fx_i32_htob(a);
|
||||
@@ -113,7 +131,8 @@ void fx_type_id_init(
|
||||
}
|
||||
|
||||
static void initialise_type_component(
|
||||
struct fx_type_component *comp, const struct fx_type_info *info,
|
||||
struct fx_type_component *comp,
|
||||
const struct fx_type_info *info,
|
||||
struct type_init_ctx *init_ctx)
|
||||
{
|
||||
comp->c_class_data_offset = init_ctx->ctx_class_offset;
|
||||
@@ -130,7 +149,8 @@ static void initialise_type_component(
|
||||
}
|
||||
|
||||
static fx_result locate_interface(
|
||||
fx_type interface_id, struct fx_type_registration *dest,
|
||||
fx_type interface_id,
|
||||
struct fx_type_registration *dest,
|
||||
struct type_init_ctx *init_ctx)
|
||||
{
|
||||
struct fx_type_component *interface_comp
|
||||
@@ -150,15 +170,20 @@ static fx_result locate_interface(
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
initialise_type_component(interface_comp, interface_reg->r_info, init_ctx);
|
||||
initialise_type_component(
|
||||
interface_comp,
|
||||
interface_reg->r_info,
|
||||
init_ctx);
|
||||
|
||||
put_type_component(&dest->r_components, interface_comp);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result locate_interfaces(
|
||||
const union fx_type *interfaces, size_t nr_interfaces,
|
||||
struct fx_type_registration *dest, struct type_init_ctx *init_ctx)
|
||||
const union fx_type *interfaces,
|
||||
size_t nr_interfaces,
|
||||
struct fx_type_registration *dest,
|
||||
struct type_init_ctx *init_ctx)
|
||||
{
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
for (size_t i = 0; i < nr_interfaces; i++) {
|
||||
@@ -190,7 +215,10 @@ static fx_result find_type_components(struct fx_type_registration *reg)
|
||||
fx_queue_push_front(®->r_class_hierarchy, &comp->c_entry);
|
||||
|
||||
fx_result result = locate_interfaces(
|
||||
current->t_interfaces, current->t_nr_interfaces, reg, &init_ctx);
|
||||
current->t_interfaces,
|
||||
current->t_nr_interfaces,
|
||||
reg,
|
||||
&init_ctx);
|
||||
|
||||
if (fx_result_is_error(result)) {
|
||||
return result;
|
||||
@@ -221,7 +249,9 @@ static fx_result find_type_components(struct fx_type_registration *reg)
|
||||
|
||||
result = locate_interfaces(
|
||||
dep_class->r_info->t_interfaces,
|
||||
dep_class->r_info->t_nr_interfaces, reg, &init_ctx);
|
||||
dep_class->r_info->t_nr_interfaces,
|
||||
reg,
|
||||
&init_ctx);
|
||||
if (fx_result_is_error(result)) {
|
||||
break;
|
||||
}
|
||||
@@ -239,7 +269,10 @@ static fx_result find_type_components(struct fx_type_registration *reg)
|
||||
fx_queue_entry *entry = fx_queue_first(®->r_class_hierarchy);
|
||||
while (entry) {
|
||||
comp = fx_unbox(struct fx_type_component, entry, c_entry);
|
||||
initialise_type_component(comp, comp->c_type->r_info, &init_ctx);
|
||||
initialise_type_component(
|
||||
comp,
|
||||
comp->c_type->r_info,
|
||||
&init_ctx);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
@@ -252,7 +285,10 @@ static fx_result find_type_components(struct fx_type_registration *reg)
|
||||
continue;
|
||||
}
|
||||
|
||||
initialise_type_component(comp, comp->c_type->r_info, &init_ctx);
|
||||
initialise_type_component(
|
||||
comp,
|
||||
comp->c_type->r_info,
|
||||
&init_ctx);
|
||||
node = fx_bst_next(node);
|
||||
}
|
||||
|
||||
@@ -303,8 +339,10 @@ fx_result fx_type_register(struct fx_type_info *info)
|
||||
if (!r->r_class) {
|
||||
free(r);
|
||||
return fx_error_with_msg_template_caused_by_error(
|
||||
FX_ERRORS_BUILTIN, FX_ERR_TYPE_REGISTRATION_FAILURE,
|
||||
result, FX_MSG_TYPE_REGISTRATION_FAILURE,
|
||||
FX_ERRORS_BUILTIN,
|
||||
FX_ERR_TYPE_REGISTRATION_FAILURE,
|
||||
result,
|
||||
FX_MSG_TYPE_REGISTRATION_FAILURE,
|
||||
FX_ERROR_PARAM("typename", info->t_name));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef _TYPE_H_
|
||||
#define _TYPE_H_
|
||||
|
||||
#include <fx/core/bst.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/core/type.h>
|
||||
#include <fx/bst.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/type.h>
|
||||
#include <stddef.h>
|
||||
|
||||
enum fx_type_category {
|
||||
@@ -24,6 +24,7 @@ struct fx_type_component {
|
||||
|
||||
struct fx_type_registration {
|
||||
enum fx_type_category r_category;
|
||||
const char *r_name;
|
||||
struct fx_bst_node r_node;
|
||||
const fx_type_info *r_info;
|
||||
struct _fx_class *r_class;
|
||||
@@ -35,6 +36,7 @@ struct fx_type_registration {
|
||||
|
||||
extern struct fx_type_registration *fx_type_get_registration(fx_type id);
|
||||
extern struct fx_type_component *fx_type_get_component(
|
||||
const fx_bst *tree, const union fx_type *key);
|
||||
const fx_bst *tree,
|
||||
const union fx_type *key);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
printf("dynamic loader\n");
|
||||
void *assembly = dlopen(argv[1], RTLD_LAZY);
|
||||
if (!assembly) {
|
||||
printf("cannot load %s\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const void *(*asm_info)(void) = dlsym(assembly, "__fx_assembly_get");
|
||||
if (!asm_info) {
|
||||
printf("cannot find assembly info for %s", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
asm_info();
|
||||
printf("OK\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user