fxruby 1.6.35-x64-mingw32 → 1.6.36-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,7 @@
29
29
  #endif
30
30
 
31
31
  #include "FXRbCommon.h"
32
+ #include "FXRbObjRegistry.h"
32
33
  #include "impl.h"
33
34
 
34
35
  // SWIG runtime functions we need
@@ -79,82 +80,9 @@ swig_type_info *FXRbTypeQuery(const char *desc){
79
80
  }
80
81
 
81
82
 
82
- /**
83
- * The FXRuby_Objects hash table basically maps C++ objects to Ruby instances.
84
- * Each key in the table is a pointer to a C++ object we've seen before, and
85
- * the corresponding value is an FXRubyObjDesc struct (see below) that tells
86
- * us which Ruby instance corresponds to that C++ object.
87
- */
88
-
89
- static st_table * FXRuby_Objects;
90
-
91
- static const char * const safe_rb_obj_classname(VALUE obj)
92
- {
93
- int tdata = TYPE(obj)==T_DATA;
94
- if( (tdata && FXRbIsInGC(DATA_PTR(obj)))
95
- #ifdef HAVE_RB_DURING_GC
96
- || rb_during_gc()
97
- #endif
98
- ){
99
- /* It's not safe to call rb_obj_classname() during GC.
100
- * Return dummy value in this case. */
101
- return "during GC";
102
- } else if (tdata) {
103
- return rb_obj_classname(obj);
104
- } else {
105
- return "no T_DATA";
106
- }
107
- }
108
-
109
- /**
110
- * Each value in the FXRuby_Objects hash table is an instance of this
111
- * struct. It identifies the Ruby instance associated with a C++ object.
112
- * It also indicates whether this is merely a "borrowed" reference to
113
- * some C++ object (i.e. it's not one we need to destroy later).
114
- *
115
- * in_gc is set for FXWindows that are in garbage collection and must
116
- * not call ruby code anymore.
117
- */
118
-
119
- struct FXRubyObjDesc {
120
- VALUE obj;
121
- bool borrowed;
122
- bool in_gc;
123
- };
124
-
125
-
126
- /**
127
- * FXRbNewPointerObj() is a wrapper around SWIG_Ruby_NewPointerObj() that also
128
- * registers this C++ object & Ruby instance pair in our FXRuby_Objects
129
- * hash table. This function should only get called for methods that return
130
- * a reference to an already-existing C++ object (i.e. one that FOX "owns")
131
- * and for that reason we mark these objects as "borrowed".
132
- */
133
-
134
83
  VALUE FXRbNewPointerObj(void *ptr,swig_type_info* ty){
135
- if(ptr!=0){
136
- FXASSERT(ty!=0);
137
- VALUE obj;
138
- FXRubyObjDesc *desc;
139
- if(FXMALLOC(&desc,FXRubyObjDesc,1)){
140
- obj=SWIG_Ruby_NewPointerObj(ptr,ty,1);
141
- FXTRACE((1,"FXRbNewPointerObj(foxObj=%p) => rubyObj=%p (%s)\n",ptr,(void *)obj,safe_rb_obj_classname(obj)));
142
- desc->obj=obj;
143
- desc->borrowed=true;
144
- desc->in_gc=false;
145
- int overwritten = st_insert(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t>(desc));
146
- FXASSERT(!overwritten);
147
- return obj;
148
- }
149
- else{
150
- FXASSERT(FALSE);
151
- return Qnil;
152
- }
153
- }
154
- else{
155
- return Qnil;
156
- }
157
- }
84
+ return FXRbObjRegistry::main.NewBorrowedObj(ptr,ty);
85
+ }
158
86
 
159
87
 
160
88
  /**
@@ -163,168 +91,27 @@ VALUE FXRbNewPointerObj(void *ptr,swig_type_info* ty){
163
91
  */
164
92
 
165
93
  bool FXRbIsBorrowed(void* ptr){
166
- FXASSERT(ptr!=0);
167
- FXRubyObjDesc *desc;
168
- if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t *>(&desc))!=0){
169
- return desc->borrowed;
170
- }
171
- else{
172
- return true;
173
- }
174
- }
94
+ return FXRbObjRegistry::main.IsBorrowed(ptr);
95
+ }
175
96
 
176
97
  bool FXRbSetInGC(const void* ptr, bool enabled){
177
- FXASSERT(ptr!=0);
178
- FXRubyObjDesc *desc;
179
- if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t *>(&desc))!=0){
180
- desc->in_gc=enabled;
181
- return enabled;
182
- }
183
- return false;
184
- }
98
+ return FXRbObjRegistry::main.SetInGC(ptr, enabled);
99
+ }
185
100
 
186
101
  bool FXRbIsInGC(const void* ptr){
187
- FXASSERT(ptr!=0);
188
- FXRubyObjDesc *desc;
189
-
190
- #ifdef HAVE_RB_DURING_GC
191
- if( rb_during_gc() ){
192
- return true;
193
- }
194
- #endif
195
- if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t *>(&desc))!=0){
196
- return desc->in_gc;
197
- }
198
- return false;
102
+ return FXRbObjRegistry::main.IsInGC(ptr);
199
103
  }
200
104
 
201
105
 
202
- /**
203
- * FXRbConvertPtr() is just a wrapper around SWIG_ConvertPtr().
204
- */
205
-
206
- void* FXRbConvertPtr(VALUE obj,swig_type_info* ty){
207
- void *ptr;
208
- SWIG_ConvertPtr(obj,&ptr,ty,1);
209
- return ptr;
210
- }
211
-
212
-
213
- // Should we catch exceptions thrown by message handlers?
214
- FXbool FXRbCatchExceptions=FALSE;
215
-
216
- // Returns an FXInputHandle for this Ruby file object
217
- FXInputHandle FXRbGetReadFileHandle(VALUE obj,FXuint mode) {
218
- int fd;
219
- fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0));
220
- #ifdef WIN32
221
- #ifdef __CYGWIN__
222
- return (FXInputHandle) get_osfhandle(fd);
223
- #else
224
- WSAEVENT hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
225
- long events = 0;
226
- if(mode&INPUT_READ) events |= FD_READ|FD_ACCEPT|FD_OOB;
227
- if(mode&INPUT_EXCEPT) events |= FD_CLOSE|FD_QOS|FD_GROUP_QOS|FD_ROUTING_INTERFACE_CHANGE|FD_ADDRESS_LIST_CHANGE;
228
- if ( WSAEventSelect(_get_osfhandle(fd), hEvent, events) == SOCKET_ERROR ) {
229
- WSACloseEvent( hEvent );
230
- rb_raise( rb_eRuntimeError, "WSAEventSelect sockett error: %d", WSAGetLastError() );
231
- }
232
- rb_iv_set(obj, "FXRuby::FXRbGetReadFileHandle", ULL2NUM((intptr_t)hEvent));
233
- return (FXInputHandle) hEvent;
234
- #endif
235
- #else
236
- return (FXInputHandle) fd;
237
- #endif
238
- }
239
-
240
- void FXRbRemoveReadFileHandle(VALUE obj,FXuint mode) {
241
- #ifdef WIN32
242
- WSAEVENT hEvent = (HANDLE)NUM2ULL(rb_iv_get(obj, "FXRuby::FXRbGetReadFileHandle"));
243
- CloseHandle( hEvent );
244
- #endif
106
+ // Register this Ruby class instance
107
+ void FXRbRegisterRubyObj(VALUE rubyObj,const void* foxObj) {
108
+ return FXRbObjRegistry::main.RegisterRubyObj(rubyObj, foxObj);
245
109
  }
246
110
 
247
- // Returns an FXInputHandle for this Ruby file object
248
- FXInputHandle FXRbGetWriteFileHandle(VALUE obj,FXuint mode) {
249
- int fd;
250
- #if defined(RUBINIUS)
251
- VALUE vwrite = rb_intern("@write");
252
- if(rb_ivar_defined(obj, vwrite)) obj = rb_ivar_get(obj, vwrite);
253
- fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0));
254
- #elif defined(RUBY_1_8)
255
- OpenFile *fptr;
256
- GetOpenFile(obj, fptr);
257
- FILE *fpw=GetWriteFile(fptr);
258
- fd = fileno(fpw);
259
- #else
260
- rb_io_t *fptr;
261
- GetOpenFile(obj, fptr);
262
- VALUE wrio = fptr->tied_io_for_writing;
263
- if(wrio) obj = wrio;
264
- fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0));
265
- #endif
266
- #ifdef WIN32
267
- #ifdef __CYGWIN__
268
- return (FXInputHandle) get_osfhandle(fd);
269
- #else
270
- WSAEVENT hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
271
- long events = 0;
272
- if(mode&INPUT_WRITE) events |= FD_WRITE|FD_CONNECT;
273
- if(mode&INPUT_EXCEPT) events |= FD_CLOSE|FD_QOS|FD_GROUP_QOS|FD_ROUTING_INTERFACE_CHANGE|FD_ADDRESS_LIST_CHANGE;
274
- if ( WSAEventSelect(_get_osfhandle(fd), hEvent, events) == SOCKET_ERROR ) {
275
- WSACloseEvent( hEvent );
276
- rb_raise( rb_eRuntimeError, "WSAEventSelect sockettt error: %d", WSAGetLastError() );
277
- }
278
- rb_iv_set(obj, "FXRuby::FXRbGetWriteFileHandle", ULL2NUM((intptr_t)hEvent));
279
- return (FXInputHandle) hEvent;
280
- #endif
281
- #else
282
- return (FXInputHandle) fd;
283
- #endif
284
- }
285
-
286
- void FXRbRemoveWriteFileHandle(VALUE obj,FXuint mode) {
287
- #ifdef WIN32
288
- WSAEVENT hEvent = (HANDLE)NUM2ULL(rb_iv_get(obj, "FXRuby::FXRbGetWriteFileHandle"));
289
- CloseHandle( hEvent );
290
- #endif
111
+ static void FXRbUnregisterRubyObj2(const void* foxObj, bool alsoOwned){
112
+ return FXRbObjRegistry::main.UnregisterRubyObj(foxObj, alsoOwned);
291
113
  }
292
114
 
293
-
294
- // Register this Ruby class instance
295
- void FXRbRegisterRubyObj(VALUE rubyObj,const void* foxObj) {
296
- FXASSERT(!NIL_P(rubyObj));
297
- FXASSERT(foxObj!=0);
298
- FXRubyObjDesc* desc;
299
- FXTRACE((1,"FXRbRegisterRubyObj(rubyObj=%p (%s),foxObj=%p)\n",(void *)rubyObj,safe_rb_obj_classname(rubyObj),foxObj));
300
- if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(&desc))!=0){
301
- FXASSERT(desc->borrowed);
302
- /* There is already a Ruby object registered for this foxObj.
303
- * This can happen, if libfox calls methods out of the C++ object constructor,
304
- * that can be overwritten in Ruby (like changeFocus) with the object as
305
- * parameter. FXFileSelector is one example.
306
- * To avoid double references to the same foxObj from different Ruby objects,
307
- * we decouple the foxObj from previoius ruby object and point to the new one.
308
- */
309
- DATA_PTR(desc->obj) = 0;
310
- desc->obj=rubyObj;
311
- desc->borrowed=false;
312
- }
313
- else{
314
- if(FXMALLOC(&desc,FXRubyObjDesc,1)){
315
- desc->obj=rubyObj;
316
- desc->borrowed=false;
317
- desc->in_gc=false;
318
- int overwritten = st_insert(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t>(desc));
319
- FXASSERT(!overwritten);
320
- }
321
- else{
322
- FXASSERT(FALSE);
323
- }
324
- }
325
- FXASSERT(FXRbGetRubyObj(foxObj,false)==rubyObj);
326
- }
327
-
328
115
  /**
329
116
  * Remove this mapping between a Ruby instance and a C++ object
330
117
  */
