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

« back to all changes in this revision

Viewing changes to Source/NSObjCRuntime.m

  • 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:
3
3
 
4
4
   Written by:  Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
5
5
   Date: Aug 1995
6
 
   
 
6
 
7
7
   This file is part of the GNUstep Base Library.
8
8
 
9
9
   This library is free software; you can redistribute it and/or
10
10
   modify it under the terms of the GNU Library General Public
11
11
   License as published by the Free Software Foundation; either
12
12
   version 2 of the License, or (at your option) any later version.
13
 
   
 
13
 
14
14
   This library is distributed in the hope that it will be useful,
15
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
17
   Library General Public License for more details.
18
 
   
 
18
 
19
19
   You should have received a copy of the GNU Library General Public
20
20
   License along with this library; if not, write to the Free
21
21
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
22
22
 
23
23
   <title>NSObjCRuntime class reference</title>
24
 
   $Date: 2002/03/13 09:58:43 $ $Revision: 1.34 $
25
 
   */ 
 
24
   $Date: 2005/02/22 11:22:44 $ $Revision: 1.43 $
 
25
   */
26
26
 
27
 
#include <config.h>
28
 
#include <base/preface.h>
29
 
#include <Foundation/NSException.h>
30
 
#include <Foundation/NSObjCRuntime.h>
31
 
#include <Foundation/NSString.h>
 
27
#include "config.h"
 
28
#include "GNUstepBase/preface.h"
 
29
#include "Foundation/NSException.h"
 
30
#include "Foundation/NSObjCRuntime.h"
 
31
#include "Foundation/NSString.h"
32
32
#include <mframe.h>
33
33
#include <string.h>
34
34
 
 
35
/**
 
36
 * Returns a string object containing the method name for
 
37
 * aSelector.  If aSelector is 0, returns nil.
 
38
 */
35
39
NSString *
36
40
NSStringFromSelector(SEL aSelector)
37
41
{
40
44
  return nil;
41
45
}
42
46
 
 
47
/**
 
48
 * Returns a selector for the method whose name is supplied in the
 
49
 * aSelectorName argument, or 0 if a nil string is supplied.
 
50
 */
43
51
SEL
44
52
NSSelectorFromString(NSString *aSelectorName)
45
53
{
46
54
  if (aSelectorName != nil)
47
 
    return GSSelectorFromName ([aSelectorName lossyCString]);
 
55
    {
 
56
      int       len = [aSelectorName cStringLength];
 
57
      char      buf[len+1];
 
58
 
 
59
      [aSelectorName getCString: buf];
 
60
      return GSSelectorFromName (buf);
 
61
    }
48
62
  return (SEL)0;
49
63
}
50
64
 
 
65
/**
 
66
 * Returns the class whose name is supplied in the
 
67
 * aClassName argument, or 0 if a nil string is supplied.
 
68
 */
51
69
Class
52
70
NSClassFromString(NSString *aClassName)
53
71
{
54
72
  if (aClassName != nil)
55
 
    return GSClassFromName ([aClassName lossyCString]);
 
73
    {
 
74
      int       len = [aClassName cStringLength];
 
75
      char      buf[len+1];
 
76
 
 
77
      [aClassName getCString: buf];
 
78
      return GSClassFromName (buf);
 
79
    }
56
80
  return (Class)0;
57
81
}
58
82
 
 
83
/**
 
84
 * Returns an [NSString] object containing the class name for
 
85
 * aClass.  If aClass is 0, returns nil.
 
86
 */
59
87
NSString *
60
88
NSStringFromClass(Class aClass)
61
89
{
64
92
  return nil;
65
93
}
66
94
 
 
95
/**
 
96
 * When provided with a C string containing encoded type information,
 
97
 * this method extracts size and alignment information for the specified
 
98
 * type into the buffers pointed to by sizep and alignp.<br />
 
99
 * If either sizep or alignp is a nil pointer, the corresponding data is
 
100
 * not extracted.<br />
 
101
 * The function returns a pointer to the type information C string.
 
102
 */
67
103
const char *
68
104
NSGetSizeAndAlignment(const char *typePtr, unsigned *sizep, unsigned *alignp)
69
105
{
75
111
    *alignp = info.align;
76
112
  return typePtr;
77
113
}
78
 
 
79
 
