From 16ea370778dcd9943fb11767992aebf6263acfd4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 21 Jul 2021 06:55:45 -0700 Subject: 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. --- ffi.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'ffi.c') diff --git a/ffi.c b/ffi.c index 282c9e55..4f8ec505 100644 --- a/ffi.c +++ b/ffi.c @@ -6464,13 +6464,6 @@ void ffi_init(void) reg_fun(intern(lit("carray-int"), user_package), ca_int); reg_fun(intern(lit("uint-carray"), user_package), uint_ca); reg_fun(intern(lit("int-carray"), user_package), int_ca); - - if (opt_compat && opt_compat <= 227) { - reg_fun(intern(lit("carray-unum"), user_package), ca_uint); - reg_fun(intern(lit("carray-num"), user_package), ca_int); - reg_fun(intern(lit("unum-carray"), user_package), uint_ca); - reg_fun(intern(lit("num-carray"), user_package), int_ca); - } } reg_fun(intern(lit("put-carray"), user_package), func_n3o(put_carray, 1)); reg_fun(intern(lit("fill-carray"), user_package), func_n3o(fill_carray, 1)); @@ -6493,3 +6486,18 @@ void ffi_init(void) ffi_init_types(); ffi_init_extra_types(); } + +void ffi_compat_fixup(int compat_ver) +{ + if (compat_ver <= 227) { + val ca_uint = func_n2o(carray_uint, 1); + val ca_int = func_n2o(carray_int, 1); + val uint_ca = func_n1(uint_carray); + val int_ca = func_n1(int_carray); + + reg_fun(intern(lit("carray-unum"), user_package), ca_uint); + reg_fun(intern(lit("carray-num"), user_package), ca_int); + reg_fun(intern(lit("unum-carray"), user_package), uint_ca); + reg_fun(intern(lit("num-carray"), user_package), int_ca); + } +} -- cgit v1.2.3