summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc-obj-c++-shared/GNUStep/CoreFoundation/CFBase.h
blob: 2df7b2925b2fd7b72d68a0f41e0fd2780ea02196 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/* CFBase.h
   
   Copyright (C) 2010 Free Software Foundation, Inc.
   
   Written by: Stefan Bidigaray
   Date: January, 2010
   
   This file is part of the GNUstep CoreBase Library.
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; see the file COPYING.LIB.
   If not, see <http://www.gnu.org/licenses/> or write to the 
   Free Software Foundation, 51 Franklin Street, Fifth Floor, 
   Boston, MA 02110-1301, USA.
*/


#ifndef __COREFOUNDATION_CFBASE_H__
#define __COREFOUNDATION_CFBASE_H__

/* CoreFoundation defines __LITTLE_ENDIAN__ or __BIG_ENDIAN__ so we'll
 * do the same here for compatibility.
 */
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
#define __LITTLE_ENDIAN__ 1
#endif

#include "CFAvailability.h"
#include "../GNUstepBase/GSVersionMacros.h"

/*
 * CoreFoundation types
 */
typedef unsigned char Boolean;
typedef unsigned char UInt8;
typedef signed char SInt8;
typedef unsigned short UInt16;
typedef signed short SInt16;
typedef unsigned int UInt32;
typedef signed int SInt32;
typedef unsigned long long UInt64;
typedef signed long long SInt64;
typedef SInt32 OSStatus;

typedef float Float32;
typedef double Float64;
typedef UInt16 UniChar;
typedef UInt8 *StringPtr;
typedef const StringPtr *ConstStringPtr;
typedef UInt8 Str255[256];
typedef const Str255 *ConstStr255Param;
typedef SInt16 OSErr;
typedef SInt16 RegionCode;
typedef SInt16 LangCode;
typedef SInt16 ScriptCode;
typedef UInt32 FourCharCode;
#ifndef OSTYPE_DECLARED
typedef FourCharCode OSType;
#define OSTYPE_DECLARED
#endif
typedef UInt8 Byte;
typedef SInt8 SignedByte;

#ifndef UTF32Char               /* UTF32Char is also defined in GSConfig.h */
typedef UInt32 UTF32Char;
#endif
typedef UInt16 UTF16Char;
typedef UInt8 UTF8Char;

#if !defined(CF_EXTERN_C_BEGIN)
#if defined(__cplusplus)
#define CF_EXTERN_C_BEGIN extern "C" {
#define CF_EXTERN_C_END }
#else
#define CF_EXTERN_C_BEGIN
#define CF_EXTERN_C_END
#endif
#endif

#if defined(_WIN32)
#if defined(BUILDING_SELF)
#if defined(__cplusplus)
#define CF_EXPORT extern "C" __declspec(dllexport)
#else
#define CF_EXPORT extern __declspec(dllexport)
#endif
#else
#if defined(__cplusplus)
#define CF_EXPORT extern "C" __declspec(dllimport)
#else
#define CF_EXPORT extern __declspec(dllimport)
#endif
#endif
#else
#if defined(__cplusplus)
#define CF_EXPORT extern "C"
#else
#define CF_EXPORT extern
#endif
#endif

#if !defined(__bool_true_false_are_defined)
#define true 1
#define false 0
#endif

#ifndef TRUE
#define TRUE  1
#endif
#ifndef FALSE
#define FALSE 0
#endif

#if !defined(CF_INLINE)
#if defined(__GNUC__) && (__GNUC__ >= 4)
#define CF_INLINE static __inline__ __attribute__((always_inline))
#elif defined(__GNUC__)
#define CF_INLINE static __inline__
#elif defined(__MWERKS__) || defined(__cplusplus)
#define CF_INLINE static inline
#elif defined(_MSC_VER)
#define CF_INLINE static __inline
#elif _WIN32
#define CF_INLINE static __inline__
#else
#define CF_INLINE static inline
#endif
#endif

#if defined(__GNUC__) || defined(__llvm__)
#define GS_PURE_FUNCTION __attribute__((pure))
#else
#define GS_PURE_FUNCTION
#endif

CF_EXTERN_C_BEGIN
/** \defgroup CFTypeRef CFType Reference
    \{
 */
