ncursesw 1.4.15 → 1.4.16

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
  SHA256:
3
- metadata.gz: 8a9aff5809632dcf68381285d9af26cf2654291b79621714e81bc257b3fcd7ae
4
- data.tar.gz: 96b081e074414294b6dbcff4e46e31c15d6f1c4f6d1382c28028998453e0589e
3
+ metadata.gz: e2c5df509b86fbeb163dd7b2ab4a951f9517f2a9ed295df95253f743b7ea3526
4
+ data.tar.gz: cf6054e27fa48239d8cdbe85e62b2e496a1bad011024a548e3c51af99feab9cb
5
5
  SHA512:
6
- metadata.gz: 59fe81fba2e564c1fbaaadc5ba67a8662ca8d528e0471b934edce668c93ba720db7e5c93fb9979d213022ffad48f5fa937c049ace6e9da1ceb98b64c18824a84
7
- data.tar.gz: 764c2878d6c11f2e88643f43b5052229ec902a32d47839df41c2ccbe563070572c9b94fddd0e7aa433c3a4519862b6569e41351798522d0ed95b0080f49a96cf
6
+ metadata.gz: bafd7a13fdd4c7b1cbd0727e3dac31e8e5994d45ae0b37f792d9dbffc74c2eb72b00cd6bb4a97b7a31de1cf4b28c727d5e2ec0516298cfc75723eb9a52d4ecc3
7
+ data.tar.gz: 9181443ee8e1dc431f6cc6979d29f2099f9e0bacd483f8f2f6e9d8b8f6062d13429cfc371d40faea60a5578203bdbb50494a2e6fac6edbf25456f627816451f9
data/Changes CHANGED
@@ -1,3 +1,9 @@
1
+ ncurses-ruby-1.4.16
2
+ * Ncurses.stdscr, Ncurses.curscr, and Ncurses.newscr are now looked up
3
+ from the C side on every access instead of caching them in Ruby, to
4
+ avoid use-after-free issues when the pointers are freed, for example
5
+ by Ncurses.delscreen.
6
+
1
7
  ncurses-ruby-1.4.15
2
8
  * Fixed leaked rb_fdset object in every iteration of getch()/wgetch().
3
9
  * Fixed busy-loop in getch()/wgetch() when input reaches EOF.
