Skip to content

Commit

Permalink
naming + attempted fix for windows constructors + dependency tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Oct 22, 2023
1 parent 28656b4 commit 3e23ee3
Show file tree
Hide file tree
Showing 14 changed files with 392 additions and 372 deletions.
368 changes: 187 additions & 181 deletions fio-stl.h

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions fio-stl.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ sidebar: 0.8.x/_sidebar.md
* An easy solution to [the C10K problem](http://www.kegel.com/c10k.html).
* Optional connectivity with Redis.

This header library is the **C Server Toolbox Library** that makes it all happen.
This header library is the **C Server Toolbox Library** (C STL) that makes it all happen.

## The C STL Design Goal

> The [facil.io](http://facil.io) C STL aims to provide C developers with easy-to-use tools to write memory safe and performant programs.

## OS Support

Expand Down Expand Up @@ -6107,17 +6111,17 @@ Returns the Key String.
#### `fio_keystr`

```c
fio_keystr_s fio_keystr(const char *buf, uint32_t len);
fio_keystr_s fio_keystr_tmp(const char *buf, uint32_t len);
```

Returns a **temporary** `fio_keystr_s` to be used as a key for a hash map.

Do **not** `fio_keystr_destroy` this key.

#### `fio_keystr_copy`
#### `fio_keystr_init`

```c
fio_keystr_s fio_keystr_copy(fio_str_info_s str, void *(*alloc_func)(size_t len))
fio_keystr_s fio_keystr_init(fio_str_info_s str, void *(*alloc_func)(size_t len))
```

Returns a copy of `fio_keystr_s` - used internally by the hash map.
Expand Down Expand Up @@ -7392,7 +7396,7 @@ This is useful in when the key was pre-allocated, if it's reference was increase
#define FIO_MAP_KEY fio_str_info_s
#define FIO_MAP_KEY_INTERNAL fio_keystr_s
#define FIO_MAP_KEY_FROM_INTERNAL(k) fio_keystr_info(&(k))
#define FIO_MAP_KEY_COPY(dest, src) (dest) = fio_keystr_copy((src), ...)
#define FIO_MAP_KEY_COPY(dest, src) (dest) = fio_keystr_init((src), ...)
#define FIO_MAP_KEY_CMP(a, b) fio_keystr_is_eq2((a), (b))
#define FIO_MAP_KEY_DESTROY(key) fio_keystr_destroy(&(key), FIO_NAME(FIO_MAP_NAME, __key_free))
#define FIO_MAP_KEY_DISCARD(key)
Expand Down
14 changes: 14 additions & 0 deletions fio-stl/000 core.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ Constructors and Destructors
***************************************************************************** */

#if _MSC_VER

#define FIO___COUNTER_RUNNER() \
__COUNTER__ + __COUNTER__ + __COUNTER__ + __COUNTER__ + __COUNTER__ + \
__COUNTER__ + __COUNTER__ + __COUNTER__ + __COUNTER__ + __COUNTER__
/* counter is used for ordering, so we need a consistent number of digits */
FIO_SFUNC void fio___msv_run_counter_macro_to_3_digits(void) {
int i = __COUNTER__;
i += FIO___COUNTER_RUNNER() + FIO___COUNTER_RUNNER() +
FIO___COUNTER_RUNNER() + FIO___COUNTER_RUNNER() + FIO___COUNTER_RUNNER();
i += FIO___COUNTER_RUNNER() + FIO___COUNTER_RUNNER() +
FIO___COUNTER_RUNNER() + FIO___COUNTER_RUNNER() + FIO___COUNTER_RUNNER();
}
#undef FIO___COUNTER_RUNNER

#pragma section(".CRT$XCU", read)
/** Marks a function as a constructor - if supported. */
#if _WIN64 /* MSVC linker uses different name mangling on 32bit systems */
Expand Down
6 changes: 5 additions & 1 deletion fio-stl/000 core.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ sidebar: 0.8.x/_sidebar.md
* An easy solution to [the C10K problem](http://www.kegel.com/c10k.html).
* Optional connectivity with Redis.

This header library is the **C Server Toolbox Library** that makes it all happen.
This header library is the **C Server Toolbox Library** (C STL) that makes it all happen.

## The C STL Design Goal

> The [facil.io](http://facil.io) C STL aims to provide C developers with easy-to-use tools to write memory safe and performant programs.
## OS Support

Expand Down
111 changes: 50 additions & 61 deletions fio-stl/000 dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,29 @@
/* *****************************************************************************
Tests Inclusion (everything + MEMALT)
***************************************************************************** */
#if (defined(FIO_TEST_ALL) || defined(FIO___TEST_MACRO_SUSPENDED)) && \
!defined(H___FIO_TESTS_INC_FINISHED___H) && \
!defined(FIO___RECURSIVE_INCLUDE)
#if !defined(FIO___RECURSIVE_INCLUDE) && \
(defined(FIO_TEST_ALL) || defined(FIO___TEST_MACRO_SUSPENDED)) && \
!defined(H___FIO_TESTS_INC_FINISHED___H)

/* Inclusion cycle three - facil.io memory allocator for all else. */
#if !defined(H___FIO_TESTS_INC_FINISHED___H) && \
defined(H___FIO_EVERYTHING_FINISHED___H)
#define H___FIO_TESTS_INC_FINISHED___H
#undef FIO___TEST_MACRO_SUSPENDED
#define FIO_TEST_ALL
#elif !defined(H___FIO_BASIC1___H)
#if !defined(H___FIO_EVERYTHING___H) /* include everything first, then test */
#undef FIO_TEST_ALL
#define FIO___TEST_MACRO_SUSPENDED
#undef FIO_LEAK_COUNTER
#define FIO_LEAK_COUNTER 1
#define FIO_EVERYTHING
#else /* define test inclusion */
#define H___FIO_TESTS_INC_FINISHED___H
#undef FIO___TEST_MACRO_SUSPENDED
#define FIO_TEST_ALL
#endif

#endif /* FIO_TEST_ALL */

/* *****************************************************************************
Special `extern` support FIO_BASIC, FIO_EVERYTHING, etc'
***************************************************************************** */
#if defined(FIO_EXTERN) && !defined(FIO___RECURSIVE_INCLUDE) && \
#if !defined(FIO___RECURSIVE_INCLUDE) && defined(FIO_EXTERN) && \
(defined(FIO_TEST_ALL) || defined(FIO_EVERYTHING) || defined(FIO_BASIC))
#if defined(FIO_EXTERN) && ((FIO_EXTERN + 1) < 3)
#undef FIO_EXTERN
Expand All @@ -51,70 +50,53 @@ Special `extern` support FIO_BASIC, FIO_EVERYTHING, etc'
/* *****************************************************************************
Everything Inclusion
***************************************************************************** */
#if defined(FIO_EVERYTHING) && !defined(FIO___RECURSIVE_INCLUDE)
#if !defined(FIO___RECURSIVE_INCLUDE) && defined(FIO_EVERYTHING) && \
!defined(H___FIO_EVERYTHING___H)

#if !defined(H___FIO_EVERYTHING_FINISHED___H) && \
defined(H___FIO_EVERYTHING2___H)
/* Inclusion cycle three - facil.io memory allocator for all else. */
#define H___FIO_EVERYTHING_FINISHED___H
#if !defined(H___FIO_EVERYTHING1___H)
#define H___FIO_EVERYTHING1___H
#undef FIO_FIOBJ
#undef FIO_HTTP
#undef FIO_MALLOC
#undef FIO_MEMALT
#define FIO_MEMALT
#define FIO_FIOBJ
#define FIO_MUSTACHE
#define FIOBJ_MALLOC
#define FIO_HTTP
#define FIO___INCLUDE_AGAIN
#elif !defined(H___FIO_EVERYTHING2___H) && defined(H___FIO_EVERYTHING1___H)
/* Inclusion cycle two - import server modules. */
#define H___FIO_EVERYTHING2___H
#define FIO_MALLOC
#define FIO_SERVER
#define FIO_PUBSUB
#define FIO___INCLUDE_AGAIN
#elif !defined(H___FIO_EVERYTHING_FINISHED___H)
/* Inclusion cycle one - import FIO_BASIC. */
#undef FIO_SERVER
#undef FIO_MUSTACHE
#undef FIO_PUBSUB
#undef FIO_HTTP
#undef FIO_BASIC
#undef FIO_SIGNAL
#undef FIO_SOCK
#define H___FIO_EVERYTHING1___H
#undef FIO_SERVER
#undef FIOBJ_MALLOC
#define FIO_CLI
#define FIO_CORE
#define FIO_CRYPT
#define FIO_SIGNAL
#define FIO_SOCK
#define FIO_STATE
#define FIO_THREADS
#define FIO___INCLUDE_AGAIN
#elif !defined(H___FIO_EVERYTHING2___H)
#define H___FIO_EVERYTHING2___H
#define FIO_FIOBJ
#define FIO_HTTP
#define FIO_MALLOC
#define FIO_MUSTACHE
#define FIO_PUBSUB
#define FIO_SERVER
#else
#undef FIO_EVERYTHING /* final cycle, allows extension */
#define H___FIO_EVERYTHING___H
#undef H___FIO_EVERYTHING1___H
#undef H___FIO_EVERYTHING2___H
#undef FIO_EVERYTHING
#undef FIO_MEMALT
#define FIO_MEMALT
#endif

#endif /* H___FIO_EVERYTHING___H */
#define FIO___INCLUDE_AGAIN
#endif /* FIO_EVERYTHING */
/* *****************************************************************************
Basics Inclusion
***************************************************************************** */
#if defined(FIO_BASIC) && !defined(FIO___RECURSIVE_INCLUDE)

#if !defined(H___FIO_BASIC_FINISHED___H) && defined(H___FIO_BASIC2___H)
/* Inclusion cycle three - facil.io memory allocator for all else. */
#define H___FIO_BASIC_FINISHED___H
#define FIO_MALLOC
#define FIO___INCLUDE_AGAIN

#elif !defined(H___FIO_BASIC_FINISHED___H) && defined(H___FIO_BASIC1___H)
/* Inclusion cycle two - FIOBJ & its dedicated memory allocator. */
#define H___FIO_BASIC2___H
#define FIO_FIOBJ
#define FIO_MUSTACHE
#define FIOBJ_MALLOC
#define FIO___INCLUDE_AGAIN
#if !defined(FIO___RECURSIVE_INCLUDE) && defined(FIO_BASIC) && \
!defined(H___FIO_BASIC___H)

#elif !defined(H___FIO_BASIC_FINISHED___H)
/* Inclusion cycle one - default (system) memory allocator. */
#define H___FIO_BASIC1___H
#if !defined(H___FIO_BASIC_ROUND1___H)
#define H___FIO_BASIC_ROUND1___H
#undef FIO_CLI
#undef FIO_CORE
#undef FIO_CRYPT
Expand All @@ -129,13 +111,20 @@ Basics Inclusion
#define FIO_CRYPT
#define FIO_STATE
#define FIO_THREADS
#define FIO___INCLUDE_AGAIN

#elif !defined(H___FIO_BASIC_ROUND2___H)
#define H___FIO_BASIC_ROUND2___H
#define FIO_FIOBJ
#define FIO_MUSTACHE
#define FIOBJ_MALLOC
#else
/* Final cycle, does nothing but allows extension from basic to everything. */
#define H___FIO_BASIC___H
#undef H___FIO_BASIC_ROUND1___H
#undef H___FIO_BASIC_ROUND2___H
#undef FIO_BASIC
#define FIO_MALLOC
#endif

#endif /* H___FIO_BASIC___H */
#define FIO___INCLUDE_AGAIN
#endif /* FIO_BASIC */
/* *****************************************************************************
Poor-man's Cryptographic Elements
Expand Down
Loading

0 comments on commit 3e23ee3

Please sign in to comment.