Check for SYS/GL during library init. Reason is that
[AROS.git] / test / exec / makelib.c
blob8f796c050e4556f2eade91398567d15f894ad543
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /* Create a Library, add it to the system, and try to open it.
7 */
9 #define DUMMY_OPEN_BUG 1
10 #define INIT_DEBUG_BUG 0
11 #define REMOVE_DUMMY 1
13 #include <exec/types.h>
14 #include <exec/libraries.h>
15 #include <proto/exec.h>
17 #ifndef AROS_ASMCALL_H
18 # include <aros/asmcall.h>
19 #endif
21 struct DummyBase
23 struct Library library;
24 struct ExecBase *sysbase;
27 #undef SysBase
28 #define SysBase (DummyBase->sysbase)
30 #define DEBUG 1
31 #include <aros/debug.h>
33 /********/
35 AROS_UFH3(struct DummyBase *,LIB_init,
36 AROS_LHA(struct DummyBase *, DummyBase, D0),
37 AROS_LHA(ULONG, seglist, A0),
38 AROS_LHA(struct ExecBase *, sysbase, A6))
40 AROS_USERFUNC_INIT
42 #if INIT_DEBUG_BUG
43 D(bug("in LIB_init a\n")); /* segfaults */
44 #endif
45 DummyBase->sysbase = sysbase;
47 DummyBase->library.lib_Node.ln_Type = NT_LIBRARY;
48 DummyBase->library.lib_Node.ln_Name = "dummy.library";
49 DummyBase->library.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
50 DummyBase->library.lib_Version = 1;
51 DummyBase->library.lib_Revision = 0;
52 DummyBase->library.lib_IdString = "dummy.library";
54 D(bug("dummy.library: Init succesfull\n"));
55 return DummyBase;
57 AROS_USERFUNC_EXIT
60 /********/
62 AROS_LH1(struct DummyBase *, LIB_open,
63 AROS_LHA(ULONG, version, D0),
64 struct DummyBase *, DummyBase, 1, Dummy)
66 AROS_LIBFUNC_INIT
68 DummyBase->library.lib_OpenCnt++;
69 DummyBase->library.lib_Flags &= ~LIBF_DELEXP;
70 return DummyBase;
72 AROS_LIBFUNC_EXIT
75 /********/
77 AROS_UFH1(ULONG,LIB_expunge,
78 AROS_UFHA(struct DummyBase *, DummyBase, A6))
80 AROS_USERFUNC_INIT
82 if (DummyBase->library.lib_OpenCnt == 0)
83 Remove((struct Node *)DummyBase);
84 else
85 DummyBase->library.lib_Flags |= LIBF_DELEXP;
86 return 0;
88 AROS_USERFUNC_EXIT
91 /********/
93 AROS_UFH1(ULONG,LIB_close,
94 AROS_UFHA(struct DummyBase *, DummyBase, D0))
96 AROS_USERFUNC_INIT
98 ULONG ret = 0;
100 DummyBase->library.lib_OpenCnt--;
101 if (!DummyBase->library.lib_OpenCnt)
102 if (DummyBase->library.lib_Flags & LIBF_DELEXP)
103 ret = AROS_UFC1(ULONG,LIB_expunge,
104 AROS_UFCA(struct DummyBase *, DummyBase, A6));
105 return ret;
107 AROS_USERFUNC_EXIT
110 /********/
112 int LIB_reserved(void)
114 return 0;
117 static struct Library *dummylib;
119 static void *function_array[] =
121 AROS_SLIB_ENTRY(LIB_open, Dummy, 1),
122 LIB_close,
123 LIB_expunge,
124 LIB_reserved,
125 (void*)~0,
128 /* Must use the global sysbase */
129 #undef SysBase
131 static struct Library *dummy = NULL;
133 int AddDummy(void)
135 D(bug("*** at %s:%d\n", __FUNCTION__, __LINE__));
137 dummylib = MakeLibrary(function_array,NULL,
138 (ULONG_FUNC)LIB_init,
139 sizeof(struct DummyBase),BNULL);
141 D(bug("*** at %s:%d\n", __FUNCTION__, __LINE__));
142 if (dummylib)
144 AddLibrary(dummylib);
145 #if DUMMY_OPEN_BUG
146 D(bug("%s: before OpenLibrary\n", __FUNCTION__));
147 dummy = OpenLibrary("dummy.library", 0); /* segfaults */
148 D(bug("%s: after OpenLibrary\n", __FUNCTION__));
149 if (!dummy)
150 return 0;
151 #endif
152 return 1;
154 return 0;
157 int RemoveDummy(void)
159 if (dummy)
160 CloseLibrary(dummy);
161 if (dummylib)
163 RemLibrary(dummylib);
165 return 1;
168 int __nocommandline = 1;
170 int main (void)
172 AddDummy();
173 #if REMOVE_DUMMY
174 RemoveDummy();
175 #endif
177 return 0;