From d89343bf6959e8a0f9bf891a8773daf6b8a9825b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 8 Mar 2019 10:12:04 +0100 Subject: Add copy-vevent. --- guile_interface.scm.c | 17 +++++++++++++++++ vcal.h | 15 +++++++++++++++ vcalendar.scm | 3 +-- vcalendar/primitive.scm | 4 +++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/guile_interface.scm.c b/guile_interface.scm.c index 2dcff513..a134848d 100644 --- a/guile_interface.scm.c +++ b/guile_interface.scm.c @@ -177,6 +177,23 @@ SCM_DEFINE(vcomponent_attr_list, "%vcomponent-attribute-list", 1, 0, 0, return llist; } +SCM_DEFINE(vcomponent_shallow_copy, "%vcomponent-shallow-copy", 1, 0, 0, + (SCM component), + "Creates a shallow copy of the given component.") +{ + scm_assert_foreign_object_type (vcomponent_type, component); + vcomponent* src = scm_foreign_object_ref (component, 0); + + vcomponent* dest = + (vcomponent*) scm_gc_malloc ( + sizeof(*dest), "vcomponent"); + INIT(vcomponent, dest, src->type, NULL); + + vcomponent_copy (dest, src); + return scm_make_foreign_object_1 + (vcomponent_type, dest); +} + void init_lib (void) { init_vcomponent_type(); diff --git a/vcal.h b/vcal.h index 798a00a1..1dfc5b17 100644 --- a/vcal.h +++ b/vcal.h @@ -73,6 +73,11 @@ struct s_vcomponent { TRIE(content_line) clines; LLIST(vcomponent) components; + /* + * Holds a Guile representation of this object. Used to always + * return the same foreign (for guile) object for the same + * vcomponent. + */ SCM scm; }; @@ -96,8 +101,18 @@ char* vcomponent_get_val (vcomponent*, const char* key); */ int PUSH(vcomponent)(vcomponent*, vcomponent*); +/* + * Deep copy is currently not implemented for vcomponentes. + * The reason for this method being here is since some + * generic methods in other places complain otherwise. + */ int DEEP_COPY(vcomponent)(vcomponent*, vcomponent*); +/* + * "Shallow" copy of vcomponent. + */ +int vcomponent_copy(vcomponent*, vcomponent*); + FMT_F(vcomponent); #endif /* VCAL_H */ diff --git a/vcalendar.scm b/vcalendar.scm index 603aefea..89dd682b 100644 --- a/vcalendar.scm +++ b/vcalendar.scm @@ -59,5 +59,4 @@ (transformer (attr ev field)))) - - +(define-public copy-vcomponent %vcomponent-shallow-copy) diff --git a/vcalendar/primitive.scm b/vcalendar/primitive.scm index b4ba1f38..e575115c 100644 --- a/vcalendar/primitive.scm +++ b/vcalendar/primitive.scm @@ -12,7 +12,9 @@ %vcomponent-set-attribute! %vcomponent-get-attribute - %vcomponent-attribute-list)) + %vcomponent-attribute-list + + %vcomponent-shallow-copy)) (setenv "LD_LIBRARY_PATH" (dirname (dirname (current-filename)))) (load-extension "libguile-calendar" "init_lib") -- cgit v1.2.3