[perl-Glib] Add gperl_hv_take_sv, a wrapper for hv_store



commit f2e674a60da1ae65de134c9e426ddcaf12e9288f
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Thu Jun 18 20:33:54 2009 +0200

    Add gperl_hv_take_sv, a wrapper for hv_store
    
    If hv_store failed, gperl_hv_take_sv will decrease the SV's reference count.
    And it only accepts string literals for the key so that the length parameter is
    unnecessary.

 gperl.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/gperl.h b/gperl.h
index 6a322be..d0914c8 100644
--- a/gperl.h
+++ b/gperl.h
@@ -85,6 +85,16 @@ gboolean gperl_sv_is_defined (SV *sv);
 #define gperl_sv_is_hash_ref(sv) \
 	(gperl_sv_is_defined (sv) && SvROK (sv) && SvTYPE (SvRV(sv)) == SVt_PVHV)
 
+/* try to store an SV in an HV.  decrease the SV's reference count if something
+ * went wrong.  key must be a string literal. */
+#define gperl_hv_take_sv(hv, key, sv) \
+	G_STMT_START { \
+		SV *tmp = sv; \
+		if (!hv_store (hv, key, sizeof(key) - 1, tmp, 0)) { \
+			sv_free (tmp); \
+		} \
+	} G_STMT_END
+
 /* internal trickery */
 gpointer gperl_type_class (GType type);
 /*



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]