Skip to content

Commit 4b5623c

Browse files
committed
Remove minor bug with null log.
1 parent d29c8f3 commit 4b5623c

File tree

7 files changed

+23
-94
lines changed

7 files changed

+23
-94
lines changed

source/benchmarks/metacall_py_call_bench/source/metacall_py_call_bench.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ class metacall_py_call_bench : public benchmark::Fixture
3030
{
3131
metacall_print_info();
3232

33-
if (metacall_log(METACALL_LOG_NULL, NULL) != 0)
34-
{
35-
state.SkipWithError("Error setting up MetaCall logs");
36-
}
33+
metacall_log_null();
3734

3835
if (metacall_initialize() != 0)
3936
{

source/benchmarks/metacall_py_init_bench/source/metacall_py_init_bench.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@
2626
class metacall_py_init_bench : public benchmark::Fixture
2727
{
2828
public:
29-
void SetUp(benchmark::State & state)
29+
void SetUp(benchmark::State &)
3030
{
3131
metacall_print_info();
3232

33-
if (metacall_log(METACALL_LOG_NULL, NULL) != 0)
34-
{
35-
state.SkipWithError("Error setting up MetaCall logs");
36-
}
33+
metacall_log_null();
3734
}
3835

3936
void TearDown(benchmark::State & state)

source/metacall/include/metacall/metacall.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ extern void * metacall_null_args[1];
7070
*/
7171
METACALL_API const char * metacall_serial(void);
7272

73+
/**
74+
* @brief
75+
* Disables MetaCall logs, must be called before @metacall_initialize
76+
*/
77+
METACALL_API void metacall_log_null(void);
78+
7379
/**
7480
* @brief
7581
* Initialize MetaCall library
@@ -432,20 +438,20 @@ METACALL_API int metacall_register(const char * name, void * (*invoke)(void *[])
432438
* Array of pointers to the values to be passed to the function
433439
*
434440
* @param[in] resolve_callback
435-
* Pointer to function that will be executed when task completion
441+
* Pointer to function that will be executed when task completion
436442
* @param[in] void *
437-
* Value representing the result of the future resolution
443+
* Value representing the result of the future resolution
438444
* @param[in] void *
439-
* A reference to @data that will be used as a closure for the chain
445+
* A reference to @data that will be used as a closure for the chain
440446
* @return
441-
* Value containing the result of the operation,
447+
* Value containing the result of the operation,
442448
* it will be wrapped into a future later on to be returned by the function
443449
*
444450
* @param[in] reject_callback
445451
* Pointer to function that will be executed when task error (signature is identical as resolve_callback)
446452
*
447453
* @param[in] data
448-
* Pointer to a context that will act as a closure for the chain
454+
* Pointer to a context that will act as a closure for the chain
449455
*
450456
* @return
451457
* Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future

source/metacall/include/metacall/metacall_log.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ enum metacall_log_id
4343
METACALL_LOG_SOCKET,
4444
METACALL_LOG_SYSLOG,
4545
METACALL_LOG_NGINX,
46-
METACALL_LOG_CUSTOM,
47-
METACALL_LOG_NULL
46+
METACALL_LOG_CUSTOM
4847
};
4948

5049
/* -- Forward Declarations -- */

source/metacall/source/metacall.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void * metacall_null_args[1];
4949
/* -- Private Variables -- */
5050

5151
static int metacall_initialize_flag = 1;
52+
static int metacall_log_null_flag = 1;
5253

5354
/* -- Methods -- */
5455

@@ -59,14 +60,19 @@ const char * metacall_serial()
5960
return metacall_serial_str;
6061
}
6162

63+
void metacall_log_null()
64+
{
65+
metacall_log_null_flag = 0;
66+
}
67+
6268
int metacall_initialize()
6369
{
6470
loader l = loader_singleton();
6571

6672
memory_allocator allocator;
6773

6874
/* Initialize logs by default to stdout if none has been defined */
69-
if (log_size() == 0)
75+
if (metacall_log_null_flag != 0 && log_size() == 0)
7076
{
7177
struct metacall_log_stdio_type log_stdio =
7278
{

source/metacall/source/metacall_log.c

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -24,73 +24,6 @@
2424

2525
#include <log/log.h>
2626

27-
/* -- Private Methods -- */
28-
29-
size_t format_size_null(void * context, const char * time, size_t thread_id, size_t line, const char * func, const char * file, const char * level, const char * message, log_policy_format_custom_va_list args)
30-
{
31-
(void)context;
32-
(void)time;
33-
(void)thread_id;
34-
(void)line;
35-
(void)func;
36-
(void)file;
37-
(void)level;
38-
(void)message;
39-
(void)args;
40-
41-
return 0;
42-
}
43-
44-
size_t format_serialize_null(void * context, void * buffer, const size_t size, const char * time, size_t thread_id, size_t line, const char * func, const char * file, const char * level, const char * message, log_policy_format_custom_va_list args)
45-
{
46-
(void)context;
47-
(void)buffer;
48-
(void)size;
49-
(void)time;
50-
(void)thread_id;
51-
(void)line;
52-
(void)func;
53-
(void)file;
54-
(void)level;
55-
(void)message;
56-
(void)args;
57-
58-
return 0;
59-
}
60-
61-
size_t format_deserialize_null(void * context, const void * buffer, const size_t size, const char * time, size_t thread_id, size_t line, const char * func, const char * file, const char * level, const char * message, log_policy_format_custom_va_list args)
62-
{
63-
(void)context;
64-
(void)buffer;
65-
(void)size;
66-
(void)time;
67-
(void)thread_id;
68-
(void)line;
69-
(void)func;
70-
(void)file;
71-
(void)level;
72-
(void)message;
73-
(void)args;
74-
75-
return 0;
76-
}
77-
78-
int stream_flush_null(void * context)
79-
{
80-
(void)context;
81-
82-
return 0;
83-
}
84-
85-
int stream_write_null(void * context, const char * buffer, const size_t size)
86-
{
87-
(void)context;
88-
(void)buffer;
89-
(void)size;
90-
91-
return 0;
92-
}
93-
9427
/* -- Methods -- */
9528

9629
int metacall_log(enum metacall_log_id log_id, void * ctx)
@@ -162,15 +95,6 @@ int metacall_log(enum metacall_log_id log_id, void * ctx)
16295
log_policy_storage_sequential(),
16396
log_policy_stream_custom(custom_ctx->context, custom_ctx->stream_write, custom_ctx->stream_flush));
16497
}
165-
166-
case METACALL_LOG_NULL :
167-
{
168-
return log_configure("metacall",
169-
log_policy_format_custom(NULL, &format_size_null, &format_serialize_null, &format_deserialize_null),
170-
log_policy_schedule_sync(),
171-
log_policy_storage_sequential(),
172-
log_policy_stream_custom(NULL, &stream_write_null, &stream_flush_null));
173-
}
17498
}
17599

176100
return 1;

source/tests/metacall_node_call_test/source/metacall_node_call_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TEST_F(metacall_node_call_test, DefaultConstructor)
3535
{
3636
metacall_print_info();
3737

38-
ASSERT_EQ((int) 0, (int) metacall_log(METACALL_LOG_NULL, NULL));
38+
metacall_log_null();
3939

4040
ASSERT_EQ((int) 0, (int) metacall_initialize());
4141

0 commit comments

Comments
 (0)