/**
80
 
 * This function is used to locate information about the instance
81
 
 * variable of obj called name.  It returns YES if the variable
82
 
 * was found, NO otherwise.  If it returns YES, then the values
83
 
 * pointed to by type, size, and offset will be set (except where
84
 
 * they are nul pointers).
85
 
 */
86
 
BOOL
87
 
GSFindInstanceVariable(id obj, const char *name,
88
 
  const char **type, unsigned int *size, int *offset)
89
 
{
90
 
  Class                 class;
91
 
  struct objc_ivar_list *ivars;
92
 
  struct objc_ivar      *ivar = 0;
93
 
 
94
 
  class = [obj class];
95
 
  while (class != nil && ivar == 0)
96
 
    {
97
 
      ivars = class->ivars;
98
 
      class = class->super_class;
99
 
      if (ivars != 0)
100
 
        {
101
 
          int   i;
102
 
 
103
 
          for (i = 0; i < ivars->ivar_count; i++)
104
 
            {
105
 
              if (strcmp(ivars->ivar_list[i].ivar_name, name) == 0)
106
 
                {
107
 
                  ivar = &ivars->ivar_list[i];
108
 
                  break;
109
 
                }
110
 
            }
111
 
        }
112
 
    }
113
 
  if (ivar == 0)
114
 
    {
115
 
      return NO;
116
 
    }
117
 
 
118
 
  if (type)
119
 
    *type = ivar->ivar_type;
120
 
  if (size)
121
 
    *size = objc_sizeof_type(ivar->ivar_type);
122
 
  if (offset)
123
 
    *offset = ivar->ivar_offset;
124
 
  return YES;
125
 
}
126
 
 
127
 
/**
128
 
 * This function performs no checking ... you should use it only where
129
 
 * you are providing information from a call to GSFindInstanceVariable()
130
 
 * and you know that the data area provided is the correct size.
131
 
 */
132
 
void
133
 
GSGetVariable(id obj, int offset, unsigned int size, void *data)
134
 
{
135
 
  memcpy(data, ((void*)obj) + offset, size);
136
 
}
137
 
 
138
 
/**
139
 
 * This function performs no checking ... you should use it only where
140
 
 * you are providing information from a call to GSFindInstanceVariable()
141
 
 * and you know that the data area provided is the correct size.
142
 
 */
143
 
void
144
 
GSSetVariable(id obj, int offset, unsigned int size, const void *data)
145
 
{
146
 
  memcpy(((void*)obj) + offset, data, size);
147
 
}
148
 
 
149
 
/** ## deprecated ##
150
 
 */
151
 
BOOL
152
 
GSInstanceVariableInfo(id obj, NSString *iVarName,
153
 
  const char **type, unsigned *size, unsigned *offset)
154
 
{
155
 
  const char    *name = [iVarName cString];
156
 
 
157
 
  return GSFindInstanceVariable(obj, name, type, size, offset);
158
 
}
159
 
 
160
 
/** ## deprecated ##
161
 
 */
162
 
BOOL
163
 
GSGetInstanceVariable(id obj, NSString *iVarName, void *data)
164
 
{
165
 
  const char    *name = [iVarName cString];
166
 
  int           offset;
167
 
  unsigned int  size;
168
 
 
169
 
  if (GSFindInstanceVariable(obj, name, 0, &size, &offset) == YES)
170
 
    {
171
 
      GSGetVariable(obj, offset, size, data);
172
 
      return YES;
173
 
    }
174
 
  return NO;
175
 
}
176
 
 
177
 
/** ## deprecated ##
178
 
 */
179
 
BOOL
180
 
GSSetInstanceVariable(id obj, NSString *iVarName, const void *data)
181
 
{
182
 
  const char    *name = [iVarName cString];
183
 
  int           offset;
184
 
  unsigned int  size;
185
 
 
186
 
  if (GSFindInstanceVariable(obj, name, 0, &size, &offset) == YES)
187
 
    {
188
 
      GSSetVariable(obj, offset, size, data);
189
 
      return YES;
190
 
    }
191
 
  return NO;
192
 
}
193
 
 
194
 
#include        <Foundation/NSValue.h>
195
 
#include        <Foundation/NSKeyValueCoding.h>
196
 
