2 * Copyright (C) 2007-2008, The Perl Foundation.
6 * defines compiler capabilities
9 #ifndef PARROT_COMPILER_H_GUARD
10 #define PARROT_COMPILER_H_GUARD
13 * This set of macros define capabilities that may or may not be available
14 * for a given compiler. They are based on GCC's __attribute__ functionality.
18 * Microsoft provides two annotations mechanisms. __declspec, which has been
19 * around for a while, and Microsoft's standard source code annotation
20 * language (SAL), introduced with Visual C++ 8.0.
21 * See <http://msdn2.microsoft.com/en-us/library/ms235402(VS.80).aspx>,
22 * <http://msdn2.microsoft.com/en-us/library/dabb5z75(VS.80).aspx>.
24 #if defined(_MSC_VER) && (_MSC_VER > 1300)
25 # define PARROT_HAS_SAL 1
28 # define PARROT_HAS_SAL 0
31 #ifdef HASATTRIBUTE_NEVER_WORKS
32 # error This attribute can never succeed. Something has mis-sniffed your configuration.
34 #ifdef HASATTRIBUTE_DEPRECATED
36 # define __attribute__deprecated__ __declspec(deprecated)
38 # define __attribute__deprecated__ __attribute__((__deprecated__))
41 #ifdef HASATTRIBUTE_FORMAT
42 # define __attribute__format__(x, y, z) __attribute__((__format__((x), (y), (z))))
44 #ifdef HASATTRIBUTE_MALLOC
45 # define __attribute__malloc__ __attribute__((__malloc__))
47 #ifdef HASATTRIBUTE_NONNULL
48 # define __attribute__nonnull__(a) __attribute__((__nonnull__(a)))
50 #ifdef HASATTRIBUTE_NORETURN
52 # define __attribute__noreturn__ __declspec(noreturn)
54 # define __attribute__noreturn__ __attribute__((__noreturn__))
57 #ifdef HASATTRIBUTE_PURE
58 # define __attribute__pure__ __attribute__((__pure__))
60 #ifdef HASATTRIBUTE_CONST
61 # define __attribute__const__ __attribute__((__const__))
63 #ifdef HASATTRIBUTE_UNUSED
64 # define __attribute__unused__ __attribute__((__unused__))
66 #ifdef HASATTRIBUTE_WARN_UNUSED_RESULT
67 # define __attribute__warn_unused_result__ __attribute__((__warn_unused_result__))
70 /* If we haven't defined the attributes yet, define them to blank. */
71 #ifndef __attribute__deprecated__
72 # define __attribute__deprecated__
74 #ifndef __attribute__format__
75 # define __attribute__format__(x, y, z)
77 #ifndef __attribute__malloc__
78 # define __attribute__malloc__
80 #ifndef __attribute__nonnull__
81 # define __attribute__nonnull__(a)
83 #ifndef __attribute__noreturn__
84 # define __attribute__noreturn__
86 #ifndef __attribute__const__
87 # define __attribute__const__
89 #ifndef __attribute__pure__
90 # define __attribute__pure__
92 #ifndef __attribute__unused__
93 # define __attribute__unused__
95 #ifndef __attribute__warn_unused_result__
96 # define __attribute__warn_unused_result__
100 /* Shim arguments are arguments that must be included in your function,
101 * but serve no purpose inside. Mark them with the SHIM() macro so that
102 * the compiler and/or lint know that it's OK it's unused. Shim arguments
103 * get "_unused" added to them so that you can't accidentally use them
104 * without removing the shim designation.
106 #define SHIM(a) /*@unused@*/ /*@null@*/ a##_unused __attribute__unused__
108 /* UNUSED() is the old way we handled shim arguments Should still be
109 used in cases where the argument should, at some point be used.
111 #define UNUSED(a) if (0) (void)(a);
114 # define PARROT_CAN_RETURN_NULL /*@null@*/ __maybenull
115 # define PARROT_CANNOT_RETURN_NULL /*@notnull@*/ __notnull
117 # define PARROT_CAN_RETURN_NULL /*@null@*/
118 # define PARROT_CANNOT_RETURN_NULL /*@notnull@*/
121 #define PARROT_DEPRECATED __attribute__deprecated__
123 #define PARROT_IGNORABLE_RESULT
124 #define PARROT_WARN_UNUSED_RESULT __attribute__warn_unused_result__
126 #define PARROT_PURE_FUNCTION __attribute__pure__ __attribute__warn_unused_result__
127 #define PARROT_CONST_FUNCTION __attribute__const__ __attribute__warn_unused_result__
128 #define PARROT_DOES_NOT_RETURN /*@noreturn@*/ __attribute__noreturn__
129 #define PARROT_DOES_NOT_RETURN_WHEN_FALSE /*@noreturnwhenfalse@*/
130 #define PARROT_MALLOC /*@only@*/ __attribute__malloc__ __attribute__warn_unused_result__
132 /* Function argument instrumentation */
133 /* For explanations of the annotations, see http://www.splint.org/manual/manual.html */
136 # define NOTNULL(x) /*@notnull@*/ __notnull x
137 /* The pointer passed may not be NULL */
139 # define NULLOK(x) /*@null@*/ __maybenull x
140 /* The pointer passed may be NULL */
142 # define ARGIN(x) /*@in@*/ /*@notnull@*/ __in x
143 # define ARGIN_NULLOK(x) /*@in@*/ /*@null@*/ __in_opt x
144 /* The pointer target must be completely defined before being passed */
145 /* to the function. */
147 # define ARGOUT(x) /*@out@*/ /*@notnull@*/ __out x
148 # define ARGOUT_NULLOK(x) /*@out@*/ /*@null@*/ __out_opt x
149 /* The pointer target will be defined by the function */
151 # define ARGMOD(x) /*@in@*/ /*@notnull@*/ __inout x
152 # define ARGMOD_NULLOK(x) /*@in@*/ /*@null@*/ __inout_opt x
153 /* The pointer target must be completely defined before being passed, */
154 /* and MAY be modified by the function. */
156 # define FUNC_MODIFIES(x) /*@modifies x@*/
157 /* Never applied by a human, only by the headerizer. */
161 # define NOTNULL(x) /*@notnull@*/ x
162 /* The pointer passed may not be NULL */
164 # define NULLOK(x) /*@null@*/ x
165 /* The pointer passed may be NULL */
167 # define ARGIN(x) /*@in@*/ /*@notnull@*/ x
168 # define ARGIN_NULLOK(x) /*@in@*/ /*@null@*/ x
169 /* The pointer target must be completely defined before being passed */
170 /* to the function. */
172 # define ARGOUT(x) /*@out@*/ /*@notnull@*/ x
173 # define ARGOUT_NULLOK(x) /*@out@*/ /*@null@*/ x
174 /* The pointer target will be defined by the function */
176 # define ARGMOD(x) /*@in@*/ /*@notnull@*/ x
177 # define ARGMOD_NULLOK(x) /*@in@*/ /*@null@*/ x
178 /* The pointer target must be completely defined before being passed, */
179 /* and MAY be modified by the function. */
181 # define FUNC_MODIFIES(x) /*@modifies x@*/
182 /* Never applied by a human, only by the headerizer. */
186 #define ARGFREE(x) /*@only@*/ /*@out@*/ /*@null@*/ x
187 /* From the Splint manual: The parameter to free() must reference */
188 /* an unshared object. Since the parameter is declared using "only", */
189 /* the caller may not use the referenced object after the call, and */
190 /* may not pass in a reference to a shared object. There is nothing */
191 /* special about malloc and free — their behavior can be described */
192 /* entirely in terms of the provided annotations. */
194 #endif /* PARROT_COMPILER_H_GUARD */
198 * c-file-style: "parrot"
200 * vim: expandtab shiftwidth=4: