~ubuntu-branches/ubuntu/karmic/gnustep-base/karmic

« back to all changes in this revision

Viewing changes to Headers/Additions/GNUstepBase/GSObjCRuntime.h

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** Interface to ObjC runtime for GNUStep
 
2
   Copyright (C) 1995, 1997, 2000, 2002, 2003 Free Software Foundation, Inc.
 
3
 
 
4
   Written by:  Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
 
5
   Date: 1995
 
6
   Written by:  Richard Frith-Macdonald <rfm@gnu.org>
 
7
   Date: 2002
 
8
   
 
9
   This file is part of the GNUstep Base Library.
 
10
 
 
11
   This library is free software; you can redistribute it and/or
 
12
   modify it under the terms of the GNU Library General Public
 
13
   License as published by the Free Software Foundation; either
 
14
   version 2 of the License, or (at your option) any later version.
 
15
   
 
16
   This library is distributed in the hope that it will be useful,
 
17
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
19
   Library General Public License for more details.
 
20
   
 
21
   You should have received a copy of the GNU Library General Public
 
22
   License along with this library; if not, write to the Free
 
23
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
24
 
 
25
    AutogsdocSource: Additions/GSObjCRuntime.m
 
26
 
 
27
   */ 
 
28
 
 
29
#ifndef __GSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
 
30
#define __GSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
 
31
 
 
32
#include <objc/objc.h>
 
33
#include <objc/objc-api.h>
 
34
 
 
35
#ifdef __cplusplus
 
