accessibility_core 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd22e137f404608ca6b7cbb145104897d85e08fb
4
- data.tar.gz: 6ce032c9c683c94e8f19c79723991ea6e6bf81a0
3
+ metadata.gz: 4cbd058164686f1cb295d5e5b2aef609c9bc0a0b
4
+ data.tar.gz: e5c662c8fae2eaa2391be2748d5f178e8c2da8c3
5
5
  SHA512:
6
- metadata.gz: 878efe9ec2813bfb7a21ee9d6149c49a46941f467c631d8fefbda0f4d0c3c8825cc25b08b7637f0e3a2311ee9488a20b0154420f43fda4fbb462ab661ce43647
7
- data.tar.gz: 10425a3d104e3326b4a1c32255193f36a7950f2a96819819f2000920df11547c764fa704321649dd4e0fda357ebb0c6da6f57e2fbde2fab1e2f63ffca1a12304
6
+ metadata.gz: fb57e3c3dad828b4c62d241971f8af1c767a8ddcd0db3ad7c0031423f178b91422ebf5566e364245be1814d1a85cbc8af6568b1ccd3cd310b3750f0bd43fe38b
7
+ data.tar.gz: 42cd3444bcc4a5c152d3cca0955b0407856fd9386c53e9b714f1f6b19f38a3c3cf3d479c0cccec04487c761e970ae581d53b385113538ab8be7f5523cc4c9c91
@@ -1,3 +1,9 @@
1
+ # 0.5.0 - Yosemite Compatability
2
+
3
+ * Fix various warnings that show up when compiling against Yosemite system ruby
4
+ * Remove MacRuby support
5
+ * Convert test app to Swift
6
+
1
7
  # 0.4.3 - Oops, -Werror
2
8
 
3
9
  * Fix a C warning generated in the Sea Lion compatability code path