typedef unsigned long CFTypeID;
typedef const void *CFTypeRef;
/** @}
 */

/** \defgroup BaseUtils Base Utilities
    \{
 */
/** An integer value to store a hash code. */
typedef unsigned long CFHashCode;
/** A bitfield for passing information to functions.  Can hold as many bits
    as a word.
 */
typedef unsigned long CFOptionFlags;
/** A signed integer representing an index, size, length or count. */
typedef signed long CFIndex;

/** A structure that represents a range of items in a container, such as
    an array.
 */
typedef struct CFRange CFRange;
struct CFRange
{
  CFIndex location;
    /**< An integer representing the start location of the range, inclusive. */
  CFIndex length;
    /**< An integer representing the total number of items in the range */
};

/** Creates a CFRange structure.
    \param location The starting location.
    \param length The length.
    \return An initialized CFRange structure.
 */
CF_INLINE CFRange
CFRangeMake (CFIndex location, CFIndex length)
{
  CFRange range;

  range.location = location;
  range.length = length;
  return range;
}

/* Returned by comparison functions */
typedef enum
{
  kCFCompareLessThan = -1,
  kCFCompareEqualTo = 0,
  kCFCompareGreaterThan = 1
} CFComparisonResult;

/* Return when a value is not found */
enum
{
  kCFNotFound = -1
};

/* Definition for standard comparison function callback. */
typedef CFComparisonResult (*CFComparatorFunction) (const void *val1,
                                                    const void *val2,
                                                    void *context);

/* CoreFoundation version numbers */
/** \name Library Version Numbers
    \{
 */
CF_EXPORT const double kCFCoreFoundationVersionNumber;
#define kCFCoreFoundationVersionNumber10_0    196.40
#define kCFCoreFoundationVersionNumber10_0_3  196.50
#define kCFCoreFoundationVersionNumber10_1    226.00
#define kCFCoreFoundationVersionNumber10_1_1  226.00
#define kCFCoreFoundationVersionNumber10_1_2  227.20
#define kCFCoreFoundationVersionNumber10_1_3  227.20
#define kCFCoreFoundationVersionNumber10_1_4  227.30
#define kCFCoreFoundationVersionNumber10_2    263.00
#define kCFCoreFoundationVersionNumber10_2_1  263.10
#define kCFCoreFoundationVersionNumber10_2_2  263.10
#define kCFCoreFoundationVersionNumber10_2_3  263.30
#define kCFCoreFoundationVersionNumber10_2_4  263.30
#define kCFCoreFoundationVersionNumber10_2_5  263.50
#define kCFCoreFoundationVersionNumber10_2_6  263.50
#define kCFCoreFoundationVersionNumber10_2_7  263.50
#define kCFCoreFoundationVersionNumber10_2_8  263.50
#define kCFCoreFoundationVersionNumber10_3    299.00
#define kCFCoreFoundationVersionNumber10_3_1  299.00
#define kCFCoreFoundationVersionNumber10_3_2  299.00
#define kCFCoreFoundationVersionNumber10_3_3  299.30
#define kCFCoreFoundationVersionNumber10_3_4  299.31
#define kCFCoreFoundationVersionNumber10_3_5  299.31
#define kCFCoreFoundationVersionNumber10_3_6  299.32
#define kCFCoreFoundationVersionNumber10_3_7  299.33
#define kCFCoreFoundationVersionNumber10_3_8  299.33
#define kCFCoreFoundationVersionNumber10_3_9  299.35
#define kCFCoreFoundationVersionNumber10_4    368.00
#define kCFCoreFoundationVersionNumber10_4_1  368.10
#define kCFCoreFoundationVersionNumber10_4_2  368.11
#define kCFCoreFoundationVersionNumber10_4_3  368.18
#define kCFCoreFoundationVersionNumber10_4_4_Intel   368.26
#define kCFCoreFoundationVersionNumber10_4_4_PowerPC 368.25
#define kCFCoreFoundationVersionNumber10_4_5_Intel   368.26
#define kCFCoreFoundationVersionNumber10_4_5_PowerPC 368.25
#define kCFCoreFoundationVersionNumber10_4_6_Intel   368.26
#define kCFCoreFoundationVersionNumber10_4_6_PowerPC 368.25
#define kCFCoreFoundationVersionNumber10_4_7  368.27
#define kCFCoreFoundationVersionNumber10_4_8  368.27
#define kCFCoreFoundationVersionNumber10_4_9  368.28
#define kCFCoreFoundationVersionNumber10_4_10 368.28
#define kCFCoreFoundationVersionNumber10_4_11 368.31
#define kCFCoreFoundationVersionNumber10_5    476.00
#define kCFCoreFoundationVersionNumber10_5_1  476.00
#define kCFCoreFoundationVersionNumber10_5_2  476.10
#define kCFCoreFoundationVersionNumber10_5_3  476.13
#define kCFCoreFoundationVersionNumber10_5_4  476.14
#define kCFCoreFoundationVersionNumber10_5_5  476.15
#define kCFCoreFoundationVersionNumber10_5_6  476.17
/** \} */
/** \} */

