ncursesw 1.4.13 → 1.4.15

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.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/Changes +17 -0
  3. data/form_wrap.c +21 -8
  4. data/menu_wrap.c +38 -9
  5. data/ncurses_wrap.c +56 -54
  6. data/panel_wrap.c +10 -2
  7. metadata +2 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8754a10870f91ce6c48d2482fb10d990f0a0429653fa9f5a7bb28f7a077e9608
4
- data.tar.gz: 108f8b3f906c2e1355354633acccaed824a1dd70dc1d770f049150f8bf7ea0e6
3
+ metadata.gz: 8a9aff5809632dcf68381285d9af26cf2654291b79621714e81bc257b3fcd7ae
4
+ data.tar.gz: 96b081e074414294b6dbcff4e46e31c15d6f1c4f6d1382c28028998453e0589e
5
5
  SHA512:
6
- metadata.gz: 762a8a786de43dea665fbecb8a936089d64a84ec20ece8ead5d8d116c93d68f8db88f63814700b813d5348bd37b2e168f1588cd80186afaaec7d5d100cb267c4
7
- data.tar.gz: df600969cf72cdb85a4691464aaa0520755acc8dd3f1aa9916c8c013805d20893deb49c3b867ad623dc766d4fd0fddf807f32880eb50222586e05037c3d9a4b7
6
+ metadata.gz: 59fe81fba2e564c1fbaaadc5ba67a8662ca8d528e0471b934edce668c93ba720db7e5c93fb9979d213022ffad48f5fa937c049ace6e9da1ceb98b64c18824a84
7
+ data.tar.gz: 764c2878d6c11f2e88643f43b5052229ec902a32d47839df41c2ccbe563070572c9b94fddd0e7aa433c3a4519862b6569e41351798522d0ed95b0080f49a96cf
data/Changes CHANGED
@@ -1,3 +1,20 @@
1
+ ncurses-ruby-1.4.15
2
+ * Fixed leaked rb_fdset object in every iteration of getch()/wgetch().
3
+ * Fixed busy-loop in getch()/wgetch() when input reaches EOF.
4
+ * Fixed potential use-after-free for ITEM name and description.
5
+ * Added missing NULL checks for ITEM name and description.
6
+
7
+ ncurses-ruby-1.4.14
8
+ * Fixed segfault when calling tigetstr() for a non-existent capability.
9
+ * Fixed incorrect binding of wenclose(), mvwgetch(), and add_wch().
10
+ * Added missing NULL checks for functions which use NULL to signal an error.
11
+ Avoids a Ruby ArgumentError or segfault in the error cases.
12
+ * Replaced deprecated Data_Wrap_Struct() with TypedData_Wrap_Struct()
13
+ to get type checking for passed-in structs and avoid deprecation warnings.
14
+ * Fixed potential use-after-free for PANEL userptr.
15
+ * Fixed redefinition of methods when Ncurses.new_term or Ncurses.initscr
16
+ are called multiple times.
17
+
1
18
  ncurses-ruby-1.4.13
2
19
  * Fixed compilation errors under C23 due to unprototyped functions.
3
20
 
data/form_wrap.c CHANGED
@@ -253,6 +253,9 @@ void init_form_opts_constants() {
253
253
  /*
254
254
  * FIELD wrapper
255
255
  */
256
+ static const struct rb_data_type_struct field_rbtype = {
257
+ .wrap_struct_name = "Ncurses::Form::FIELDTYPE",
258
+ };
256
259
  static VALUE wrap_field(FIELD* field)
257
260
  {
258
261
  if (field == 0) return Qnil;
@@ -261,7 +264,7 @@ static VALUE wrap_field(FIELD* field)
261
264
  VALUE field_adress = INT2NUM((long)(field));
262
265
  VALUE rb_field = rb_hash_aref(fields_hash, field_adress);
263
266
  if (rb_field == Qnil) {
264
- rb_field = Data_Wrap_Struct(cFIELD, 0, 0, field);
267
+ rb_field = TypedData_Wrap_Struct(cFIELD, &field_rbtype, field);
265
268
  rb_iv_set(rb_field, "@destroyed", Qfalse);
266
269
  rb_hash_aset(fields_hash, field_adress, rb_field);
267
270
  }
@@ -276,13 +279,16 @@ static FIELD* get_field(VALUE rb_field)
276
279
  rb_raise(rb_eRuntimeError, "Attempt to access a destroyed field");
277
280
  return 0;
278
281
  }
279
- Data_Get_Struct(rb_field, FIELD, field);
282
+ TypedData_Get_Struct(rb_field, FIELD, &field_rbtype, field);
280
283
  return field;
281
284
  }
282
285
 
283
286
  /*
284
287
  * FIELDTYPE wrapper
285
288
  */
289
+ static const struct rb_data_type_struct fieldtype_rbtype = {
290
+ .wrap_struct_name = "Ncurses::Form::FIELDTYPE",
291
+ };
286
292
  static VALUE wrap_fieldtype(FIELDTYPE* fieldtype)
287
293
  {
288
294
  if (fieldtype == NULL) return Qnil;
@@ -291,7 +297,7 @@ static VALUE wrap_fieldtype(FIELDTYPE* fieldtype)
291
297
  VALUE fieldtype_adress = INT2NUM((long)(fieldtype));
292
298
  VALUE rb_fieldtype = rb_hash_aref(fieldtypes_hash, fieldtype_adress);
293
299
  if (rb_fieldtype == Qnil) {
294
- rb_fieldtype = Data_Wrap_Struct(cFIELDTYPE, 0, 0, fieldtype);
300
+ rb_fieldtype = TypedData_Wrap_Struct(cFIELDTYPE, &fieldtype_rbtype, fieldtype);
295
301
  rb_iv_set(rb_fieldtype, "@destroyed", Qfalse);
296
302
  rb_hash_aset(fieldtypes_hash, fieldtype_adress, rb_fieldtype);
297
303
  }
@@ -306,13 +312,16 @@ static FIELDTYPE* get_fieldtype(VALUE rb_fieldtype)
306
312
  rb_raise(rb_eRuntimeError, "Attempt to access a destroyed fieldtype");
307
313
  return 0;
308
314
  }
309
- Data_Get_Struct(rb_fieldtype, FIELDTYPE, fieldtype);
315
+ TypedData_Get_Struct(rb_fieldtype, FIELDTYPE, &fieldtype_rbtype, fieldtype);
310
316
  return fieldtype;
311
317
  }
312
318
 
313
319
  /*
314
320
  * FORM wrapper
315
321
  */
322
+ static const struct rb_data_type_struct form_rbtype = {
323
+ .wrap_struct_name = "Ncurses::Form::FORM",
324
+ };
316
325
  static VALUE wrap_form(FORM* form)
317
326
  {
318
327
  if (form == 0) return Qnil;
@@ -321,7 +330,7 @@ static VALUE wrap_form(FORM* form)
321
330
  VALUE form_adress = INT2NUM((long)(form));
322
331
  VALUE rb_form = rb_hash_aref(forms_hash, form_adress);
323
332
  if (rb_form == Qnil) {
324
- rb_form = Data_Wrap_Struct(cFORM, 0, 0, form);
333
+ rb_form = TypedData_Wrap_Struct(cFORM, &form_rbtype, form);
325
334
  rb_iv_set(rb_form, "@destroyed", Qfalse);
326
335
  rb_hash_aset(forms_hash, form_adress, rb_form);
327
336
  }
@@ -336,7 +345,7 @@ static FORM* get_form(VALUE rb_form)
336
345
  rb_raise(rb_eRuntimeError, "Attempt to access a destroyed form");
337
346
  return 0;
338
347
  }
339
- Data_Get_Struct(rb_form, FORM, form);
348
+ TypedData_Get_Struct(rb_form, FORM, &form_rbtype, form);
340
349
  return form;
341
350
  }
342
351
 