@@ -332,20 +119,6 @@ void FXRbUnregisterRubyObj(const void* foxObj){
332
119
  FXRbUnregisterRubyObj2(foxObj, true);
333
120
  }
334
121
 
335
- void FXRbUnregisterRubyObj2(const void* foxObj, bool alsoOwned){
336
- if(foxObj!=0){
337
- FXRubyObjDesc* desc;
338
- if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(&desc))!=0){
339
- if( !alsoOwned && !desc->borrowed ) return;
340
- FXTRACE((1,"FXRbUnregisterRubyObj(rubyObj=%p (%s),foxObj=%p)\n",(void *)desc->obj,safe_rb_obj_classname(desc->obj),foxObj));
341
- DATA_PTR(desc->obj)=0;
342
- FXFREE(&desc);
343
- st_delete(FXRuby_Objects,reinterpret_cast<st_data_t *>(const_cast<void**>(&foxObj)),reinterpret_cast<st_data_t *>(0));
344
- FXASSERT(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(0))==0);
345
- }
346
- }
347
- }
348
-
349
122
  void FXRbUnregisterBorrowedRubyObj(const void* foxObj){
350
123
  FXRbUnregisterRubyObj2( foxObj, false );
351
124
  };
@@ -380,18 +153,9 @@ VALUE to_ruby(const FXObject* obj){
380
153
  * Return the registered Ruby class instance associated with this
381
154
  * FOX object, or Qnil if not found.
382
155
  */
383
- VALUE FXRbGetRubyObj(const void *foxObj,bool alsoBorrowed, bool in_gc){
384
- FXRubyObjDesc* desc;
385
- if(foxObj!=0 && st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(&desc))!=0){
386
- FXASSERT(desc!=0);
387
- if(alsoBorrowed || !desc->borrowed){
388
- const char *classname = in_gc ? "in GC" : safe_rb_obj_classname(desc->obj);
389
- FXTRACE((2,"FXRbGetRubyObj(foxObj=%p) => rubyObj=%p (%s)\n", foxObj, (void *)desc->obj, classname));
390
- return desc->obj;
391
- }
392
- }
393
- return Qnil;
394
- }
156
+ VALUE FXRbGetRubyObj(const void *foxObj,bool alsoBorrowed, bool in_gc_mark){
157
+ return FXRbObjRegistry::main.GetRubyObj(foxObj, alsoBorrowed, in_gc_mark);
158
+ }
395
159
 
396
160
  /**
397
161
  * Return the registered Ruby class instance associated with this
@@ -438,7 +202,7 @@ void FXRbGcMark(void *obj){
438
202
  * example program works if you invoke the GC in ShutterWindow#create;
439
203
  * make sure that the shutter items' contents don't get blown away!
440
204
  */
441
- VALUE value=FXRbGetRubyObj(obj,true, true);
205
+ VALUE value=FXRbGetRubyObj(obj, true, true);
442
206
  if(!NIL_P(value)){
443
207
  rb_gc_mark(value);
444
208
  }
