From f8859a43cff0d42fc8730879f7b21134313af040 Mon Sep 17 00:00:00 2001
From: Martin Stjernholm <mast@lysator.liu.se>
Date: Mon, 28 Jun 1999 04:53:12 +0200
Subject: [PATCH] Keep local and remote objects apart in id_for() too.

Rev: lib/modules/Remote.pmod/context.pike:1.5
---
 lib/modules/Remote.pmod/context.pike | 35 ++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/lib/modules/Remote.pmod/context.pike b/lib/modules/Remote.pmod/context.pike
index 21200d3361..21c71e1d9e 100644
--- a/lib/modules/Remote.pmod/context.pike
+++ b/lib/modules/Remote.pmod/context.pike
@@ -10,25 +10,37 @@ int counter;
 mapping id2val = ([ ]);
 mapping val2id = ([ ]);
 mapping other  = ([ ]);
+mapping val2other = ([ ]);
 
 string id_for(mixed thing)
 {
   string id;
-  if(id=val2id[thing])
+  if(id=val2id[thing]) {
+    DEBUGMSG(sprintf("id_for(%O) found locally: %s\n", thing, id));
     return id;
+  }
+
+  if(id=val2other[thing]) {
+    DEBUGMSG(sprintf("id_for(%O) found remote: %s\n", thing, id));
+    return id;
+  }
 
-  if(server_context && (id=server_context->id_for(thing)))
+  if(server_context && (id=server_context->id_for(thing))) {
+    DEBUGMSG(sprintf("id_for(%O) found in server_context: %s\n", thing, id));
     return id;
+  }
   
   val2id[thing] = id = (base+(counter++));
   id2val[id] = thing;
+  DEBUGMSG(sprintf("id_for(%O) not found; added %s locally\n", thing, id));
   return id;
 }
 
 object object_for(string id)
 {
   object o;
-  if(o=id2val[id]) {
+  int destructed = zero_type (o = id2val[id]) != 1;
+  if(o) {
     DEBUGMSG("object_for(" + id + ") found locally\n");
     return o;
   }
@@ -41,15 +53,21 @@ object object_for(string id)
     val2id[o]=id;
     return id2val[id]=o;
   }
+  if(destructed) {
+    DEBUGMSG("object_for(" + id + ") found destructed locally\n");
+    return 0;
+  }
   DEBUGMSG("object_for(" + id + ") not found; making remote object\n");
-  return other[id] = Obj(id, con, this_object());
+  o = Obj(id, con, this_object());
+  val2other[o] = id;
+  return other[id] = o;
 }
 
 object function_for(string id)
 {
   object o;
-  if(o=id2val[id]) {
-    DEBUGMSG("function_for(" + id + ") found locally\n");
+  if(zero_type (o=id2val[id]) != 1) {
+    DEBUGMSG("function_for(" + id + ") found " + (o ? "" : "destructed ") + "locally\n");
     return o;
   }
   if(o=other[id]) {
@@ -57,7 +75,9 @@ object function_for(string id)
     return o;
   }
   DEBUGMSG("function_for(" + id + ") not found; making remote object\n");
-  return other[id] = Call(0, id, con, this_object(), 0);
+  o = Call(0, id, con, this_object(), 0);
+  val2other[o] = id;
+  return other[id] = o;
 }
 
 // Encoding:
@@ -184,6 +204,7 @@ function decode_call(array data)
 
 void add(object o, string id)
 {
+  DEBUGMSG(id + " added locally\n");
   id2val[id] = o;
   val2id[o]  = id;
 }
-- 
GitLab