7 Versionstring: $VER: SDI_lib.h 1.4 (05.10.2004)
10 Description: defines to hide OS specific library function definitions
12 1.0 09.05.04 : initial version which allows to hide OS specific shared
13 library function definition like it has been introduced with
14 the new interface based library system in AmigaOS4.
15 1.1 13.05.04 : replaced the LIBENTRY() macro with some more sophisticated
16 LFUNC_ macros which allow to maintain varargs library functions
17 in a much easier manner.
18 1.2 22.05.04 : removed the anyway not required SAVEDS and ASM statements
19 from the LIBFUNC macro for OS4. Also removed the LIBFUNC
20 statement in the 68k LIBPROTOVA() macro so that no registers
21 can be used in there (which should be the default).
22 1.3 04.07.04 : added empty LIBFUNC define for MorphOS which was missing.
23 1.4 05.10.04 : added missing LIBFUNC call to OS3/MOS interface
28 ** This is PD (Public Domain). This means you can do with it whatever you want
29 ** without any restrictions. I only ask you to tell me improvements, so I may
30 ** fix the main line of this files as well.
32 ** To keep confusion level low: When changing this file, please note it in
33 ** above history list and indicate that the change was not made by myself
34 ** (e.g. add your name or nick name).
36 ** Jens Langner <Jens.Langner@light-speed.de> and
37 ** Dirk Stöcker <stoecker@epost.de>
40 #include "SDI_compiler.h"
43 ** Library function macros to handle the definition/usage for different
44 ** Operating System versions.
45 ** Currently special library function handling for AmigaOS version 4 is
50 ** Defines a library jump function "TestFunc" with a ULONG return value and
51 ** which is called by the corresponding library vector of a shared library.
53 ** ULONG LIBFUNC TestFunc(REG(d0, text))
59 ** Please note the use of the LIBFUNC macro which defines this function
60 ** automatically as a function which is directly called from within a shared
63 ** If you now require to have some OS/compiler independent prototype
64 ** definition please use the following statement:
66 ** LIBPROTO(TestFunc, ULONG, REG(d0, text));
68 ** This will ensure that you get a proper prototype for the same function
69 ** where this macro will automatically take care that a libstub_* stub
70 ** will also automatically defines as required if you are generating a
71 ** OS4 shared library which should also be backward compatible to OS3.
73 ** So if you then want to add this function to a library interface please
74 ** use the LIBFUNC_* macros to generate your library function vector
75 ** like this example one:
77 ** #define libvector LIBFUNC_FAS(SomeFunc) \
78 ** LIBFUNC_FA_(TestFunc) \
79 ** LIBFUNC_VA_(VarargsFunc)
81 ** This way you can then easily put the "libvector" define in your real
82 ** library function vector of your shared library instead of having to
83 ** specify each function with surrounded "#ifdef" defines. These macros
84 ** will then also take automatically care that the varargs functions
85 ** will only be specified on OS versions where these functions are now
86 ** real functions (like with OS4)
88 ** Such stub functions can then also be easily specified as followed
89 ** (in analogy to the above example)
91 ** LIBPROTO(TestFunc, ULONG, REG(d0, text))
93 ** return TestFunc(text);
96 ** On AmigaOS4 using this mechanism for the definition of the library functions
97 ** will automatically ensure that the "struct Interface *self" pointer is included
98 ** and can be easily referenced as such in the function.
100 ** By using this schema a developer might ensure full source code backward
101 ** compatibility to AmigaOS3 without having to introduce dozens of #ifdef
102 ** statements in his code.
109 #if defined(__amigaos4__)
111 #if !defined(__cplusplus) && \
112 (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \
113 (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
114 #define LIBPROTO(name, ret, ...) \
115 ret LIBFUNC name(__VA_ARGS__); \
116 ret LIBFUNC libstub_##name(struct Interface *self UNUSED , ## __VA_ARGS__)
117 #define LIBPROTOVA(name, ret, ...) \
118 ret LIBFUNC VARARGS68K name(__VA_ARGS__); \
119 ret LIBFUNC VARARGS68K \
120 libstub_##name(struct Interface *self UNUSED , ## __VA_ARGS__)
122 #define LFUNC_FAS(name) libstub_##name
123 #define LFUNC_VAS(name) libstub_##name
124 #define LFUNC_FA_(name) ,libstub_##name
125 #define LFUNC_VA_(name) ,libstub_##name
126 #define LFUNC(name) libstub_##name
128 #if defined(__MORPHOS__)
131 #define LIBFUNC SAVEDS ASM
133 #if !defined(__cplusplus) && \
134 (__STDC_VERSION__ >= 199901L || __GNUC__ >= 3 || \
135 (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
136 #define LIBPROTO(name, ret, ...) \
137 ret LIBFUNC name(__VA_ARGS__)
138 #define LIBPROTOVA(name, ret, ...) \
139 ret LIBFUNC STDARGS name(__VA_ARGS__)
141 #define LFUNC_FAS(name) name
142 #define LFUNC_VAS(name)
143 #define LFUNC_FA_(name) ,name
144 #define LFUNC_VA_(name)
145 #define LFUNC(name) name
148 #if !defined(LIBPROTO) || !defined(LIBPROTOVA)
149 #error "OS or compiler are not yet supported by SDI_lib.h"
152 #endif /* SDI_LIB_H */