From 900bf909a9a0528620ba82eb8453c6bd2847a52b Mon Sep 17 00:00:00 2001
From: Per Hedbor <ph@opera.com>
Date: Tue, 25 Feb 2014 14:10:29 +0100
Subject: [PATCH] Restored FIND_LFUN to work with all lfuns.

Also make the debug code conditional on PIKE_DEBUG.

It is now possible to use F_LOOKUP_LFUN again for all lfuns, not only
'real' ones.
---
 src/docode.c  | 3 +--
 src/program.h | 8 ++++----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/docode.c b/src/docode.c
index aa012e6fce..4fd864d0be 100644
--- a/src/docode.c
+++ b/src/docode.c
@@ -2463,8 +2463,7 @@ static int do_docode2(node *n, int flags)
       return 2;
     }else{
       tmp1 = do_docode(CAR(n), DO_NOT_COPY);
-      /* fake lfuns start at NUM_LFUN and are not accessible via F_LOOKUP_LFUN */
-      if ((tmp2 = lfun_lookup_id(CDR(n)->u.sval.u.string)) != -1 && tmp2 < NUM_LFUNS) {
+      if ((tmp2 = lfun_lookup_id(CDR(n)->u.sval.u.string)) != -1 ) {
 	emit1(F_LOOKUP_LFUN, tmp2);
       } else {
 	emit1(F_ARROW, store_prog_string(CDR(n)->u.sval.u.string));
diff --git a/src/program.h b/src/program.h
index a1f53b5ef9..1a09732b35 100644
--- a/src/program.h
+++ b/src/program.h
@@ -104,7 +104,6 @@ extern struct pike_string *type_check_system_string;
 #define NUM_LFUNS 45
 
 /* NOTE: After this point there are only fake lfuns.
- *       ie use low_find_lfun(), and NOT FIND_LFUN()!
  */
 #define LFUN__SEARCH 45
 #define LFUN__TYPES 46
@@ -1069,10 +1068,11 @@ void make_program_executable(struct program *p);
 /* Prototypes end here */
 
 static INLINE int FIND_LFUN(struct program * p, int lfun) {
+#ifdef PIKE_DEBUG
     dmalloc_touch(struct program*, p);
-    if (lfun < 0 || lfun >= NUM_LFUNS) return find_lfun_fatal(p, lfun);
-
-    if (p->flags & PROGRAM_FIXED) return p->lfuns[lfun];
+    if (lfun < 0) return find_lfun_fatal(p, lfun);
+#endif
+    if (p->flags & PROGRAM_FIXED && lfun < NUM_LFUNS) return p->lfuns[lfun];
     return low_find_lfun(p, lfun);
 }
 
-- 
GitLab