Skip to content

Commit a66073e

Browse files
committed
init: mark val and str subsystem init functions as constructors
This way, the linker will call them for us before anything can use it. This means that we no longer have to call jeffpc_init(NULL) early in the program's execution if all we want is struct val or struct str. Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
1 parent f042e6f commit a66073e

File tree

4 files changed

+4
-11
lines changed

4 files changed

+4
-11
lines changed

init.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016 Josef 'Jeff' Sipek <[email protected]>
2+
* Copyright (c) 2016-2017 Josef 'Jeff' Sipek <[email protected]>
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -54,8 +54,4 @@ void jeffpc_init(struct jeffpc_ops *ops)
5454
SET_OP(log, default_log);
5555
SET_OP(assfail, default_assfail);
5656
SET_OP(assfail3, default_assfail3);
57-
58-
init_str_subsys();
59-
init_val_subsys();
60-
6157
}

init.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016 Josef 'Jeff' Sipek <[email protected]>
2+
* Copyright (c) 2016-2017 Josef 'Jeff' Sipek <[email protected]>
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -25,9 +25,6 @@
2525

2626
#include <jeffpc/jeffpc.h>
2727

28-
extern void init_val_subsys(void);
29-
extern void init_str_subsys(void);
30-
3128
extern struct jeffpc_ops libops;
3229

3330
#endif

str.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
static struct mem_cache *str_cache;
3232

33-
void init_str_subsys(void)
33+
static void __attribute__((constructor)) init_str_subsys(void)
3434
{
3535
str_cache = mem_cache_create("str-cache", sizeof(struct str), 0);
3636
ASSERT(!IS_ERR(str_cache));

val.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static const struct val val_ints[10] = {
5858

5959
static struct mem_cache *val_cache;
6060

61-
void init_val_subsys(void)
61+
static void __attribute__((constructor)) init_val_subsys(void)
6262
{
6363
val_cache = mem_cache_create("val-cache", sizeof(struct val), 0);
6464
ASSERT(!IS_ERR(val_cache));

0 commit comments

Comments
 (0)