diff --git a/src/builtin.cmod b/src/builtin.cmod index 1041a96d305de0abe0013754036f6be4f956bb43..41f95e62e5e86f9207aed0b1bb6bd4c4eec11eee 100644 --- a/src/builtin.cmod +++ b/src/builtin.cmod @@ -3746,8 +3746,23 @@ PIKECLASS Null push_int(0); return; } + + /* Look for the is_val_null constant directly in the program of + * other, without going through its `[]. When this is called in a + * codec, other can be a completely arbitrary object which may not + * have a `[] that works in that context. */ + push_int (0); + ref_push_program (other->u.object->prog); push_constant_text("is_val_null"); - o_index(); + if (program_index_no_free (Pike_sp - 3, Pike_sp - 2, Pike_sp - 1) && + Pike_sp[-3].type == T_INT && Pike_sp[-3].u.integer) { + pop_n_elems (4); + push_int (1); + } + else { + pop_n_elems (4); + push_int (0); + } } /*! @decl string encode_json()