From 1dc55b63d82f8b5f9fc806d51da79408b79693e0 Mon Sep 17 00:00:00 2001
From: Martin Stjernholm <mast@lysator.liu.se>
Date: Fri, 17 Dec 2004 17:25:03 +0100
Subject: [PATCH] Make it possible to feed a backtrace to the error objects.

Rev: src/error.c:1.142
Rev: src/errors.h:1.29
---
 src/error.c  | 29 +++++++++++++++++++++--------
 src/errors.h |  4 ++--
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/src/error.c b/src/error.c
index d22cdc7363..5768df6ef5 100644
--- a/src/error.c
+++ b/src/error.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: error.c,v 1.141 2004/11/14 17:44:05 mast Exp $
+|| $Id: error.c,v 1.142 2004/12/17 16:25:03 mast Exp $
 */
 
 #define NO_PIKE_SHORTHAND
@@ -755,15 +755,28 @@ static void f_error__sprintf(INT32 args)
 static void f_error_create(INT32 args)
 {
   struct pike_string *msg;
-  get_all_args("create", args, "%W", &msg);
+  struct array *bt = NULL;
+
+  get_all_args("create", args, "%W.%A", &msg, &bt);
+
   do_free_string(GENERIC_ERROR_THIS->error_message);
   copy_shared_string(GENERIC_ERROR_THIS->error_message, msg);
-  f_backtrace(0);
-  push_int (1);
-  o_range2 (RANGE_LOW_OPEN|RANGE_HIGH_FROM_END);
-  assign_to_short_svalue ((union anything *)&GENERIC_ERROR_THIS->error_backtrace,
-			  PIKE_T_ARRAY, Pike_sp-1);
-  pop_n_elems(args+1);
+
+  if (bt) {
+    if (GENERIC_ERROR_THIS->error_backtrace)
+      free_array (GENERIC_ERROR_THIS->error_backtrace);
+    add_ref (GENERIC_ERROR_THIS->error_backtrace = bt);
+  }
+  else {
+    f_backtrace(0);
+    push_int (1);
+    o_range2 (RANGE_LOW_OPEN|RANGE_HIGH_FROM_END);
+    assign_to_short_svalue ((union anything *)&GENERIC_ERROR_THIS->error_backtrace,
+			    PIKE_T_ARRAY, Pike_sp-1);
+    pop_stack();
+  }
+
+  pop_n_elems(args);
 }
 
 /*! @endclass
diff --git a/src/errors.h b/src/errors.h
index 2cc5ce96af..7abf9f64d5 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: errors.h,v 1.28 2004/11/05 20:03:26 nilsson Exp $
+|| $Id: errors.h,v 1.29 2004/12/17 16:25:03 mast Exp $
 */
 
 #ifdef ERR_DECLARE
@@ -87,7 +87,7 @@ DECLARE_ERROR(generic, Generic, EMPTY ,
   ERR_FUNC("message", f_error_message, tFunc(tVoid,tString), 0)
   ERR_FUNC("backtrace",f_error_backtrace,tFunc(tVoid,tArr(tMixed)),0)
   ERR_FUNC("_sprintf",f_error__sprintf,tFunc(tNone,tString),0)
-  ERR_FUNC("create",f_error_create,tFunc(tStr,tVoid),ID_STATIC)
+  ERR_FUNC("create",f_error_create,tFunc(tStr tOr(tVoid,tArr(tMixed)),tVoid),ID_STATIC)
 )
 
 #define GENERIC_ERROR_THIS ((struct generic_error_struct *)CURRENT_STORAGE)
-- 
GitLab