[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-guile-ncurses] [PATCH 1/2] Add reference count to ITEM structs cont
From: |
John Darrington |
Subject: |
[Bug-guile-ncurses] [PATCH 1/2] Add reference count to ITEM structs contained by SCMs |
Date: |
Tue, 3 May 2016 13:22:34 +0200 |
* ncurses/menu_type.c (_scm_from_item, new_item, free_item): Add reference
counting.
---
ncurses/menu_type.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/ncurses/menu_type.c b/ncurses/menu_type.c
index 679e9c1..712cd35 100644
--- a/ncurses/menu_type.c
+++ b/ncurses/menu_type.c
@@ -88,6 +88,8 @@ gucu_new_item (SCM name, SCM description)
abort ();
}
+ /* Use the userptr member as a reference count */
+ set_item_userptr (c_item, 0);
SCM ret = _scm_from_item (c_item);
return ret;
@@ -117,6 +119,9 @@ _scm_from_item (ITEM * x)
assert (x == (ITEM *) SCM_SMOB_DATA (s_item));
+ intptr_t refcnt = (intptr_t) item_userptr (x);
+ set_item_userptr (x, (void *) (++refcnt));
+
if (0)
{
fprintf (stderr, "Making <#item> smob from ITEM * %p\n", (void *) x);
@@ -157,7 +162,11 @@ gc_free_item (SCM item)
assert (m != NULL);
- free_item (m);
+ intptr_t refcnt = (intptr_t) item_userptr (m);
+ set_item_userptr (m, (void *) (--refcnt));
+
+ if (refcnt == 0)
+ free_item (m);
return 0;
}
--
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 <=
- 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, 2016/05/03