@@ -522,7 +286,7 @@ VALUE FXRbMakeArray(const FXSegment* segments,FXuint nsegments){
522
286
  // Returns a Ruby array of FXColor values
523
287
  VALUE FXRbMakeColorArray(const FXColor* colors,FXint w,FXint h){
524
288
  VALUE result=rb_ary_new();
525
- FXint size=w*h;
289
+ FXuint size=w*h;
526
290
  for(FXuint i=0; i<size; i++)
527
291
  rb_ary_push(result,to_ruby(colors[i]));
528
292
  return result;
@@ -575,7 +339,6 @@ FXColor *FXRbConvertToFXColors(VALUE string_or_ary, FXuint *opts){
575
339
  */
576
340
  static VALUE FXRbConvertMessageData(FXObject* sender,FXObject* recv,FXSelector sel,void* ptr){
577
341
  FXTRACE((1,"FXRbConvertMessageData(%s(%p),FXSEL(%s,%d),%p)\n",sender->getClassName(),sender,FXDebugTarget::messageTypeName[FXSELTYPE(sel)],FXSELID(sel),ptr));
578
- FXInputHandle fff;
579
342
  FXushort type=FXSELTYPE(sel);
580
343
  FXushort id=FXSELID(sel);
581
344
 
@@ -642,11 +405,6 @@ static VALUE FXRbConvertMessageData(FXObject* sender,FXObject* recv,FXSelector s
642
405
  else if(type==SEL_IO_READ ||
643
406
  type==SEL_IO_WRITE ||
644
407
  type==SEL_IO_EXCEPT){
645
- #ifdef WIN32
646
- fff=reinterpret_cast<FXInputHandle>(ptr);
647
- #else
648
- fff=static_cast<FXInputHandle>(reinterpret_cast<long>(ptr));
649
- #endif
650
408
  return Qnil;
651
409
  }
652
410
  else if(type==SEL_CLOSE ||
@@ -1368,6 +1126,10 @@ static VALUE handle_rescue(VALUE args,VALUE error){
1368
1126
  }
1369
1127
 
1370
1128
 
1129
+ // Should we catch exceptions thrown by message handlers?
1130
+ FXbool FXRbCatchExceptions=FALSE;
1131
+
1132
+
1371
1133
  // Call the designated function and return its result (which should be a long).
1372
1134
  long FXRbHandleMessage_gvlcb(FXObject* recv,ID func,FXObject* sender,FXSelector key,void* ptr){
1373
1135
  FXRbHandleArgs hArgs;
@@ -1805,6 +1567,94 @@ FXbool FXRbGLViewer::sortProc(FXfloat*& buffer,FXint& used,FXint& size){
1805
1567
  return TRUE;
1806
1568
  }
1807
1569
 
1570
+ /**
1571
+ * FXRbConvertPtr() is just a wrapper around SWIG_ConvertPtr().
1572
+ */
1573
+
1574
+ void* FXRbConvertPtr(VALUE obj,swig_type_info* ty){
1575
+ void *ptr;
1576
+ SWIG_ConvertPtr(obj,&ptr,ty,1);
1577
+ return ptr;
1578
+ }
1579
+
1580
+
1581
+ // Returns an FXInputHandle for this Ruby file object
1582
+ FXInputHandle FXRbGetReadFileHandle(VALUE obj,FXuint mode) {
1583
+ int fd;
1584
+ fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0));
1585
+ #ifdef WIN32
1586
+ #ifdef __CYGWIN__
1587
+ return (FXInputHandle) get_osfhandle(fd);
1588
+ #else
1589
+ WSAEVENT hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
1590
+ long events = 0;
1591
+ if(mode&INPUT_READ) events |= FD_READ|FD_ACCEPT|FD_OOB;
1592
+ if(mode&INPUT_EXCEPT) events |= FD_CLOSE|FD_QOS|FD_GROUP_QOS|FD_ROUTING_INTERFACE_CHANGE|FD_ADDRESS_LIST_CHANGE;
1593
+ if ( WSAEventSelect(_get_osfhandle(fd), hEvent, events) == SOCKET_ERROR ) {
1594
+ WSACloseEvent( hEvent );
1595
+ rb_raise( rb_eRuntimeError, "WSAEventSelect sockett error: %d", WSAGetLastError() );
1596
+ }
1597
+ rb_iv_set(obj, "FXRuby::FXRbGetReadFileHandle", ULL2NUM((intptr_t)hEvent));
1598
+ return (FXInputHandle) hEvent;
1599
+ #endif
1600
+ #else
1601
+ return (FXInputHandle) fd;
1602
+ #endif
1603
+ }
1604
+
1605
+ void FXRbRemoveReadFileHandle(VALUE obj,FXuint mode) {
1606
+ #ifdef WIN32
1607
+ WSAEVENT hEvent = (HANDLE)NUM2ULL(rb_iv_get(obj, "FXRuby::FXRbGetReadFileHandle"));
1608
+ CloseHandle( hEvent );
1609
+ #endif
1610
+ }
1611
+
1612
+ // Returns an FXInputHandle for this Ruby file object
1613
+ FXInputHandle FXRbGetWriteFileHandle(VALUE obj,FXuint mode) {
1614
+ int fd;
1615
+ #if defined(RUBINIUS)
1616
+ VALUE vwrite = rb_intern("@write");
1617
+ if(rb_ivar_defined(obj, vwrite)) obj = rb_ivar_get(obj, vwrite);
1618
+ fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0));
1619
+ #elif defined(RUBY_1_8)
1620
+ OpenFile *fptr;
1621
+ GetOpenFile(obj, fptr);
1622
+ FILE *fpw=GetWriteFile(fptr);
1623
+ fd = fileno(fpw);
1624
+ #else
1625
+ rb_io_t *fptr;
1626
+ GetOpenFile(obj, fptr);
1627
+ VALUE wrio = fptr->tied_io_for_writing;
1628
+ if(wrio) obj = wrio;
1629
+ fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0));
1630
+ #endif
1631
+ #ifdef WIN32
1632
+ #ifdef __CYGWIN__
1633
+ return (FXInputHandle) get_osfhandle(fd);
1634
+ #else
1635
+ WSAEVENT hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
1636
+ long events = 0;
1637
+ if(mode&INPUT_WRITE) events |= FD_WRITE|FD_CONNECT;
1638
+ if(mode&INPUT_EXCEPT) events |= FD_CLOSE|FD_QOS|FD_GROUP_QOS|FD_ROUTING_INTERFACE_CHANGE|FD_ADDRESS_LIST_CHANGE;
1639
+ if ( WSAEventSelect(_get_osfhandle(fd), hEvent, events) == SOCKET_ERROR ) {
1640
+ WSACloseEvent( hEvent );
1641
+ rb_raise( rb_eRuntimeError, "WSAEventSelect sockettt error: %d", WSAGetLastError() );
1642
+ }
1643
+ rb_iv_set(obj, "FXRuby::FXRbGetWriteFileHandle", ULL2NUM((intptr_t)hEvent));
1644
+ return (FXInputHandle) hEvent;
1645
+ #endif
1646
+ #else
1647
+ return (FXInputHandle) fd;
1648
+ #endif
1649
+ }
1650
+
1651
+ void FXRbRemoveWriteFileHandle(VALUE obj,FXuint mode) {
1652
+ #ifdef WIN32
1653
+ WSAEVENT hEvent = (HANDLE)NUM2ULL(rb_iv_get(obj, "FXRuby::FXRbGetWriteFileHandle"));
1654
+ CloseHandle( hEvent );
1655
+ #endif
1656
+ }
1657
+
1808
1658
  //----------------------------------------------------------------------
1809
1659
 
1810
1660
  // Copied from the Ruby 1.8.6 sources (signal.c)
@@ -2128,7 +1978,6 @@ Init_fox16_c(void) {
2128
1978
  utf8_enc_idx = rb_enc_find_index("UTF-8");
2129
1979
  #endif
2130
1980
 
2131
- FXRuby_Objects=st_init_numtable();
2132
1981
  appSensitiveObjs=st_init_numtable();
2133
1982
  appSensitiveDCs=st_init_numtable();
2134
1983
  }