#if __has_feature(attribute_cf_returns_retained)
#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
#else
#define CF_RETURNS_RETAINED
#endif

#if __has_feature(attribute_cf_returns_not_retained)
#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
#else
#define CF_RETURNS_NOT_RETAINED
#endif

/** \ingroup CFPropertyListRef
 */
typedef CFTypeRef CFPropertyListRef;

/** \ingroup CFStringRef
 */
typedef const struct __CFString *CFStringRef;
/** \ingroup CFMutableStringRef
 */
typedef struct __CFString *CFMutableStringRef;



/** \defgroup CFAllocatorRef CFAllocator Reference
    \brief CFAllocator is an opaque type used to allocate and deallocate
    memory.
    \{
 */
/** \brief A reference to a CFAllocator object.
 */
typedef const struct __CFAllocator *CFAllocatorRef;

typedef void *(*CFAllocatorAllocateCallBack) (CFIndex allocSize,
                                              CFOptionFlags hint, void *info);
typedef void (*CFAllocatorDeallocateCallBack) (void *ptr, void *info);
typedef void *(*CFAllocatorReallocateCallBack) (void *ptr,
                                                CFIndex newsize,
                                                CFOptionFlags hint, void *info);
typedef CFIndex (*CFAllocatorPreferredSizeCallBack) (CFIndex size,
                                                     CFOptionFlags hint,
                                                     void *info);
typedef const void *(*CFAllocatorRetainCallBack) (const void *info);
typedef void (*CFAllocatorReleaseCallBack) (const void *info);
typedef CFStringRef (*CFAllocatorCopyDescriptionCallBack) (const void *info);

struct _CFAllocatorContext
{
  CFIndex version;
  void *info;
  CFAllocatorRetainCallBack retain;
  CFAllocatorReleaseCallBack release;
  CFAllocatorCopyDescriptionCallBack copyDescription;
  CFAllocatorAllocateCallBack allocate;
  CFAllocatorReallocateCallBack reallocate;
  CFAllocatorDeallocateCallBack deallocate;
  CFAllocatorPreferredSizeCallBack preferredSize;
};
typedef struct _CFAllocatorContext CFAllocatorContext;

/** The default allocator and is equivalent to NULL.
    \see CFAllocatorGetDefault()
    \see CFAllocatorSetDefault()
 */
CF_EXPORT CFAllocatorRef kCFAllocatorDefault;
/** The default system allocator is used internally by GNUstep and is the
    default allocator if none is been defined.
    \see CFAllocatorSetDefault()
 */
CF_EXPORT CFAllocatorRef kCFAllocatorSystemDefault;
/** An allocator that uses the system's malloc, realloc and free functions.
 */
CF_EXPORT CFAllocatorRef kCFAllocatorMalloc;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
/** Equivalent to kCFAllocatorSystemDefault
 */
CF_EXPORT CFAllocatorRef kCFAllocatorMallocZone;
#endif
/** The NULL allocator does perform any operations.  Can be passed as
    a deallocator if you do not want GNUstep to deallocate the data.
 */
CF_EXPORT CFAllocatorRef kCFAllocatorNull;
/** This is a special case allocator directing CFAllocatorCreate() to use
    the given CFAllocatorContext structure to allocate the new allocator.
 */
