|
5 | 5 | // Created by John Holdsworth on 26/09/2015.
|
6 | 6 | // Copyright © 2015 John Holdsworth. All rights reserved.
|
7 | 7 | //
|
8 |
| -// $Id: //depot/SwiftRuby/Utilities.m#17 $ |
| 8 | +// $Id: //depot/SwiftRuby/Utilities.m#18 $ |
9 | 9 | //
|
10 | 10 | // Repo: https://github.com/RubyNative/SwiftRuby
|
11 | 11 | //
|
|
28 | 28 | int f1, f2; // added for 1.0 Beta5
|
29 | 29 | int size, tos, mdsize, eight;
|
30 | 30 |
|
31 |
| - struct __swift_data { |
32 |
| - unsigned long flags; |
| 31 | + struct _swift_data3 { |
| 32 | +// unsigned long flags; |
33 | 33 | const char *className;
|
34 | 34 | int fieldcount, flags2;
|
35 |
| - const char *ivarNames; |
36 |
| - struct _swift_field **(*get_field_data)(); |
| 35 | + int ivarNames; |
| 36 | + int get_field_data; |
| 37 | +// const char *ivarNames; |
| 38 | +// struct _swift_field **(*get_field_data)(); |
37 | 39 | } *swiftData;
|
38 | 40 |
|
39 | 41 | IMP dispatch[1];
|
40 | 42 | };
|
41 | 43 |
|
| 44 | +// Swift3 pointers to some metadata are relative |
| 45 | +static const char *swift3Relative( void *ptrPtr ) { |
| 46 | + intptr_t offset = *(int *)ptrPtr; |
| 47 | + return offset < 0 ? (const char *)((intptr_t)ptrPtr + offset) : (const char *)offset; |
| 48 | +} |
| 49 | + |
42 | 50 | NSArray<NSString *> *instanceVariablesForClass( Class cls, NSMutableArray<NSString *> *ivarNames ) {
|
43 | 51 | Class superCls = class_getSuperclass( cls );
|
44 | 52 | if ( superCls )
|
|
47 | 55 | struct _in_objc_class *swiftClass = (__bridge struct _in_objc_class *)cls;
|
48 | 56 |
|
49 | 57 | if ( (uintptr_t)swiftClass->internal & 0x1 ) {
|
50 |
| - const char *names = swiftClass->swiftData->ivarNames; |
| 58 | + struct _swift_data3 *swiftData = (struct _swift_data3 *)swift3Relative( &swiftClass->swiftData ); |
| 59 | + const char *nameptr = swift3Relative( &swiftData->ivarNames ); |
51 | 60 |
|
52 |
| - for ( int f = 0 ; f < swiftClass->swiftData->fieldcount ; f++ ) { |
| 61 | + for ( int f = 0 ; f < swiftData->fieldcount ; f++ ) { |
53 | 62 | [ivarNames addObject:[NSString stringWithFormat:@"%@.%@", NSStringFromClass( cls ),
|
54 |
| - [NSString stringWithUTF8String:names]]]; |
55 |
| - names += strlen( names ) + 1; |
| 63 | + [NSString stringWithUTF8String:nameptr]]]; |
| 64 | + nameptr += strlen( nameptr ) + 1; |
56 | 65 | }
|
57 | 66 | }
|
58 | 67 | else {
|
|
0 commit comments