diff options
author | Andy Wingo <wingo@pobox.com> | 2012-03-18 20:04:28 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2012-03-18 20:21:49 +0100 |
commit | c05805a4ea764dec5a0559edefcdfb9761191d07 (patch) | |
tree | 3925d77d81c82be61e407abf36f17634ee18b462 /libguile/vm.c | |
parent | 89d45e850725e232ae685803ee476da5b046c2b0 (diff) | |
download | guile-c05805a4ea764dec5a0559edefcdfb9761191d07.tar.gz |
make applicable smob calls cheaper, and fix a memory leak
* libguile/vm.c (prepare_smob_call): New helper. Now, instead of making
a per-smob trampoline, we will shuffle the smob into the args and use
a gsubr. This prevents a memory leak in which the trampolines, which
were values in a weak-key table, were preventing the smobs from being
collected.
* libguile/vm-i-system.c (call, tail-call, mv-call): Adapt to new smob
application mechanism.
(smob-call): Remove this instruction.
* libguile/smob.h (scm_smob_descriptor): Rename apply_trampoline_objcode
to apply_trampoline.
* libguile/smob.c: Remove our own objcode trampolines in favor of using
scm_c_make_gsubr.
(scm_smob_prehistory): No more trampoline weak map.
* libguile/procprop.c (scm_i_procedure_arity): Adapt to applicable smob
representation change.
Diffstat (limited to 'libguile/vm.c')
-rw-r--r-- | libguile/vm.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libguile/vm.c b/libguile/vm.c index 8fae65604..d1c7bbcb0 100644 --- a/libguile/vm.c +++ b/libguile/vm.c @@ -423,6 +423,25 @@ vm_make_boot_program (long nargs) * VM */ +/* We are calling a SMOB. The calling code pushed the SMOB after the + args, and incremented nargs. That nargs is passed here. This + function's job is to replace the procedure with the trampoline, and + shuffle the smob itself to be argument 0. This function must not + allocate or throw, as the VM registers are not synchronized. */ +static void +prepare_smob_call (SCM *sp, int nargs, SCM smob) +{ + SCM *args = sp - nargs + 1; + + /* Shuffle args up. */ + while (nargs--) + args[nargs + 1] = args[nargs]; + + args[0] = smob; + /* apply_trampoline_objcode is actually a program. */ + args[-1] = SCM_SMOB_DESCRIPTOR (smob).apply_trampoline_objcode; +} + static SCM resolve_variable (SCM what, SCM program_module) { |