/**
197
 
 * This is used internally by the key-value coding methods, to get a
198
 
 * value from an object either via an accessor method (if sel is
199
 
 * supplied), or via direct access (if type, size, and offset are
200
 
 * supplied).<br />
201
 
 * Automatic conversion between NSNumber and C scalar types is performed.<br />
202
 
 * If type is nul and can't be determined from the selector, the
203
 
 * [NSObject-handleQueryWithUnboundKey:] method is called to try
204
 
 * to get a value.
205
 
 */
206
 
id
207
 
GSGetValue(NSObject *self, NSString *key, SEL sel,
208
 
  const char *type, unsigned size, int offset)
209
 
{
210
 
  if (sel != 0)
211
 
    {
212
 
      NSMethodSignature *sig = [self methodSignatureForSelector: sel];
213
 
 
214
 
      if ([sig numberOfArguments] != 2)
215
 
        {
216
 
          [NSException raise: NSInvalidArgumentException
217
 
                      format: @"key-value get method has wrong number of args"];
218
 
        }
219
 
      type = [sig methodReturnType];
220
 
    }
221
 
  if (type == NULL)
222
 
    {
223
 
      return [self handleQueryWithUnboundKey: key];
224
 
    }
225
 
  else
226
 
    {
227
 
      id        val = nil;
228
 
 
229
 
      switch (*type)
230
 
        {
231
 
          case _C_ID:
232
 
          case _C_CLASS:
233
 
            {
234
 
              id        v;
235
 
 
236
 
              if (sel == 0)
237
 
                {
238
 
                  v = *(id *)((char *)self + offset);
239
 
                }
240
 
              else
241
 
                {
242
 
                  id    (*imp)(id, SEL) =
243
 
                    (id (*)(id, SEL))[self methodForSelector: sel];
244
 
 
245
 
                  v = (*imp)(self, sel);
246
 
                }
247
 
              val = v;
248
 
            }
249
 
            break;
250
 
 
251
 
          case _C_CHR:
252
 
            {
253
 
              signed char       v;
254
 
 
255
 
              if (sel == 0)
256
 
                {
257
 
                  v = *(char *)((char *)self + offset);
258
 
                }
259
 
              else
260
 
                {
261
 
                  signed char   (*imp)(id, SEL) =
262
 
                    (signed char (*)(id, SEL))[self methodForSelector: sel];
263
 
 
264
 
                  v = (*imp)(self, sel);
265
 
                }
266
 
              val = [NSNumber numberWithChar: v];
267
 
            }
268
 
            break;
269
 
 
270
 
          case _C_UCHR:
271
 
            {
272
 
              unsigned char     v;
273
 
 
274
 
              if (sel == 0)
275
 
                {
276
 
                  v = *(unsigned char *)((char *)self + offset);
277
 
                }
278
 
              else
279
 
                {
280
 
                  unsigned char (*imp)(id, SEL) =
281
 
                    (unsigned char (*)(id, SEL))[self methodForSelector:
282
 
                    sel];
283
 
 
284
 
                  v = (*imp)(self, sel);
285
 
                }
286
 
              val = [NSNumber numberWithUnsignedChar: v];
287
 
            }
288
 
            break;
289
 
 
290
 
          case _C_SHT:
291
 
            {
292
 
              short     v;
293
 
 
294
 
              if (sel == 0)
295
 
                {
296
 
                  v = *(short *)((char *)self + offset);
297
 
                }
298
 
              else
299
 
                {
300
 
                  short (*imp)(id, SEL) =
301
 
                    (short (*)(id, SEL))[self methodForSelector: sel];
302
 
 
303
 
                  v = (*imp)(self, sel);
304
 
                }
305
 
              val = [NSNumber numberWithShort: v];
306
 
            }
307
 
            break;
308
 
 
309
 
          case _C_USHT:
310
 
            {
311
 
              unsigned short    v;
312
 
 
313
 
              if (sel == 0)
314
 
                {
315
 
                  v = *(unsigned short *)((char *)self + offset);
316
 
                }
317
 
              else
318
 
                {
319
 
                  unsigned short        (*imp)(id, SEL) =
320
 
                    (unsigned short (*)(id, SEL))[self methodForSelector:
321
 
                    sel];
322
 
 
323
 
                  v = (*imp)(self, sel);
324
 
                }
325
 
              val = [NSNumber numberWithUnsignedShort: v];
326
 
            }
327
 
            break;
328
 
 
329
 
          case _C_INT:
330
 
            {
331
 
              int       v;
332
 
 
333
 
              if (sel == 0)
334
 
                {
335
 
                  v = *(int *)((char *)self + offset);
336
 
                }
337
 
              else
338
 
                {
339
 
                  int   (*imp)(id, SEL) =
340
 
                    (int (*)(id, SEL))[self methodForSelector: sel];
341
 
 
342
 
                  v = (*imp)(self, sel);
343
 
                }
344
 
              val = [NSNumber numberWithInt: v];
345
 
            }
346
 
            break;
347
 
 
348
 
          case _C_UINT:
349
 
            {
350
 
              unsigned int      v;
351
 
 
352
 
              if (sel == 0)
353
 
                {
354
 
                  v = *(unsigned int *)((char *)self + offset);
355
 
                }
356
 
              else
357
 
                {
358
 
                  unsigned int  (*imp)(id, SEL) =
359
 
                    (unsigned int (*)(id, SEL))[self methodForSelector:
360
 
                    sel];
361
 
 
362
 
                  v = (*imp)(self, sel);
363
 
                }
364
 
              val = [NSNumber numberWithUnsignedInt: v];
365
 
            }
366
 
            break;
367
 
 
368
 
          case _C_LNG:
369
 
            {
370
 
              long      v;
371
 
 
372
 
              if (sel == 0)
373
 
                {
374
 
                  v = *(long *)((char *)self + offset);
375
 
                }
376
 
              else
377
 
                {
378
 
                  long  (*imp)(id, SEL) =
379
 
                    (long (*)(id, SEL))[self methodForSelector: sel];
380
 
 
381
 
                  v = (*imp)(self, sel);
382
 
                }
383
 
              val = [NSNumber numberWithLong: v];
384
 
            }
385
 
            break;
386
 
 
387
 
          case _C_ULNG:
388
 
            {
389
 
              unsigned long     v;
390
 
 
391
 
              if (sel == 0)
392
 
                {
393
 
                  v = *(unsigned long *)((char *)self + offset);
394
 
                }
395
 
              else
396
 
                {
397
 
                  unsigned long (*imp)(id, SEL) =
398
 
                    (unsigned long (*)(id, SEL))[self methodForSelector:
399
 
                    sel];
400
 
 
401
 
                  v = (*imp)(self, sel);
402
 
                }
403
 
              val = [NSNumber numberWithUnsignedLong: v];
404
 
            }
405
 
            break;
406
 
 
407
 
#ifdef  _C_LNG_LNG
408
 
          case _C_LNG_LNG:
409
 
            {
410
 
              long long v;
411
 
 
412
 
              if (sel == 0)
413
 
                {
414
 
                  v = *(long long *)((char *)self + offset);
415
 
                }
416
 
              else
417
 
                {
418
 
                   long long    (*imp)(id, SEL) =
419
 
                    (long long (*)(id, SEL))[self methodForSelector: sel];
420
 
 
421
 
                  v = (*imp)(self, sel);
422
 
                }
423
 
              val = [NSNumber numberWithLongLong: v];
424
 
            }
425
 
            break;
426
 
#endif
427
 
 
428
 
#ifdef  _C_ULNG_LNG
429
 
          case _C_ULNG_LNG:
430
 
            {
431
 
              unsigned long long        v;
432
 
 
433
 
              if (sel == 0)
434
 
                {
435
 
                  v = *(unsigned long long *)((char *)self + offset);
436
 
                }
437
 
              else
438
 
                {
439
 
                  unsigned long long    (*imp)(id, SEL) =
440
 
                    (unsigned long long (*)(id, SEL))[self
441
 
                    methodForSelector: sel];
442
 
 
443
 
                  v = (*imp)(self, sel);
444
 
                }
445
 
              val = [NSNumber numberWithUnsignedLongLong: v];
446
 
            }
447
 
            break;
448
 
#endif
449
 
 
450
 
          case _C_FLT:
451
 
            {
452
 
              float     v;
453
 
 
454
 
              if (sel == 0)
455
 
                {
456
 
                  v = *(float *)((char *)self + offset);
457
 
                }
458
 
              else
459
 
                {
460
 
                  float (*imp)(id, SEL) =
461
 
                    (float (*)(id, SEL))[self methodForSelector: sel];
462
 
 
463
 
                  v = (*imp)(self, sel);
464
 
                }
465
 
              val = [NSNumber numberWithFloat: v];
466
 
            }
467
 
            break;
468
 
 
469
 
          case _C_DBL:
470
 
            {
471
 
              double    v;
472
 
 
473
 
              if (sel == 0)
474
 
                {
475
 
                  v = *(double *)((char *)self + offset);
476
 
                }
477
 
              else
478
 
                {
479
 
                  double        (*imp)(id, SEL) =
480
 
                    (double (*)(id, SEL))[self methodForSelector: sel];
481
 
 
482
 
                  v = (*imp)(self, sel);
483
 
                }
484
 
              val = [NSNumber numberWithDouble: v];
485
 
            }
486
 
            break;
487
 
 
488
 
          case _C_VOID:
489
 
            {
490
 
              void        (*imp)(id, SEL) =
491
 
                (void (*)(id, SEL))[self methodForSelector: sel];
492
 
              
493
 
              (*imp)(self, sel);
494
 
            }
495
 
            val = nil;
496
 
            break;
497
 
 
498
 
          default:
499
 
            [NSException raise: NSInvalidArgumentException
500
 
                        format: @"key-value get method has unsupported type"];
501
 
        }
502
 
      return val;
503
 
    }
504
 
}
505
 
 
506
 