@@ -763,7 +772,9 @@ static VALUE rbncurs_m_set_field_buffer(VALUE dummy, VALUE rb_field, VALUE buf,
763
772
 
764
773
  static VALUE rbncurs_c_field_buffer(VALUE rb_field, VALUE buffer) {
765
774
  FIELD* field = get_field(rb_field);
766
- return rb_str_new2(field_buffer(field, NUM2INT(buffer)));
775
+ char * str = field_buffer(field, NUM2INT(buffer));
776
+ if (str == NULL) return Qnil;
777
+ return rb_str_new2(str);
767
778
  }
768
779
  static VALUE rbncurs_m_field_buffer(VALUE dummy, VALUE rb_field, VALUE buffer)
769
780
  { return rbncurs_c_field_buffer(rb_field, buffer); }
@@ -1060,7 +1071,9 @@ static VALUE rbncurs_m_form_opts(VALUE dummy, VALUE rb_form)
1060
1071
  * form_requestname
1061
1072
  */
1062
1073
  static VALUE rbncurs_c_form_request_name(VALUE request) {
1063
- return rb_str_new2(form_request_name(NUM2INT(request)));
1074
+ char * str = form_request_name(NUM2INT(request));
1075
+ if (str == NULL) return Qnil;
1076
+ return rb_str_new2(str);
1064
1077
  }
1065
1078
  static VALUE rbncurs_m_form_request_name(VALUE dummy, VALUE request)
1066
1079
  { return rbncurs_c_form_request_name(request); }
data/menu_wrap.c CHANGED
@@ -28,6 +28,7 @@
28
28
 
29
29
  #if defined(HAVE_MENU_H) || defined(HAVE_NCURSESW_MENU_H)
30
30
 
31
+ #include <ruby/util.h>
31
32
  #include "menu_wrap.h"
32
33
  #include "ncurses_wrap.h"
33
34
  #include "compat.h"
@@ -140,6 +141,9 @@ void init_menu_opts_constants(void)
140
141
  /*
141
142
  * ITEM wrapper
142
143
  */
144
+ static const struct rb_data_type_struct item_rbtype = {
145
+ .wrap_struct_name = "Ncurses::Menu::ITEM",
146
+ };
143
147
  static VALUE wrap_item(ITEM *item)
144
148
  {
145
149
  if (item == 0) return Qnil;
@@ -150,7 +154,7 @@ static VALUE wrap_item(ITEM *item)
150
154
 
151
155
  if (rb_item == Qnil)
152
156
  {
153
- rb_item = Data_Wrap_Struct(cITEM, 0, 0, item);
157
+ rb_item = TypedData_Wrap_Struct(cITEM, &item_rbtype, item);
154
158
  rb_iv_set(rb_item, "@destroyed", Qfalse);
155
159
  rb_hash_aset(items_hash, item_address, rb_item);
156
160
  }
@@ -167,7 +171,7 @@ static ITEM *get_item(VALUE rb_item)
167
171
  rb_raise(rb_eRuntimeError, "Attempt to access a destroyed item");
168
172
  return 0;
169
173
  }
170
- Data_Get_Struct(rb_item, ITEM, item);
174
+ TypedData_Get_Struct(rb_item, ITEM, &item_rbtype, item);
171
175
  return item;
172
176
  }
173
177
 
@@ -175,6 +179,9 @@ static ITEM *get_item(VALUE rb_item)
175
179
  /*
176
180
  * MENU wrapper
177
181
  */
182
+ static const struct rb_data_type_struct menu_rbtype = {
183
+ .wrap_struct_name = "Ncurses::Menu::MENU",
184
+ };
178
185
  static VALUE wrap_menu(MENU *menu)
179
186
  {
180
187
  if (menu == 0) return Qnil;
@@ -185,7 +192,7 @@ static VALUE wrap_menu(MENU *menu)
185
192
 
186
193
  if (rb_menu == Qnil)
187
194
  {
188
- rb_menu = Data_Wrap_Struct(cMENU, 0, 0, menu);
195
+ rb_menu = TypedData_Wrap_Struct(cMENU, &menu_rbtype, menu);
189
196
  rb_iv_set(rb_menu, "@destroyed", Qfalse);
190
197
  rb_hash_aset(menus_hash, menu_address, rb_menu);
191
198
  }
@@ -202,7 +209,7 @@ static MENU *get_menu(VALUE rb_menu)
202
209
  rb_raise(rb_eRuntimeError, "Attempt to access a destroyed menu");
203
210
  return 0;
204
211
  }
205
- Data_Get_Struct(rb_menu, MENU, menu);
212
+ TypedData_Get_Struct(rb_menu, MENU, &menu_rbtype, menu);
206
213
  return menu;
