From 84c74d4906c6c627bc64829dfcdfa39943214e3f Mon Sep 17 00:00:00 2001
From: Martin Nilsson <nilsson@opera.com>
Date: Thu, 28 Aug 2014 18:26:18 +0200
Subject: [PATCH] On second thought, this is so obscure that we shouldn't
 probably do it at all.

---
 lib/7.8/modules/__default.pmod | 19 +++++++++++++++++++
 lib/7.8/modules/testsuite.in   |  1 +
 src/builtin_functions.c        | 31 -------------------------------
 src/testsuite.in               |  1 -
 4 files changed, 20 insertions(+), 32 deletions(-)

diff --git a/lib/7.8/modules/__default.pmod b/lib/7.8/modules/__default.pmod
index 51c6b13fc4..60807418b9 100644
--- a/lib/7.8/modules/__default.pmod
+++ b/lib/7.8/modules/__default.pmod
@@ -9,9 +9,28 @@
 
 //! @decl inherit predef::
 
+array|mapping|multiset|string map(array|mapping|multiset|string|object|program stuff, function(mixed,mixed...:mixed) f, mixed ... args)
+{
+  if(objectp(stuff))
+  {
+    if( catch { stuff = (array)stuff; } )
+      if( catch { stuff = (mapping)stuff; } )
+        if( catch { stuff = (multiset)stuff; } )
+          if( catch {
+              object o = stuff;
+              stuff = allocate(sizeof(o));
+              for( int i; i<sizeof(stuff); i++ )
+                stuff[i] = o[i];
+            } )
+           error("Bad argument 1 to map. Expected object that works in map.\n");
+  }
+  return 7.9::map(stuff, f, @args);
+}
+
 protected Mapping.ShadowedMapping compat_all_constants =
   Mapping.ShadowedMapping(predef::all_constants(),
 			  ([
+                            "map" : map,
 			  ]), 1);
 
 mapping(string:mixed) all_constants()
diff --git a/lib/7.8/modules/testsuite.in b/lib/7.8/modules/testsuite.in
index dafc7a2589..78569d8599 100644
--- a/lib/7.8/modules/testsuite.in
+++ b/lib/7.8/modules/testsuite.in
@@ -302,5 +302,6 @@ test_do([[
   class A { static int foo = 1; int bar() { return foo; } }
 ]])
 
+test_any_equal([[ class A { int a0=1,a1=2; protected int `[](int what) { return ::`[]("a"+what); } protected int _sizeof() { return 2; } }; return map(A(), `+, 1);]], ({2,3}))
 
 END_MARKER
diff --git a/src/builtin_functions.c b/src/builtin_functions.c
index f1d69fbaa5..b76b9a2692 100644
--- a/src/builtin_functions.c
+++ b/src/builtin_functions.c
@@ -8818,37 +8818,6 @@ PMOD_EXPORT void f_map(INT32 args)
              }
              pop_stack();
            }
-
-           /* if arr->_sizeof && arr->`[]
-              array ret; ret[i]=arr[i];
-              ret=map(ret,fun,@extra); */
-
-           f = FIND_LFUN(o->prog->inherits[osub].prog,
-                         LFUN_INDEX) |
-             FIND_LFUN(o->prog->inherits[osub].prog,
-                       LFUN__SIZEOF);
-
-           if( f != -1 )
-           {
-             struct svalue tmp;
-             TYPEOF(tmp) = PIKE_T_INT;
-             SUBTYPEOF(tmp) = 0;
-             n=pike_sizeof(mysp-3);
-             push_array(d=allocate_array(n));
-             types = 0;
-             for (i=0; i<n; i++)
-             {
-               tmp.u.integer = i;
-               object_index_no_free(ITEM(d)+i, o, osub, &tmp );
-               types |= 1 << TYPEOF(ITEM(d)[i]);
-             }
-             d->type_field = types;
-             free_svalue(mysp-3);
-             mysp[-3]=*(--Pike_sp);
-             dmalloc_touch_svalue(Pike_sp);
-             f_map(args);
-             return;
-           }
 	 }
 
 	 SIMPLE_BAD_ARG_ERROR("map",1,
diff --git a/src/testsuite.in b/src/testsuite.in
index 4909375f86..d755ba3080 100644
--- a/src/testsuite.in
+++ b/src/testsuite.in
@@ -4707,7 +4707,6 @@ test_any_equal(class A { constant a=1; constant b=2; }; return map(A, `+ ,1);, (
 test_any_equal(class A { protected mixed cast(string t) { if(t=="mapping") return (["a":1,"b":2]);}}; return map(A(), `+, 1);, (["a":2,"b":3]))
 test_any_equal(class A { protected mixed cast(string t) { if(t=="array") return ({1,2,3});}}; return map(A(), `+, 1);, ({2,3,4}))
 test_any_equal(class A { protected mixed cast(string t) { if(t=="multiset") return (<1,2,3>);}}; return map(A(), `+, 1);, (<2,3,4>))
-test_any_equal([[ class A { int a0=1,a1=2; protected int `[](int what) { return ::`[]("a"+what); } protected int _sizeof() { return 2; } }; return map(A(), `+, 1);]], ({2,3}))
 test_any_equal(array a = ({({1,0,0}),({1,1,0}),({0,1,1})}); return map(a,`[],1);,
                ({0,1,1}))
 test_any_equal(array a = ({({1,0,0}),({1,1,0}),({0,1,1})}); map(a,`[]=,1,0); return a;,
-- 
GitLab