From 0c09333ce888adc7c3120c4be3e3682884a89ad6 Mon Sep 17 00:00:00 2001 From: Charles Day Date: Fri, 20 Feb 2009 04:37:28 +0000 Subject: [PATCH] Bug #570887: Change the swig type mapping for GUID* so that Scheme can tell the difference between a GUID* that is NULL, and a GUID* pointing to storage containing the "null" GUID. Previously the former case returned SCM_UNDEFINED to Scheme, which would unbind Scheme variables and make crashes. Now SCM_BOOL_F is used instead, and Scheme code can check for a NULL by comparing to #f. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17939 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/base-typemaps.i | 2 +- src/engine/engine-helpers.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/base-typemaps.i b/src/base-typemaps.i index 8878bfb44a..baac9f57c3 100644 --- a/src/base-typemaps.i +++ b/src/base-typemaps.i @@ -30,7 +30,7 @@ typedef char gchar; %typemap(in) GUID "$1 = gnc_scm2guid($input);" %typemap(out) GUID "$result = gnc_guid2scm($1);" %typemap(in) GUID * (GUID g) " g = gnc_scm2guid($input); $1 = &g; " -%typemap(out) GUID * " $result = ($1) ? gnc_guid2scm(*($1)): SCM_UNDEFINED; " +%typemap(out) GUID * " $result = ($1) ? gnc_guid2scm(*($1)): SCM_BOOL_F; " %typemap(in) gnc_numeric "$1 = gnc_scm_to_numeric($input);" %typemap(out) gnc_numeric "$result = gnc_numeric_to_scm($1);" diff --git a/src/engine/engine-helpers.c b/src/engine/engine-helpers.c index e117eb22e9..6ce60d0129 100644 --- a/src/engine/engine-helpers.c +++ b/src/engine/engine-helpers.c @@ -125,7 +125,7 @@ gnc_guid2scm(GUID guid) char string[GUID_ENCODING_LENGTH + 1]; if (!guid_to_string_buff(&guid, string)) - return SCM_UNDEFINED; + return SCM_BOOL_F; return scm_makfrom0str(string); } @@ -409,10 +409,13 @@ gnc_scm2guid_glist (SCM guids_scm) while (!SCM_NULLP (guids_scm)) { SCM guid_scm = SCM_CAR (guids_scm); - GUID *guid; + GUID *guid = NULL; - guid = guid_malloc (); - *guid = gnc_scm2guid (guid_scm); + if (guids_scm != SCM_BOOL_F) + { + guid = guid_malloc (); + *guid = gnc_scm2guid (guid_scm); + } guids = g_list_prepend (guids, guid); @@ -663,8 +666,13 @@ gnc_scm2KvpValue (SCM value_scm) } case KVP_TYPE_GUID: { - GUID guid = gnc_scm2guid (val_scm); - value = kvp_value_new_guid (&guid); + if (val_scm != SCM_BOOL_F) + { + GUID guid = gnc_scm2guid (val_scm); + value = kvp_value_new_guid (&guid); + } + else + value = NULL; break; }