1 /*** emodules-ng.h -- Dynamic Loader routines (via ltdl)
3 * Copyright (C) 2007 Sebastian Freundt
5 * Author: Sebastian Freundt <hroptatyr@sxemacs.org>
7 * This file is part of SXEmacs.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the author nor the names of any contributors
21 * may be used to endorse or promote products derived from this
22 * software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #ifndef INCLUDED_emodules_ng_h_
39 #define INCLUDED_emodules_ng_h_
44 #define EMODNG_INIT "init"
45 #define EMODNG_REINIT "reinit"
46 #define EMODNG_DEINIT "deinit"
48 #define LTX_PREFIX(_name) _name##_LTX_
49 #define LTX_PUBFUN(_name, _fun) _name##_LTX_##_fun
50 #define LTX_PUBINIT(_name) LTX_PUBFUN(_name, init)
51 #define LTX_PUBREINIT(_name) LTX_PUBFUN(_name, reinit)
52 #define LTX_PUBDEINIT(_name) LTX_PUBFUN(_name, deinit)
54 #define EMOD_PUBFUN(_fun) LTX_PUBFUN(EMODNAME, _fun)
55 #define EMOD_PUBINIT LTX_PUBINIT(EMODNAME)
56 #define EMOD_PUBREINIT LTX_PUBREINIT(EMODNAME)
57 #define EMOD_PUBDEINIT LTX_PUBDEINIT(EMODNAME)
59 #define PROVIDE(_name) \
60 static bool _inittedp = false; \
61 bool *_name##_LTX_inittedp = &_inittedp;
62 #define REQUIRE(_name, args...) \
63 const char *_name##_LTX_dependencies[] = { args, NULL }; \
64 const size_t _name##_LTX_ndependencies = \
65 countof(_name##_LTX_dependencies);
67 #ifdef ALL_DEBUG_FLAGS
68 #undef EMOD_DEBUG_FLAG
69 #define EMOD_DEBUG_FLAG
72 #define __EMOD_DEBUG__(args...) fprintf(stderr, "EMOD " args)
73 #ifndef EMOD_DEBUG_FLAG
74 #define EMOD_DEBUG(args...)
76 #define EMOD_DEBUG(args...) __EMOD_DEBUG__(args)
78 #define EMOD_DEBUG_LOADER(args...) EMOD_DEBUG("[loader]: " args)
79 #define EMOD_CRITICAL(args...) __EMOD_DEBUG__("CRITICAL: " args)
81 typedef struct emodng_s *emodng_t;
82 typedef bool (*emodng_init_f)(const emodng_t);
83 typedef bool (*emodng_reinit_f)(const emodng_t);
84 typedef bool (*emodng_deinit_f)(const emodng_t);
85 typedef bool (*emodng_docs_f)(const emodng_t);
87 struct emodng_state_s {
93 * Because subrs and symbols added by a dynamic module are not part of
94 * the make-docfile process, we need a clean way to get the variables
95 * and functions documented. Since people don't like the idea of making
96 * shared modules use different versions of DEFSUBR() and DEFVAR_LISP()
97 * and friends, we need these two functions to insert the documentation
98 * into the right place. These functions will be called by the module
99 * init code, generated by ellcc during initialization mode.
101 extern void emodng_doc_subr(const char *objname, const char *docstr);
102 extern void emodng_doc_sym(const char *objname, const char *docstr);
104 #define CDOCSUBR(Fname, DOC) emodng_doc_subr(Fname, DOC)
105 #define CDOCSYM(Sname, DOC) emodng_doc_sym(Sname, DOC)
108 extern void syms_of_emodng(void);
109 extern void reinit_vars_of_emodng(void);
110 extern void vars_of_emodng(void);
112 #endif /* INCLUDED_emodules_ng_h_ */