From: Andy Glew (glew_at_[hidden])
Date: 1999-07-24 23:01:56


>> I.e. what I want to do is take an arbitrary existing library function foo(),
>> write my own library function foo() that intercepts all existing calls to foo(),
>> which typically does some work, and then may optionally call the original
>> function foo().
>
>That would be quite a trick, although you might could do it at link time on
>some systems with the right shenanigans.

Exactly.

Ever since Xeriox Cedar/Mesa you can play linker tricks to do this,
but not portably.

Or, if you have full source code for EVERYTHING, including the libraries,
you can play #define tricks.

Or... in sufficiently powerful languages like LISP and Smalltalk, you can do this both
statically and dynamically.

(By the way, in case folks are interested: I think that I have just figured out a way
to make the LISP approach "safe" in a C++ like manner. What you need to do
is ensure that all calls to a given signature foo(int,float) all go to the same (new)
function. Calls of that signature to the old function should only be allowed in
a tightly limited, explicitly marked, domain.
    I.e. the problem with the LISP approach is that occasionally you get a mix
of calls to foo(), some of which have been intercepted, and some not, depending
on whether the interception was done lexically or dynamically, and early enough.)