data/form_wrap.c CHANGED
@@ -228,7 +228,7 @@ void init_form_opts_constants() {
228
228
  /* if (page == 0) return Qnil; */
229
229
  /* { */
230
230
  /* VALUE pages_hash = rb_iv_get(mForm, "@pages_hash"); */
231
- /* VALUE page_adress = INT2NUM((long)(page)); */
231
+ /* VALUE page_adress = RBNCURS_PTR_KEY(page); */
232
232
  /* VALUE rb_page = rb_hash_aref(pages_hash, page_adress); */
233
233
  /* if (rb_page == Qnil) { */
234
234
  /* rb_page = Data_Wrap_Struct(cPAGE, 0, 0, page); */
@@ -261,7 +261,7 @@ static VALUE wrap_field(FIELD* field)
261
261
  if (field == 0) return Qnil;
262
262
  {
263
263
  VALUE fields_hash = rb_iv_get(mForm, "@fields_hash");
264
- VALUE field_adress = INT2NUM((long)(field));
264
+ VALUE field_adress = RBNCURS_PTR_KEY(field);
265
265
  VALUE rb_field = rb_hash_aref(fields_hash, field_adress);
266
266
  if (rb_field == Qnil) {
267
267
  rb_field = TypedData_Wrap_Struct(cFIELD, &field_rbtype, field);
@@ -294,7 +294,7 @@ static VALUE wrap_fieldtype(FIELDTYPE* fieldtype)
294
294
  if (fieldtype == NULL) return Qnil;
295
295
  {
296
296
  VALUE fieldtypes_hash = rb_iv_get(mForm, "@fieldtypes_hash");
297
- VALUE fieldtype_adress = INT2NUM((long)(fieldtype));
297
+ VALUE fieldtype_adress = RBNCURS_PTR_KEY(fieldtype);
298
298
  VALUE rb_fieldtype = rb_hash_aref(fieldtypes_hash, fieldtype_adress);
299
299
  if (rb_fieldtype == Qnil) {
300
300
  rb_fieldtype = TypedData_Wrap_Struct(cFIELDTYPE, &fieldtype_rbtype, fieldtype);
@@ -327,7 +327,7 @@ static VALUE wrap_form(FORM* form)
327
327
  if (form == 0) return Qnil;
328
328
  {
329
329
  VALUE forms_hash = rb_iv_get(mForm, "@forms_hash");
330
- VALUE form_adress = INT2NUM((long)(form));
330
+ VALUE form_adress = RBNCURS_PTR_KEY(form);
331
331
  VALUE rb_form = rb_hash_aref(forms_hash, form_adress);
332
332
  if (rb_form == Qnil) {
333
333
  rb_form = TypedData_Wrap_Struct(cFORM, &form_rbtype, form);
@@ -380,7 +380,7 @@ static VALUE get_proc_hash(int hook) {
380
380
  static VALUE get_proc(void* owner, int hook) {
381
381
  if (owner == 0) return Qnil;
382
382
  {
383
- VALUE owner_adress = INT2NUM((long)(owner));
383
+ VALUE owner_adress = RBNCURS_PTR_KEY(owner);
384
384
  VALUE proc_hash = get_proc_hash(hook);
385
385
  VALUE proc = rb_hash_aref(proc_hash, owner_adress);
386
386
  return proc;
@@ -394,7 +394,7 @@ static void reg_proc(void* owner, int hook, VALUE proc) {
394
394
  if (owner == NULL) return;
395
395
  {
396
396
  VALUE proc_hash = get_proc_hash(hook);
397
- VALUE owner_address = INT2NUM((long)(owner));
397
+ VALUE owner_address = RBNCURS_PTR_KEY(owner);
398
398
  if (proc == Qnil) {
399
399
  rb_hash_delete(proc_hash, owner_address);
400
400
  }
@@ -423,7 +423,7 @@ static VALUE rbncurs_m_new_form(VALUE dummy, VALUE rb_field_array)
423
423
  static VALUE rbncurs_c_free_form(VALUE rb_form) {
424
424
  VALUE forms_hash = rb_iv_get(mForm, "@forms_hash");
425
425
  FORM* form = get_form(rb_form);
426
- VALUE form_adress = INT2NUM((long)(form));
426
+ VALUE form_adress = RBNCURS_PTR_KEY(form);
427
427
  rb_funcall(forms_hash, rb_intern("delete"), 1, form_adress);
428
428
  rb_iv_set(rb_form, "@destroyed", Qtrue);
429
429
  return INT2NUM(free_form(form));
@@ -555,7 +555,7 @@ static VALUE rbncurs_m_link_field(VALUE dummy, VALUE rb_field, VALUE toprow, VAL
555
555
  static VALUE rbncurs_c_free_field(VALUE rb_field) {
556
556
  VALUE fields_hash = rb_iv_get(mForm, "@fields_hash");
557
557
  FIELD* field = get_field(rb_field);
558
- VALUE field_adress = INT2NUM((long)(field));
558
+ VALUE field_adress = RBNCURS_PTR_KEY(field);
559
559
  rb_funcall(fields_hash, rb_intern("delete"), 1, field_adress);
560
560
  rb_iv_set(rb_field, "@destroyed", Qtrue);
561
561
  return INT2NUM(free_field(field));
data/menu_wrap.c CHANGED
@@ -149,7 +149,7 @@ static VALUE wrap_item(ITEM *item)
149
149
  if (item == 0) return Qnil;
150
150
  {
151
151
  VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
152
- VALUE item_address = INT2NUM((long)(item));
152
+ VALUE item_address = RBNCURS_PTR_KEY(item);
153
153
  VALUE rb_item = rb_hash_aref(items_hash, item_address);
154
154
 
155
155
  if (rb_item == Qnil)
@@ -187,7 +187,7 @@ static VALUE wrap_menu(MENU *menu)
187
187
  if (menu == 0) return Qnil;
188
188
  {
189
189
  VALUE menus_hash = rb_iv_get(mMenu, "@menus_hash");
190
- VALUE menu_address = INT2NUM((long)(menu));
190
+ VALUE menu_address = RBNCURS_PTR_KEY(menu);
191
191
  VALUE rb_menu = rb_hash_aref(menus_hash, menu_address);
192
192
 
193
193
  if (rb_menu == Qnil)
@@ -242,7 +242,7 @@ static VALUE get_proc(void *owner, int hook)
242
242
  {
243
243
  if (owner == 0) return Qnil;
244
244
  {
245
- VALUE owner_address = INT2NUM((long)(owner));
245
+ VALUE owner_address = RBNCURS_PTR_KEY(owner);
246
246
  VALUE proc_hash = get_proc_hash(hook);
247
247
  VALUE proc = rb_hash_aref(proc_hash, owner_address);
248
248
 
@@ -259,7 +259,7 @@ static void reg_proc(void *owner, int hook, VALUE proc)
259
259
  if (owner == NULL) return;
260
260
  {
261
261
  VALUE proc_hash = get_proc_hash(hook);
262
- VALUE owner_address = INT2NUM((long)(owner));
262
+ VALUE owner_address = RBNCURS_PTR_KEY(owner);
263
263
 
264
264
  if (proc == Qnil)
265
265
  rb_hash_delete(proc_hash, owner_address);
@@ -289,7 +289,7 @@ static VALUE rbncurs_c_free_menu(VALUE rb_menu)
289
289
  {
290
290
  VALUE menus_hash = rb_iv_get(mMenu, "@menus_hash");
291
291
  MENU *menu = get_menu(rb_menu);
292
- VALUE menu_address = INT2NUM((long)(menu));
292
+ VALUE menu_address = RBNCURS_PTR_KEY(menu);
293
293
 
294
294
  rb_funcall(menus_hash, rb_intern("delete"), 1, menu_address);
295
295
  rb_iv_set(rb_menu, "@destroyed", Qtrue);
@@ -396,7 +396,7 @@ static VALUE rbncurs_c_free_item(VALUE rb_item)
396
396
  {
397
397
  VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
398
398
  ITEM *item = get_item(rb_item);
399
- VALUE item_address = INT2NUM((long)(item));
399
+ VALUE item_address = RBNCURS_PTR_KEY(item);
400
400
  char *c_name = (char *)item_name(item);
401
401
  char *c_desc = (char *)item_description(item);
402
402
  int result = free_item(item);
data/ncurses_wrap.c CHANGED
@@ -231,7 +231,7 @@ VALUE wrap_window(WINDOW* window)
231
231
  if (window == 0) return Qnil;
232
232
  {
233
233
  VALUE windows_hash = rb_iv_get(mNcurses, "@windows_hash");
234
- VALUE window_adress = INT2NUM((long)(window));
234
+ VALUE window_adress = RBNCURS_PTR_KEY(window);
235
235
  VALUE rb_window = rb_hash_aref(windows_hash, window_adress);
236
236
  if (rb_window == Qnil) {
237
237
  rb_window = TypedData_Wrap_Struct(cWINDOW, &window_rbtype, window);
@@ -256,7 +256,7 @@ WINDOW* get_window(VALUE rb_window)
256
256
  static VALUE rbncurs_delwin(VALUE dummy, VALUE arg1) {
257
257
  VALUE windows_hash = rb_iv_get(mNcurses, "@windows_hash");
258
258
  WINDOW* window = get_window(arg1);
259
- VALUE window_adress = INT2NUM((long)(window));
259
+ VALUE window_adress = RBNCURS_PTR_KEY(window);
260
260
  rb_funcall(windows_hash, rb_intern("delete"), 1, window_adress);
261
261
  rb_iv_set(arg1, "@destroyed", Qtrue);
262
262
  return INT2NUM(delwin(window));
@@ -270,7 +270,7 @@ static VALUE wrap_screen(SCREEN* screen)
270
270
  if (screen == 0) return Qnil;
271
271
  {
272
272
  VALUE screens_hash = rb_iv_get(mNcurses, "@screens_hash");
273
- VALUE screen_adress = INT2NUM((long)(screen));
273
+ VALUE screen_adress = RBNCURS_PTR_KEY(screen);
274
274
  VALUE rb_screen = rb_hash_aref(screens_hash, screen_adress);
275
275
  if (rb_screen == Qnil) {
276
276
  rb_screen = TypedData_Wrap_Struct(cSCREEN, &screen_rbtype, screen);
@@ -295,7 +295,7 @@ static SCREEN* get_screen(VALUE rb_screen)
295
295
  static VALUE rbncurs_delscreen(VALUE dummy, VALUE arg1) {
296
296
  VALUE screens_hash = rb_iv_get(mNcurses, "@screens_hash");
297
297
  SCREEN* screen = get_screen(arg1);
298
- VALUE screen_adress = INT2NUM((long)(screen));
298
+ VALUE screen_adress = RBNCURS_PTR_KEY(screen);
299
299
  rb_funcall(screens_hash, rb_intern("delete"), 1, screen_adress);
300
300
  rb_iv_set(arg1, "@destroyed", Qtrue);
301
301
  delscreen(screen);
@@ -377,34 +377,10 @@ init_functions_0(void)
377
377
  NCFUNC(wgetnstr, 3);
378
378
  }
379
379
 
380
- static VALUE get_stdscr(VALUE dummy)
381
- {
382
- VALUE rb_stdscr = rb_iv_get(mNcurses, "@stdscr");
383
- if (rb_stdscr == Qnil) {
384
- rb_stdscr = wrap_window(stdscr);
385
- rb_iv_set(mNcurses, "@stdscr", rb_stdscr);
386
- }
387
- return rb_stdscr;
388
- }
389
- static VALUE get_curscr(VALUE dummy)
390
- {
391
- VALUE rb_curscr = rb_iv_get(mNcurses, "@curscr");
392
- if (rb_curscr == Qnil) {
393
- rb_curscr = wrap_window(curscr);
394
- rb_iv_set(mNcurses, "@curscr", rb_curscr);
395
- }
396
- return rb_curscr;
397
- }
380
+ static VALUE get_stdscr(VALUE dummy) {return wrap_window(stdscr);}
381
+ static VALUE get_curscr(VALUE dummy) {return wrap_window(curscr);}
398
382
  #ifdef HAVE_NEWSCR
399
- static VALUE get_newscr(VALUE dummy)
400
- {
401
- VALUE rb_newscr = rb_iv_get(mNcurses, "@newscr");
402
- if (rb_newscr == Qnil) {
403
- rb_newscr = wrap_window(newscr);
404
- rb_iv_set(mNcurses, "@newscr", rb_newscr);
405
- }
406
- return rb_newscr;
407
- }
383
+ static VALUE get_newscr(VALUE dummy) {return wrap_window(newscr);}
408
384
  #endif
409
385
  static VALUE get_LINES(VALUE dummy) {return INT2NUM(LINES);}
410
386
  static VALUE get_COLS(VALUE dummy) {return INT2NUM(COLS);}
@@ -440,10 +416,6 @@ static
440
416
  void
441
417
  init_globals_2(void)
442
418
  {
443
- rb_iv_set(mNcurses, "@stdscr", Qnil);
444
- rb_iv_set(mNcurses, "@curscr", Qnil);
445
- rb_iv_set(mNcurses, "@newscr", Qnil);
446
-
447
419
  rb_define_module_function(mNcurses, "stdscr",
448
420
  (&get_stdscr), 0);
449
421
  rb_define_module_function(mNcurses, "curscr",
data/ncurses_wrap.h CHANGED
@@ -88,6 +88,7 @@ int close(int);
88
88
  # endif
89
89
  #endif
90
90
 
91
+ #include <stdint.h>
91
92
  #include <ruby.h>
92
93
 
93
94
  extern VALUE mNcurses; /* module Ncurses */
@@ -101,6 +102,8 @@ extern VALUE eNcurses; /* Ncurses::Exception thrown by this extension */
101
102
  &rbncurs_ ## name, \
102
103
  nargs)
103
104
 
105
+ #define RBNCURS_PTR_KEY(ptr) ULL2NUM((uintptr_t)(ptr))
106
+
104
107
  WINDOW* get_window(VALUE rb_window);
105
108
  VALUE wrap_window(WINDOW* window);
106
109
  long rbncurs_array_length(VALUE rb_array);
data/panel_wrap.c CHANGED
@@ -42,7 +42,7 @@ static VALUE wrap_panel(PANEL* panel)
42
42
  if (panel == 0) return Qnil;
43
43
  {
44
44
  VALUE panels_hash = rb_iv_get(mPanel, "@panels_hash");
45
- VALUE panel_adress = INT2NUM((long)(panel));
45
+ VALUE panel_adress = RBNCURS_PTR_KEY(panel);
46
46
  VALUE rb_panel = rb_hash_aref(panels_hash, panel_adress);
47
47
  if (rb_panel == Qnil) {
48
48
  rb_panel = TypedData_Wrap_Struct(cPANEL, &panel_rbtype, panel);
@@ -66,7 +66,7 @@ static PANEL* get_panel(VALUE rb_panel)
66
66
  static VALUE rbncurs_c_del_panel(VALUE rb_panel) {
67
67
  VALUE panels_hash = rb_iv_get(mPanel, "@panels_hash");
68
68
  PANEL* panel = get_panel(rb_panel);
69
- VALUE panel_adress = INT2NUM((long)(panel));
69
+ VALUE panel_adress = RBNCURS_PTR_KEY(panel);
70
70
  rb_funcall(panels_hash, rb_intern("delete"), 1, panel_adress);
71
71
  rb_iv_set(rb_panel, "@destroyed", Qtrue);
72
72
  return INT2NUM(del_panel(panel));
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncursesw
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.15
4
+ version: 1.4.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Herzke