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