From 2d01ffb13084d0062c111663d99d40b61b78bfe3 Mon Sep 17 00:00:00 2001
From: Martin Stjernholm <mast@lysator.liu.se>
Date: Tue, 9 Sep 2003 18:57:34 +0200
Subject: [PATCH] Backported fixes for handling bignum objects in the describe
 functions.

Rev: lib/master.pike.in:1.297
---
 lib/master.pike.in | 46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/lib/master.pike.in b/lib/master.pike.in
index b414385d6e..a8228550b5 100644
--- a/lib/master.pike.in
+++ b/lib/master.pike.in
@@ -6,7 +6,7 @@
 // Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 // for more information.
 //
-// $Id: master.pike.in,v 1.296 2003/09/08 12:57:33 grubba Exp $
+// $Id: master.pike.in,v 1.297 2003/09/09 16:57:34 mast Exp $
 
 #pike __REAL_VERSION__
 
@@ -2800,20 +2800,19 @@ string program_path_to_name ( string path,
 //!   currently either @expr{"."@} or @expr{"->"@}.
 string describe_module(object|program mod, array(object)|void ret_obj)
 {
-  if (!mod) return "";	// efun or function in gmp(0).
-  program parent_fun;
-  if (objectp(mod)) {
-    parent_fun = object_program(mod);
-    if (ret_obj) ret_obj[0] = [object]mod;
-  } else if (intp(mod)) {
-    // Function in gmp
-    if (ret_obj) ret_obj[0] = [object]mod;
-    return sprintf("%O->", mod);
-  }else {
-    parent_fun = [program]mod;
-    if (objectp (mod = objects[parent_fun]) && ret_obj)
-      ret_obj[0] = [object]mod;
+  // Note: mod might be a bignum object; objectp won't work right for
+  // our purposes. object_program returns zero for non-objects, so we
+  // use it instead.
+  program parent_fun = object_program(mod);
+  if (parent_fun) {
+    if (ret_obj) ret_obj[0] = mod;
+  } else if (programp (mod)) {
+    parent_fun = mod;
+    if (objectp (mod = objects[parent_fun]) && ret_obj) ret_obj[0] = mod;
   }
+  else
+    return "";			// efun
+
   if (mod) {
     catch {
       string res = sprintf("%O", mod);
@@ -2835,8 +2834,8 @@ string describe_module(object|program mod, array(object)|void ret_obj)
 			       parent_obj);
   // werror("So far: %O parent_obj:%O\n", res, parent_obj);
   object|program parent =
-    objectp (parent_obj[0]) ? parent_obj[0] : object_program(parent_fun);
-  if (mod && (objectp (parent) || parent)) {
+    object_program (parent_obj[0]) ? parent_obj[0] : object_program(parent_fun);
+  if (mod && (object_program (parent) || parent)) {
     // Object identified.
     catch {
       // Check if we're an object in parent.
@@ -2854,14 +2853,14 @@ string describe_module(object|program mod, array(object)|void ret_obj)
 
   // No such luck.
   // Try identifying a clone of ourselves.
-  if (!mod && (objectp (parent) || parent)) {
+  if (!mod && (object_program (parent) || parent)) {
     catch {
       // Check if there's a clone of parent_fun in parent_obj.
       int i;
       array(mixed) val = values(parent);
       array(string) ind = [array(string)]indices(parent);
       for (i=0; i < sizeof(val); i++) {
-	if (objectp(val[i]) && object_program(val[i]) == parent_fun) {
+	if (object_program(val[i]) && object_program(val[i]) == parent_fun) {
 	  return res + ind[i] + ".";
 	}
       }
@@ -2894,14 +2893,14 @@ string describe_object(object o)
 
       /* Try finding ourselves in parent_obj. */
       int i;
-      if (objectp(o)) {
+      if (object_program(o)) {
 	i = search(values(parent_obj), o);
       } else {
 	i = search(map(values(parent_obj),
 		       lambda(mixed x) {
-			 if (objectp(x)) return object_program(x);
+			 if (program p = object_program(x)) return p;
 			 return 0;
-		       }), o);
+		       }), (mixed) o);
       }
       if (i >= 0) {
 	s = [string]indices(parent_obj)[i];
@@ -2965,8 +2964,9 @@ string describe_function (function f)
     if (catch (name = function_name (f))) name = "function";
 
   object o = function_object([function(mixed...:void|mixed)]f);
-  if(objectp (o)) { // Check if it's an object in a way that (hopefully) doesn't
-		    // call any functions in it (neither `== nor `!).
+  if(object_program (o)) { // Check if it's an object in a way that
+			   // (hopefully) doesn't call any functions
+			   // in it (neither `== nor `!).
     string s;
     if (!catch (s = sprintf("%O",o)) && s != "object")
       return s+"->"+name;
-- 
GitLab