CF_EXPORT CFAllocatorRef kCFAllocatorUseContext;

/** Create a new CFAllocator.
    \param allocator The allocator used to create this allocator or
      kCFAllocatorUseContext to use the functions in \b context.
    \param context The new allocator's context functions.
    \return A new CFAllocator or NULL in case of failure.
    \see CFAllocatorContext
 */
CF_EXPORT CFAllocatorRef
CFAllocatorCreate (CFAllocatorRef allocator, CFAllocatorContext * context);

/** Allocate new memory.
    \param allocator The CFAllocator to use.
    \param size The number of bytes to allocate.
    \param hint Option flags.  Currently unused and should be 0.
    \return Newly allocated memory of NULL in case of failure.
    \see CFAllocatorDeallocate()
 */
CF_EXPORT void *CFAllocatorAllocate (CFAllocatorRef allocator, CFIndex size,
                                     CFOptionFlags hint);

/** Deallocate the memory pointed to by \b ptr.
    \param allocator The CFAllocator to use.
    \param ptr A pointer previously allocated by CFAllocatorAllocate().
    \see CFAllocatorAllocate()
 */
CF_EXPORT void CFAllocatorDeallocate (CFAllocatorRef allocator, void *ptr);

CF_EXPORT CFIndex
CFAllocatorGetPreferredSizeForSize (CFAllocatorRef allocator, CFIndex size,
                                    CFOptionFlags hint);

CF_EXPORT void *CFAllocatorReallocate (CFAllocatorRef allocator, void *ptr,
                                       CFIndex newsize, CFOptionFlags hint);

CF_EXPORT CFAllocatorRef CFAllocatorGetDefault (void);

CF_EXPORT void CFAllocatorSetDefault (CFAllocatorRef allocator);

CF_EXPORT void
CFAllocatorGetContext (CFAllocatorRef allocator, CFAllocatorContext * context);

CF_EXPORT CFTypeID CFAllocatorGetTypeID (void);
/** \} */



/** \ingroup CFTypeRef
    \{
 */
/* These function will be implemented in CFRuntime.c since they 
   require runtime support. */
CF_EXPORT CFStringRef CFCopyDescription (CFTypeRef cf);

CF_EXPORT CFStringRef CFCopyTypeIDDescription (CFTypeID typeID);

CF_EXPORT Boolean CFEqual (CFTypeRef cf1, CFTypeRef cf2);

CF_EXPORT CFAllocatorRef CFGetAllocator (CFTypeRef cf);

CF_EXPORT CFIndex CFGetRetainCount (CFTypeRef cf);

CF_EXPORT CFTypeID CFGetTypeID (CFTypeRef cf);

CF_EXPORT CFHashCode CFHash (CFTypeRef cf);

#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
CF_EXPORT CFTypeRef CFMakeCollectable (CFTypeRef cf);
#endif

CF_EXPORT void CFRelease (CFTypeRef cf);

CF_EXPORT CFTypeRef CFRetain (CFTypeRef cf);

CF_EXPORT CFTypeRef CFAutorelease(CFTypeRef arg);

#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
CF_EXPORT void *_CFBridgingRelease (CFTypeRef cf);
CF_EXPORT CFTypeRef _CFBridgingRetain (void *obj);

#if __has_feature(objc_arc)
#define CFBridgingRetain(x) (__bridge_retained CFTypeRef)(x)
#define CFBridgingRelease(x) (__bridge_transfer id)(x)
#elif __OBJC__
#define CFBridgingRetain(x) _CFBridgingRetain((void *)(x))
#define CFBridgingRelease(x) (id)_CFBridgingRelease((x))
#else
#define CFBridgingRetain(x) _CFBridgingRetain((void *)(x))
#define CFBridgingRelease(x) _CFBridgingRelease((x))
#endif
#endif
/** \} */



/** \defgroup CFNullRef CFNull Reference
    \{
 */
#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST)
typedef struct __CFNull *CFNullRef;

CF_EXPORT CFNullRef kCFNull;

CFTypeID CFNullGetTypeID (void);
#endif
/** \} */

CF_EXTERN_C_END
#endif /* __COREFOUNDATION_CFBASE_H__ */