Re: ICU4C API Addition Proposal: ucol_openFromBinary

Markus Scherer <[email protected]> Tue, 12 Oct 2004 15:31:30 -0700
Newsgroups gmane.comp.lib.icu.general
Organization IBM
Message-ID <[email protected]>
Vladimir Weinstein wrote:
> - binary image used in instantiation of the collator remains owned by 
> the user and should stay around for the lifetime of the collator.

Similarly, the base collator remains owned by the caller and must stay around for the lifetime of 
the new collator. Right?

> - For the purpose of creating a collator binary image, the following API 
> is proposed:
> 
> /**
>  * Clones collator's  binary image. The image can be stored and
>  * used for opening a collator using ucol_openBinary.
>  *
>  * @param coll The collator to get the image from
>  * @param length returns the length of the data, in bytes.
>  * @param status the error status
>  * @return memory, owned by the caller, of size 'length' bytes.
>  */
> U_CAPI uint8_t* U_EXPORT2
> ucol_cloneBinary(const UCollator *coll, int32_t *length, UErrorCode 
> *status);

Problematic: This would transfer ownership of an ICU-library-allocated memory block to the 
application. Bad idea.

Better:
U_CAPI int32_t U_EXPORT2
ucol_cloneBinary(const UCollator *coll,
                  uint8_t *dest, int32_t *destCapacity,
                  UErrorCode *status);

returning the length (and doing the usual preflighting). This way, the caller always owns the storage.

markus

-- 
Opinions expressed here may not reflect my company's positions unless otherwise noted.