From 3ee7480b50363146bdba4fcfb3af4eaa473cb405 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Sun, 27 Jul 2014 12:30:59 +0200
Subject: [PATCH] Object: Added secure().

This function sets the OBJECT_CLEAR_ON_EXIT flag on the provided
object (analogous to String.secure() and STRING_CLEAR_ON_EXIT).

Also fixes the documented type of String.secure().
---
 lib/modules/Object.pmod |  2 ++
 src/builtin.cmod        | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/lib/modules/Object.pmod b/lib/modules/Object.pmod
index 5acdfa2071..8511a9f3fe 100644
--- a/lib/modules/Object.pmod
+++ b/lib/modules/Object.pmod
@@ -11,3 +11,5 @@ constant DESTRUCT_CLEANUP = __builtin.DESTRUCT_CLEANUP;
 //! @note
 //! @[Object.DESTRUCT_EXPLICIT] is @expr{0@} and
 //! @[Object.DESTRUCT_CLEANUP] is @expr{1@} for compatibility.
+
+constant secure = __builtin.object_secure;
diff --git a/src/builtin.cmod b/src/builtin.cmod
index 6f47de33de..3487745644 100644
--- a/src/builtin.cmod
+++ b/src/builtin.cmod
@@ -1336,7 +1336,7 @@ PIKEFUN mapping(1:2) mkmapping(array(1=mixed) ind, array(2=mixed) val)
   RETURN mkmapping(ind, val);
 }
 
-/*! @decl void secure(string str)
+/*! @decl string secure(string str)
  *! @belongs String
  *!
  *! Marks the string as secure, which will clear the memory area
@@ -1350,6 +1350,20 @@ PIKEFUN string string_secure(string str)
   REF_RETURN str;
 }
 
+/*! @decl object secure(object str)
+ *! @belongs Object
+ *!
+ *! Marks the object as secure, which will clear the memory area
+ *! before freeing the object.
+ */
+PIKEFUN object object_secure(object obj)
+  optflags OPT_SIDE_EFFECT;
+  rawtype tFunc(tSetvar(0, tObj), tVar(0));
+{
+  obj->flags |= OBJECT_CLEAR_ON_EXIT;
+  REF_RETURN obj;
+}
+
 /*! @decl int count(string haystack, string needle)
  *! @belongs String
  *!
-- 
GitLab