diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-07-21 06:55:45 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-07-21 06:55:45 -0700 |
commit | 16ea370778dcd9943fb11767992aebf6263acfd4 (patch) | |
tree | 02f66ea406e46eb7571a27ab6a4b3510d24fe05f /struct.c | |
parent | 5613a3b0d42a89d061df18cd9ae4e1008696572c (diff) | |
download | txr-16ea370778dcd9943fb11767992aebf6263acfd4.tar.gz txr-16ea370778dcd9943fb11767992aebf6263acfd4.tar.bz2 txr-16ea370778dcd9943fb11767992aebf6263acfd4.zip |
compat: fix glaringly broken init-time handling.
We are doing numerous compat_ver checks in various init
functions, to enact alternative symbol registrations. Only
problem is, compat_ver is always zero during initialization;
it is not set until the -C option is processed in txr_main.
Registrations must be fixed up after initialization;
that's what the compat_fixup mechanism is for.
This is an long-standing problem which affects compatibility
operation going back over 150 versions.
* arith.c (arith_init): Move compat logic to
arith_compat_fixup.
(arith_compat_fixup): New function.
* arith.h (arith_compat_fixup): Declared.
* eval.c (eval_init): Move compat logic to eval_compat_fixup.
* ffi.c (ffi_init): Move compat logic to ffi_compat_fixup.
(ffi_compat_fixup): New function.
* ffi.h (ffi_compat_fixup): Declared.
* regex.c (regex_init): Move compat logic to
regex_compat_fixup.
(regex_compat_fixup): New function.
* regex.h (regex_compat_fixup): Declared.
* stream.c (stream_init): Move compat logic to
stream_compat_fixup.
(stream_compat_fixup): New function.
* stream.h (stream_compat_fixup): Declared.
* struct.c (struct_init): Move compat logic to
struct_compat_fixup.
(struct_compat_fixup): New function.
* struct.h (stream_compat_fixup): Declared.
* lib.c (compat_fixup): Call arith_compat_fixup,
ffi_compat_fixup, regex_compat_fixup, stream_compat_fixup and
struct_compat_fixup.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -165,12 +165,8 @@ void struct_init(void) static_slot_type_hash = make_hash(nil, nil, nil); struct_type_finalize_f = func_n1(struct_type_finalize); - if (opt_compat && opt_compat <= 117) - reg_fun(intern(lit("make-struct-type"), user_package), - func_n5(make_struct_type_compat)); - else - reg_fun(intern(lit("make-struct-type"), user_package), - func_n8o(make_struct_type, 7)); + reg_fun(intern(lit("make-struct-type"), user_package), + func_n8o(make_struct_type, 7)); reg_fun(intern(lit("make-struct-type"), system_package), func_n8(make_struct_type)); @@ -210,8 +206,6 @@ void struct_init(void) reg_fun(intern(lit("call-super-fun"), user_package), func_n2v(call_super_fun)); reg_fun(intern(lit("slotp"), user_package), func_n2(slotp)); - if (opt_compat && opt_compat <= 118) - reg_fun(intern(lit("slot-p"), user_package), func_n2(slotp)); reg_fun(intern(lit("static-slot-p"), user_package), func_n2(static_slot_p)); reg_fun(intern(lit("structp"), user_package), func_n1(structp)); reg_fun(intern(lit("struct-type"), user_package), func_n1(struct_type)); @@ -225,6 +219,16 @@ void struct_init(void) reg_fun(intern(lit("static-slot-types"), system_package), func_n1(static_slot_types)); } +void struct_compat_fixup(int compat_ver) +{ + if (compat_ver <= 118) + reg_fun(intern(lit("slot-p"), user_package), func_n2(slotp)); + + if (compat_ver <= 117) + reg_fun(intern(lit("make-struct-type"), user_package), + func_n5(make_struct_type_compat)); +} + static NORETURN void no_such_struct(val ctx, val sym) { uw_throwf(error_s, lit("~a: ~s does not name a struct type"), |