commit 12b91bf689d85edf45557c6f5517ba888ed2710c
parent b88f1af6ad1ff48fab49280dc1f5598fa253def8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 18 Dec 2024 12:16:51 +0100
Add internal header for sphin data structure
This defines sphin's private API, i.e. the one that can be used
internally. The sphin data structure has therefore been moved here to
allow any C file to access its internal member variables such as its
logger or memory allocator.
This is where you'll find the logging macros already used in the
configuration implementation. To simplify their invocation, these are
variadic macros, i.e. they accept a variable number of arguments, like
printf/scanf functions. However, this feature is not supported by the C
standard in use. It has therefore been updated to C99, which is the
standard that introduces it.
Diffstat:
3 files changed, 57 insertions(+), 12 deletions(-)
diff --git a/config.mk b/config.mk
@@ -40,7 +40,7 @@ CFLAGS_HARDENED =\
-fstack-protector-strong
CFLAGS_COMMON =\
- -std=c89\
+ -std=c99\
-pedantic\
-fvisibility=hidden\
-fstrict-aliasing\
diff --git a/src/sphin.c b/src/sphin.c
@@ -23,19 +23,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "sphin.h"
+#include "sphin_c.h"
+
#include <rsys/logger.h>
#include <rsys/mem_allocator.h>
-#include <rsys/ref_count.h> /* ref_get/ref_put */
-
-struct sphin {
- /* Log */
- struct logger* logger;
- int verbose;
-
- /* Memory management */
- struct mem_allocator* allocator;
- ref_T ref;
-};
/*******************************************************************************
* Helper functions
diff --git a/src/sphin_c.h b/src/sphin_c.h
@@ -0,0 +1,54 @@
+/* Copyright (C) 2024 Centre National de la Recherche Scientifique
+ * Copyright (C) 2024 Clermont Auvergne INP
+ * Copyright (C) 2024 INSA Lyon
+ * Copyright (C) 2024 Institut Mines Télécom Albi-Carmaux
+ * Copyright (C) 2024 Institut National Polytechnique de Toulouse
+ * Copyright (C) 2024 |Méso|Star> (contact@meso-star.com)
+ * Copyright (C) 2024 PhotonLyX (info@photonlyx.com)
+ * Copyright (C) 2024 Université de Lorraine
+ * Copyright (C) 2024 Université Paul Sabatier
+ * Copyright (C) 2024 Université Toulouse - Jean Jaurès
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SPHIN_C_H
+#define SPHIN_C_H
+
+#include <rsys/logger.h>
+#include <rsys/ref_count.h>
+
+/* Helper macros for logging */
+#define LOG__(Dev, Lvl, Type, ...) { \
+ if((Dev)->verbose >= (Lvl)) \
+ logger_print((Dev)->logger, Type, __VA_ARGS__); \
+} (void)0
+#define ERROR(Dev, ...) LOG__(Dev, 1, LOG_ERROR, __VA_ARGS__)
+#define WARN(Dev, ...) LOG__(Dev, 2, LOG_WARNING, __VA_ARGS__)
+#define INFO(Dev, ...) LOG__(Dev, 3, LOG_OUTPUT, __VA_ARGS__)
+
+/* Forward declarations */
+struct logger;
+struct mem_allocator;
+
+struct sphin {
+ /* Log */
+ struct logger* logger;
+ int verbose;
+
+ /* Memory management */
+ struct mem_allocator* allocator;
+ ref_T ref;
+};
+
+#endif /* SPHIN_C_H */