207
214
  }
208
215
 
@@ -373,16 +380,32 @@ static VALUE rbncurs_m_item_index(VALUE dummy, VALUE rb_item)
373
380
  * Item creation/destruction functions - mitem_new(3X) man page
374
381
  */
375
382
  static VALUE rbncurs_m_new_item(VALUE dummy, VALUE name, VALUE description)
376
- { return wrap_item(new_item(STR2CSTR(name), STR2CSTR(description))); }
383
+ {
384
+ char *c_name = ruby_strdup(STR2CSTR(name));
385
+ char *c_desc = ruby_strdup(STR2CSTR(description));
386
+ ITEM *item = new_item(c_name, c_desc);
387
+ if (item == NULL) { xfree(c_name); xfree(c_desc); return Qnil; }
388
+ if (item_description(item) != c_desc) {
389
+ /* ncurses rejected the description */
390
+ xfree(c_desc);
391
+ }
392
+ return wrap_item(item);
393
+ }
377
394
 
378
395
  static VALUE rbncurs_c_free_item(VALUE rb_item)
379
396
  {
380
397
  VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
381
398
  ITEM *item = get_item(rb_item);
382
399
  VALUE item_address = INT2NUM((long)(item));
400
+ char *c_name = (char *)item_name(item);
401
+ char *c_desc = (char *)item_description(item);
402
+ int result = free_item(item);
403
+ if (result != E_OK) return INT2NUM(result);
404
+ xfree(c_name);
405
+ xfree(c_desc);
383
406
  rb_funcall(items_hash, rb_intern("delete"), 1, item_address);
384
407
  rb_iv_set(rb_item, "@destroyed", Qtrue);
385
- return INT2NUM(free_item(item));
408
+ return INT2NUM(result);
386
409
  }
387
410
  static VALUE rbncurs_m_free_item(VALUE dummy, VALUE rb_item)
388
411
  { return rbncurs_c_free_item(rb_item); }
@@ -664,7 +687,9 @@ static VALUE rbncurs_m_menu_opts(VALUE dummy, VALUE rb_menu)
664
687
  */
665
688
  static VALUE rbncurs_c_menu_request_name(VALUE request)
666
689
  {
667
- return rb_str_new2(menu_request_name(NUM2INT(request)));
690
+ char *str = menu_request_name(NUM2INT(request));
691
+ if (str == NULL) return Qnil;
692
+ return rb_str_new2(str);
668
693
  }
669
694
  static VALUE rbncurs_m_menu_request_name(VALUE dummy, VALUE request)
670
695
  { return rbncurs_c_menu_request_name(request); }
@@ -756,7 +781,9 @@ static VALUE rbncurs_m_pos_menu_cursor(VALUE dummy, VALUE rb_menu)
756
781
  static VALUE rbncurs_c_item_name(VALUE rb_item)
757
782
  {
758
783
  ITEM *item = get_item(rb_item);
759
- return rb_str_new2(item_name(item));
784
+ char *str = item_name(item);
785
+ if (str == NULL) return Qnil;
786
+ return rb_str_new2(str);
760
787
  }
761
788
  static VALUE rbncurs_m_item_name(VALUE dummy, VALUE rb_item)
762
789
  { return rbncurs_c_item_name(rb_item); }
@@ -764,7 +791,9 @@ static VALUE rbncurs_m_item_name(VALUE dummy, VALUE rb_item)
764
791
  static VALUE rbncurs_c_item_description(VALUE rb_item)
765
792
  {
766
793
  ITEM *item = get_item(rb_item);
767
- return rb_str_new2(item_description(item));
794
+ char *str = item_description(item);
795
+ if (str == NULL) return Qnil;
796
+ return rb_str_new2(str);
768
797
  }
769
798
  static VALUE rbncurs_m_item_description(VALUE dummy, VALUE rb_item)
770
799
  { return rbncurs_c_item_description(rb_item); }
data/ncurses_wrap.c CHANGED
@@ -223,6 +223,9 @@ long rbncurs_array_length(VALUE array)
223
223
  return NUM2LONG(rb_funcall(array, rb_intern("length"), 0));
224
224
  }
225
225
 
