9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] calling function with (variable number of) parameters
@ 2001-06-20 19:51 rog
  2001-06-20 19:54 ` Latchesar Ionkov
  0 siblings, 1 reply; 12+ messages in thread
From: rog @ 2001-06-20 19:51 UTC (permalink / raw)
  To: 9fans

> The interface is called JNI and I can't change it.

presumably you could write a bit of assembler to get around the
problem. you'd have to do it for each platform, but it wouldn't be hard
and as far as i can see there wouldn't be a problem doing it: just push
all the args on the stack (last first) & call the fn.

  cheers,
    rog.



^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [9fans] calling function with (variable number of) parameters
@ 2001-06-21 14:33 rog
  2001-06-21 15:16 ` Dan Cross
  2001-06-21 15:17 ` Latchesar Ionkov
  0 siblings, 2 replies; 12+ messages in thread
From: rog @ 2001-06-21 14:33 UTC (permalink / raw)
  To: 9fans

> So save space for n + 1 parameters on the stack; the last won't be used
> by your called function, and you could store the number of parameters in
> it.  When you return, pop the last item off the stack, and use that to
> recalculate the frame pointer.

no actually, parameters are pushed on last first, so the last one
you've pushed (the one you've got access after the return) is the first
parameter to the function (which doesn't expect it).

i think that probably the only way of getting around the problem is to
change the prototype of the called function so that the first parameter
signifies the number of parameters.

the only other alternative is if the function is guaranteed to be
non-reentrant (fat chance) in which case you could store the number of
params in a static variable.

of course, that then makes it incompatible with the original...

  cheers,
    rog.



^ permalink raw reply	[flat|nested] 12+ messages in thread
* [9fans] calling function with (variable number of) parameters
@ 2001-06-20 14:11 Latchesar Ionkov
  2001-06-20 16:30 ` Douglas A. Gwyn
  0 siblings, 1 reply; 12+ messages in thread
From: Latchesar Ionkov @ 2001-06-20 14:11 UTC (permalink / raw)
  To: 9fans

Hi,

I am trying to write a function

	int callf(void *f, int nargs, int *args)
	
f is a pointer to a function of a type

	int f(int, int, int, ..., int)
	
callf should copy nargs number of ints from args to the stack and call f,
and then return f's return value.

The requirement is to not restrict nargs -- theoretically f can have 1000+
arguments.

Is this possible with Plan9 C calling convention? The caller function saves
the registers that it needs (obviously in the stack), then SP is modified
with a non-constant value, f is called, and after the execution returns in
callf, there is no any way go guess, what that value was.

Do I miss something? Any ideas how to implement it?

Unfortunately I don't have any control on the requirements or the way f gets
its parameters. If there is no way to do it for any number of args, I'll
limit nargs (and hope nobody will write function with more than 15
arguments) and will modify SP with a constant value.

Thanks,
	Lucho


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2001-06-29 22:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-20 19:51 [9fans] calling function with (variable number of) parameters rog
2001-06-20 19:54 ` Latchesar Ionkov
2001-06-21 12:39   ` Douglas A. Gwyn
2001-06-21 13:48     ` Latchesar Ionkov
2001-06-21 14:13   ` Dan Cross
  -- strict thread matches above, loose matches on Subject: below --
2001-06-21 14:33 rog
2001-06-21 15:16 ` Dan Cross
2001-06-21 15:17 ` Latchesar Ionkov
2001-06-29 22:11   ` Boyd Roberts
2001-06-20 14:11 Latchesar Ionkov
2001-06-20 16:30 ` Douglas A. Gwyn
2001-06-20 18:23   ` Latchesar Ionkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).