[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-guile-ncurses] [PATCH 2/2] Do not allow menu's internal data to be
From: |
John Darrington |
Subject: |
[Bug-guile-ncurses] [PATCH 2/2] Do not allow menu's internal data to be destroyed, until the menu itself is destroyed. |
Date: |
Tue, 3 May 2016 13:30:07 +0200 |
* ncurses/menu_type.c, ncurses/menu_type.h: Remove guards for items container
and have the
memory owned by the menu itself, instead of the list used in its creation.
---
ncurses/menu_type.c | 16 +++++++---------
ncurses/menu_type.h | 3 +--
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/ncurses/menu_type.c b/ncurses/menu_type.c
index 712cd35..277891f 100644
--- a/ncurses/menu_type.c
+++ b/ncurses/menu_type.c
@@ -259,7 +259,6 @@ mark_menu (SCM x)
scm_assert_smob_type (menu_tag, x);
gm = (struct gucu_menu *) SCM_SMOB_DATA (x);
- scm_gc_mark (gm->items_guard);
scm_gc_mark (gm->win_guard);
return (gm->subwin_guard);
@@ -272,11 +271,15 @@ gc_free_menu (SCM x)
{
struct gucu_menu *gm;
int retval;
+ ITEM **items;
scm_assert_smob_type (menu_tag, x);
gm = (struct gucu_menu *) SCM_SMOB_DATA (x);
+ items = SCM_SMOB_DATA_2 (x);
+ free (items);
+
assert (gm != NULL);
retval = free_menu (gm->menu);
@@ -304,8 +307,6 @@ gc_free_menu (SCM x)
}
/* Release scheme objects from the guardians */
- while (scm_is_true (scm_call_0 (gm->items_guard)))
- ;
while (scm_is_true (scm_call_0 (gm->win_guard)))
;
while (scm_is_true (scm_call_0 (gm->subwin_guard)))
@@ -372,13 +373,15 @@ gucu_new_menu (SCM items)
// Step 1: allocate memory
gm = scm_gc_malloc (sizeof (struct gucu_menu), "gucu_menu");
- c_items = scm_gc_malloc (sizeof (ITEM *) * (len + 1), "gucu_menu");
+ c_items = calloc (len + 1, sizeof (ITEM *));
// Step 2: initialize it with C code
// Step 3: create the smob
SCM_NEWSMOB (smob, menu_tag, gm);
+ SCM_SET_SMOB_DATA_2 (smob, c_items);
+
// Step 4: finish the initialization
for (i = 0; i < len; i++)
{
@@ -411,18 +414,13 @@ gucu_new_menu (SCM items)
scm_remember_upto_here_1 (items);
#ifndef GUILE_1_POINT_6
- gm->items_guard = scm_make_guardian ();
gm->win_guard = scm_make_guardian ();
gm->subwin_guard = scm_make_guardian ();
#else
- gm->items_guard = scm_make_guardian (SCM_BOOL_F);
gm->win_guard = scm_make_guardian (SCM_BOOL_F);
gm->subwin_guard = scm_make_guardian (SCM_BOOL_F);
#endif
- /* Guard the items list */
- scm_call_1 (gm->items_guard, items);
-
return smob;
}
diff --git a/ncurses/menu_type.h b/ncurses/menu_type.h
index 6a17e34..94291ed 100644
--- a/ncurses/menu_type.h
+++ b/ncurses/menu_type.h
@@ -48,8 +48,7 @@ struct gucu_menu
// Pointer to the menu
MENU *menu;
- /* Guardians to hold the items, window, and subwindow SCM objects */
- SCM items_guard;
+ /* Guardians to hold the window, and subwindow SCM objects */
SCM win_guard;
SCM subwin_guard;
};
--
2.1.4
- [Bug-guile-ncurses] Segmentation violations in menus, John Darrington, 2016/05/03
- [Bug-guile-ncurses] [PATCH 1/2] Add reference count to ITEM structs contained by SCMs, John Darrington, 2016/05/03
- Re: [Bug-guile-ncurses] [PATCH 1/2] Add reference count to ITEM structs contained by SCMs, John Darrington, 2016/05/03
- Re: [Bug-guile-ncurses] [PATCH 1/2] Add reference count to ITEM structs contained by SCMs, Mike Gran, 2016/05/03
- Re: [Bug-guile-ncurses] [PATCH 1/2] Add reference count to ITEM structs contained by SCMs, John Darrington, 2016/05/03
- Re: [Bug-guile-ncurses] [PATCH 1/2] Add reference count to ITEM structs contained by SCMs, Mike Gran, 2016/05/26
- Re: [Bug-guile-ncurses] [PATCH 1/2] Add reference count to ITEM structs contained by SCMs, John Darrington, 2016/05/26
- Re: [Bug-guile-ncurses] [PATCH 1/2] Add reference count to ITEM structs contained by SCMs, Mike Gran, 2016/05/26
[Bug-guile-ncurses] [PATCH 2/2] Do not allow menu's internal data to be destroyed, until the menu itself is destroyed.,
John Darrington <=