Re: Converting UC_STRING to/from C pointer to UTF8 octet sequences

Berend de Boer <[email protected]> Tue, 19 May 2009 08:03:13 +0200
Newsgroups gmane.comp.lang.eiffel.gobo.devel
Message-ID <[email protected]>
>>>>> "Paul" == Paul Cohen <[email protected]> writes:

    Paul> Hi all, I need some advice/feedback on how to convert/create
    Paul> a UC_STRING from a C pointer to a UTF8 byte sequence (and
    Paul> vice versa). I can't find any routines or examples in the
    Paul> Gobo unicode library for doing it. The need for this arises
    Paul> when writing Eiffel shared libraries (with C-style API:s).

    Paul> It is unfortunate that I have to create two "string objects"
    Paul> to perform the "conversion".

You can iterate over the C pointer and do what make_from_utf8 does if
this is a concern. 


    Paul> Returning a pointer to a UTF8 octet sequence is trickier.

It is. I've found out that the only safe way to do this in ISE is to
allocate memory with C (malloc), copy the string to there and give a
pointer to that area to C.

This was tested on a large production system with millions of such
calls, and any attempt to give pointers to an Eiffel object would fail
with weird errors after a while. There appeared to be no safe way to
retrieve a pointer to an ISE Eiffel object, whatever tricks were
applied.

-- 
Cheers,

Berend de Boer

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects