[kaffe] Inlining BEGIN/END_EXCEPTION_HANDLING macros in jni.c
(Was: Re: [kaffe] Moving away from macros to inlined functions)
Guilhem Lavaux
guilhem@kaffe.org
Sun Sep 21 10:36:02 2003
Dalibor Topic wrote:
> Guilhem Lavaux wrote:
>
>> Dalibor Topic wrote:
>>
>>> Hi,
>>>
>>> this is a simple code hygene issue: I'd like to move away from using
>>> preprocessor macros all over kaffe's C sources, to use inline
>>> functions. Since the gdb debugger has a much better time with
>>> inlines, the gcc compiler produces more useful error and warning
>>> messages, inlines can be prototyped to check for type violations,
>>> and so on.
>>>
>>> I'd like to start with BEGIN/END_EXCEPTION_HANDLING in jni.c and the
>>> sysdepCallMethod on arm, as that's what I'm trying to debug at the
>>> moment. Is everyone O.K. with the idea to move away from macros?
>>>
>>> cheers,
>>> dalibor topic
>>
>>
>>
>> As far as it doesn't complicate kaffe's structure I don't see why we
>> should keep them. By the way, introducing true function calls helps
>> the programmers to keep a clean way to program. Usually macros are
>> bad used... So this should be done at a time or another. I am for it.
>
After a very simple test using that program you may see that the
returned pointers are different. To fix this with gcc is pretty easy
(just call __builtins_frame_address(1) in the inlined function) but for
a more general approach it is difficult.
#include <stdio.h>
typedef struct {
int retbp;
int retpc;
} frame;
static inline void func()
{
void *inl_addr = __builtin_frame_address(0);
frame f = *(frame *) inl_addr;
printf("f.bp=0x%08lx f.pc=0x%08lx\n", f.retbp, f.retpc);
}
int main(int argc, char **argv)
{
void *addr = __builtin_frame_address(0);
frame f = *(frame *) addr;
printf("f.bp=0x%08lx f.pc=0x%08lx\n", f.retbp, f.retpc);
func();
return 0;
}
It's just a quick and dirty test...
Cheers,
Guilhem.