we don't need to set the last char since the mem is cleared.
[AROS.git] / test / sdi / SDI_lib.h
blobb261af5143864b2c1d91b97d3901fad598e0631a
1 #ifndef SDI_LIB_H
2 #define SDI_LIB_H
4 /* Includeheader
6 Name: SDI_lib.h
7 Versionstring: $VER: SDI_lib.h 1.14 (18.02.2016)
8 Author: Jens Maus
9 Distribution: PD
10 Project page: https://github.com/adtools/SDI
11 Description: defines to hide OS specific library function definitions
13 1.0 09.05.04 : initial version which allows to hide OS specific shared
14 library function definition like it has been introduced with
15 the new interface based library system in AmigaOS4.
16 1.1 13.05.04 : replaced the LIBENTRY() macro with some more sophisticated
17 LFUNC_ macros which allow to maintain varargs library functions
18 in a much easier manner.
19 1.2 22.05.04 : removed the anyway not required SAVEDS and ASM statements
20 from the LIBFUNC macro for OS4. Also removed the LIBFUNC
21 statement in the 68k LIBPROTOVA() macro so that no registers
22 can be used in there (which should be the default).
23 1.3 04.07.04 : added empty LIBFUNC define for MorphOS which was missing.
24 1.4 05.10.04 : added missing LIBFUNC call to OS3/MOS interface
25 1.5 19.05.05 : fixed some documentation glitches (Guido Mersmann)
26 1.6 08.06.05 : swapped LIBFUNC and ret within the prototype, because
27 c standard says attributes first and vbcc want them like
28 this. (Guido Mersmann)
29 changed the documentation to explain that LIBFUNC must be
30 set first. (Guido Mersmann)
31 1.7 11.12.05 : adapted all macros to be somewhat more compatible to also
32 OS3 and MorphOS. Now in the real use case (codesets.library)
33 it required a fundamental rework of the macros. (Jens Langner)
34 1.8 28.02.06 : removed "##" in front of the OS3 __VARARGS__ usage as they
35 causing errors on GCC >= 3.x.
36 1.9 15.03.09 : fixed some missing function prototype in LIBPROTOVA()
37 1.10 30.04.09 : added approriate LIBPROTOVA() definition for OS3 and MorphOS
38 to at least make the functions known. The same pattern as for
39 LIBSTUBVA() will be used now (Thore Böckelmann)
40 1.11 04.05.09 : reverted the faulty LIBPROTOVA() definition to its previous
41 version (Thore Böckelmann)
42 1.12 01.04.14 : removed the necessity of stub functions for AmigaOS4 (Thore
43 Böckelmann)
44 1.13 28.09.15 : removed the exclusion of C++ (Thore Böckelmann)
45 1.14 18.02.16 : added LFUNC_NULL (Jens Maus)
50 ** This is PD (Public Domain). This means you can do with it whatever you want
51 ** without any restrictions. I only ask you to tell me improvements, so I may
52 ** fix the main line of this files as well.
54 ** To keep confusion level low: When changing this file, please note it in
55 ** above history list and indicate that the change was not made by myself
56 ** (e.g. add your name or nick name).
58 ** Find the latest version of this file at:
59 ** https://github.com/adtools/SDI
61 ** Jens Maus <mail@jens-maus.de>
62 ** Dirk Stöcker <soft@dstoecker.de>
65 #include "SDI_compiler.h"
68 ** Library function macros to handle the definition/usage for different
69 ** Operating System versions.
70 ** Currently special library function handling for AmigaOS version 4 is
71 ** supported
73 ** Example:
75 ** Defines a library jump function "TestFunc" with a ULONG return value and
76 ** which is called by the corresponding library vector of a shared library.
78 ** LIBPROTO(TestFunc, ULONG, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *text))
79 ** {
80 ** Printf(text);
81 ** return 0;
82 ** }
84 ** Please note the use of the LIBPROTO macro which defines this function
85 ** automatically as a function which is directly called from within a shared
86 ** library. For AmigaOS4 the library interface pointer is passed as a variable
87 ** named "self" to the function. For all other systems the library base pointer
88 ** is passed.
89 ** Since this macro contains compiler attributes it must be called first, even
90 ** if some compiler allow attributes and result type mixed, other do not and we
91 ** want to keep the stuff compiler independent.
93 ** If you now require to have some OS/compiler independent prototype
94 ** definition please use the following statement:
96 ** LIBPROTO(TestFunc, ULONG, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, char *text));
98 ** This will ensure that you get a proper prototype for the same function
99 ** where this macro will automatically take care that a LIBSTUB_* stub
100 ** function will also automatically defined as required if you are generating
101 ** a shared library for MorphOS.
103 ** So if you then want to add this function to a library interface please
104 ** use the LFUNC_* macros to generate your library function vector
105 ** like this example one:
107 ** #define libvector LFUNC_FAS(SomeFunc) \
108 ** LFUNC_FA_(TestFunc) \
109 ** LFUNC_VA_(VarargsFunc)
111 ** This way you can then easily put the "libvector" define in your real
112 ** library function vector of your shared library instead of having to
113 ** specify each function with surrounded "#ifdef" defines. These macros
114 ** will then also take automatically care that the varargs functions
115 ** will only be specified on OS versions where these functions are now
116 ** real functions, like with AmigaOS4.
118 ** Stub functions are needed for MorphOS only and usually look like this:
120 ** LIBSTUB(TestFunc, ULONG)
121 ** {
122 ** __BASE_OR_IFACE = (__BASE_OR_IFACE_TYPE)REG_A6;
123 ** return CALL_LFUNC(TestFunc, (char *)REG_A0);
124 ** }
126 ** The CALL_LFUNC macro must be used to internally call one of the public
127 ** library functions without going through the interface/jump table.
128 ** The CALL_LFUNC_NP macro does the same job for functions without further
129 ** parameters, except the implicit interface/base pointer.
131 ** By using this schema a developer might ensure full source code backward
132 ** compatibility to AmigaOS3 without having to introduce dozens of #ifdef
133 ** statements in his code.
136 #ifdef LIBFUNC
137 #undef LIBFUNC
138 #endif
140 #if defined(__amigaos4__)
141 #define LIBFUNC
142 #if (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
143 #define LIBPROTO(name, ret, ...) LIBFUNC ret LIB_##name(__VA_ARGS__)
144 #define LIBPROTOVA(name, ret, ...) LIBFUNC ret VARARGS68K LIB_##name(__VA_ARGS__)
145 #define LIBSTUB(name, ret, ...)
146 #define CALL_LFUNC_NP(name, ...) LIB_##name(__BASE_OR_IFACE_VAR)
147 #define CALL_LFUNC(name, ...) LIB_##name(__BASE_OR_IFACE_VAR, __VA_ARGS__)
148 #endif
149 #define LFUNC_FAS(name) LIB_##name
150 #define LFUNC_VAS(name) LIB_##name
151 #define LFUNC_FA_(name) ,LIB_##name
152 #define LFUNC_VA_(name) ,LIB_##name
153 #define LFUNC_NULL ,NULL
154 #define LFUNC(name) LIB_##name
155 #elif defined(__MORPHOS__)
156 #define LIBFUNC
157 #if (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
158 #define LIBPROTO(name, ret, ...) LIBFUNC ret LIBSTUB_##name(void); LIBFUNC ret LIB_##name(__VA_ARGS__)
159 #define LIBPROTOVA(name, ret, ...)
160 #define LIBSTUB(name, ret, ...) LIBFUNC ret LIBSTUB_##name(void)
161 #define CALL_LFUNC_NP(name, ...) LIB_##name(__BASE_OR_IFACE_VAR)
162 #define CALL_LFUNC(name, ...) LIB_##name(__BASE_OR_IFACE_VAR, __VA_ARGS__)
163 #endif
164 #define LFUNC_FAS(name) LIBSTUB_##name
165 #define LFUNC_VAS(name)
166 #define LFUNC_FA_(name) ,LIBSTUB_##name
167 #define LFUNC_VA_(name)
168 #define LFUNC_NULL ,NULL
169 #define LFUNC(name) LIBSTUB_##name
170 #else
171 #define LIBFUNC SAVEDS ASM
172 #if (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
173 #define LIBPROTO(name, ret, ...) LIBFUNC ret LIB_##name(__VA_ARGS__)
174 #define LIBPROTOVA(name, ret, ...)
175 #define LIBSTUB(name, ret, ...)
176 #define CALL_LFUNC_NP(name, ...) LIB_##name(__BASE_OR_IFACE_VAR)
177 #define CALL_LFUNC(name, ...) LIB_##name(__BASE_OR_IFACE_VAR, __VA_ARGS__)
178 #endif
179 #define LFUNC_FAS(name) LIB_##name
180 #define LFUNC_VAS(name)
181 #define LFUNC_FA_(name) ,LIB_##name
182 #define LFUNC_VA_(name)
183 #define LFUNC_NULL ,NULL
184 #define LFUNC(name) LIB_##name
185 #endif
187 #if !defined(LIBPROTO) || !defined(LIBPROTOVA)
188 #error "OS or compiler is not yet supported by SDI_lib.h"
189 #endif
191 #endif /* SDI_LIB_H */