chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] FFI: wrapping method that returns object


From: Sergey Khorev
Subject: Re: [Chicken-users] FFI: wrapping method that returns object
Date: Thu, 23 Sep 2004 09:56:39 +0400

Returning to discussion (complete thread is below for reference)
Does "is not possible" mean, that creating wrapper for

class A
{
public:
  T makeT();
};

in the following form:
T* makeT(A *a)
{
  return new T(a.makeT());
}
will not work? And such a wrapper should return pointer to
gc-collected area? If so, how to achive that? Invoke C_alloc() and
then C_mpointer() to move object to the heap?

> > Is there an easy way to teach Chicken to process the declarations below?
> > Maybe some magic with ___declare(type,...)?
> >
> > #>!
> > class T
> > {
> > public:
> >     T() {}
> >     int m(int i) { return i + 1 }
> > };
> >
> > class A
> > {
> > public:
> >     A() {}
> >     T makeT()
> >     {
> >       T t;
> >       return t;
> >     }
> > };
> > <#
> >
> > Of course one can write wrapper like
> > T* makeT_() { return new T(makeT()); }
> > But this is too boring, especially for dozens of such methods.
> >
> >
> 
> Sorry, no that is not possible. Chicken knows internally only
> one type, the "C_word", a machine-sized typeless word (32 or
> 64 bit wide). Immediate values like fixnums and booleans are
> marked words and everything else is a pointer. The makeT()
> method above returns a non-pointer object, something we can
> currently not handle.
> 
> One possible solution would be to create a piece of storage
> and memcpy(..., ..., sizeof(T)) into it, passing this storage
> around, but this may be a very dangerous thing to do, if T
> does funky stuff, or prefers it's copy-constructor to be used.
> 
> Hm... I'll check this out. Perhaps we can kludge around this
> problem somehow...




reply via email to

[Prev in Thread] Current Thread [Next in Thread]