Re: ICU4C API Addition Proposal: ucol_openFromBinary
Vladimir Weinstein <[email protected]> Tue, 12 Oct 2004 18:48:52 -0700
| Newsgroups | gmane.comp.lib.icu.general |
|---|---|
| Message-ID | <[email protected]> |
See below. Regards, v. Markus Scherer wrote: > 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? Yes. > >> - 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. Not a big fan of preflighting etc. but I see the point. API amended. > > markus > -- Vladimir Weinstein, IBM GCoC-Unicode/ICU San Jose, CA [email protected]