226
+ static const struct rb_data_type_struct window_rbtype = {
227
+ .wrap_struct_name = "Ncurses::WINDOW",
228
+ };
226
229
  VALUE wrap_window(WINDOW* window)
227
230
  {
228
231
  if (window == 0) return Qnil;
@@ -231,7 +234,7 @@ VALUE wrap_window(WINDOW* window)
231
234
  VALUE window_adress = INT2NUM((long)(window));
232
235
  VALUE rb_window = rb_hash_aref(windows_hash, window_adress);
233
236
  if (rb_window == Qnil) {
234
- rb_window = Data_Wrap_Struct(cWINDOW, 0, 0, window);
237
+ rb_window = TypedData_Wrap_Struct(cWINDOW, &window_rbtype, window);
235
238
  rb_iv_set(rb_window, "@destroyed", Qfalse);
236
239
  rb_iv_set(rb_window, "@timeout", INT2FIX(-1));
237
240
  rb_hash_aset(windows_hash, window_adress, rb_window);
@@ -247,7 +250,7 @@ WINDOW* get_window(VALUE rb_window)
247
250
  rb_raise(eNcurses, "Attempt to access a destroyed window");
248
251
  return 0;
249
252
  }
250
- Data_Get_Struct(rb_window, WINDOW, window);
253
+ TypedData_Get_Struct(rb_window, WINDOW, &window_rbtype, window);
251
254
  return window;
252
255
  }
253
256
  static VALUE rbncurs_delwin(VALUE dummy, VALUE arg1) {
@@ -259,6 +262,9 @@ static VALUE rbncurs_delwin(VALUE dummy, VALUE arg1) {
259
262
  return INT2NUM(delwin(window));
260
263
  }
261
264
 
265
+ static const struct rb_data_type_struct screen_rbtype = {
266
+ .wrap_struct_name = "Ncurses::SCREEN",
267
+ };
262
268
  static VALUE wrap_screen(SCREEN* screen)
263
269
  {
264
270
  if (screen == 0) return Qnil;
@@ -267,7 +273,7 @@ static VALUE wrap_screen(SCREEN* screen)
267
273
  VALUE screen_adress = INT2NUM((long)(screen));
268
274
  VALUE rb_screen = rb_hash_aref(screens_hash, screen_adress);
269
275
  if (rb_screen == Qnil) {
270
- rb_screen = Data_Wrap_Struct(cSCREEN, 0, 0, screen);
276
+ rb_screen = TypedData_Wrap_Struct(cSCREEN, &screen_rbtype, screen);
271
277
  rb_iv_set(rb_screen, "@destroyed", Qfalse);
272
278
  rb_hash_aset(screens_hash, screen_adress, rb_screen);
273
279
  }
@@ -282,7 +288,7 @@ static SCREEN* get_screen(VALUE rb_screen)
282
288
  rb_raise(eNcurses, "Attempt to access a destroyed screen");
283
289
  return 0;
284
290
  }
285
- Data_Get_Struct(rb_screen, SCREEN, screen);
291
+ TypedData_Get_Struct(rb_screen, SCREEN, &screen_rbtype, screen);
286
292
  return screen;
287
293
  }
288
294
  #ifdef HAVE_DELSCREEN
@@ -580,8 +586,8 @@ static VALUE rbncurs_addch(VALUE dummy, VALUE arg1) {
580
586
  }
581
587
  #ifdef HAVE_ADD_WCH
582
588
  static VALUE rbncurs_add_wch(VALUE dummy, VALUE arg1) {
583
- wchar_t c = NUM2ULONG(arg1);
584
- return INT2NUM(add_wch((cchar_t *)&c));
589
+ cchar_t c = { 0, { NUM2ULONG(arg1), 0 } };
590
+ return INT2NUM(add_wch(&c));
585
591
  }
586
592
  #endif
