[comp.sys.amiga] libraries & function-calling

d85_kitte@tekn01.chalmers.se (Kristian Wedberg) (09/29/88)

Hi!

I'm making a library of routines with Lattice C, and I wonder if there 
is a way to do this:

I want the user to call a function foo() in my library. foo() is part
of the normal Amiga-functions, and in my library I want to call the 
Amiga-version of foo(), not my own. Is this possible? I'm using
macros and a different name now, but that is not altogether satisfactory.


kitte				also known as d85_kitte@tekn01.chalmers.se

peter@sugar.uu.net (Peter da Silva) (10/01/88)

In article <209@tekn01.chalmers.se>, d85_kitte@tekn01.chalmers.se (Kristian Wedberg) writes:
> I want the user to call a function foo() in my library. foo() is part
> of the normal Amiga-functions, and in my library I want to call the 
> Amiga-version of foo(), not my own. Is this possible? I'm using
> macros and a different name now, but that is not altogether satisfactory.

Ah, this would be so easy in Forth:

: foo ... foo ... ;	/* Call old version of foo in foo */
: foo ... [ smudge ] foo [ smudge ] ... ;	/* Recursive call */

In 'C'? Macros and a different name. You could also SetFunction it, but there
isn't a safe way to do this in general without worrying about:

	proga setfunctions foo
		progb setfunctions foo
	proga restores foo & exits (prog b's setfunction now invalid)
		progb restores foo and exits (foo now pointing to proga's foo)
anyone calls foo. guru.

You can always check to see if foo has been changed behind your nack and not
restore it, but that still leaves the possibiliy of someone invalidating
your setfunction.

If you know that Lattice always calls foo through a glue routine, you can
always duplicate the glue routine with another name and override it with
your code at link time. This won't help with, say, M2Amiga or with any future
version of the 'C' compiler that does the libcall directly.
-- 
		Peter da Silva  `-_-'  peter@sugar.uu.net
		 Have you hugged  U  your wolf today?

d85_kitte%tekn01.chalmers.se@UDEL.EDU (10/04/88)

Received: from CUNYVM by CUNYVM.BITNET (Mailer X2.00) with BSMTP id 6410; Fri,
 30 Sep 88 22:05:44 EDT
Received: from UDEL.EDU by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with TCP; Fri, 30
 Sep 88 22:05:42 EDT
Received: from Louie.UDEL.EDU by Louie.UDEL.EDU id ac16073; 30 Sep 88 19:30 EDT
Received: from USENET by Louie.UDEL.EDU id aa16062; 30 Sep 88 19:28 EDT
From: Kristian Wedberg <d85_kitte@tekn01.chalmers.se>
Subject: libraries & function-calling
Message-ID: <209@tekn01.chalmers.se>
Date: 28 Sep 88 22:50:11 GMT
Organization: Chalmers Univ. of Technology, Gothenburg, Sweden
To:       amiga-relay@UDEL.EDU
Sender:   amiga-relay-request@UDEL.EDU

Hi!

I'm making a library of routines with Lattice C, and I wonder if there
is a way to do this:

I want the user to call a function foo() in my library. foo() is part
of the normal Amiga-functions, and in my library I want to call the
Amiga-version of foo(), not my own. Is this possible? I'm using
macros and a different name now, but that is not altogether satisfactory.


kitte                also known as d85_kitte@tekn01.chalmers.se

peter%sugar.uu.net@UDEL.EDU (10/04/88)

Received: from CUNYVM by CUNYVM.BITNET (Mailer X2.00) with BSMTP id 4784; Sun,
 02 Oct 88 00:28:50 EDT
Received: from UDEL.EDU by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with TCP; Sun, 02
 Oct 88 00:28:46 EDT
Received: from Louie.UDEL.EDU by Louie.UDEL.EDU id aa01552; 1 Oct 88 12:38 EDT
Received: from USENET by Louie.UDEL.EDU id aa01514; 1 Oct 88 12:34 EDT
From: Peter da Silva <peter@sugar.uu.net>
Subject: Re: libraries & function-calling
Message-ID: <2719@sugar.uu.net>
Date: 1 Oct 88 12:46:43 GMT
Organization: Sugar Land Unix - Houston, TX
To:       amiga-relay@UDEL.EDU
Sender:   amiga-relay-request@UDEL.EDU

In article <209@tekn01.chalmers.se>, d85_kitte@tekn01.chalmers.se (Kristian
 Wedberg) writes:
> I want the user to call a function foo() in my library. foo() is part
> of the normal Amiga-functions, and in my library I want to call the
> Amiga-version of foo(), not my own. Is this possible? I'm using
> macros and a different name now, but that is not altogether satisfactory.

Ah, this would be so easy in Forth:

: foo ... foo ... ;    /* Call old version of foo in foo */
: foo ... [ smudge ] foo [ smudge ] ... ;    /* Recursive call */

In 'C'? Macros and a different name. You could also SetFunction it, but there
isn't a safe way to do this in general without worrying about:

    proga setfunctions foo
        progb setfunctions foo
    proga restores foo & exits (prog b's setfunction now invalid)
        progb restores foo and exits (foo now pointing to proga's foo)
anyone calls foo. guru.

You can always check to see if foo has been changed behind your nack and not
restore it, but that still leaves the possibiliy of someone invalidating
your setfunction.

If you know that Lattice always calls foo through a glue routine, you can
always duplicate the glue routine with another name and override it with
your code at link time. This won't help with, say, M2Amiga or with any future
version of the 'C' compiler that does the libcall directly.
--
        Peter da Silva  `-_-'  peter@sugar.uu.net
         Have you hugged  U  your wolf today?

d85_kitte%tekn01.chalmers.se%UDEL.EDU@cunyvm.cuny.edu (10/04/88)

Received: from CUNYVM by CUNYVM.BITNET (Mailer X2.00) with BSMTP id 5995; Mon,
 03 Oct 88 22:00:16 EDT
Received: from UDEL.EDU by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with TCP; Mon, 03
 Oct 88 22:00:11 EDT
Received: from Louie.UDEL.EDU by Louie.UDEL.EDU id ah10567; 3 Oct 88 18:09 EDT
Received: from USENET by Louie.UDEL.EDU id aa10253; 3 Oct 88 17:59 EDT
From: d85_kitte%tekn01.chalmers.se@UDEL.EDU
Subject: libraries & function-calling
Message-ID: <4389@louie.udel.EDU>
Date: 3 Oct 88 21:58:42 GMT
To:       amiga-relay@UDEL.EDU
Sender:   amiga-relay-request@UDEL.EDU

Received: from CUNYVM by CUNYVM.BITNET (Mailer X2.00) with BSMTP id 6410; Fri,
 30 Sep 88 22:05:44 EDT
Received: from UDEL.EDU by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with TCP; Fri, 30
 Sep 88 22:05:42 EDT
Received: from Louie.UDEL.EDU by Louie.UDEL.EDU id ac16073; 30 Sep 88 19:30 EDT
Received: from USENET by Louie.UDEL.EDU id aa16062; 30 Sep 88 19:28 EDT
From: Kristian Wedberg <d85_kitte@tekn01.chalmers.se>
Subject: libraries & function-calling
Message-ID: <209@tekn01.chalmers.se>
Date: 28 Sep 88 22:50:11 GMT
Organization: Chalmers Univ. of Technology, Gothenburg, Sweden
To:       amiga-relay@UDEL.EDU
Sender:   amiga-relay-request@UDEL.EDU

Hi!

I'm making a library of routines with Lattice C, and I wonder if there
is a way to do this:

I want the user to call a function foo() in my library. foo() is part
of the normal Amiga-functions, and in my library I want to call the
Amiga-version of foo(), not my own. Is this possible? I'm using
macros and a different name now, but that is not altogether satisfactory.


kitte                also known as d85_kitte@tekn01.chalmers.se

d85_kitte%tekn01.chalmers.se%UDEL.EDU%cunyvm.cuny.edu@cunyvm.cuny.edu (10/04/88)

Received: from CUNYVM by CUNYVM.BITNET (Mailer X2.00) with BSMTP id 6898; Tue,
 04 Oct 88 00:44:00 EDT
Received: from UDEL.EDU by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with TCP; Tue, 04
 Oct 88 00:43:58 EDT
Received: from Louie.UDEL.EDU by Louie.UDEL.EDU id ab16810; 3 Oct 88 22:16 EDT
Received: from USENET by Louie.UDEL.EDU id aa16632; 3 Oct 88 22:08 EDT
From: d85_kitte%tekn01.chalmers.se%UDEL.EDU@cunyvm.cuny.edu
Subject: libraries & function-calling
Message-ID: <4485@louie.udel.EDU>
Date: 4 Oct 88 02:07:43 GMT
To:       amiga-relay@UDEL.EDU
Sender:   amiga-relay-request@UDEL.EDU

Received: from CUNYVM by CUNYVM.BITNET (Mailer X2.00) with BSMTP id 5995; Mon,
 03 Oct 88 22:00:16 EDT
Received: from UDEL.EDU by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with TCP; Mon, 03
 Oct 88 22:00:11 EDT
Received: from Louie.UDEL.EDU by Louie.UDEL.EDU id ah10567; 3 Oct 88 18:09 EDT
Received: from USENET by Louie.UDEL.EDU id aa10253; 3 Oct 88 17:59 EDT
From: d85_kitte%tekn01.chalmers.se@UDEL.EDU
Subject: libraries & function-calling
Message-ID: <4389@louie.udel.EDU>
Date: 3 Oct 88 21:58:42 GMT
To:       amiga-relay@UDEL.EDU
Sender:   amiga-relay-request@UDEL.EDU

Received: from CUNYVM by CUNYVM.BITNET (Mailer X2.00) with BSMTP id 6410; Fri,
 30 Sep 88 22:05:44 EDT
Received: from UDEL.EDU by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with TCP; Fri, 30
 Sep 88 22:05:42 EDT
Received: from Louie.UDEL.EDU by Louie.UDEL.EDU id ac16073; 30 Sep 88 19:30 EDT
Received: from USENET by Louie.UDEL.EDU id aa16062; 30 Sep 88 19:28 EDT
From: Kristian Wedberg <d85_kitte@tekn01.chalmers.se>
Subject: libraries & function-calling
Message-ID: <209@tekn01.chalmers.se>
Date: 28 Sep 88 22:50:11 GMT
Organization: Chalmers Univ. of Technology, Gothenburg, Sweden
To:       amiga-relay@UDEL.EDU
Sender:   amiga-relay-request@UDEL.EDU

Hi!

I'm making a library of routines with Lattice C, and I wonder if there
is a way to do this:

I want the user to call a function foo() in my library. foo() is part
of the normal Amiga-functions, and in my library I want to call the
Amiga-version of foo(), not my own. Is this possible? I'm using
macros and a different name now, but that is not altogether satisfactory.


kitte                also known as d85_kitte@tekn01.chalmers.se