[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] FFI: wrapping method that returns object
From: |
Felix Winkelmann |
Subject: |
Re: [Chicken-users] FFI: wrapping method that returns object |
Date: |
Mon, 20 Sep 2004 09:03:52 +0200 |
User-agent: |
Mozilla Thunderbird 0.5 (X11/20040208) |
Sergey Khorev wrote:
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...
cheers,
felix