36
extern "C" {
 
37
#endif
 
38
 
 
39
#include <stdarg.h>
 
40
 
 
41
#ifdef GNUSTEP_WITH_DLL
 
42
 
 
43
#if BUILD_libgnustep_base_DLL
 
44
#  define GS_EXPORT  __declspec(dllexport)
 
45
#  define GS_DECLARE __declspec(dllexport)
 
46
#else
 
47
#  define GS_EXPORT  extern __declspec(dllimport)
 
48
#  define GS_DECLARE __declspec(dllimport)
 
49
#endif
 
50
 
 
51
#else /* GNUSTEP_WITH[OUT]_DLL */
 
52
 
 
53
#  define GS_EXPORT extern
 
54
#  define GS_DECLARE 
 
55
 
 
56
#endif
 
57
 
 
58
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
 
59
#define GS_ATTRIB_DEPRECATED __attribute__ ((deprecated))
 
60
#else
 
61
#define GS_ATTRIB_DEPRECATED
 
62
#endif
 
63
 
 
64
@class  NSArray;
 
65
@class  NSDictionary;
 
66
@class  NSObject;
 
67
@class  NSString;
 
68
@class  NSValue;
 
69
 
 
70
#ifndef YES
 
71
#define YES             1
 
72
#endif
 
73
#ifndef NO
 
74
#define NO              0
 
75
#endif
 
76
#ifndef nil
 
77
#define nil             0
 
78
#endif
 
79
 
 
80
#ifdef NeXT_RUNTIME
 
81
#define _C_CONST        'r'
 
82
#define _C_IN           'n'
 
83
#define _C_INOUT        'N'
 
84
#define _C_OUT          'o'
 
85
#define _C_BYCOPY       'O'
 
86
#define _C_BYREF        'R'
 
87
#define _C_ONEWAY       'V'
 
88
#define _C_GCINVISIBLE  '!'
 
89
#endif
 
90
 
 
91
#ifndef NO_GNUSTEP
 
92
/*
 
93
 * Functions for accessing instance variables directly -
 
94
 * We can copy an ivar into arbitrary data,
 
95
 * Get the type encoding for a named ivar,
 
96
 * and copy a value into an ivar.
 
97
 */
 
98
GS_EXPORT BOOL
 
99
GSObjCFindVariable(id obj, const char *name,
 
100
                   const char **type, unsigned int *size, int *offset);
 
101
 
 
102
GS_EXPORT void
 
103
GSObjCGetVariable(id obj, int offset, unsigned int size, void *data);
 
104
 
 
105
GS_EXPORT void
 
106
GSObjCSetVariable(id obj, int offset, unsigned int size, const void *data);
 
107
 
 
108
GS_EXPORT NSArray *
 
109
GSObjCMethodNames(id obj);
 
110
 
 
111
GS_EXPORT NSArray *
 
112
GSObjCVariableNames(id obj);
 
113
 
 
114
GS_EXPORT void
 
115
GSObjCAddClassBehavior(Class receiver, Class behavior);
 
116
 
 
117
GS_EXPORT NSValue *
 
118
GSObjCMakeClass(NSString *name, NSString *superName, NSDictionary *iVars);
 
119
 
 
120
GS_EXPORT void
 
121
GSObjCAddClasses(NSArray *classes);
 
122
 
 
123
/*
 
124
 * Functions for key-value encoding ... they access values in an object
 
125
 * either by selector or directly, but do so using NSNumber for the
 
126
 * scalar types of data.
 
127
 */
 
128
GS_EXPORT id
 
129
GSObjCGetValue(NSObject *self, NSString *key, SEL sel,
 
130
               const char *type, unsigned size, int offset);
 
131
 
 
132
GS_EXPORT void
 
133
GSObjCSetValue(NSObject *self, NSString *key, id val, SEL sel,
 
134
               const char *type, unsigned size, int offset);
 
135
 
 
136
#include <GNUstepBase/objc-gnu2next.h>
 
137
 
 
138
/*
 
139
 * This section includes runtime functions
 
140
 * to query and manipulate the ObjC runtime structures.
 
141
 * These functions take care to not use ObjC code so
 
142
 * that they can safely be used in +(void)load implementations
 
143
 * where applicable.
 
144
 */
 
145
 
 
146
#define GS_STATIC_INLINE static inline
 
147
 
 
148
/**
 
149
 * Fills a nil terminated array of Class objects referenced by buffer
 
150
 * with max number of classes registered with the objc runtime.  
 
151
 * The provided buffer must be large enough to hold max + 1 Class objects.
 
152
 * If buffer is nil, the function returns the number of Class
 
153
 * objects that would be inserted if the buffer is large enough.
 
154
 * Otherwise returns the number of Class objects that did not fit
 
155
 * into the provided buffer.  This function keeps a cache of the class
 
156
 * list for future invocations when used with the GNU runtime.  If
 
157
 * clearCache is YES, this cache will be invalidated and rebuild.  The
 
158
 * flag has no effect for the NeXT runtime.
 
159
 * This function is provided as consistent API to both runtimes.  
 
160
 * In the case of the GNU runtime it is likely more efficient to use
 
161
 * objc_next_class() to iterate over the classes.
 
162
 */
 
163
GS_EXPORT unsigned int
 
164
GSClassList(Class *buffer, unsigned int max, BOOL clearCache);
 
165
 
 
166
/**
 
167
 * GSObjCClass() return the class of an instance.
 
168
 * Returns a nul pointer if the argument is nil.
 
169
 */
 
170
GS_STATIC_INLINE Class
 
171
GSObjCClass(id obj)
 
172
{
 
173
  if (obj == nil)
 
174
    return 0;
 
175
  return obj->class_pointer;
 
176
}
 
177
 
 
178
/**
 
179
 * Returns the superclass of this.
 
180
 */
 
181
GS_STATIC_INLINE Class
 
182
GSObjCSuper(Class cls)
 
183
{
 
184
#ifndef NeXT_RUNTIME
 
185
  if (cls != 0 && CLS_ISRESOLV (cls) == NO)
 
186
    {
 
187
      const char *name;
 
188
      name = (const char *)cls->super_class;
 
189
      if (name == NULL)
 
190
        {
 
191
          return 0;
 
192
        }
 
193
      return objc_lookup_class (name);
 
194
    }
 
195
#endif
 
196
  return class_get_super_class(cls);
 
197
}
 
198
 
 
199
/**
 
200
 * GSObjCIsInstance() tests to see if an id is an instance.
 
201
 * Returns NO if the argument is nil.
 
202
 */
 
203
GS_STATIC_INLINE BOOL
 
204
GSObjCIsInstance(id obj)
 
205
{
 
206
  if (obj == nil)
 
207
    return NO;
 
208
  return object_is_instance(obj);
 
209
}
 
210
 
 
211
/**
 
212
 * GSObjCIsClass() tests to see if an id is a class.
 
213
 * Returns NO if the argument is nil.
 
214
 */
 
215
GS_STATIC_INLINE BOOL
 
216
GSObjCIsClass(Class cls)
 
217
{
 
218
  if (cls == nil)
 
219
    return NO;
 
220
  return object_is_class(cls);
 
221
}
 
222
 
 
223
/**
 
224
 * GSObjCIsKindOf() tests to see if a class inherits from another class
 
225
 * The argument to this function must NOT be nil.
 
226
 */
 
227
GS_STATIC_INLINE BOOL
 
228
GSObjCIsKindOf(Class cls, Class other)
 
229
{
 
230
  while (cls != Nil)
 
231
    {
 
232
      if (cls == other)
 
233
        {
 
234
          return YES;
 
235
        }
 
236
      cls = GSObjCSuper(cls);
 
237
    }
 
238
  return NO;
 
239
}
 
240
 
 
241
/**
 
242
 * Given a class name, return the corresponding class or
 
243
 * a nul pointer if the class cannot be found. <br />
 
244
 * If the argument is nil, return a nul pointer.
 
245
 */
 
246
GS_STATIC_INLINE Class
 
247
GSClassFromName(const char *name)
 
248
{
 
249
  if (name == 0)
 
250
    return 0;
 
251
  return objc_lookup_class(name);
 
252
}
 
253
 
 
254
/**
 
255
 * Return the name of the supplied class, or a nul pointer if no class
 
256
 * was supplied.
 
257
 */
 
258
GS_STATIC_INLINE const char *
 
259
GSNameFromClass(Class cls)
 
260
{
 
261
  if (cls == 0)
 
262
    return 0;
 
263
  return class_get_class_name(cls);
 
264
}
 
265
 
 
266
/**
 
267
 * Return the name of the object's class, or a nul pointer if no object
 
268
 * was supplied.
 
269
 */
 
270
GS_STATIC_INLINE const char *
 
271
GSClassNameFromObject(id obj)
 
272
{
 
273
  if (obj == 0)
 
274
    return 0;
 
275
  return object_get_class_name(obj);
 
276
}
 
277
 
 
278
/**
 
279
 * Return the name of the supplied selector, or a nul pointer if no selector
 
280
 * was supplied.
 
281
 */
 
282
GS_STATIC_INLINE const char *
 
283
GSNameFromSelector(SEL sel)
 
284
{
 
285
  if (sel == 0)
 
286
    return 0;
 
287
  return sel_get_name(sel);
 
288
}
 
289
 
 
290
/**
 
291
 * Return a selector matching the specified name, or nil if no name is
 
292
 * supplied.  The returned selector could be any one with the name.<br />
 
293
 * If no selector exists, returns nil.
 
294
 */
 
295
GS_STATIC_INLINE SEL
 
296
GSSelectorFromName(const char *name)
 
297
{
 
298
  if (name == 0)
 
299
    {
 
300
      return 0;
 
301
    }
 
302
  else
 
303
    {
 
304
      return sel_get_any_uid(name);
 
305
    }
 
306
}
 
307
 
 
308
/**
 
309
 * Return the selector for the specified name and types.  Returns a nul
 
310
 * pointer if the name is nul.  Uses any available selector if the types
 
311
 * argument is nul. <br />
 
312
 * Creates a new selector if necessary.
 
313
 */
 
314
GS_STATIC_INLINE SEL
 
315
GSSelectorFromNameAndTypes(const char *name, const char *types)
 
316
{
 
317
  if (name == 0)
 
318
    {
 
319
      return 0;
 
320
    }
 
321
  else
 
322
    {
 
323
      SEL s;
 
324
 
 
325
      if (types == 0)
 
326
        {
 
327
          s = sel_get_any_typed_uid(name);
 
328
        }
 
329
      else
 
330
        {
 
331
          s = sel_get_typed_uid(name, types);
 
332
        }
 
333
      if (s == 0)
 
334
        {
 
335
          if (types == 0)
 
336
            {
 
337
              s = sel_register_name(name);
 
338
            }
 
339
          else
 
340
            {
 
341
              s = sel_register_typed_name(name, types);
 
342
            }
 
343
        }
 
344
      return s;
 
345
    }
 
346
 
 
347
}
 
348
 
 
349
/**
 
350
 * Return the type information from the specified selector.
 
351
 * May return a nul pointer if the selector was a nul pointer or if it
 
352
 * was not typed.
 
353
 */
 
354
GS_STATIC_INLINE const char *
 
355
GSTypesFromSelector(SEL sel)
 
356
{
 
357
  if (sel == 0)
 
358
    return 0;
 
359
  return sel_get_type(sel);
 
360
}
 
361
 
 
362
/**
 
363
 * Compare only the type information ignoring qualifiers, the frame layout
 
364
 * and register markers.  Unlike sel_types_match, this function also
 
365
 * handles comparisons of types with and without any layout information.
 
366
 */
 
367
GS_EXPORT BOOL
 
368
GSSelectorTypesMatch(const char *types1, const char *types2);
 
369
 
 
370
/**
 
371
 * Returns a protocol object with the corresponding name.
 
372
 * This function searches the registered classes for any protocol
 
373
 * with the supplied name.  If one is found, it is cached in
 
374
 * for future requests.  If efficiency is a factor then use
 
375
 * GSRegisterProtocol() to insert a protocol explicitly into the cache
 
376
 * used by this function.  If no protocol is found this function returns
 
377
 * nil.
 
378
 */
 
379
GS_EXPORT Protocol *
 
380
GSProtocolFromName(const char *name);
 
381
 
 
382
/**
 
383
 * Registers proto in the cache used by GSProtocolFromName().
 
384
 */
 
385
GS_EXPORT void
 
386
GSRegisterProtocol(Protocol *proto);
 
387
 
 
388
 
 
389
/*
 
390
 * Unfortunately the definition of the symbols
 
391
 * 'Method(_t)', 'MethodList(_t)'  and 'IVar(_t)'
 
392
 * are incompatible between the GNU and NeXT/Apple runtimes.
 
393
 * We introduce GSMethod, GSMethodList and GSIVar to allow portability.
 
394
 */
 
395
typedef struct objc_method      *GSMethod;
 
396
typedef struct objc_method_list *GSMethodList;
 
397
typedef struct objc_ivar        *GSIVar;
 
398
 
 
399
/**
 
400
 * Returns the pointer to the method structure
 
401
 * for the selector in the specified class.
 
402
 * Depending on searchInstanceMethods, this function searches
 
403
 * either instance or class methods.
 
404
 * Depending on searchSuperClassesm this function searches
 
405
 * either the specified class only or also its superclasses.<br/>
 
406
 * To obtain the implementation pointer IMP use returnValue->method_imp
 
407
 * which should be safe across all runtimes.<br/>
 
408
 * It should be safe to use this function in +load implementations.<br/>
 
409
 * This function should currently (June 2004) be considered WIP.
 
410
 * Please follow potential changes (Name, parameters, ...) closely until
 
411
 * it stabilizes.
 
412
 */
 
413
GS_EXPORT GSMethod
 
414
GSGetMethod(Class cls, SEL sel,
 
415
            BOOL searchInstanceMethods,
 
416
            BOOL searchSuperClasses);
 
417
 
 
418
/**
 
419
 * Flushes the cached method dispatch table for the class.
 
420
 * Call this function after any manipulations in the method structures.<br/>
 
421
 * It should be safe to use this function in +load implementations.<br/>
 
422
 * This function should currently (June 2003) be considered WIP.
 
423
 * Please follow potential changes (Name, parameters, ...) closely until
 
424
 * it stabilizes.
 
425
 */
 
426
GS_STATIC_INLINE void
 
427
GSFlushMethodCacheForClass (Class cls)
 
428
{
 
429
  extern void __objc_update_dispatch_table_for_class (Class);
 
430
  __objc_update_dispatch_table_for_class (cls);
 
431
}
 
432
 
 
433
/**
 
434
 * Returns the pointer to the instance variable structure
 
435
 * for the instance variable name in the specified class.
 
436
 * This function searches the specified class and its superclasses.<br/>
 
437
 * It should be safe to use this function in +load implementations.<br/>
 
438
 * This function should currently (June 2003) be considered WIP.
 
439
 * Please follow potential changes (Name, parameters, ...) closely until
 
440
 * it stabilizes.
 
441
 */
 
442
GS_EXPORT GSIVar
 
443
GSCGetInstanceVariableDefinition(Class cls, const char *name);
 
444
 
 
445
/**
 
446
 * Returns the pointer to the instance variable structure
 
447
 * for the instance variable name in the specified class.
 
448
 * This function searches the specified class and its superclasses.<br/>
 
449
 * It is not necessarily safe to use this function
 
450
 * in +load implementations.<br/>
 
451
 * This function should currently (June 2003) be considered WIP.
 
452
 * Please follow potential changes (Name, parameters, ...) closely until
 
453
 * it stabilizes.
 
454
 */
 
455
GS_EXPORT GSIVar
 
456
GSObjCGetInstanceVariableDefinition(Class cls, NSString *name);
 
457
 
 
458
/**
 
459
 * <p>Returns a pointer to objc_malloc'ed memory large enough
 
460
 * to hold a struct objc_method_list with 'count' number of
 
461
 * struct objc_method entries.  The memory returned is
 
462
 * initialized with 0, including the method count and
 
463
 * next method list fields.  </p>
 
464
 * <p> This function is intended for use in conjunction with
 
465
 * GSAppendMethodToList() to fill the memory and GSAddMethodList()
 
466
 * to activate the method list.  </p>
 
467
 * <p>After method list manipulation you should call
 
468
 * GSFlushMethodCacheForClass() for the changes to take effect.</p>
 
469
 * <p><em>WARNING:</em> Manipulating the runtime structures
 
470
 * can be hazardous!</p>
 
471
 * <p>This function should currently (June 2004) be considered WIP.
 
472
 * Please follow potential changes (Name, parameters, ...) closely until
 
473
 * it stabilizes.</p>
 
474
 */
 
475
GSMethodList
 
476
GSAllocMethodList (unsigned int count);
 
477
 
 
478
/**
 
479
 * <p>Inserts the method described by sel, types and imp
 
480
 * into the slot of the list's method_count incremented by 1.
 
481
 * This function does not and cannot check whether
 
482
 * the list provided has the necessary capacity.</p>
 
483
 * <p>The GNU runtime makes a difference between method lists
 
484
 * that are "free standing" and those that "attached" to classes.
 
485
 * For "free standing" method lists (e.g. created with GSAllocMethodList()
 
486
 * that have not been added to a class or those which have been removed
 
487
 * via GSRemoveMethodList()) isFree must be passed YES.
 
488
 * When manipulating "attached" method lists, specify NO.</p>
 
489
 * <p>This function is intended for use in conjunction with
 
490
 * GSAllocMethodList() to allocate the list and GSAddMethodList()
 
491
 * to activate the method list. </p>
 
492
 * <p>After method list manipulation you should call
 
493
 * GSFlushMethodCacheForClass() for the changes to take effect.</p>
 
494
 * <p><em>WARNING:</em> Manipulating the runtime structures
 
495
 * can be hazardous!</p>
 
496
 * <p>This function should currently (June 2004) be considered WIP.
 
497
 * Please follow potential changes (Name, parameters, ...) closely until
 
498
 * it stabilizes.</p>
 
499
 */
 
500
void
 
501
GSAppendMethodToList (GSMethodList list,
 
502
                      SEL sel,
 
503
                      const char *types,
 
504
                      IMP imp,
 
505
                      BOOL isFree);
 
506
 
 
507
/**
 
508
 * <p>Removes the method identified by sel
 
509
 * from the method list moving the following methods up in the list,
 
510
 * leaving the last entry blank.  After this call, all references
 
511
 * of previous GSMethodFromList() calls with this list should be
 
512
 * considered invalid.  If the values they referenced are needed, they
 
513
 * must be copied to external buffers before this function is called.</p>
 
514
 * <p>Returns YES if the a matching method was found a removed,
 
515
 * NO otherwise.</p>
 
516
 * <p>The GNU runtime makes a difference between method lists
 
517
 * that are "free standing" and those that "attached" to classes.
 
518
 * For "free standing" method lists (e.g. created with GSAllocMethodList()
 
519
 * that have not been added to a class or those which have been removed
 
520
 * via GSRemoveMethodList()) isFree must be passed YES.
 
521
 * When manipulating "attached" method lists, specify NO.</p>
 
522
 * <p>After method list manipulation you should call
 
523
 * GSFlushMethodCacheForClass() for the changes to take effect.</p>
 
524
 * <p><em>WARNING:</em> Manipulating the runtime structures
 
525
 * can be hazardous!</p>
 
526
 * <p>This function should currently (June 2004) be considered WIP.
 
527
 * Please follow potential changes (Name, parameters, ...) closely until
 
528
 * it stabilizes.</p>
 
529
 */
 
530
BOOL
 
531
GSRemoveMethodFromList (GSMethodList list,
 
532
                        SEL sel,
 
533
                        BOOL isFree);
 
534
 
 
535
/**
 
536
 * <p>Returns a method list of the class that contains the selector.
 
537
 * Depending on searchInstanceMethods either instance or class methods
 
538
 * are searched.
 
539
 * Returns NULL if none are found.
 
540
 * This function does not search the superclasses method lists.
 
541
 * Call this method with the address of a <code>void *</code>
 
542
 * pointing to NULL to obtain the first (active) method list
 
543
 * containing the selector.
 
544
 * Subsequent calls will return further method lists which contain the
 
545
 * selector.  If none are found, it returns NULL.
 
546
 * You may instead pass NULL as the iterator in which case the first
 
547
 * method list containing the selector will be returned.
 
548
 * Do not call it with an uninitialized iterator.
 
549
 * If either class or selector are NULL the function returns NULL.
 
550
 * If subsequent calls to this function with the same non-NULL iterator yet
 
551
 * different searchInstanceMethods value are called, the behavior
 
552
 * is undefined.</p>
 
553
 * <p>This function should currently (June 2004) be considered WIP.
 
554
 * Please follow potential changes (Name, parameters, ...) closely until
 
555
 * it stabilizes.</p>
 
556
 */
 
557
GSMethodList
 
558
GSMethodListForSelector(Class cls,
 
559
                        SEL selector,
 
560
                        void **iterator,
 
561
                        BOOL searchInstanceMethods);
 
562
 
 
563
/**
 
564
 * <p>Returns the (first) GSMethod contained in the supplied list
 
565
 * that corresponds to sel.
 
566
 * Returns NULL if none is found.</p>
 
567
 * <p>The GNU runtime makes a difference between method lists
 
568
 * that are "free standing" and those that "attached" to classes.
 
569
 * For "free standing" method lists (e.g. created with GSAllocMethodList()
 
570
 * that have not been added to a class or those which have been removed
 
571
 * via GSRemoveMethodList()) isFree must be passed YES.
 
572
 * When manipulating "attached" method lists, specify NO.</p>
 
573
 */
 
574
GSMethod
 
575
GSMethodFromList(GSMethodList list,
 
576
                 SEL sel,
 
577
                 BOOL isFree);
 
578
 
 
579
/**
 
580
 * <p>Add the method list to the class as the first list to be
 
581
 * searched during method invocation for the given class.
 
582
 * Depending on toInstanceMethods, this list will be added as 
 
583
 * an instance or a class method list.
 
584
 * If the list is in use by another class, behavior is undefined.
 
585
 * Create a new list with GSAllocMethodList() or use GSRemoveMethodList()
 
586
 * to remove a list before inserting it in a class.</p>
 
587
 * <p>After method list manipulation you should call
 
588
 * GSFlushMethodCacheForClass() for the changes to take effect.</p>
 
589
 * <p>This function should currently (June 2004) be considered WIP.
 
590
 * Please follow potential changes (Name, parameters, ...) closely until
 
591
 * it stabilizes.</p>
 
592
 */
 
593
void
 
594
GSAddMethodList(Class cls,
 
595
                GSMethodList list,
 
596
                BOOL toInstanceMethods);
 
597
 
 
598
/**
 
599
 * <p>Removes the method list from the classes instance or class method
 
600
 * lists depending on fromInstanceMethods.
 
601
 * If the list is not part of the class, behavior is undefined.</p>
 
602
 * <p>After method list manipulation you should call
 
603
 * GSFlushMethodCacheForClass() for the changes to take effect.</p>
 
604
 * <p>This function should currently (June 2004) be considered WIP.
 
605
 * Please follow potential changes (Name, parameters, ...) closely until
 
606
 * it stabilizes.</p>
 
607
 */
 
608
void
 
609
GSRemoveMethodList(Class cls,
 
610
                   GSMethodList list,
 
611
                   BOOL fromInstanceMethods);
 
612
 
 
613
 
 
614
/**
 
615
 * Returns the version number of this.
 
616
 */
 
617
GS_STATIC_INLINE int
 
618
GSObjCVersion(Class cls)
 
619
{
 
620
  return class_get_version(cls);
 
621
}
 
622
 
 
623
#ifndef NeXT_Foundation_LIBRARY
 
624
#include        <Foundation/NSZone.h>
 
625
#else
 
626
#include <Foundation/Foundation.h>
 
627
#endif
 
628
 
 
629
/**
 
630
 * Return the zone in which an object belongs, without using the zone method
 
631
 */
 
632
GS_EXPORT NSZone *
 
633
GSObjCZone(NSObject *obj);
 
634
 
 
635
/**
 
636
 * Quickly return autoreleased data storage area.
 
637
 */
 
638
GS_EXPORT void *
 
639
GSAutoreleasedBuffer(unsigned size);
 
640
 
 
641
/**
 
642
 * Allocate a new objc_mutex_t and store it in the location
 
643
 * pointed to by request.  A mutex is only created if the value
 
644
 * pointed to by request is NULL.  This function is thread safe
 
645
 * in the sense that multiple threads my call this function with the same
 
646
 * value of request and only one will actually set the mutex.
 
647
 * It is the users responsibility that no one else attempts to set
 
648
 * the mutex pointed to.  This function should be
 
649
 * used with objc_mutex_t variables which were statically initialized
 
650
 * to NULL like:
 
651
 * <example>
 
652
 * void function (void)
 
653
 * {
 
654
 *   static objc_mutex_t my_lock = NULL;
 
655
 *   if (my_lock == NULL)
 
656
 *     GSAllocateMutexAt(&amp;my_lock);
 
657
 *   objc_mutex_lock(my_lock);
 
658
 *   do_work ();
 
659
 *   objc_mutex_unlock(my_lock);
 
660
 * }
 
661
 * </example>
 
662
 */
 
663
GS_EXPORT void
 
664
GSAllocateMutexAt(objc_mutex_t *request);
 
665
 
 
666
/** Returns a system error message on a variety of systems
 
667
 */
 
668
GS_EXPORT const char *
 
669
GSLastErrorStr(long error_id);
 
670
 
 
671
/**
 
672
 * <p>Prints a message to fptr using the format string provided and any
 
673
 * additional arguments.  The format string is interpreted as by
 
674
 * the NSString formatted initialisers, and understands the '%@' syntax
 
675
 * for printing an object.
 
676
 * </p>
 
677
 * <p>The data is written to the file pointer in the default CString
 
678
 * encoding if possible, as a UTF8 string otherwise.
 
679
 * </p>
 
680
 * <p>This function is recommended for printing general log messages.
 
681
 * For debug messages use NSDebugLog() and friends.  For error logging
 
682
 * use NSLog(), and for warnings you might consider NSWarnLog().
 
683
 * </p>
 
684
 */
 
685
GS_EXPORT BOOL
 
686
GSPrintf (FILE *fptr, NSString *format, ...);
 
687
 
 
688
 
 
689
 
 
690
#ifndef NO_DEPRECATED
 
691
 
 
692
GS_EXPORT BOOL
 
693
GSFindInstanceVariable(id obj, const char *name,
 
694
                       const char **type,
 
695
                       unsigned int *size, 
 
696
                       int *offset) GS_ATTRIB_DEPRECATED;
 
697
 
 
698
GS_EXPORT void
 
699
GSGetVariable(id obj, int offset, unsigned int size,
 
700
              void *data) GS_ATTRIB_DEPRECATED;
 
701
 
 
702
GS_EXPORT void
 
703
GSSetVariable(id obj, int offset, unsigned int size,
 
704
              const void *data) GS_ATTRIB_DEPRECATED;
 
705
 
 
706
GS_EXPORT id
 
707
GSGetValue(NSObject *self, NSString *key, SEL sel,
 
708
           const char *type,
 
709
           unsigned size,
 
710
           int offset) GS_ATTRIB_DEPRECATED;
 
711
 
 
712
GS_EXPORT void
 
713
GSSetValue(NSObject *self, NSString *key, id val, SEL sel,
 
714
           const char *type,
 
715
           unsigned size,
 
716
           int offset) GS_ATTRIB_DEPRECATED;
 
717
 
 
718
GS_EXPORT NSArray *
 
719
GSObjCAllSubclassesOfClass(Class cls);
 
720
 
 
721
GS_EXPORT NSArray *
 
722
GSObjCDirectSubclassesOfClass(Class cls);
 
723
 
 
724
/** ## deprecated ##
 
725
 */
 
726
GS_STATIC_INLINE const char*
 
727
GSObjCName(Class cls) GS_ATTRIB_DEPRECATED;
 
728
GS_STATIC_INLINE const char*
 
729
GSObjCName(Class cls)
 
730
{
 
731
  return class_get_class_name(cls);
 
732
}
 
733
 
 
734
/** ## deprecated ##
 
735
 */
 
736
GS_STATIC_INLINE const char*
 
737
GSObjCSelectorName(SEL sel) GS_ATTRIB_DEPRECATED;
 
738
GS_STATIC_INLINE const char*
 
739
GSObjCSelectorName(SEL sel)
 
740
{
 
741
  if (sel == 0)
 
742
    return 0;
 
743
  return sel_get_name(sel);
 
744
}
 
745
 
 
746
/** ## deprecated ##
 
747
 */
 
748
GS_STATIC_INLINE const char*
 
749
GSObjCSelectorTypes(SEL sel) GS_ATTRIB_DEPRECATED;
 
750
GS_STATIC_INLINE const char*
 
751
GSObjCSelectorTypes(SEL sel)
 
752
{
 
753
  return sel_get_type(sel);
 
754
}
 
755
 
 
756
GS_STATIC_INLINE GSMethod
 
757
GSGetInstanceMethod(Class cls, SEL sel) GS_ATTRIB_DEPRECATED;
 
758
GS_STATIC_INLINE GSMethod
 
759
GSGetInstanceMethod(Class cls, SEL sel)
 
760
{
 
761
  return GSGetMethod(cls, sel, YES, YES);
 
762
}
 
763
 
 
764
GS_STATIC_INLINE GSMethod
 
765
GSGetClassMethod(Class cls, SEL sel) GS_ATTRIB_DEPRECATED;
 
766
GS_STATIC_INLINE GSMethod
 
767
GSGetClassMethod(Class cls, SEL sel)
 
768
{
 
769
  return GSGetMethod(cls, sel, NO, YES);
 
770
}
 
771
 
 
772
GS_STATIC_INLINE GSMethod
 
773
GSGetInstanceMethodNotInherited(Class cls, 
 
774
                                SEL sel) GS_ATTRIB_DEPRECATED;
 
775
GS_STATIC_INLINE GSMethod
 
776
GSGetInstanceMethodNotInherited(Class cls, SEL sel)
 
777
{
 
778
  return GSGetMethod(cls, sel, YES, NO);
 
779
}
 
780
 
 
781
GS_STATIC_INLINE GSMethod
 
782
GSGetClassMethodNotInherited(Class cls, SEL sel) GS_ATTRIB_DEPRECATED;
 
783
GS_STATIC_INLINE GSMethod
 
784
GSGetClassMethodNotInherited(Class cls, SEL sel)
 
785
{
 
786
  return GSGetMethod(cls, sel, NO, NO);
 
787
}
 
788
 
 
789
 
 
790
#endif  /* NO_DEPRECATED */
 
791
 
 
792
 
 
793
 
 
794
#ifndef GS_MAX_OBJECTS_FROM_STACK
 
795
/**
 
796
 * The number of objects to try to get from varargs into an array on
 
797
 * the stack ... if there are more than this, use the heap.
 
798
 * NB. This MUST be a multiple of 2
 
799
 */
 
800
#define GS_MAX_OBJECTS_FROM_STACK       128
 
801
#endif
 
802
 
 
803
/**
 
804
 * <p>This is a macro designed to minimise the use of memory allocation and
 
805
 * deallocation when you need to work with a vararg list of objects.<br />
 
806
 * The objects are unpacked from the vararg list into two 'C' arrays and
 
807
 * then a code fragment you specify is able to make use of them before
 
808
 * that 'C' array is destroyed. 
 
809
 * </p>
 
810
 * <p>The firstObject argument is the name of the formal parameter in your
 
811
 * method or function which precedes the ', ...' denoting variable args.
 
812
 * </p>
 
813
 * <p>The code argument is a piece of objective-c code to be executed to
 
814
 * make use of the objects stored in the 'C' arrays.<br />
 
815
 * When this code is called the unsigned integer '__count' will contain the
 
816
 * number of objects unpacked, the pointer '__objects' will point to
 
817
 * the first object in each pair, and the pointer '__pairs' will point
 
818
 * to an array containing the second halves of the pairs of objects
 
819
 * whose first halves are in '__objects'.<br />
 
820
 * This lets you pack a list of the form 'key, value, key, value, ...'
 
821
 * into an array of keys and an array of values.
 
822
 * </p>
 
823
 */
 
824
#define GS_USEIDPAIRLIST(firstObject, code...) ({\
 
825
  va_list       __ap; \
 
826
  unsigned int  __max = GS_MAX_OBJECTS_FROM_STACK; \
 
827
  unsigned int  __count = 0; \
 
828
  id            __buf[__max]; \
 
829
  id            *__objects = __buf; \
 
830
  id            *__pairs = &__objects[__max/2]; \
 
831
  id            __obj = firstObject; \
 
832
  va_start(__ap, firstObject); \
 
833
  while (__obj != nil && __count < __max) \
 
834
    { \
 
835
      if ((__count % 2) == 0) \
 
836
        { \
 
837
          __objects[__count/2] = __obj; \
 
838
        } \
 
839
      else \
 
840
        { \
 
841
          __pairs[__count/2] = __obj; \
 
842
        } \
 
843
      __obj = va_arg(__ap, id); \
 
844
      if (++__count == __max) \
 
845
        { \
 
846
          while (__obj != nil) \
 
847
            { \
 
848
              __count++; \
 
849
              __obj = va_arg(__ap, id); \
 
850
            } \
 
851
        } \
 
852
    } \
 
853
  if ((__count % 2) == 1) \
 
854
    { \
 
855
      __pairs[__count/2] = nil; \
 
856
      __count++; \
 
857
    } \
 
858
  va_end(__ap); \
 
859
  if (__count > __max) \
 
860
    { \
 
861
      unsigned int      __tmp; \
 
862
      __objects = (id*)objc_malloc(__count*sizeof(id)); \
 
863
      __pairs = &__objects[__count/2]; \
 
864
      __objects[0] = firstObject; \
 
865
      va_start(__ap, firstObject); \
 
866
      for (__tmp = 1; __tmp < __count; __tmp++) \
 
867
        { \
 
868
          if ((__tmp % 2) == 0) \
 
869
            { \
 
870
              __objects[__tmp/2] = va_arg(__ap, id); \
 
871
            } \
 
872
          else \
 
873
            { \
 
874
              __pairs[__tmp/2] = va_arg(__ap, id); \
 
875
            } \
 
876
        } \
 
877
      va_end(__ap); \
 
878
    } \
 
879
  code; \
 
880
  if (__objects != __buf) objc_free(__objects); \
 
881
})
 