/**
507
 
 * This is used internally by the key-value coding methods, to set a
508
 
 * value in an object either via an accessor method (if sel is
509
 
 * supplied), or via direct access (if type, size, and offset are
510
 
 * supplied).<br />
511
 
 * Automatic conversion between NSNumber and C scalar types is performed.<br />
512
 
 * If type is nul and can't be determined from the selector, the
513
 
 * [NSObject-handleTakevalue:forUnboundKey:] method is called to try
514
 
 * to set a value.
515
 
 */
516
 
void
517
 
GSSetValue(NSObject *self, NSString *key, id val, SEL sel,
518
 
  const char *type, unsigned size, int offset)
519
 
{
520
 
  if (sel != 0)
521
 
    {
522
 
      NSMethodSignature *sig = [self methodSignatureForSelector: sel];
523
 
 
524
 
      if ([sig numberOfArguments] != 3)
525
 
        {
526
 
          [NSException raise: NSInvalidArgumentException
527
 
                      format: @"key-value set method has wrong number of args"];
528
 
        }
529
 
      type = [sig getArgumentTypeAtIndex: 2];
530
 
    }
531
 
  if (type == NULL)
532
 
    {
533
 
      [self handleTakeValue: val forUnboundKey: key];
534
 
    }
535
 
  else
536
 
    {
537
 
      switch (*type)
538
 
        {
539
 
          case _C_ID:
540
 
          case _C_CLASS:
541
 
            {
542
 
              id        v = val;
543
 
 
544
 
              if (sel == 0)
545
 
                {
546
 
                  id *ptr = (id *)((char *)self + offset);
547
 
 
548
 
                  [*ptr autorelease];
549
 
                  *ptr = [v retain];
550
 
                }
551
 
              else
552
 
                {
553
 
                  void  (*imp)(id, SEL, id) =
554
 
                    (void (*)(id, SEL, id))[self methodForSelector: sel];
555
 
 
556
 
                  (*imp)(self, sel, val);
557
 
                }
558
 
            }
559
 
            break;
560
 
 
561
 
          case _C_CHR:
562
 
            {
563
 
              char      v = [val charValue];
564
 
 
565
 
              if (sel == 0)
566
 
                {
567
 
                  char *ptr = (char *)((char *)self + offset);
568
 
 
569
 
                  *ptr = v;
570
 
                }
571
 
              else
572
 
                {
573
 
                  void  (*imp)(id, SEL, char) =
574
 
                    (void (*)(id, SEL, char))[self methodForSelector: sel];
575
 
 
576
 
                  (*imp)(self, sel, v);
577
 
                }
578
 
            }
579
 
            break;
580
 
 
581
 
          case _C_UCHR:
582
 
            {
583
 
              unsigned char     v = [val unsignedCharValue];
584
 
 
585
 
              if (sel == 0)
586
 
                {
587
 
                  unsigned char *ptr = (unsigned char*)((char *)self + offset);
588
 
 
589
 
                  *ptr = v;
590
 
                }
591
 
              else
592
 
                {
593
 
                  void  (*imp)(id, SEL, unsigned char) =
594
 
                    (void (*)(id, SEL, unsigned char))[self methodForSelector:
595
 
                    sel];
596
 
 
597
 
                  (*imp)(self, sel, v);
598
 
                }
599
 
            }
600
 
            break;
601
 
 
602
 
          case _C_SHT:
603
 
            {
604
 
              short     v = [val shortValue];
605
 
 
606
 
              if (sel == 0)
607
 
                {
608
 
                  short *ptr = (short*)((char *)self + offset);
609
 
 
610
 
                  *ptr = v;
611
 
                }
612
 
              else
613
 
                {
614
 
                  void  (*imp)(id, SEL, short) =
615
 
                    (void (*)(id, SEL, short))[self methodForSelector: sel];
616
 
 
617
 
                  (*imp)(self, sel, v);
618
 
                }
619
 
            }
620
 
            break;
621
 
 
622
 
          case _C_USHT:
623
 
            {
624
 
              unsigned short    v = [val unsignedShortValue];
625
 
 
626
 
              if (sel == 0)
627
 
                {
628
 
                  unsigned short *ptr;
629
 
 
630
 
                  ptr = (unsigned short*)((char *)self + offset);
631
 
                  *ptr = v;
632
 
                }
633
 
              else
634
 
                {
635
 
                  void  (*imp)(id, SEL, unsigned short) =
636
 
                    (void (*)(id, SEL, unsigned short))[self methodForSelector:
637
 
                    sel];
638
 
 
639
 
                  (*imp)(self, sel, v);
640
 
                }
641
 
            }
642
 
            break;
643
 
 
644
 
          case _C_INT:
645
 
            {
646
 
              int       v = [val intValue];
647
 
 
648
 
              if (sel == 0)
649
 
                {
650
 
                  int *ptr = (int*)((char *)self + offset);
651
 
 
652
 
                  *ptr = v;
653
 
                }
654
 
              else
655
 
                {
656
 
                  void  (*imp)(id, SEL, int) =
657
 
                    (void (*)(id, SEL, int))[self methodForSelector: sel];
658
 
 
659
 
                  (*imp)(self, sel, v);
660
 
                }
661
 
            }
662
 
            break;
663
 
 
664
 
          case _C_UINT:
665
 
            {
666
 
              unsigned int      v = [val unsignedIntValue];
667
 
 
668
 
              if (sel == 0)
669
 
                {
670
 
                  unsigned int *ptr = (unsigned int*)((char *)self + offset);
671
 
 
672
 
                  *ptr = v;
673
 
                }
674
 
              else
675
 
                {
676
 
                  void  (*imp)(id, SEL, unsigned int) =
677
 
                    (void (*)(id, SEL, unsigned int))[self methodForSelector:
678
 
                    sel];
679
 
 
680
 
                  (*imp)(self, sel, v);
681
 
                }
682
 
            }
683
 
            break;
684
 
 
685
 
          case _C_LNG:
686
 
            {
687
 
              long      v = [val longValue];
688
 
 
689
 
              if (sel == 0)
690
 
                {
691
 
                  long *ptr = (long*)((char *)self + offset);
692
 
 
693
 
                  *ptr = v;
694
 
                }
695
 
              else
696
 
                {
697
 
                  void  (*imp)(id, SEL, long) =
698
 
                    (void (*)(id, SEL, long))[self methodForSelector: sel];
699
 
 
700
 
                  (*imp)(self, sel, v);
701
 
                }
702
 
            }
703
 
            break;
704
 
 
705
 
          case _C_ULNG:
706
 
            {
707
 
              unsigned long     v = [val unsignedLongValue];
708
 
 
709
 
              if (sel == 0)
710
 
                {
711
 
                  unsigned long *ptr = (unsigned long*)((char *)self + offset);
712
 
 
713
 
                  *ptr = v;
714
 
                }
715
 
              else
716
 
                {
717
 
                  void  (*imp)(id, SEL, unsigned long) =
718
 
                    (void (*)(id, SEL, unsigned long))[self methodForSelector:
719
 
                    sel];
720
 
 
721
 
                  (*imp)(self, sel, v);
722
 
                }
723
 
            }
724
 
            break;
725
 
 
726
 
#ifdef  _C_LNG_LNG
727
 
          case _C_LNG_LNG:
728
 
            {
729
 
              long long v = [val longLongValue];
730
 
 
731
 
              if (sel == 0)
732
 
                {
733
 
                  long long *ptr = (long long*)((char *)self + offset);
734
 
 
735
 
                  *ptr = v;
736
 
                }
737
 
              else
738
 
                {
739
 
                  void  (*imp)(id, SEL, long long) =
740
 
                    (void (*)(id, SEL, long long))[self methodForSelector: sel];
741
 
 
742
 
                  (*imp)(self, sel, v);
743
 
                }
744
 
            }
745
 
            break;
746
 
#endif
747
 
 
748
 
#ifdef  _C_ULNG_LNG
749
 
          case _C_ULNG_LNG:
750
 
            {
751
 
              unsigned long long        v = [val unsignedLongLongValue];
752
 
 
753
 
              if (sel == 0)
754
 
                {
755
 
                  unsigned long long *ptr = (unsigned long long*)((char*)self +
756
 
                                                                  offset);
757
 
 
758
 
                  *ptr = v;
759
 
                }
760
 
              else
761
 
                {
762
 
                  void  (*imp)(id, SEL, unsigned long long) =
763
 
                    (void (*)(id, SEL, unsigned long long))[self
764
 
                    methodForSelector: sel];
765
 
 
766
 
                  (*imp)(self, sel, v);
767
 
                }
768
 
            }
769
 
            break;
770
 
#endif
771
 
 
772
 
          case _C_FLT:
773
 
            {
774
 
              float     v = [val floatValue];
775
 
 
776
 
              if (sel == 0)
777
 
                {
778
 
                  float *ptr = (float*)((char *)self + offset);
779
 
 
780
 
                  *ptr = v;
781
 
                }
782
 
              else
783
 
                {
784
 
                  void  (*imp)(id, SEL, float) =
785
 
                    (void (*)(id, SEL, float))[self methodForSelector: sel];
786
 
 
787
 
                  (*imp)(self, sel, v);
788
 
                }
789
 
            }
790
 
            break;
791
 
 
792
 
          case _C_DBL:
793
 
            {
794
 
              double    v = [val doubleValue];
795
 
 
796
 
              if (sel == 0)
797
 
                {
798
 
                  double *ptr = (double*)((char *)self + offset);
799
 
 
800
 
                  *ptr = v;
801
 
                }
802
 
              else
803
 
                {
804
 
                  void  (*imp)(id, SEL, double) =
805
 
                    (void (*)(id, SEL, double))[self methodForSelector: sel];
806
 
 
807
 
                  (*imp)(self, sel, v);
808
 
                }
809
 
            }
810
 
            break;
811
 
 
812
 
          default:
813
 
            [NSException raise: NSInvalidArgumentException
814
 
                        format: @"key-value set method has unsupported type"];
815
 
        }
816
 
    }
817
 
}
818
 
 
819
 
 
820
 
