add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / codesetslib / include / SDI_lib.h
blob99890da2efcd96ff1b06411d09347d07e57a1caf
1 #ifndef SDI_LIB_H
2 #define SDI_LIB_H
4 /* Includeheader
6 Name: SDI_lib.h
7 Versionstring: $VER: SDI_lib.h 1.8 (28.02.2006)
8 Author: Jens Langner
9 Distribution: PD
10 Project page: http://www.sf.net/projects/sditools/
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.
40 ** This is PD (Public Domain). This means you can do with it whatever you want
41 ** without any restrictions. I only ask you to tell me improvements, so I may
42 ** fix the main line of this files as well.
44 ** To keep confusion level low: When changing this file, please note it in
45 ** above history list and indicate that the change was not made by myself
46 ** (e.g. add your name or nick name).
48 ** Find the latest version of this file at:
49 ** http://cvs.sourceforge.net/viewcvs.py/sditools/sditools/headers/
51 ** Jens Langner <Jens.Langner@light-speed.de> and
52 ** Dirk Stöcker <soft@dstoecker.de>
55 #include "SDI_compiler.h"
58 ** Library function macros to handle the definition/usage for different
59 ** Operating System versions.
60 ** Currently special library function handling for AmigaOS version 4 is
61 ** supported
63 ** Example:
65 ** Defines a library jump function "TestFunc" with a ULONG return value and
66 ** which is called by the corresponding library vector of a shared library.
68 ** LIBFUNC ULONG TestFunc(REG(d0, text))
69 ** {
70 ** Printf(text);
71 ** return 0;
72 ** }
74 ** Please note the use of the LIBFUNC macro which defines this function
75 ** automatically as a function which is directly called from within a shared
76 ** library. Since this macro contains compiler attributes it must be
77 ** called first, even if some compiler allow attributes and result type
78 ** mixed, other do not and we want to keep the stuff compiler independent.
80 ** If you now require to have some OS/compiler independent prototype
81 ** definition please use the following statement:
83 ** LIBPROTO(TestFunc, ULONG, REG(d0, text));
85 ** This will ensure that you get a proper prototype for the same function
86 ** where this macro will automatically take care that a libstub_* stub
87 ** will also automatically defines as required if you are generating a
88 ** OS4 shared library which should also be backward compatible to OS3.
90 ** So if you then want to add this function to a library interface please
91 ** use the LFUNC_* macros to generate your library function vector
92 ** like this example one:
94 ** #define libvector LFUNC_FAS(SomeFunc) \
95 ** LFUNC_FA_(TestFunc) \
96 ** LFUNC_VA_(VarargsFunc)
98 ** This way you can then easily put the "libvector" define in your real
99 ** library function vector of your shared library instead of having to
100 ** specify each function with surrounded "#ifdef" defines. These macros
101 ** will then also take automatically care that the varargs functions
102 ** will only be specified on OS versions where these functions are now
103 ** real functions (like with OS4)
105 ** Such stub functions can then also be easily specified as followed
106 ** (in analogy to the above example)
108 ** LIBPROTO(TestFunc, ULONG, REG(d0, text))
109 ** {
110 ** return TestFunc(text);
111 ** }
113 ** On AmigaOS4 using this mechanism for the definition of the library functions
114 ** will automatically ensure that the "struct Interface *self" pointer is included
115 ** and can be easily referenced as such in the function.
117 ** By using this schema a developer might ensure full source code backward
118 ** compatibility to AmigaOS3 without having to introduce dozens of #ifdef
119 ** statements in his code.
122 #ifdef LIBFUNC
123 #undef LIBFUNC
124 #endif
126 #if defined(__amigaos4__)
127 #define LIBFUNC
128 #if !defined(__cplusplus) && \
129 (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \
130 (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
131 #define LIBPROTO(name, ret, ...) \
132 LIBFUNC ret name(__VA_ARGS__); \
133 LIBFUNC ret libstub_##name(struct Interface *self UNUSED, \
134 ## __VA_ARGS__)
135 #define LIBPROTOVA(name, ret, ...) \
136 LIBFUNC ret VARARGS68K \
137 libstub_##name(struct Interface *self UNUSED, ## __VA_ARGS__)
138 #define LIBSTUB(name, ret, ...) \
139 LIBFUNC ret name(__VA_ARGS__); \
140 LIBFUNC ret libstub_##name(struct Interface *self UNUSED, \
141 ## __VA_ARGS__)
142 #define LIBSTUBVA(name, ret, ...) \
143 LIBFUNC ret VARARGS68K \
144 libstub_##name(struct Interface *self UNUSED, ## __VA_ARGS__)
145 #endif
146 #define LFUNC_FAS(name) libstub_##name
147 #define LFUNC_VAS(name) libstub_##name
148 #define LFUNC_FA_(name) ,libstub_##name
149 #define LFUNC_VA_(name) ,libstub_##name
150 #define LFUNC(name) libstub_##name
151 #elif defined(__MORPHOS__)
152 #define LIBFUNC
153 #if !defined(__cplusplus) && \
154 (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \
155 (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
156 #define LIBPROTO(name, ret, ...) \
157 LIBFUNC ret name(__VA_ARGS__); \
158 LIBFUNC ret libstub_##name(void)
159 #define LIBPROTOVA(name, ret, ...)
160 #define LIBSTUB(name, ret, ...) \
161 LIBFUNC ret name(__VA_ARGS__); \
162 LIBFUNC ret libstub_##name(void)
163 #define LIBSTUBVA(name, ret, ...) \
164 LIBFUNC UNUSED ret VARARGS68K libstub_##name(void)
165 #endif
166 #define LFUNC_FAS(name) libstub_##name
167 #define LFUNC_VAS(name)
168 #define LFUNC_FA_(name) ,libstub_##name
169 #define LFUNC_VA_(name)
170 #define LFUNC(name) libstub_##name
171 #else
172 #define LIBFUNC SAVEDS ASM
173 #if !defined(__cplusplus) && \
174 (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \
175 (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
176 #define LIBPROTO(name, ret, ...) \
177 LIBFUNC ret name(__VA_ARGS__)
178 #define LIBPROTOVA(name, ret, ...)
179 #define LIBSTUB(name, ret, ...) \
180 LIBFUNC ret name(__VA_ARGS__); \
181 LIBFUNC ret libstub_##name(__VA_ARGS__)
182 #define LIBSTUBVA(name, ret, ...) \
183 LIBFUNC UNUSED ret STDARGS libstub_##name(__VA_ARGS__)
184 #endif
185 #define LFUNC_FAS(name) name
186 #define LFUNC_VAS(name)
187 #define LFUNC_FA_(name) ,name
188 #define LFUNC_VA_(name)
189 #define LFUNC(name) name
190 #endif
192 #if !defined(LIBPROTO) || !defined(LIBPROTOVA)
193 #error "OS or compiler is not yet supported by SDI_lib.h"
194 #endif
196 #endif /* SDI_LIB_H */