882
 
 
883
/**
 
884
 * <p>This is a macro designed to minimise the use of memory allocation and
 
885
 * deallocation when you need to work with a vararg list of objects.<br />
 
886
 * The objects are unpacked from the vararg list into a 'C' array and
 
887
 * then a code fragment you specify is able to make use of them before
 
888
 * that 'C' array is destroyed. 
 
889
 * </p>
 
890
 * <p>The firstObject argument is the name of the formal parameter in your
 
891
 * method or function which precedes the ', ...' denoting variable args.
 
892
 * </p>
 
893
 * <p>The code argument is a piece of objective-c code to be executed to
 
894
 * make use of the objects stored in the 'C' array.<br />
 
895
 * When this code is called the unsigned integer '__count' will contain the
 
896
 * number of objects unpacked, and the pointer '__objects' will point to
 
897
 * the unpacked objects, ie. firstObject followed by the vararg arguments
 
898
 * up to (but not including) the first nil.
 
899
 * </p>
 
900
 */
 
901
#define GS_USEIDLIST(firstObject, code...) ({\
 
902
  va_list       __ap; \
 
903
  unsigned int  __max = GS_MAX_OBJECTS_FROM_STACK; \
 
904
  unsigned int  __count = 0; \
 
905
  id            __buf[__max]; \
 
