[1851] in BarnOwl Developers
[PATCH 7/7] Add owl_new_hv for future Perl code
daemon@ATHENA.MIT.EDU (David Benjamin)
Thu Oct 29 18:23:13 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@lunatique.mit.edu
From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Sat, 24 Oct 2009 13:43:41 -0400
In-Reply-To: <1256406221-22905-7-git-send-email-davidben@mit.edu>
While we're at it, might as well make it easy to export dictionaries in
future.
Signed-off-by: David Benjamin <davidben@mit.edu>
---
perlconfig.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/perlconfig.c b/perlconfig.c
index 5b34fe8..8b31e4a 100644
--- a/perlconfig.c
+++ b/perlconfig.c
@@ -51,6 +51,28 @@ AV *owl_new_av(const owl_list *l, SV *(*to_sv)(const void *))
return ret;
}
+HV *owl_new_hv(const owl_dict *d, SV *(*to_sv)(const void *))
+{
+ HV *ret;
+ owl_list l;
+ const char *key;
+ void *element;
+ int i;
+
+ ret = newHV();
+
+ /* TODO: add an iterator-like interface to owl_dict */
+ owl_dict_get_keys(d, &l);
+ for(i = 0; i < owl_list_get_size(&l); i++) {
+ key = owl_list_get_element(&l, i);
+ element = owl_dict_find_element(d, key);
+ (void)hv_store(ret, key, strlen(key), to_sv(element), 0);
+ }
+ owl_list_free_all(&l, owl_free);
+
+ return ret;
+}
+
SV *owl_perlconfig_message2hashref(const owl_message *m)
{
HV *h, *stash;
--
1.6.3.3