/* Getting a system error message on a variety of systems */
821
 
#ifdef __MINGW__
822
 
LPTSTR GetErrorMsg(DWORD msgId)
823
 
{
824
 
  LPVOID lpMsgBuf;
825
 
 
826
 
  FormatMessage(
827
 
    FORMAT_MESSAGE_ALLOCATE_BUFFER |
828
 
    FORMAT_MESSAGE_FROM_SYSTEM |
829
 
    FORMAT_MESSAGE_IGNORE_INSERTS,
830
 
    NULL, msgId,
831
 
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
832
 
    (LPTSTR)&lpMsgBuf, 0, NULL);
833
 
 
834
 
  return (LPTSTR)lpMsgBuf;
835
 
}
836
 
#else
837
 
#ifndef HAVE_STRERROR
838
 
const char*
839
 
strerror(int eno)
840
 
{
841
 
  extern char*  sys_errlist[];
842
 
  extern int    sys_nerr;
843
 
 
844
 
  if (eno < 0 || eno >= sys_nerr)
845
 
    {
846
 
      return("unknown error number");
847
 
    }
848
 
  return(sys_errlist[eno]);
849
 
}
850
 
#endif
851
 
#endif /* __MINGW__ */
852
 
 
853
 
const char *GSLastErrorStr(long error_id)
854
 
{
855
 
#ifdef __MINGW__
856
 
  return GetErrorMsg(GetLastError());
857
 
#else
858
 
  return strerror(error_id);
859
 
#endif
860
 
}
 
114