@@ -9,6 +9,8 @@ runtimes.
9
9
  [![Dependency Status](https://gemnasium.com/AXElements/accessibility_core.png)](https://gemnasium.com/AXElements/accessibility_core)
10
10
  [![Code Climate](https://codeclimate.com/github/AXElements/accessibility_core.png)](https://codeclimate.com/github/AXElements/accessibility_core)
11
11
 
12
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/AXElements/accessibility_core/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
13
+
12
14
 
13
15
  ## Examples
14
16
 
@@ -25,9 +27,10 @@ runtimes.
25
27
 
26
28
  ## TODO
27
29
 
28
- * more descriptive error handling for the C extension
29
- * handle string encodings that are not UTF8 (or a subset of UTF8)
30
-
30
+ - [ ] run static analyzer on code and change warning level to -Weverything
31
+ - [ ] remove all old MacRuby related code
32
+ - [ ] more descriptive error handling
33
+ - [ ] handle stirng encodings that are not UTF8
31
34
 
32
35
  ## Tests
33
36
 
data/Rakefile CHANGED
@@ -1,17 +1,3 @@
1
- if defined? MACRUBY_REVISION
2
- def on_macruby?
3
- true
4
- end
5
- else
6
- def on_macruby?
7
- false
8
- end
9
- end
10
-
11
- def on_mri?
12
- !on_macruby?
13
- end
14
-
15
1
  task :default => :test
16
2
 
17
3
  # @todo restore the clang analyze task, don't forget to add rubyhdrdir
@@ -1,18 +1,17 @@
1
1
  #include "bridge.h"
2
2
  #include "ruby/encoding.h"
3
+ #include "assert.h"
3
4
 
4
5
 
5
6
  void
6
- spin(double seconds)
7
+ spin(const double seconds)
7
8
  {
8
- NSDate* interval = [NSDate dateWithTimeIntervalSinceNow:seconds];
9
+ NSDate* const interval = [NSDate dateWithTimeIntervalSinceNow:seconds];
9
10
  [[NSRunLoop currentRunLoop] runUntilDate:interval];
10
11
  [interval release];
11
12
  }
12
13
 
13
14
 
14
- #ifdef NOT_MACRUBY
15
-
16
15
  VALUE rb_cData;
17
16
  VALUE rb_cAttributedString;
18
17
  VALUE rb_mAccessibility;
@@ -37,154 +36,134 @@ ID sel_to_s;
37
36
  ID sel_parse;
38
37
 
39
38
 
40
- void
41
- cf_finalizer(void* obj)
42
- {
43
- CFRelease((CFTypeRef)obj);
44
- }
45
-
46
- void
47
- objc_finalizer(void* obj)
39
+ VALUE
40
+ wrap_unknown(CFTypeRef const obj)
48
41
  {
49
- [(id)obj release];
50
- }
42
+ // TODO: this will leak...
43
+ CFStringRef const description = CFCopyDescription(obj);
51
44
 
45
+ rb_raise(rb_eRuntimeError,
46
+ "accessibility-core doesn't know how to wrap `%s` objects yet",
47
+ CFStringGetCStringPtr(description, kCFStringEncodingMacRoman));
52
48
 
53
- VALUE
54
- wrap_unknown(CFTypeRef obj)
55
- {
56
- // TODO: this will leak...
57
- CFStringRef description = CFCopyDescription(obj);
58
- rb_raise(
59
- rb_eRuntimeError,
60
- "accessibility-core doesn't know how to wrap `%s` objects yet",
61
- CFStringGetCStringPtr(description, kCFStringEncodingMacRoman)
62
- );
63
- return Qnil; // unreachable
49
+ return Qnil; // unreachable
64
50
  }
65
51
 
66
52
  CFTypeRef
67
- unwrap_unknown(VALUE obj)
53
+ unwrap_unknown(const VALUE obj)
68
54
  {
69
55
  // TODO: rb_check_convert_type instead?
70
- obj = rb_funcall(obj, sel_to_s, 0);
71
- rb_raise(
72
- rb_eRuntimeError,
56
+ VALUE obj_string = rb_funcall(obj, sel_to_s, 0);
57
+ rb_raise(rb_eRuntimeError,
73
58
  "accessibility-core doesn't know how to unwrap `%s'",
74
- StringValuePtr(obj)
75
- );
59
+ StringValuePtr(obj_string));
76
60
  return NULL; // unreachable
77
61
  }
78
62
 
79
63
 
80
64
  VALUE
81
- wrap_point(CGPoint point)
65
+ wrap_point(const CGPoint point)
82
66
  {
83
67
  return rb_struct_new(rb_cCGPoint, DBL2NUM(point.x), DBL2NUM(point.y));
84
68
  }
85
69
 
86
70
  CGPoint
87
- unwrap_point(VALUE point)
71
+ unwrap_point(const VALUE point)
88
72
  {
89
- point = rb_funcall(point, sel_to_point, 0);
90
- double x = NUM2DBL(rb_struct_getmember(point, sel_x));
91
- double y = NUM2DBL(rb_struct_getmember(point, sel_y));
92
- return CGPointMake(x, y);
73
+ const VALUE p = rb_funcall(point, sel_to_point, 0);
74
+ const double x = NUM2DBL(rb_struct_getmember(p, sel_x));
75
+ const double y = NUM2DBL(rb_struct_getmember(p, sel_y));
76
+ return CGPointMake(x, y);
93
77
  }
94
78
 
95
79
 
96
80
  VALUE
97
- wrap_size(CGSize size)
81
+ wrap_size(const CGSize size)
98
82
  {
99
83
  return rb_struct_new(rb_cCGSize, DBL2NUM(size.width), DBL2NUM(size.height));
100
84
  }
101
85
 
102
86
  CGSize
103
- unwrap_size(VALUE size)
87
+ unwrap_size(const VALUE size)
104
88
  {
105
- size = rb_funcall(size, sel_to_size, 0);
106
- double width = NUM2DBL(rb_struct_getmember(size, sel_width));
107
- double height = NUM2DBL(rb_struct_getmember(size, sel_height));
108
- return CGSizeMake(width, height);
89
+ const VALUE s = rb_funcall(size, sel_to_size, 0);
90
+ const double width = NUM2DBL(rb_struct_getmember(s, sel_width));
91
+ const double height = NUM2DBL(rb_struct_getmember(s, sel_height));
92
+ return CGSizeMake(width, height);
109
93
  }
110
94
 
111
95
 
112
-
113
96
  VALUE
114
- wrap_rect(CGRect rect)
97
+ wrap_rect(const CGRect rect)
115
98
  {
116
- VALUE point = wrap_point(rect.origin);
117
- VALUE size = wrap_size(rect.size);
118
- return rb_struct_new(rb_cCGRect, point, size);
99
+ const VALUE point = wrap_point(rect.origin);
100
+ const VALUE size = wrap_size(rect.size);
101
+ return rb_struct_new(rb_cCGRect, point, size);
119
102
  }
120
103
 
121
104
 
122
105
  VALUE
123
- coerce_to_rect(VALUE obj)
106
+ coerce_to_rect(const VALUE obj)
124
107
  {
125
108
  return rb_funcall(obj, sel_to_rect, 0);
126
109
  }
127
110
 
128
111
  CGRect
129
- unwrap_rect(VALUE rect)
112
+ unwrap_rect(const VALUE rect)
130
113
  {
131
- rect = rb_funcall(rect, sel_to_rect, 0);
132
- CGPoint origin = unwrap_point(rb_struct_getmember(rect, sel_origin));
133
- CGSize size = unwrap_size(rb_struct_getmember(rect, sel_size));
134
- return CGRectMake(origin.x, origin.y, size.width, size.height);
114
+ const VALUE r = rb_funcall(rect, sel_to_rect, 0);
115
+ const CGPoint origin = unwrap_point(rb_struct_getmember(r, sel_origin));
116
+ const CGSize size = unwrap_size(rb_struct_getmember(r, sel_size));
117
+ return CGRectMake(origin.x, origin.y, size.width, size.height);
135
118
  }
136
119
 
137
120
 
138
121
  VALUE
139
- convert_cf_range(CFRange range)
122
+ convert_cf_range(const CFRange range)
140
123
  {
141
- CFIndex end_index = range.location + range.length;
142
- if (range.length != 0)
143
- end_index -= 1;
144
- return rb_range_new(INT2FIX(range.location), INT2FIX(end_index), 0);
124
+ const CFIndex end_index =
125
+ range.location + (range.length ? range.length - 1 : 0);
126
+ return rb_range_new(INT2FIX(range.location), INT2FIX(end_index), 0);
145
127
  }
146
128
 
147
129
  CFRange
148
- convert_rb_range(VALUE range)
130
+ convert_rb_range(const VALUE range)
149
131
  {
150
- VALUE b, e;
151
- int exclusive;
132
+ VALUE b, e;
133
+ int exclusive;
152
134
 
153
- rb_range_values(range, &b, &e, &exclusive);
135
+ rb_range_values(range, &b, &e, &exclusive);
154
136
 
155
- int begin = NUM2INT(b);
156
- int end = NUM2INT(e);
137
+ const int begin = NUM2INT(b);
138
+ const int end = NUM2INT(e);
157
139
 
158
- if (begin < 0 || end < 0)
159
- // We don't know what the max length of the range will be, so we
160
- // can't count backwards.
161
- rb_raise(
162
- rb_eArgError,
163
- "negative values are not allowed in ranges " \
164
- "that are converted to CFRange structures."
165
- );
140
+ if (begin < 0 || end < 0)
141
+ // We don't know what the max length of the range will be, so we
142
+ // can't count backwards.
143
+ rb_raise(rb_eArgError,
144
+ "negative values are not allowed in ranges "
145
+ "that are converted to CFRange structures.");
166
146
 
167
- int length = exclusive ? end-begin : end-begin + 1;
168
- return CFRangeMake(begin, length);
147
+ const int length = exclusive ? end-begin : end-begin + 1;
148
+ return CFRangeMake(begin, length);
169
149
  }
170
150
 
171
151
 
172
- #define WRAP_VALUE(type, cookie, wrapper) do { \
173
- type st; \
174
- AXValueGetValue(value, cookie, &st); \
175
- return wrapper(st); \
176
- } while (0); \
152
+ #define WRAP_VALUE(type, cookie, wrapper) \
153
+ type st; \
154
+ const Boolean result = AXValueGetValue(value, cookie, &st); \
155
+ assert(result); \
156
+ return wrapper(st);
177
157
 
178
- VALUE wrap_value_point(AXValueRef value) { WRAP_VALUE(CGPoint, kAXValueCGPointType, wrap_point) }
179
- VALUE wrap_value_size(AXValueRef value) { WRAP_VALUE(CGSize, kAXValueCGSizeType, wrap_size) }
180
- VALUE wrap_value_rect(AXValueRef value) { WRAP_VALUE(CGRect, kAXValueCGRectType, wrap_rect) }
181
- VALUE wrap_value_range(AXValueRef value) { WRAP_VALUE(CFRange, kAXValueCFRangeType, convert_cf_range) }
182
- VALUE wrap_value_error(AXValueRef value) { WRAP_VALUE(AXError, kAXValueAXErrorType, INT2NUM) }
158
+ VALUE wrap_value_point(AXValueRef const value) { WRAP_VALUE(CGPoint, kAXValueCGPointType, wrap_point) }
159
+ VALUE wrap_value_size(AXValueRef const value) { WRAP_VALUE(CGSize, kAXValueCGSizeType, wrap_size) }
160
+ VALUE wrap_value_rect(AXValueRef const value) { WRAP_VALUE(CGRect, kAXValueCGRectType, wrap_rect) }
161
+ VALUE wrap_value_range(AXValueRef const value) { WRAP_VALUE(CFRange, kAXValueCFRangeType, convert_cf_range) }
162
+ VALUE wrap_value_error(AXValueRef const value) { WRAP_VALUE(AXError, kAXValueAXErrorType, INT2NUM) }
183
163
 
184
- #define UNWRAP_VALUE(type, value, unwrapper) do { \
185
- type st = unwrapper(val); \
186
- return AXValueCreate(value, &st); \
187
- } while(0);
164
+ #define UNWRAP_VALUE(type, value, unwrapper) \
165
+ const type st = unwrapper(val); \
166
+ return AXValueCreate(value, &st);
188
167
 
189
168
  AXValueRef unwrap_value_point(VALUE val) { UNWRAP_VALUE(CGPoint, kAXValueCGPointType, unwrap_point) }
190
169
  AXValueRef unwrap_value_size(VALUE val) { UNWRAP_VALUE(CGSize, kAXValueCGSizeType, unwrap_size) }
@@ -193,232 +172,227 @@ AXValueRef unwrap_value_range(VALUE val) { UNWRAP_VALUE(CFRange, kAXValueCFRange
193
172
 
194
173
 
195
174
  VALUE
196
- wrap_value(AXValueRef value)
175
+ wrap_value(AXValueRef const value)
197
176
  {
198
- switch (AXValueGetType(value))
199
- {
177
+ switch (AXValueGetType(value)) {
200
178
  case kAXValueIllegalType:
201
- rb_raise(rb_eArgError, "cannot wrap %s objects", rb_class2name(CLASS_OF(value)));
179
+ rb_raise(rb_eArgError, "cannot wrap %s objects", rb_class2name(CLASS_OF(value)));
202
180
  case kAXValueCGPointType:
203
- return wrap_value_point(value);
181
+ return wrap_value_point(value);
204
182
  case kAXValueCGSizeType:
205
- return wrap_value_size(value);
183
+ return wrap_value_size(value);
206
184
  case kAXValueCGRectType:
207
- return wrap_value_rect(value);
185
+ return wrap_value_rect(value);
208
186
  case kAXValueCFRangeType:
209
- return wrap_value_range(value);
187
+ return wrap_value_range(value);
210
188
  case kAXValueAXErrorType:
211
- return wrap_value_error(value);
189
+ return wrap_value_error(value);
212
190
  default:
213
- // TODO better error message
214
- rb_raise(
215
- rb_eRuntimeError,
216
- "Either accessibility_core is out of date or your system has had a serious error"
217
- );
191
+ // TODO better error message
192
+ rb_raise(rb_eRuntimeError,
193
+ "Either accessibility_core is out of date or your system "
194
+ "has had a serious error");
218
195
  }
219
196
 
220
- return Qnil; // unreachable
197
+ return Qnil; // unreachable
221
198
  }
222
199
 
223
200
  AXValueRef
224
- unwrap_value(VALUE value)
225
- {
226
- VALUE type = CLASS_OF(value);
227
- if (type == rb_cCGPoint)
228
- return unwrap_value_point(value);
229
- else if (type == rb_cCGSize)
230
- return unwrap_value_size(value);
231
- else if (type == rb_cCGRect)
232
- return unwrap_value_rect(value);
233
- else if (type == rb_cRange)
234
- return unwrap_value_range(value);
235
-
236
- rb_raise(rb_eArgError, "could not wrap %s", rb_class2name(type));
237
- return NULL; // unreachable
201
+ unwrap_value(const VALUE value)
202
+ {
203
+ const VALUE type = CLASS_OF(value);
204
+ if (type == rb_cCGPoint)
205
+ return unwrap_value_point(value);
206
+ else if (type == rb_cCGSize)
207
+ return unwrap_value_size(value);
208
+ else if (type == rb_cCGRect)
209
+ return unwrap_value_rect(value);
210
+ else if (type == rb_cRange)
211
+ return unwrap_value_range(value);
212
+
213
+ rb_raise(rb_eArgError, "could not wrap %s", rb_class2name(type));
214
+ return NULL; // unreachable
238
215
  }
239
216
 
240
- VALUE wrap_array_values(CFArrayRef array) { WRAP_ARRAY(wrap_value) }
217
+ VALUE wrap_array_values(CFArrayRef const array) { WRAP_ARRAY(wrap_value) }
241
218
 
242
219
 
243
- VALUE wrap_ref(AXUIElementRef obj) { WRAP_OBJC(rb_cElement, cf_finalizer); }
220
+ VALUE wrap_ref(AXUIElementRef const obj) { WRAP_OBJC(rb_cElement, cf_finalizer); }
244
221
 
245
222
  AXUIElementRef
246
- unwrap_ref(VALUE obj)
223
+ unwrap_ref(const VALUE obj)
247
224
  {
248
- AXUIElementRef* ref;
249
- Data_Get_Struct(obj, AXUIElementRef, ref);
250
- // TODO we should return *ref? but that seems to fuck things up...
251
- return (AXUIElementRef)ref;
225
+ AXUIElementRef* ref;
226
+ Data_Get_Struct(obj, AXUIElementRef, ref);
227
+ // TODO we should return *ref? but that seems to fuck things up...
228
+ return (AXUIElementRef)ref;
252
229
  }
253
230
 
254
- VALUE wrap_array_refs(CFArrayRef array) { WRAP_ARRAY(wrap_ref) }
231
+ VALUE wrap_array_refs(CFArrayRef const array) { WRAP_ARRAY(wrap_ref) }
255
232
 
256
233
 
257
234
  VALUE
258
- wrap_string(CFStringRef string)
235
+ wrap_string(CFStringRef const string)
259
236
  {
260
- VALUE rb_str = Qnil;
261
- CFDataRef data = CFStringCreateExternalRepresentation(
262
- NULL,
263
- string,
264
- kCFStringEncodingUTF8,
265
- 0
266
- );
267
- if (data) {
268
- rb_str = rb_enc_str_new(
269
- (char*)CFDataGetBytePtr(data),
270
- CFDataGetLength(data),
271
- rb_utf8_encoding()
272
- );
273
- CFRelease(data);
274
- }
275
- else {
237
+ CFDataRef const data =
238
+ CFStringCreateExternalRepresentation(NULL,
239
+ string,
240
+ kCFStringEncodingUTF8,
241
+ 0);
242
+ if (data) {
243
+ const VALUE rb_str =
244
+ rb_enc_str_new((char*)CFDataGetBytePtr(data),
245
+ CFDataGetLength(data),
246
+ rb_utf8_encoding());
247
+ CFRelease(data);
248
+ return rb_str;
249
+ }
250
+
276
251
  CFRelease(data);
277
- CFShow(string);
252
+ CFShow(string); // uhh....why?
278
253
  rb_raise(rb_eRuntimeError, "Could not convert a string to a Ruby string");
279
- }
280
-
281
- return rb_str;
254
+ return Qnil;
282
255
  }
283
256
 
284
257
  VALUE
285
- wrap_nsstring(NSString* string)
258
+ wrap_nsstring(NSString* const string)
286
259
  {
287
260
  return wrap_string((CFStringRef)string);
288
261
  }
289
262
 
290
263
  CFStringRef
291
- unwrap_string(VALUE string)
264
+ unwrap_string(const VALUE string)
292
265
  {
293
- return CFStringCreateWithBytes(
294
- NULL,
295
- (UInt8*)StringValueCStr(string),
296
- RSTRING_LEN(string),
297
- kCFStringEncodingUTF8,
298
- false
299
- );
266
+ volatile VALUE str = string; // StringValue needs volatility guarantees :(
267
+ return CFStringCreateWithBytes(NULL,
268
+ (UInt8*)StringValueCStr(str),
269
+ RSTRING_LEN(string),
270
+ kCFStringEncodingUTF8,
271
+ false);
300
272
  }
301
273
 
302
274
  NSString*
303
- unwrap_nsstring(VALUE string)
275
+ unwrap_nsstring(const VALUE string)
304
276
  {
305
277
  return (NSString*)unwrap_string(string);
306
278
  }
307
279
 
308
- VALUE wrap_array_strings(CFArrayRef array) { WRAP_ARRAY(wrap_string); }
309
- VALUE wrap_array_nsstrings(NSArray* ary)
280
+ VALUE wrap_array_strings(CFArrayRef const array) { WRAP_ARRAY(wrap_string); }
281
+ VALUE wrap_array_nsstrings(NSArray* const ary)
310
282
  {
311
- CFArrayRef array = (CFArrayRef)ary;
283
+ CFArrayRef const array = (CFArrayRef const)ary;
312
284
  WRAP_ARRAY(wrap_string);
313
285
  }
314
286
 
315
287
 
316
288
  VALUE
317
- wrap_attributed_string(CFAttributedStringRef string)
289
+ wrap_attributed_string(CFAttributedStringRef const string)
318
290
  {
319
- return wrap_nsattributed_string((NSAttributedString*)string);
291
+ return wrap_nsattributed_string((NSAttributedString* const)string);
320
292
  }
321
293
 
322
294
  VALUE
323
- wrap_nsattributed_string(NSAttributedString* obj)
295
+ wrap_nsattributed_string(NSAttributedString* const obj)
324
296
  {
325
297
  WRAP_OBJC(rb_cAttributedString, objc_finalizer);
326
298
  }
327
299
 
328
300
  CFAttributedStringRef
329
- unwrap_attributed_string(VALUE string)
301
+ unwrap_attributed_string(const VALUE string)
330
302
  {
331
303
  return (CFAttributedStringRef)unwrap_nsattributed_string(string);
332
304
  }
333
305
 
334
306
  NSAttributedString*
335
- unwrap_nsattributed_string(VALUE obj)
307
+ unwrap_nsattributed_string(const VALUE obj)
336
308
  {
337
309
  UNWRAP_OBJC(NSAttributedString);
338
310
  }
339
311
 
340
312
  VALUE
341
- wrap_array_attributed_strings(CFArrayRef array)
313
+ wrap_array_attributed_strings(CFArrayRef const array)
342
314
  {
343
315
  WRAP_ARRAY(wrap_attributed_string);
344
316
  }
345
317
 
346
- VALUE wrap_array_nsattributed_strings(NSArray* ary)
318
+ VALUE wrap_array_nsattributed_strings(NSArray* const ary)
347
319
  {
348
- CFArrayRef array = (CFArrayRef)ary;
320
+ CFArrayRef const array = (CFArrayRef)ary;
349
321
  WRAP_ARRAY(wrap_nsattributed_string);
350
322
  }
351
323
 
352
324
  static
353
325
  VALUE
354
- rb_astring_alloc(VALUE self)
326
+ rb_astring_alloc(const VALUE self)
355
327
  {
356
328
  return wrap_nsattributed_string([NSAttributedString alloc]);
357
329
  }
358
330
 
359
331
  static
360
332
  VALUE
361
- rb_astring_init_with_string(int argc, VALUE* argv, VALUE self)
333
+ rb_astring_init_with_string(const int argc, VALUE* const argv, const VALUE self)
362
334
  {
363
- if (!argc)
364
- rb_raise(rb_eArgError, "wrong number of arguments (0 for 1+)");
335
+ if (!argc)
336
+ rb_raise(rb_eArgError, "wrong number of arguments (0 for 1+)");
365
337
 
366
- NSString* nsstring = unwrap_nsstring(argv[0]);
367
- NSAttributedString* old_astring = unwrap_nsattributed_string(self);
368
- NSAttributedString* new_astring = [old_astring initWithString:nsstring];
369
- [nsstring release];
370
- if (old_astring == new_astring)
371
- return self;
372
- return wrap_nsattributed_string(new_astring);
338
+ NSString* const nsstring =
339
+ unwrap_nsstring(argv[0]);
340
+ NSAttributedString* const old_astring =
341
+ unwrap_nsattributed_string(self);
342
+ NSAttributedString* const new_astring =
343
+ [old_astring initWithString:nsstring];
344
+ [nsstring release];
345
+
346
+ if (old_astring == new_astring)
347
+ return self;
348
+ return wrap_nsattributed_string(new_astring);
373
349
  }
374
350
 
375
351
  static
376
352
  VALUE
377
- rb_astring_string(VALUE self)
353
+ rb_astring_string(const VALUE self)
378
354
  {
379
- NSString* string = [unwrap_nsattributed_string(self) string];
380
- VALUE rb_str = wrap_nsstring(string);
381
- return rb_str;
355
+ NSString* const string = [unwrap_nsattributed_string(self) string];
356
+ const VALUE rb_str = wrap_nsstring(string);
357
+ return rb_str;
382
358
  }
383
359
 
384
360
  static
385
361
  VALUE
386
- rb_astring_length(VALUE self)
362
+ rb_astring_length(const VALUE self)
387
363
  {
388
364
  return ULONG2NUM([unwrap_nsattributed_string(self) length]);
389
365
  }
390
366
 
391
367
  static
392
368
  VALUE
393
- rb_astring_equality(VALUE self, VALUE other)
369
+ rb_astring_equality(const VALUE self, const VALUE other)
394
370
  {
395
371
  OBJC_EQUALITY(rb_cAttributedString, unwrap_nsattributed_string);
396
372
  }
397
373
 
398
374
 
399
- #define WRAP_NUM(type, cookie, macro) do { \
375
+ #define WRAP_NUM(type, cookie, macro) \
400
376
  type value; \
401
377
  if (CFNumberGetValue(num, cookie, &value)) \
402
- return macro(value); \
378
+ return macro(value); \
403
379
  rb_raise(rb_eRuntimeError, "I goofed wrapping a number"); \
404
- return Qnil; \
405
- } while(0);
380
+ return Qnil;
406
381
 
407
- VALUE wrap_long(CFNumberRef num) { WRAP_NUM(long, kCFNumberLongType, LONG2FIX) }
408
- VALUE wrap_long_long(CFNumberRef num) { WRAP_NUM(long long, kCFNumberLongLongType, LL2NUM) }
409
- VALUE wrap_float(CFNumberRef num) { WRAP_NUM(double, kCFNumberDoubleType, DBL2NUM) }
382
+ VALUE wrap_long(CFNumberRef const num) { WRAP_NUM(long, kCFNumberLongType, LONG2FIX) }
383
+ VALUE wrap_long_long(CFNumberRef const num) { WRAP_NUM(long long, kCFNumberLongLongType, LL2NUM) }
384
+ VALUE wrap_float(CFNumberRef const num) { WRAP_NUM(double, kCFNumberDoubleType, DBL2NUM) }
410
385
 
411
- #define UNWRAP_NUM(type, cookie, macro) do { \
412
- type base = macro(num); \
413
- return CFNumberCreate(NULL, cookie, &base); \
414
- } while(0);
386
+ #define UNWRAP_NUM(type, cookie, macro) \
387
+ const type base = macro(num); \
388
+ return CFNumberCreate(NULL, cookie, &base);
415
389
 
416
- CFNumberRef unwrap_long(VALUE num) { UNWRAP_NUM(long, kCFNumberLongType, NUM2LONG) }
417
- CFNumberRef unwrap_long_long(VALUE num) { UNWRAP_NUM(long long, kCFNumberLongLongType, NUM2LL) }
418
- CFNumberRef unwrap_float(VALUE num) { UNWRAP_NUM(double, kCFNumberDoubleType, NUM2DBL) }
390
+ CFNumberRef unwrap_long(const VALUE num) { UNWRAP_NUM(long, kCFNumberLongType, NUM2LONG) }
391
+ CFNumberRef unwrap_long_long(const VALUE num) { UNWRAP_NUM(long long, kCFNumberLongLongType, NUM2LL) }
392
+ CFNumberRef unwrap_float(const VALUE num) { UNWRAP_NUM(double, kCFNumberDoubleType, NUM2DBL) }
419
393
 
420
394
  VALUE
421
- wrap_number(CFNumberRef number)
395
+ wrap_number(CFNumberRef const number)
422
396
  {
423
397
  switch (CFNumberGetType(number))
424
398
  {
@@ -451,7 +425,7 @@ wrap_number(CFNumberRef number)
451
425
  }
452
426
 
453
427
  CFNumberRef
454
- unwrap_number(VALUE number)
428
+ unwrap_number(const VALUE number)
455
429
  {
456
430
  switch (TYPE(number))
457
431
  {
@@ -459,218 +433,217 @@ unwrap_number(VALUE number)
459
433
  return unwrap_long(number);
460
434
  case T_FLOAT:
461
435
  return unwrap_float(number);
462
- default:
463
- rb_raise(
464
- rb_eRuntimeError,
465
- "wrapping %s is not supported; log a bug?",
466
- rb_string_value_cstr(&number)
467
- );
468
- return kCFNumberNegativeInfinity; // unreachable
436
+ default: {
437
+ volatile VALUE num = number;
438
+ rb_raise(rb_eRuntimeError,
439
+ "wrapping %s is not supported; log a bug?",
440
+ rb_string_value_cstr(&num));
441
+ return kCFNumberNegativeInfinity; // unreachable
442
+ }
469
443
  }
470
444
  }
471
445
 
472
- VALUE wrap_array_numbers(CFArrayRef array) { WRAP_ARRAY(wrap_number) }
446
+ VALUE wrap_array_numbers(CFArrayRef const array) { WRAP_ARRAY(wrap_number) }
473
447
 
474
448
 
475
449
 
476
450
  VALUE
477
- wrap_url(CFURLRef url)
451
+ wrap_url(CFURLRef const url)
478
452
  {
479
453
  // @note CFURLGetString does not need to be CFReleased since it is a Get
480
454
  return rb_funcall(rb_mURI, sel_parse, 1, wrap_string(CFURLGetString(url)));
481
455
  }
482
456
 
483
457
  VALUE
484
- wrap_nsurl(NSURL* url)
458
+ wrap_nsurl(NSURL* const url)
485
459
  {
486
- NSString* str = [url absoluteString];
487
- VALUE rb_str = wrap_nsstring(str);
460
+ NSString* const str = [url absoluteString];
461
+ const VALUE rb_str = wrap_nsstring(str);
488
462
  [str release];
489
463
  return rb_funcall(rb_mURI, sel_parse, 1, rb_str);
490
464
  }
491
465
 
492
466
  CFURLRef
493
- unwrap_url(VALUE url)
467
+ unwrap_url(const VALUE url)
494
468
  {
495
469
  // TODO: should also force encoding to UTF-8 first?
496
- url = rb_funcall(url, sel_to_s, 0);
497
- CFStringRef string = CFStringCreateWithCString(
498
- NULL,
499
- StringValuePtr(url),
500
- kCFStringEncodingUTF8
501
- );
502
- CFURLRef url_ref = CFURLCreateWithString(NULL, string, NULL);
503
- CFRelease(string);
504
- return url_ref;
470
+ VALUE url_string = rb_funcall(url, sel_to_s, 0);
471
+ CFStringRef const string =
472
+ CFStringCreateWithCString(NULL,
473
+ StringValuePtr(url_string),
474
+ kCFStringEncodingUTF8);
475
+ CFURLRef const url_ref = CFURLCreateWithString(NULL, string, NULL);
476
+ CFRelease(string);
477
+ return url_ref;
505
478
  }
506
479
 
507
480
  NSURL*
508
- unwrap_nsurl(VALUE url)
481
+ unwrap_nsurl(const VALUE url)
509
482
  {
510
483
  return (NSURL*)unwrap_url(url);
511
484
  }
512
485
 
513
- VALUE wrap_array_urls(CFArrayRef array) { WRAP_ARRAY(wrap_url) }
486
+ VALUE wrap_array_urls(CFArrayRef const array) { WRAP_ARRAY(wrap_url) }
514
487
 
515
488
 
516
489
  VALUE
517
- wrap_date(CFDateRef date)
490
+ wrap_date(CFDateRef const date)
518
491
  {
519
- NSTimeInterval time = [(NSDate*)date timeIntervalSince1970];
520
- return rb_time_new((time_t)time, 0);
492
+ const NSTimeInterval time = [(NSDate*)date timeIntervalSince1970];
493
+ return rb_time_new((time_t)time, 0);
521
494
  }
522
495
 
523
496
  VALUE
524
- wrap_nsdate(NSDate* date)
497
+ wrap_nsdate(NSDate* const date)
525
498
  {
526
499
  return wrap_date((CFDateRef)date);
527
500
  }
528
501
 
529
502
  CFDateRef
530
- unwrap_date(VALUE date)
503
+ unwrap_date(const VALUE date)
531
504
  {
532
- struct timeval t = rb_time_timeval(date);
533
- NSDate* ns_date = [NSDate dateWithTimeIntervalSince1970:t.tv_sec];
534
- return (CFDateRef)ns_date;
505
+ const struct timeval t = rb_time_timeval(date);
506
+ NSDate* const ns_date = [NSDate dateWithTimeIntervalSince1970:t.tv_sec];
507
+ return (CFDateRef)ns_date;
535
508
  }
536
509
 
537
- VALUE wrap_array_dates(CFArrayRef array) { WRAP_ARRAY(wrap_date) }
510
+ VALUE wrap_array_dates(CFArrayRef const array) { WRAP_ARRAY(wrap_date) }
538
511
 
539
512
 
540
513
  VALUE
541
- wrap_boolean(CFBooleanRef bool_val)
514
+ wrap_boolean(CFBooleanRef const bool_val)
542
515
  {
543
516
  return (CFBooleanGetValue(bool_val) ? Qtrue : Qfalse);
544
517
  }
545
518
 
546
519
  CFBooleanRef
547
- unwrap_boolean(VALUE bool_val)
520
+ unwrap_boolean(const VALUE bool_val)
548
521
  {
549
522
  return (bool_val == Qtrue ? kCFBooleanTrue : kCFBooleanFalse);
550
523
  }
551
524
 
552
- VALUE wrap_array_booleans(CFArrayRef array) { WRAP_ARRAY(wrap_boolean) }
525
+ VALUE wrap_array_booleans(CFArrayRef const array) { WRAP_ARRAY(wrap_boolean) }
553
526
 
554
527
 
555
528
  VALUE
556
- wrap_array(CFArrayRef array)
529
+ wrap_array(CFArrayRef const array)
557
530
  {
558
- CFIndex length = CFArrayGetCount(array);
559
- if (length) {
560
- CFTypeRef obj = CFArrayGetValueAtIndex(array, 0);
561
- CFTypeID di = CFGetTypeID(obj);
562
- if (di == AXUIElementGetTypeID()) return wrap_array_refs(array);
563
- else if (di == AXValueGetTypeID()) return wrap_array_values(array);
564
- else if (di == CFStringGetTypeID()) return wrap_array_strings(array);
565
- else if (di == CFNumberGetTypeID()) return wrap_array_numbers(array);
566
- else if (di == CFBooleanGetTypeID()) return wrap_array_booleans(array);
567
- else if (di == CFURLGetTypeID()) return wrap_array_urls(array);
568
- else if (di == CFDateGetTypeID()) return wrap_array_dates(array);
569
- else if (di == CFDictionaryGetTypeID()) return wrap_array_dictionaries(array);
570
- else return wrap_unknown(obj);
571
- }
572
- return rb_ary_new();
531
+ const CFIndex length = CFArrayGetCount(array);
532
+ if (length) {
533
+ const CFTypeRef obj = CFArrayGetValueAtIndex(array, 0);
534
+ const CFTypeID di = CFGetTypeID(obj);
535
+ if (di == AXUIElementGetTypeID()) return wrap_array_refs(array);
536
+ else if (di == AXValueGetTypeID()) return wrap_array_values(array);
537
+ else if (di == CFStringGetTypeID()) return wrap_array_strings(array);
538
+ else if (di == CFNumberGetTypeID()) return wrap_array_numbers(array);
539
+ else if (di == CFBooleanGetTypeID()) return wrap_array_booleans(array);
540
+ else if (di == CFURLGetTypeID()) return wrap_array_urls(array);
541
+ else if (di == CFDateGetTypeID()) return wrap_array_dates(array);
542
+ else if (di == CFDictionaryGetTypeID()) return wrap_array_dictionaries(array);
543
+ else return wrap_unknown(obj);
544
+ }
545
+ return rb_ary_new();
573
546
  }
574
547
 
575
548
 
576
549
  VALUE
577
- wrap_dictionary(NSDictionary* dict)
550
+ wrap_dictionary(NSDictionary* const dict)
578
551
  {
579
- __block VALUE hash = rb_hash_new();
552
+ const VALUE hash = rb_hash_new();
580
553
 
581
- [dict enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL* stop) {
582
- rb_hash_aset(hash, to_ruby(key), to_ruby(obj));
583
- }];
554
+ [dict enumerateKeysAndObjectsUsingBlock:
555
+ ^(const id key, const id obj, BOOL* const stop) {
556
+ rb_hash_aset(hash, to_ruby(key), to_ruby(obj));
557
+ }];
584
558
 
585
559
  return hash;
586
560
  }
587
561
 
588
- VALUE wrap_array_dictionaries(CFArrayRef array) { WRAP_ARRAY(wrap_dictionary); }
562
+ VALUE wrap_array_dictionaries(CFArrayRef const array) { WRAP_ARRAY(wrap_dictionary); }
589
563
 
590
564
 
591
565
  VALUE
592
- to_ruby(CFTypeRef obj)
566
+ to_ruby(CFTypeRef const obj)
593
567
  {
594
- CFTypeID di = CFGetTypeID(obj);
595
- if (di == CFArrayGetTypeID()) return wrap_array(obj);
596
- else if (di == AXUIElementGetTypeID()) return wrap_ref(obj);
597
- else if (di == AXValueGetTypeID()) return wrap_value(obj);
598
- else if (di == CFStringGetTypeID()) return wrap_string(obj);
599
- else if (di == CFNumberGetTypeID()) return wrap_number(obj);
600
- else if (di == CFBooleanGetTypeID()) return wrap_boolean(obj);
601
- else if (di == CFURLGetTypeID()) return wrap_url(obj);
602
- else if (di == CFDateGetTypeID()) return wrap_date(obj);
603
- else if (di == CFDataGetTypeID()) return wrap_data(obj);
604
- else if (di == CFAttributedStringGetTypeID()) return wrap_attributed_string(obj);
605
- else if (di == CFDictionaryGetTypeID()) return wrap_dictionary(obj);
606
- else return wrap_unknown(obj);
568
+ const CFTypeID di = CFGetTypeID(obj);
569
+ if (di == CFArrayGetTypeID()) return wrap_array(obj);
570
+ else if (di == AXUIElementGetTypeID()) return wrap_ref(obj);
571
+ else if (di == AXValueGetTypeID()) return wrap_value(obj);
572
+ else if (di == CFStringGetTypeID()) return wrap_string(obj);
573
+ else if (di == CFNumberGetTypeID()) return wrap_number(obj);
574
+ else if (di == CFBooleanGetTypeID()) return wrap_boolean(obj);
575
+ else if (di == CFURLGetTypeID()) return wrap_url(obj);
576
+ else if (di == CFDateGetTypeID()) return wrap_date(obj);
577
+ else if (di == CFDataGetTypeID()) return wrap_data(obj);
578
+ else if (di == CFAttributedStringGetTypeID()) return wrap_attributed_string(obj);
579
+ else if (di == CFDictionaryGetTypeID()) return wrap_dictionary(obj);
580
+ else return wrap_unknown(obj);
607
581
  }
608
582
 
609
583
  CFTypeRef
610
- to_ax(VALUE obj)
584
+ to_ax(const VALUE obj)
611
585
  {
612
- switch (TYPE(obj))
613
- {
586
+ switch (TYPE(obj)) {
614
587
  case T_STRING:
615
- return unwrap_string(obj);
588
+ return unwrap_string(obj);
616
589
  case T_FIXNUM:
617
- return unwrap_number(obj);
590
+ return unwrap_number(obj);
618
591
  case T_STRUCT:
619
- return unwrap_value(obj);
592
+ return unwrap_value(obj);
620
593
  case T_FLOAT:
621
- return unwrap_number(obj);
594
+ return unwrap_number(obj);
622
595
  case T_TRUE:
623
- return kCFBooleanTrue;
596
+ return kCFBooleanTrue;
624
597
  case T_FALSE:
625
- return kCFBooleanFalse;
598
+ return kCFBooleanFalse;
626
599
  }
627
600
 
628
- VALUE type = CLASS_OF(obj);
629
- if (type == rb_cTime)
630
- return unwrap_date(obj);
631
- else if (type == rb_cRange)
632
- return unwrap_value_range(obj);
633
- else if (type == rb_cAttributedString)
634
- return unwrap_attributed_string(obj);
635
- else if (type == rb_cData)
636
- return unwrap_data(obj);
601
+ const VALUE type = CLASS_OF(obj);
602
+ if (type == rb_cTime)
603
+ return unwrap_date(obj);
604
+ else if (type == rb_cRange)
605
+ return unwrap_value_range(obj);
606
+ else if (type == rb_cAttributedString)
607
+ return unwrap_attributed_string(obj);
608
+ else if (type == rb_cData)
609
+ return unwrap_data(obj);
637
610
 
638
- if (rb_obj_is_kind_of(obj, rb_cURI))
639
- return unwrap_url(obj);
611
+ if (rb_obj_is_kind_of(obj, rb_cURI))
612
+ return unwrap_url(obj);
640
613
 
641
- // give up if we get this far
642
- return unwrap_unknown(obj);
614
+ // give up if we get this far
615
+ return unwrap_unknown(obj);
643
616
  }
644
617
 
645
618
 
646
619
  VALUE
647
- wrap_data(CFDataRef data)
620
+ wrap_data(CFDataRef const data)
648
621
  {
649
622
  return wrap_nsdata((NSData*)data);
650
623
  }
651
624
 
652
625
  VALUE
653
- wrap_nsdata(NSData* obj)
626
+ wrap_nsdata(NSData* const obj)
654
627
  {
655
628
  WRAP_OBJC(rb_cData, objc_finalizer);
656
629
  }
657
630
 
658
- VALUE wrap_array_data(CFArrayRef array) { WRAP_ARRAY(wrap_data); }
631
+ VALUE wrap_array_data(CFArrayRef const array) { WRAP_ARRAY(wrap_data); }
659
632
  VALUE
660
- wrap_array_nsdata(NSArray* ary)
633
+ wrap_array_nsdata(NSArray* const ary)
661
634
  {
662
- CFArrayRef array = (CFArrayRef)ary;
635
+ CFArrayRef const array = (CFArrayRef)ary;
663
636
  WRAP_ARRAY(wrap_data);
664
637
  }
665
638
 
666
639
  CFDataRef
667
- unwrap_data(VALUE data)
640
+ unwrap_data(const VALUE data)
668
641
  {
669
642
  return (CFDataRef)unwrap_nsdata(data);
670
643
  }
671
644
 
672
645
  NSData*
673
- unwrap_nsdata(VALUE obj)
646
+ unwrap_nsdata(const VALUE obj)
674
647
  {
675
648
  UNWRAP_OBJC(NSData);
676
649
  }
@@ -678,177 +651,172 @@ unwrap_nsdata(VALUE obj)
678
651
 
679
652
  static
680
653
  VALUE
681
- rb_data_data(VALUE self)
654
+ rb_data_data(const VALUE self)
682
655
  {
683
656
  return wrap_nsdata([NSData data]);
684
657
  }
685
658
 
686
659
  static
687
660
  VALUE
688
- rb_data_with_contents_of_url(VALUE self, VALUE url)
661
+ rb_data_with_contents_of_url(const VALUE self, const VALUE url)
689
662
  {
690
- NSData* data = [NSData dataWithContentsOfURL:unwrap_nsurl(url)];
691
- if (data)
692
- return wrap_nsdata(data);
693
- return Qnil;
663
+ NSData* const data = [NSData dataWithContentsOfURL:unwrap_nsurl(url)];
664
+ if (data)
665
+ return wrap_nsdata(data);
666
+ return Qnil;
694
667
  }
695
668
 
696
669
  static
697
670
  VALUE
698
- rb_data_length(VALUE self)
671
+ rb_data_length(const VALUE self)
699
672
  {
700
673
  return ULONG2NUM([unwrap_nsdata(self) length]);
701
674
  }
702
675
 
703
676
  static
704
677
  VALUE
705
- rb_data_equality(VALUE self, VALUE other)
678
+ rb_data_equality(const VALUE self, const VALUE other)
706
679
  {
707
680
  OBJC_EQUALITY(rb_cData, unwrap_nsdata);
708
681
  }
709
682
 
710
683
  static
711
684
  VALUE
712
- rb_data_write_to_file(int argc, VALUE* argv, VALUE self)
685
+ rb_data_write_to_file(const int argc, VALUE* const argv, const VALUE self)
713
686
  {
714
- if (argc < 2)
715
- rb_raise(
716
- rb_eArgError,
717
- "wrong number of arguments, got %d, expected 2",
718
- argc
719
- );
687
+ if (argc < 2)
688
+ rb_raise(rb_eArgError,
689
+ "wrong number of arguments, got %d, expected 2",
690
+ argc);
720
691
 
721
- NSString* path = unwrap_nsstring(argv[0]);
722
- BOOL result = [unwrap_nsdata(self) writeToFile:path
723
- atomically:(argv[1] == Qtrue)];
692
+ NSString* const path = unwrap_nsstring(argv[0]);
693
+ const BOOL result = [unwrap_nsdata(self) writeToFile:path
694
+ atomically:(argv[1] == Qtrue)];
724
695
 
725
- [path release];
696
+ [path release];
726
697
 
727
- return (result ? Qtrue : Qfalse);
698
+ return (result ? Qtrue : Qfalse);
728
699
  }
729
700
 
730
701
 
731
702
  static
732
703
  VALUE
733
- rb_data_to_str(VALUE self)
704
+ rb_data_to_str(const VALUE self)
734
705
  {
735
- NSData* data = unwrap_nsdata(self);
736
- const void* bytes = [data bytes];
737
- NSUInteger length = [data length];
738
- return rb_enc_str_new(bytes, length, rb_utf8_encoding());
706
+ NSData* const data = unwrap_nsdata(self);
707
+ const void* const bytes = [data bytes];
708
+ const NSUInteger length = [data length];
709
+ return rb_enc_str_new(bytes, length, rb_utf8_encoding());
739
710
  }
740
711
 
741
712
  static
742
713
  VALUE
743
- rb_str_to_data(VALUE self)
714
+ rb_str_to_data(const VALUE self)
744
715
  {
745
- NSData* data = [NSData dataWithBytes:(void*)StringValuePtr(self)
746
- length:RSTRING_LEN(self)];
747
- if (data)
748
- return wrap_nsdata(data);
749
- return Qnil; // I don't think this is possible except in case of ENOMEM
716
+ VALUE self_string = self;
717
+ NSData* const data = [NSData dataWithBytes:(void*)StringValuePtr(self_string)
718
+ length:RSTRING_LEN(self)];
719
+ if (data)
720
+ return wrap_nsdata(data);
721
+ return Qnil; // I don't think this is possible except in case of ENOMEM
750
722
  }
751
723
 
752
724
 
753
725
  static VALUE
754
- rb_spin(int argc, VALUE* argv, VALUE self)
726
+ rb_spin(const int argc, VALUE* const argv, const VALUE self)
755
727
  {
756
- if (argc == 0)
757
- spin(0);
758
- else
759
- spin(NUM2DBL(argv[0]));
728
+ if (argc == 0)
729
+ spin(0);
730
+ else
731
+ spin(NUM2DBL(argv[0]));
760
732
 
761
- return self;
733
+ return self;
762
734
  }
763
735
 
764
- #endif
765
-
766
736
 
767
737
  void
768
738
  Init_bridge()
769
739
  {
770
- #ifdef NOT_MACRUBY
771
- sel_x = rb_intern("x");
772
- sel_y = rb_intern("y");
773
- sel_width = rb_intern("width");
774
- sel_height = rb_intern("height");
775
- sel_origin = rb_intern("origin");
776
- sel_size = rb_intern("size");
777
- sel_to_point = rb_intern("to_point");
778
- sel_to_size = rb_intern("to_size");
779
- sel_to_rect = rb_intern("to_rect");
780
- sel_to_s = rb_intern("to_s");
781
- sel_parse = rb_intern("parse");
782
-
783
- rb_mAccessibility = rb_define_module("Accessibility");
784
- rb_cElement = rb_define_class_under(rb_mAccessibility, "Element", rb_cObject);
785
- rb_cCGPoint = rb_const_get(rb_cObject, rb_intern("CGPoint"));
786
- rb_cCGSize = rb_const_get(rb_cObject, rb_intern("CGSize"));
787
- rb_cCGRect = rb_const_get(rb_cObject, rb_intern("CGRect"));
788
- rb_mURI = rb_const_get(rb_cObject, rb_intern("URI"));
789
- rb_cURI = rb_const_get(rb_mURI, rb_intern("Generic"));
790
-
791
-
792
- /*
793
- * Document-class: NSAttributedString
794
- *
795
- * A 90% drop-in replacement for Cocoa's `NSAttributedString` class. The most likely
796
- * to use methods have been bridged. Remaining methods can be bridged upon request.
797
- *
798
- * See [Apple's Developer Reference](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/Reference/Reference.html)
799
- * for documentation on the methods available in this class.
800
- */
801
- rb_cAttributedString = rb_define_class("NSAttributedString", rb_cObject);
802
-
803
- // LOL, but required to be a drop-in replacement
804
- rb_define_singleton_method(rb_cAttributedString, "alloc", rb_astring_alloc, 0);
805
-
806
- // TODO: all these methods :(
807
- rb_define_method(rb_cAttributedString, "initWithString", rb_astring_init_with_string, -1);
808
- /* rb_define_method(rb_cAttributedString, "initWithAttributedString", rb_astring_init_with_astring, 2); */
809
- rb_define_method(rb_cAttributedString, "string", rb_astring_string, 0);
810
- rb_define_method(rb_cAttributedString, "length", rb_astring_length, 0);
811
- /* rb_define_method(rb_cAttributedString, "attributesAtIndex", rb_astring_attrs_at_index, -1); */
812
- rb_define_method(rb_cAttributedString, "isEqualToAttributedString", rb_astring_equality, 1);
813
- /* rb_define_method(rb_cAttributedString, "attributedSubstringFromRange", rb_astring_astring_from_range, 1); */
814
-
815
- rb_define_alias(rb_cAttributedString, "to_s", "string");
816
- rb_define_alias(rb_cAttributedString, "to_str", "string");
817
- rb_define_alias(rb_cAttributedString, "==", "isEqualToAttributedString");
818
-
819
-
820
- /*
821
- * Document-class: NSData
822
- *
823
- * A 50% drop-in replacement for Cocoa's `NSData` class. Almost all
824
- * non-deprecated methods have been bridged.
825
- *
826
- * See [Apple's Developer Reference](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html)
827
- * for documentation on the methods available in this class.
828
- */
829
- rb_cData = rb_define_class("NSData", rb_cObject);
830
-
831
- // TODO: implement commented out methods
832
- rb_define_singleton_method(rb_cData, "data", rb_data_data, 0);
833
- //rb_define_singleton_method(rb_cData, "dataWithBytes", rb_data_with_bytes, 2);
834
- //rb_define_singleton_method(rb_cData, "dataWithContentsOfFile", rb_data_with_contents_of_file, 1);
835
- rb_define_singleton_method(rb_cData, "dataWithContentsOfURL", rb_data_with_contents_of_url, 1);
836
- //rb_define_singleton_method(rb_cData, "dataWithData", rb_data_with_data, 1);
837
-
838
- //rb_define_method(rb_cData, "bytes", rb_data_bytes, 0);
839
- //rb_define_method(rb_cData, "description", rb_data_description, 0);
840
- //rb_define_method(rb_cData, "subdataWithRange", rb_data_subrange, 1);
841
- rb_define_method(rb_cData, "isEqualToData", rb_data_equality, 1);
842
- rb_define_method(rb_cData, "length", rb_data_length, 0);
843
- rb_define_method(rb_cData, "writeToFile", rb_data_write_to_file, -1);
844
- //rb_define_method(rb_cData, "writeToURL", rb_data_write_to_url, -1);
845
- rb_define_method(rb_cData, "to_str", rb_data_to_str, 0);
846
-
847
- rb_define_alias(rb_cData, "==", "isEqualToData");
848
-
849
-
850
- // misc freedom patches
851
- rb_define_method(rb_cString, "to_data", rb_str_to_data, 0);
852
- rb_define_method(rb_cObject, "spin", rb_spin, -1); // semi-private method
853
- #endif
740
+ sel_x = rb_intern("x");
741
+ sel_y = rb_intern("y");
742
+ sel_width = rb_intern("width");
743
+ sel_height = rb_intern("height");
744
+ sel_origin = rb_intern("origin");
745
+ sel_size = rb_intern("size");
746
+ sel_to_point = rb_intern("to_point");
747
+ sel_to_size = rb_intern("to_size");
748
+ sel_to_rect = rb_intern("to_rect");
749
+ sel_to_s = rb_intern("to_s");
750
+ sel_parse = rb_intern("parse");
751
+
752
+ rb_mAccessibility = rb_define_module("Accessibility");
753
+ rb_cElement = rb_define_class_under(rb_mAccessibility, "Element", rb_cObject);
754
+ rb_cCGPoint = rb_const_get(rb_cObject, rb_intern("CGPoint"));
755
+ rb_cCGSize = rb_const_get(rb_cObject, rb_intern("CGSize"));
756
+ rb_cCGRect = rb_const_get(rb_cObject, rb_intern("CGRect"));
757
+ rb_mURI = rb_const_get(rb_cObject, rb_intern("URI"));
758
+ rb_cURI = rb_const_get(rb_mURI, rb_intern("Generic"));
759
+
760
+
761
+ /*
762
+ * Document-class: NSAttributedString
763
+ *
764
+ * A 90% drop-in replacement for Cocoa's `NSAttributedString` class. The most likely
765
+ * to use methods have been bridged. Remaining methods can be bridged upon request.
766
+ *
767
+ * See [Apple's Developer Reference](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/Reference/Reference.html)
768
+ * for documentation on the methods available in this class.
769
+ */
770
+ rb_cAttributedString = rb_define_class("NSAttributedString", rb_cObject);
771
+
772
+ // LOL, but required to be a drop-in replacement
773
+ rb_define_singleton_method(rb_cAttributedString, "alloc", rb_astring_alloc, 0);
774
+
775
+ // TODO: all these methods :(
776
+ rb_define_method(rb_cAttributedString, "initWithString", rb_astring_init_with_string, -1);
777
+ /* rb_define_method(rb_cAttributedString, "initWithAttributedString", rb_astring_init_with_astring, 2); */
778
+ rb_define_method(rb_cAttributedString, "string", rb_astring_string, 0);
779
+ rb_define_method(rb_cAttributedString, "length", rb_astring_length, 0);
780
+ /* rb_define_method(rb_cAttributedString, "attributesAtIndex", rb_astring_attrs_at_index, -1); */
781
+ rb_define_method(rb_cAttributedString, "isEqualToAttributedString", rb_astring_equality, 1);
782
+ /* rb_define_method(rb_cAttributedString, "attributedSubstringFromRange", rb_astring_astring_from_range, 1); */
783
+
784
+ rb_define_alias(rb_cAttributedString, "to_s", "string");
785
+ rb_define_alias(rb_cAttributedString, "to_str", "string");
786
+ rb_define_alias(rb_cAttributedString, "==", "isEqualToAttributedString");
787
+
788
+
789
+ /*
790
+ * Document-class: NSData
791
+ *
792
+ * A 50% drop-in replacement for Cocoa's `NSData` class. Almost all
793
+ * non-deprecated methods have been bridged.
794
+ *
795
+ * See [Apple's Developer Reference](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html)
796
+ * for documentation on the methods available in this class.
797
+ */
798
+ rb_cData = rb_define_class("NSData", rb_cObject);
799
+
800
+ // TODO: implement commented out methods
801
+ rb_define_singleton_method(rb_cData, "data", rb_data_data, 0);
802
+ //rb_define_singleton_method(rb_cData, "dataWithBytes", rb_data_with_bytes, 2);
803
+ //rb_define_singleton_method(rb_cData, "dataWithContentsOfFile", rb_data_with_contents_of_file, 1);
804
+ rb_define_singleton_method(rb_cData, "dataWithContentsOfURL", rb_data_with_contents_of_url, 1);
805
+ //rb_define_singleton_method(rb_cData, "dataWithData", rb_data_with_data, 1);
806
+
807
+ //rb_define_method(rb_cData, "bytes", rb_data_bytes, 0);
808
+ //rb_define_method(rb_cData, "description", rb_data_description, 0);
809
+ //rb_define_method(rb_cData, "subdataWithRange", rb_data_subrange, 1);
810
+ rb_define_method(rb_cData, "isEqualToData", rb_data_equality, 1);
811
+ rb_define_method(rb_cData, "length", rb_data_length, 0);
812
+ rb_define_method(rb_cData, "writeToFile", rb_data_write_to_file, -1);
813
+ //rb_define_method(rb_cData, "writeToURL", rb_data_write_to_url, -1);
814
+ rb_define_method(rb_cData, "to_str", rb_data_to_str, 0);
815
+
816
+ rb_define_alias(rb_cData, "==", "isEqualToData");
817
+
818
+
819
+ // misc freedom patches
820
+ rb_define_method(rb_cString, "to_data", rb_str_to_data, 0);
821
+ rb_define_method(rb_cObject, "spin", rb_spin, -1); // semi-private method
854
822
  }