logo       

Re: Q&D implementation of dlfunc(): msg#00033

Subject: Re: Q&D implementation of dlfunc()
* From Garrett Wollman <wollman@xxxxxxxxxxxxxxxxxxxxx>
> <<On Tue, 28 May 2002 19:52:36 -0700, "J. Mallett" <jmallett@xxxxxxxxxxx> 
> said:
> 
> > rv = (uintptr_t)dlsym(handle, symbol);
> 
> For the same reason as you can't cast from a data pointer to a
> function pointer, there's no guarantee that you can cast from a
> uintptr_t (if such a type even exists) to a function pointer.  Since
> we're depending on all pointers having the same representation, I'd
> rather make it explicit.

Right, I understand the situation, and how evil it is.  Look at the code
I put below, I think I forgot to include parts of my hello world, which
removes that assumption, by doing (note inocrrectness of hello was to deal
with having prototypes in scope, I could have done something cleaner, but...):



convptr hello(convptr function, uintptr_t *data)
{
  printf("## hello: %p, %p\n", function, data);

  printf("Hello, world!\n");

  return function;
}

int main(int argc, char *argv[])
{
  convptr foo, bar;
  uintptr_t data[sizeof(convptr)/sizeof(uintptr_t)];

  printf("## main: 0x%x, %p\n", argc, argv);

  function_to_data_ptr((convptr)data_to_function_ptr, data);
  data_to_function_ptr(&foo, data);
  function_to_data_ptr((convptr)hello, data);
  (*foo)(&bar, data);
  (*bar)(NULL, NULL);

  return 0;
}
-- 
J. Mallett <jmallett@xxxxxxxxxxx>                    FreeBSD: The Power To Serve

To Unsubscribe: send mail to majordomo@xxxxxxxxxxx
with "unsubscribe freebsd-standards" in the body of the message



<Prev in Thread] Current Thread [Next in Thread>