587
593
  static VALUE rbncurs_addchnstr(VALUE dummy, VALUE arg1, VALUE arg2) {
@@ -850,28 +856,28 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
850
856
  int result;
851
857
  double starttime, nowtime, finishtime;
852
858
  double resize_delay = NUM2INT(get_RESIZEDELAY(mNcurses)) / 1000.0;
859
+ #ifdef HAVE_RB_THREAD_FD_SELECT
860
+ rb_fdset_t in_fds;
861
+ #else
853
862
  fd_set in_fds;
863
+ #endif
864
+ bool ready = false;
865
+ struct timeval tv;
854
866
  #ifdef HAVE_CLOCK_GETTIME
855
- struct timespec tv;
856
- struct timeval ts;
857
- clock_gettime (CLOCK_MONOTONIC, &tv);
858
- starttime = tv.tv_sec + tv.tv_nsec * 1e-9;
867
+ struct timespec ts;
868
+ clock_gettime (CLOCK_MONOTONIC, &ts);
869
+ starttime = ts.tv_sec + ts.tv_nsec * 1e-9;
859
870
  #else
860
- struct timeval tv;
861
871
  struct timezone tz = {0,0};
862
872
  gettimeofday(&tv, &tz);
863
873
  starttime = tv.tv_sec + tv.tv_usec * 1e-6;
864
874
  #endif
865
875
  finishtime = starttime + delay;
866
876
  wtimeout(c_win, 0);
867
- while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR) {
868
- #ifdef HAVE_RB_THREAD_FD_SELECT
869
- rb_fdset_t fdsets[3];
870
- rb_fdset_t *rfds = NULL;
871
- #endif
877
+ while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR && !ready) {
872
878
  #ifdef HAVE_CLOCK_GETTIME
873
- clock_gettime (CLOCK_MONOTONIC, &tv);
874
- nowtime = tv.tv_sec + tv.tv_nsec * 1e-9;
879
+ clock_gettime (CLOCK_MONOTONIC, &ts);
880
+ nowtime = ts.tv_sec + ts.tv_nsec * 1e-9;
875
881
  #else
876
882
  gettimeofday(&tv, &tz);
877
883
  nowtime = tv.tv_sec + tv.tv_usec * 1e-6;
@@ -882,38 +888,20 @@ static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_f
882
888
  /* Check for terminal size change every resize_delay seconds */
883
889
  if (resize_delay > delay) resize_delay = delay;
884
890
  tv.tv_sec = (time_t)resize_delay;
885
- #ifdef HAVE_CLOCK_GETTIME
886
- tv.tv_nsec = (unsigned)( (resize_delay - tv.tv_sec) * 1e9 );
887
- #else
888
891
  tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 );
889
- #endif
890
-
891
- #if HAVE_CLOCK_GETTIME
892
- ts.tv_sec = tv.tv_sec;
893
- ts.tv_usec = tv.tv_nsec * 1e-3;
894
- #endif
895
892
 
896
893
  /* sleep on infd until input is available or tv reaches timeout */
897
- FD_ZERO(&in_fds);
898
- FD_SET(infd, &in_fds);
899
-
900
894
  #ifdef HAVE_RB_THREAD_FD_SELECT
901
- rfds = &fdsets[0];
902
- rb_fd_init(rfds);
903
- rb_fd_copy(rfds, &in_fds, infd +1);
904
-
905
- #if HAVE_CLOCK_GETTIME
906
- rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &ts);
907
- #else
908
- rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &tv);
909
- #endif
910
-
911
- #else
912
- #if HAVE_CLOCK_GETTIME
913
- rb_thread_select(infd + 1, &in_fds, NULL, NULL, &ts);
895
+ rb_fd_init(&in_fds);
896
+ rb_fd_set(infd, &in_fds);
897
+ rb_thread_fd_select(infd + 1, &in_fds, NULL, NULL, &tv);
898
+ ready = rb_fd_isset(infd, &in_fds);
899
+ rb_fd_term(&in_fds);
914
900
  #else
901
+ FD_ZERO(&in_fds);
902
+ FD_SET(infd, &in_fds);
915
903
  rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv);
916
- #endif
904
+ ready = FD_ISSET(infd, &in_fds);
917
905
  #endif
918
906
  }
919
907
  wtimeout(c_win, windelay);
@@ -1126,7 +1114,9 @@ static VALUE rbncurs_is_wintouched(VALUE dummy, VALUE arg1) {
1126
1114
  return (is_wintouched(get_window(arg1))) ? Qtrue : Qfalse;
1127
1115
  }
