add init.c, force BUG_ON in safe_malloc()
This commit is contained in:
4
Makefile
4
Makefile
@@ -56,7 +56,6 @@ CPPFILES := $(SRC:.c=.i) $(TSTSRC:.c=.i)
|
||||
CPPFLAGS := -I$(BRINCDIR) -I$(INCDIR)
|
||||
|
||||
CPPFLAGS += -DNDEBUG # assert
|
||||
CPPFLAGS += -DBUG_ON # brlib bug.h
|
||||
CPPFLAGS += -DWARN_ON # brlib bug.h
|
||||
|
||||
#CPPFLAGS += -DDEBUG # global - unused
|
||||
@@ -79,6 +78,9 @@ CPPFLAGS += -DWARN_ON # brlib bug.h
|
||||
|
||||
CPPFLAGS += -DDIAGRAM_SYM # UTF8 symbols in diagrams
|
||||
|
||||
# Never comment this one !
|
||||
CPPFLAGS += -DBUG_ON # brlib bug.h
|
||||
|
||||
# remove extraneous spaces (due to spaces before comments)
|
||||
CPPFLAGS := $(strip $(CPPFLAGS))
|
||||
|
||||
|
@@ -173,6 +173,8 @@ s64 clock_elapsed_μs(mclock_t *clock);
|
||||
s64 clock_elapsed_ms(mclock_t *clock);
|
||||
double clock_elapsed_sec(mclock_t *clock);
|
||||
|
||||
#define RAND_SEED_DEFAULT U64(1)
|
||||
|
||||
void rand_init(u64 seed);
|
||||
u64 rand64(void);
|
||||
|
||||
|
42
src/init.c
Normal file
42
src/init.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* init.c - initialize all.
|
||||
*
|
||||
* Copyright (C) 2024 Bruno Raoult ("br")
|
||||
* Licensed under the GNU General Public License v3.0 or later.
|
||||
* Some rights reserved. See COPYING.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this
|
||||
* program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include "chessdefs.h"
|
||||
|
||||
#include "bitboard.h"
|
||||
#include "hyperbola-quintessence.h"
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
void init_all()
|
||||
{
|
||||
/* for printf() numeric thousands separator */
|
||||
setlocale(LC_NUMERIC, "");
|
||||
/* line-buffered stdout */
|
||||
setlinebuf(stdout);
|
||||
|
||||
/* pseudo random generator seed */
|
||||
rand_init(RAND_SEED_DEFAULT);
|
||||
|
||||
/* bitboards & hq */
|
||||
bitboard_init();
|
||||
hyperbola_init();
|
||||
|
||||
/* zobrist tables & default tt hashtable */
|
||||
zobrist_init();
|
||||
hash_create(HASH_DEFAULT);
|
||||
|
||||
}
|
12
src/util.h
12
src/util.h
@@ -17,13 +17,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bug.h"
|
||||
#include <bug.h>
|
||||
|
||||
#include "chessdefs.h"
|
||||
|
||||
#undef safe_malloc
|
||||
#undef safe_free
|
||||
|
||||
/* force BUG_ON, to get a program abort for failed malloc/free
|
||||
*/
|
||||
#pragma push_macro("BUG_ON")
|
||||
#undef BUG_ON
|
||||
#define BUG_ON
|
||||
|
||||
#define safe_malloc(size) ({ \
|
||||
void *_ret = malloc(size); \
|
||||
bug_on(_ret == NULL); \
|
||||
@@ -35,4 +41,8 @@
|
||||
free(ptr); \
|
||||
} while (0)
|
||||
|
||||
/* restore BUG_ON
|
||||
*/
|
||||
# pragma pop_macro("BUG_ON")
|
||||
|
||||
#endif /* UTIL_H */
|
||||
|
Reference in New Issue
Block a user