From 27f1f9d40f53076a8425e10433844f15bf7cff97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Mon, 20 May 2019 12:33:29 +0200
Subject: [PATCH] Thread.MutexKey: Added _sprintf().

Fixes [PIKE-189].
---
 .gitattributes |  1 -
 src/threads.c  | 22 +++++++++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/.gitattributes b/.gitattributes
index 9555a0d2ae..5b1a8dfd15 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -886,7 +886,6 @@ testfont binary
 /src/svalue.h foreign_ident
 /src/test_co.pike foreign_ident
 /src/testsuite.in foreign_ident
-/src/threads.c foreign_ident
 /src/threads.h foreign_ident
 /src/time_stuff.h foreign_ident
 /src/tmodule.c foreign_ident
diff --git a/src/threads.c b/src/threads.c
index 6950350965..e6a046b038 100644
--- a/src/threads.c
+++ b/src/threads.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: threads.c,v 1.259 2008/06/29 12:37:11 nilsson Exp $
+|| $Id$
 */
 
 #include "global.h"
@@ -1544,6 +1544,25 @@ void exit_mutex_key_obj(struct object *o)
   }
 }
 
+static void f_mutex_key__sprintf(INT32 args)
+{
+  int c = 0;
+  if(args>0 && TYPEOF(Pike_sp[-args]) == PIKE_T_INT)
+    c = Pike_sp[-args].u.integer;
+  pop_n_elems (args);
+  if(c != 'O') {
+    push_undefined();
+    return;
+  }
+  if (THIS_KEY->mutex_obj) {
+    push_text("MutexKey(/* %O */)");
+    ref_push_object(THIS_KEY->mutex_obj);
+    f_sprintf(2);
+  } else {
+    push_text("MutexKey()");
+  }
+}
+
 /*! @endclass
  */
 
@@ -2283,6 +2302,7 @@ void th_init(void)
 		    tObjIs_THREAD_ID, T_OBJECT, 0);
   PIKE_MAP_VARIABLE("_mutex", mutex_key_offset + OFFSETOF(key_storage, mutex_obj),
 		    tObjIs_THREAD_MUTEX, T_OBJECT, ID_PROTECTED|ID_PRIVATE);
+  ADD_FUNCTION("_sprintf",f_mutex_key__sprintf,tFunc(tInt,tStr),ID_PROTECTED);
   set_init_callback(init_mutex_key_obj);
   set_exit_callback(exit_mutex_key_obj);
   mutex_key=Pike_compiler->new_program;
-- 
GitLab