906
  id            *__objects = __buf; \
 
907
  id            __obj = firstObject; \
 
908
  va_start(__ap, firstObject); \
 
909
  while (__obj != nil && __count < __max) \
 
910
    { \
 
911
      __objects[__count] = __obj; \
 
912
      __obj = va_arg(__ap, id); \
 
913
      if (++__count == __max) \
 
914
        { \
 
915
          while (__obj != nil) \
 
916
            { \
 
917
              __count++; \
 
918
              __obj = va_arg(__ap, id); \
 
919
            } \
 
920
        } \
 
921
    } \
 
922
  va_end(__ap); \
 
923
  if (__count > __max) \
 
924
    { \
 
925
      unsigned int      __tmp; \
 
926
      __objects = (id*)objc_malloc(__count*sizeof(id)); \
 
927
      va_start(__ap, firstObject); \
 
928
      __objects[0] = firstObject; \
 
929
      for (__tmp = 1; __tmp < __count; __tmp++) \
 
930
        { \
 
931
          __objects[__tmp] = va_arg(__ap, id); \
 
932
        } \
 
933
      va_end(__ap); \
 
934
    } \
 
935
  code; \
 
936
  if (__objects != __buf) objc_free(__objects); \
 
937
})
 
938
 
 
939
 
 
940
#endif /* NO_GNUSTEP */
 
941
 
 
942
#ifdef __cplusplus
 
943
}
 
944
#endif
 
945
 
 
946
#endif /* __GSObjCRuntime_h_GNUSTEP_BASE_INCLUDE */