Browse Source

FFI: Treat cdata metatable+methods as immutable in trace recorder.

Mike Pall 14 years ago
parent
commit
2a917a9d83
1 changed files with 13 additions and 0 deletions
  1. 13 0
      src/lj_record.c

+ 13 - 0
src/lj_record.c

@@ -667,6 +667,19 @@ int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)
       ix->mt = TREF_NIL;
       ix->mt = TREF_NIL;
       return 0;  /* No metamethod. */
       return 0;  /* No metamethod. */
     }
     }
+#if LJ_HASFFI
+    /* The cdata metatable is treated as immutable. */
+    if (tref_iscdata(ix->tab)) {
+      cTValue *mo = lj_tab_getstr(mt, mmname_str(J2G(J), mm));
+      if (!mo || tvisnil(mo))
+	return 0;  /* No metamethod. */
+      setfuncV(J->L, &ix->mobjv, funcV(mo));
+      ix->mobj = lj_ir_kfunc(J, funcV(mo));  /* Immutable metamethod. */
+      ix->mtv = mt;
+      ix->mt = TREF_NIL;  /* Dummy value for comparison semantics. */
+      return 1;  /* Got cdata metamethod. */
+    }
+#endif
     ix->mt = mix.tab = lj_ir_ktab(J, mt);
     ix->mt = mix.tab = lj_ir_ktab(J, mt);
     goto nocheck;
     goto nocheck;
   }
   }