Compare commits
7 Commits
6b04920d29
...
912c450e6e
| Author | SHA1 | Date | |
|---|---|---|---|
| 912c450e6e | |||
| fc43d104dc | |||
| 8eba5c7462 | |||
| 5212ef4bc8 | |||
| fc4a422a79 | |||
| ef3f64f095 | |||
| 467c13e161 |
+10
-10
@@ -52,12 +52,12 @@ PenaltyBreakOpenParenthesis: 5
|
||||
PenaltyBreakBeforeFirstCallParameter: 5
|
||||
PenaltyIndentedWhitespace: 0
|
||||
AttributeMacros:
|
||||
- BLUELIB_API
|
||||
- FX_API
|
||||
ForEachMacros:
|
||||
- b_btree_foreach
|
||||
- b_queue_foreach
|
||||
MacroBlockBegin: "B_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "B_TYPE_.*_END"
|
||||
- fx_btree_foreach
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
---
|
||||
Language: ObjC
|
||||
DerivePointerAlignment: false
|
||||
@@ -110,9 +110,9 @@ PenaltyBreakOpenParenthesis: 5
|
||||
PenaltyBreakBeforeFirstCallParameter: 5
|
||||
PenaltyIndentedWhitespace: 0
|
||||
AttributeMacros:
|
||||
- BLUELIB_API
|
||||
- FX_API
|
||||
ForEachMacros:
|
||||
- b_btree_foreach
|
||||
- b_queue_foreach
|
||||
MacroBlockBegin: "B_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "B_TYPE_.*_END"
|
||||
- fx_btree_foreach
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
|
||||
+34
-19
@@ -9,7 +9,19 @@ set(CMAKE_C_EXTENSIONS OFF)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
set(fx_modules core ds serial term cmd io compress)
|
||||
if (NOT DEFINED fx_modules)
|
||||
set(fx_modules core ds serial term cmd io compress)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED fx_enable_floating_point)
|
||||
set(fx_enable_floating_point 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED fx_enable_tests)
|
||||
set(fx_enable_tests 1)
|
||||
endif ()
|
||||
|
||||
message(STATUS "Floating point support: ${fx_enable_floating_point}")
|
||||
|
||||
set(fx_system_name ${CMAKE_SYSTEM_NAME})
|
||||
string(TOLOWER ${fx_system_name} fx_system_name)
|
||||
@@ -25,7 +37,7 @@ foreach (module ${fx_modules})
|
||||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module})
|
||||
message(STATUS "Building unit tests for module ${module}")
|
||||
|
||||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c)
|
||||
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
|
||||
@@ -34,33 +46,36 @@ foreach (module ${fx_modules})
|
||||
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}")
|
||||
|
||||
endif ()
|
||||
|
||||
file(GLOB test_sources test/${module}/*.c)
|
||||
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c")
|
||||
|
||||
foreach (test_file ${test_sources})
|
||||
get_filename_component(test_name ${test_file} NAME_WE)
|
||||
add_executable(fx-${module}-${test_name} ${test_file})
|
||||
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}")
|
||||
set_target_properties(fx-${module}-${test_name} PROPERTIES FOLDER "Tests/${module}")
|
||||
|
||||
target_link_libraries(fx-${module}-${test_name} fx-${module})
|
||||
endforeach (test_file)
|
||||
target_link_libraries(fx-${module}-${test_name} fx-${module})
|
||||
endforeach (test_file)
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach (module)
|
||||
|
||||
file(GLOB test_sources test/*.c)
|
||||
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/units.c")
|
||||
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})
|
||||
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")
|
||||
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)
|
||||
foreach (module ${fx_modules})
|
||||
target_link_libraries(fx-${test_name} fx-${module})
|
||||
endforeach (module)
|
||||
endforeach (test_file)
|
||||
endif ()
|
||||
|
||||
@@ -50,11 +50,13 @@ function(add_fx_module)
|
||||
|
||||
target_compile_definitions(fx-${module_name} PUBLIC
|
||||
${module_preproc_token}
|
||||
FX_EXPORT=1)
|
||||
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_STATIC=1
|
||||
FX_ENABLE_FLOATING_POINT=${fx_enable_floating_point})
|
||||
|
||||
set_target_properties(fx-${module_name}
|
||||
PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
+1
-1
@@ -1179,7 +1179,7 @@ bool fx_wchar_is_alpha(fx_wchar c)
|
||||
|
||||
bool fx_wchar_is_hex_digit(fx_wchar c)
|
||||
{
|
||||
return isxdigit(c);
|
||||
return iswxdigit(c);
|
||||
}
|
||||
|
||||
bool fx_wchar_is_space(fx_wchar c)
|
||||
|
||||
+1
-1
@@ -4,10 +4,10 @@
|
||||
#include "hash.h"
|
||||
|
||||
#include <fx/core/hash.h>
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define F(x, y, z) (z ^ (x & (y ^ z)))
|
||||
#define G(x, y, z) (y ^ (z & (x ^ y)))
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <fx/core/misc.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined(__APPLE__) || defined(__linux__)
|
||||
#if defined(__APPLE__) || defined(__linux__) || defined(__rosetta__)
|
||||
#include <pthread.h>
|
||||
|
||||
#define FX_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
@@ -217,6 +217,7 @@ static uint64_t genrand64_int64(struct fx_random_ctx *context)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FX_ENABLE_FLOATING_POINT == 1
|
||||
/* generates a random number on [0,1]-real-interval */
|
||||
double genrand64_real1(struct fx_random_ctx *context)
|
||||
{
|
||||
@@ -235,6 +236,7 @@ double genrand64_real3(struct fx_random_ctx *context)
|
||||
return ((genrand64_int64(context) >> 12) + 0.5)
|
||||
* (1.0 / 4503599627370496.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct fx_random_algorithm z__fx_gen_mt19937 = {
|
||||
.gen_name = "mt19937",
|
||||
|
||||
@@ -45,6 +45,11 @@
|
||||
|
||||
#include "printf.h"
|
||||
|
||||
#if FX_ENABLE_FLOATING_POINT == 0
|
||||
#define PRINTF_SUPPORT_DECIMAL_SPECIFIERS 0
|
||||
#define PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
|
||||
+4
-1
@@ -60,6 +60,7 @@ unsigned long long fx_random_next_int64(struct fx_random_ctx *ctx)
|
||||
return ctx->__a->gen_getrand(ctx);
|
||||
}
|
||||
|
||||
#if FX_ENABLE_FLOATING_POINT
|
||||
double fx_random_next_double(struct fx_random_ctx *ctx)
|
||||
{
|
||||
unsigned long long v = fx_random_next_int64(ctx);
|
||||
@@ -69,8 +70,10 @@ double fx_random_next_double(struct fx_random_ctx *ctx)
|
||||
|
||||
return (double)(v >> 11) * (1.0 / 9007199254740991.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
void fx_random_next_bytes(struct fx_random_ctx *ctx, unsigned char *out, size_t nbytes)
|
||||
void fx_random_next_bytes(
|
||||
struct fx_random_ctx *ctx, unsigned char *out, size_t nbytes)
|
||||
{
|
||||
size_t n_qwords = 0;
|
||||
n_qwords = nbytes >> 3;
|
||||
|
||||
+7
-3
@@ -84,6 +84,7 @@ static enum fx_status __puts(
|
||||
}
|
||||
|
||||
memcpy(ss->ss_buf + ss->ss_len, s, to_copy);
|
||||
ss->ss_buf[ss->ss_len + to_copy] = 0;
|
||||
|
||||
/* increment the length by the full string length, even if only a
|
||||
* portion was copied */
|
||||
@@ -154,7 +155,8 @@ fx_stringstream *fx_stringstream_create_with_buffer(char *buf, size_t max)
|
||||
}
|
||||
|
||||
fx_stream_cfg *cfg = fx_object_get_protected(s, FX_TYPE_STREAM);
|
||||
struct fx_stringstream_p *p = fx_object_get_private(s, FX_TYPE_STRINGSTREAM);
|
||||
struct fx_stringstream_p *p
|
||||
= fx_object_get_private(s, FX_TYPE_STRINGSTREAM);
|
||||
|
||||
cfg->s_mode = FX_STREAM_READ | FX_STREAM_WRITE | Z__FX_STREAM_STATIC;
|
||||
|
||||
@@ -174,7 +176,8 @@ fx_stringstream *fx_stringstream_create(void)
|
||||
}
|
||||
|
||||
fx_stream_cfg *cfg = fx_object_get_protected(s, FX_TYPE_STREAM);
|
||||
struct fx_stringstream_p *p = fx_object_get_private(s, FX_TYPE_STRINGSTREAM);
|
||||
struct fx_stringstream_p *p
|
||||
= fx_object_get_private(s, FX_TYPE_STRINGSTREAM);
|
||||
|
||||
cfg->s_mode = FX_STREAM_READ | FX_STREAM_WRITE | Z__FX_STREAM_STATIC;
|
||||
|
||||
@@ -248,7 +251,8 @@ enum fx_status stream_getc(fx_stream *stream, fx_wchar *c)
|
||||
return status;
|
||||
}
|
||||
|
||||
enum fx_status stream_read(fx_stream *stream, void *buf, size_t count, size_t *nr_read)
|
||||
enum fx_status stream_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);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <fx/core/bitop.h>
|
||||
|
||||
int fx_popcountl(long v)
|
||||
{
|
||||
return __builtin_popcountl(v);
|
||||
}
|
||||
|
||||
int fx_ctzl(long v)
|
||||
{
|
||||
return __builtin_ctzl(v);
|
||||
}
|
||||
|
||||
int fx_clzl(long v)
|
||||
{
|
||||
return __builtin_clzl(v);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
uint64_t z__fx_platform_random_seed()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t z__fx_platform_random_seed_secure()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -5,9 +5,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define HASH_OFFSET_BASIS 0xcbf29ce484222325
|
||||
#define HASH_PRIME 0x100000001b3
|
||||
|
||||
/*** PRIVATE DATA *************************************************************/
|
||||
|
||||
struct fx_dict_bucket_item {
|
||||
@@ -45,11 +42,14 @@ static FX_BST_DEFINE_SIMPLE_INSERT(
|
||||
|
||||
uint64_t fx_cstr_hash(const char *s)
|
||||
{
|
||||
uint64_t hash = HASH_OFFSET_BASIS;
|
||||
#define FNV1_OFFSET_BASIS 0xcbf29ce484222325
|
||||
#define FNV1_PRIME 0x100000001b3
|
||||
uint64_t hash = FNV1_OFFSET_BASIS;
|
||||
size_t i = 0;
|
||||
|
||||
for (size_t i = 0; s[i]; i++) {
|
||||
hash *= HASH_PRIME;
|
||||
for (i = 0; s[i]; i++) {
|
||||
hash ^= s[i];
|
||||
hash *= FNV1_PRIME;
|
||||
}
|
||||
|
||||
return hash;
|
||||
@@ -448,8 +448,8 @@ static void dict_to_string(const fx_object *obj, fx_stream *out)
|
||||
fx_object_to_string(item->bi_str, out);
|
||||
fx_stream_write_string(out, ": ", NULL);
|
||||
|
||||
bool is_string
|
||||
= fx_object_is_type(item->bi_value, FX_TYPE_STRING);
|
||||
bool is_string = fx_object_is_type(
|
||||
item->bi_value, FX_TYPE_STRING);
|
||||
|
||||
if (is_string) {
|
||||
fx_stream_write_char(out, '"');
|
||||
|
||||
Reference in New Issue
Block a user