1128
1116
  static VALUE rbncurs_keyname(VALUE dummy, VALUE arg1) {
1129
- return rb_str_new2(keyname(NUM2INT(arg1)));
1117
+ const char * str = keyname(NUM2INT(arg1));
1118
+ if (str == NULL) return Qnil;
1119
+ return rb_str_new2(str);
1130
1120
  }
1131
1121
  static VALUE rbncurs_keypad(VALUE dummy, VALUE arg1, VALUE arg2) {
1132
1122
  return INT2NUM(keypad(get_window(arg1), RTEST(arg2)));
@@ -1246,10 +1236,10 @@ static VALUE rbncurs_mvwchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, V
1246
1236
  static VALUE rbncurs_mvwdelch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1247
1237
  return INT2NUM(mvwdelch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
1248
1238
  }
1249
- static VALUE rbncurs_mvwgetch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1250
- WINDOW * c_win = get_window(arg1);
1251
- int windelay = NUM2INT(rb_iv_get(arg1, "@timeout"));
1252
- if (wmove(c_win, NUM2INT(arg1), NUM2INT(arg2)) == ERR)
1239
+ static VALUE rbncurs_mvwgetch(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x) {
1240
+ WINDOW * c_win = get_window(rb_win);
1241
+ int windelay = NUM2INT(rb_iv_get(rb_win, "@timeout"));
1242
+ if (wmove(c_win, NUM2INT(rb_y), NUM2INT(rb_x)) == ERR)
1253
1243
  return INT2NUM(ERR);
1254
1244
  return INT2NUM(rbncurshelper_nonblocking_wgetch(c_win, windelay));
1255
1245
  }
@@ -1442,7 +1432,9 @@ static VALUE rbncurs_slk_init(VALUE dummy, VALUE arg1) {
1442
1432
  return INT2NUM(slk_init(NUM2INT(arg1)));
1443
1433
  }
1444
1434
  static VALUE rbncurs_slk_label(VALUE dummy, VALUE arg1) {
1445
- return rb_str_new2(slk_label(NUM2INT(arg1)));
1435
+ char * str = slk_label(NUM2INT(arg1));
1436
+ if (str == NULL) return Qnil;
1437
+ return rb_str_new2(str);
1446
1438
  }
1447
1439
  static VALUE rbncurs_slk_noutrefresh(VALUE dummy) {
1448
1440
  return INT2NUM(slk_noutrefresh());
@@ -1495,7 +1487,9 @@ static VALUE rbncurs_tigetnum(VALUE dummy, VALUE arg1) {
1495
1487
  #endif
1496
1488
  #ifdef HAVE_TIGETSTR
1497
1489
  static VALUE rbncurs_tigetstr(VALUE dummy, VALUE arg1) {
1498
- return rb_str_new2(tigetstr(STR2CSTR(arg1)));
1490
+ char * str = tigetstr(STR2CSTR(arg1));
1491
+ if (str == NULL || str == (char *)-1) return Qnil;
1492
+ return rb_str_new2(str);
1499
1493
  }
1500
1494
  #endif
1501
1495
  static VALUE rbncurs_timeout(VALUE dummy, VALUE arg1) {
@@ -2078,7 +2072,6 @@ static void init_functions_2(void) {
2078
2072
  NCFUNC(wvline, 3);
2079
2073
  NCFUNC(color_content, 4);
2080
2074
  NCFUNC(pair_content, 3);
2081
- NCFUNC(pair_content, 3);
2082
2075
  #ifdef HAVE_GETWIN
2083
2076
  NCFUNC(getwin, 1);
2084
2077
  #endif
@@ -2375,7 +2368,7 @@ static VALUE rbncurs_mousemask(VALUE dummy, VALUE rb_newmask, VALUE rb_oldmask)
2375
2368
  #ifdef HAVE_WENCLOSE
2376
2369
  static VALUE rbncurs_wenclose(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
2377
2370
  {
2378
- return wenclose(get_window(rb_win), NUM2INT(rb_y), NUM2INT(rb_y))
2371
+ return wenclose(get_window(rb_win), NUM2INT(rb_y), NUM2INT(rb_x))
2379
2372
  ? Qtrue : Qfalse;
2380
2373
  }
2381
2374
  #endif
@@ -2837,7 +2830,11 @@ void init_SCREEN_methods(void)
2837
2830
 
2838
2831
  #ifdef HAVE_LOCALE_H
2839
2832
  static VALUE rbncurs_setlocale(VALUE dummy, VALUE category, VALUE locale)
2840
- { return rb_str_new2(setlocale(NUM2INT(category), STR2CSTR(locale)));}
2833
+ {
2834
+ char * str = setlocale(NUM2INT(category), STR2CSTR(locale));
2835
+ if (str == NULL) return Qnil;
2836
+ return rb_str_new2(str);
2837
+ }
2841
2838
  #endif
2842
2839
 
2843
2840
  static void init_safe_functions(void)
@@ -2881,6 +2878,9 @@ void Init_ncursesw_bin(void)
2881
2878
  }
2882
2879
  static void Init_ncurses_full(void)
2883
2880
  {
2881
+ static bool already_done = false;
2882
+ if (already_done) return;
2883
+
2884
2884
  init_globals_1();
2885
2885
  init_globals_2();
2886
2886
  init_functions_0();
@@ -2898,4 +2898,6 @@ static void Init_ncurses_full(void)
2898
2898
  #if defined(HAVE_MENU_H) || defined(HAVE_NCURSESW_MENU_H)
2899
2899
  init_menu();
2900
2900
  #endif
2901
+
2902
+ already_done = true;
2901
2903
  }
data/panel_wrap.c CHANGED
@@ -29,6 +29,14 @@
29
29
  VALUE mPanel;
30
30
  VALUE cPANEL;
31
31
 
32
+ static void panel_rb_mark(void * panel) {
33
+ const void * userptr = panel_userptr((PANEL*)panel);
34
+ if (userptr != NULL) rb_gc_mark((VALUE)userptr);
35
+ }
36
+ static const struct rb_data_type_struct panel_rbtype = {
37
+ .wrap_struct_name = "Ncurses::Panel::PANEL",
38
+ .function.dmark = panel_rb_mark,
39
+ };
32
40
  static VALUE wrap_panel(PANEL* panel)
33
41
  {
34
42
  if (panel == 0) return Qnil;
@@ -37,7 +45,7 @@ static VALUE wrap_panel(PANEL* panel)
37
45
  VALUE panel_adress = INT2NUM((long)(panel));
38
46
  VALUE rb_panel = rb_hash_aref(panels_hash, panel_adress);
39
47
  if (rb_panel == Qnil) {
40
- rb_panel = Data_Wrap_Struct(cPANEL, 0, 0, panel);
48
+ rb_panel = TypedData_Wrap_Struct(cPANEL, &panel_rbtype, panel);
41
49
  rb_iv_set(rb_panel, "@destroyed", Qfalse);
42
50
  rb_hash_aset(panels_hash, panel_adress, rb_panel);
43
51
  }
@@ -52,7 +60,7 @@ static PANEL* get_panel(VALUE rb_panel)
52
60
  rb_raise(rb_eRuntimeError, "Attempt to access a destroyed panel");
53
61
  return 0;
54
62
  }
55
- Data_Get_Struct(rb_panel, PANEL, panel);
63
+ TypedData_Get_Struct(rb_panel, PANEL, &panel_rbtype, panel);
56
64
  return panel;
57
65
  }
58
66
  static VALUE rbncurs_c_del_panel(VALUE rb_panel) {
metadata CHANGED
@@ -1,12 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncursesw
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.13
4
+ version: 1.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Herzke
8
8
  - Sup developers
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
  date: 1980-01-01 00:00:00.000000000 Z
@@ -50,7 +49,6 @@ homepage: http://github.com/sup-heliotrope/ncursesw-ruby
50
49
  licenses:
51
50
  - LGPL-2.1
52
51
  metadata: {}
53
- post_install_message:
54
52
  rdoc_options: []
55
53
  require_paths:
56
54
  - lib
@@ -65,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
63
  - !ruby/object:Gem::Version
66
64
  version: '0'
67
65
  requirements: []
68
- rubygems_version: 3.5.22
69
- signing_key:
66
+ rubygems_version: 3.7.2
70
67
  specification_version: 4
71
68
  summary: 'This wrapper provides access to the functions, macros, global variables
72
69
  and constants of the ncurses library. These are mapped to a Ruby Module named "Ncurses": Functions