You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucy.apache.org by Marvin Humphrey <ma...@rectangular.com> on 2013/09/18 02:04:05 UTC

[lucy-dev] Expose Clownfish::Util::Memory?

On Sat, Sep 14, 2013 at 12:29 PM,  <nw...@apache.org> wrote:
> Introduce Str_To_Utf8

> Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
> Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/41a5ef76
> Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/41a5ef76
> Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/41a5ef76

> -    /** Return a fresh copy of the string data in a String with an internal
> -     * encoding of UTF-8.
> +    /** Return a NULL-terminated copy of the string data in UTF-8 encoding.
> +     * The buffer must be freed by the caller.
>       */
> -    String*
> -    To_CB8(String *self);
> +    char*
> +    To_Utf8(String *self);

Will we need to expose the routines in Clownfish::Util::Memory as public APIs
because `free` doesn't mean the same thing everywhere?  See "free to wrong
pool" errors on Windows, for example.

Marvin Humphrey

Re: [lucy-dev] Expose Clownfish::Util::Memory?

Posted by Nick Wellnhofer <we...@aevum.de>.
On 19/09/2013 03:43, Marvin Humphrey wrote:
> I'd suggest that we use a literal `malloc` instead of MALLOCATE inside of
> Str_To_Utf8, because that allows us to experiment with alternative allocators
> inside Clownfish::Util::Memory without screwing up what happens when a user
> invokes free() on the pointer returned from To_Utf8.

+1

Nick


Re: [lucy-dev] Expose Clownfish::Util::Memory?

Posted by Marvin Humphrey <ma...@rectangular.com>.
On Wed, Sep 18, 2013 at 4:41 AM, Nick Wellnhofer <we...@aevum.de> wrote:
> The buffer returned by Str_To_Utf8 is allocated with MALLOCATE which is a
> wrapper around the system malloc. So it should be safe to simply free() the
> buffer. The "free to wrong pool" seems to be related to the Perl allocator
> which isn't used in this case.

Ah, I thought it had something to do with conflicts between various
MSCVRT*.DLL files.  But yeah, a web search for "free to wrong pool" only turns
up Perl-related documents.

I'd suggest that we use a literal `malloc` instead of MALLOCATE inside of
Str_To_Utf8, because that allows us to experiment with alternative allocators
inside Clownfish::Util::Memory without screwing up what happens when a user
invokes free() on the pointer returned from To_Utf8.

Marvin Humphrey

Re: [lucy-dev] Expose Clownfish::Util::Memory?

Posted by Nick Wellnhofer <we...@aevum.de>.
On 18/09/2013 02:04, Marvin Humphrey wrote:
> On Sat, Sep 14, 2013 at 12:29 PM,  <nw...@apache.org> wrote:
>> Introduce Str_To_Utf8
>
>> Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/41a5ef76
>> Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/41a5ef76
>> Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/41a5ef76
>
>> -    /** Return a fresh copy of the string data in a String with an internal
>> -     * encoding of UTF-8.
>> +    /** Return a NULL-terminated copy of the string data in UTF-8 encoding.
>> +     * The buffer must be freed by the caller.
>>        */
>> -    String*
>> -    To_CB8(String *self);
>> +    char*
>> +    To_Utf8(String *self);
>
> Will we need to expose the routines in Clownfish::Util::Memory as public APIs
> because `free` doesn't mean the same thing everywhere?  See "free to wrong
> pool" errors on Windows, for example.

The buffer returned by Str_To_Utf8 is allocated with MALLOCATE which is 
a wrapper around the system malloc. So it should be safe to simply 
free() the buffer. The "free to wrong pool" seems to be related to the 
Perl allocator which isn't used in this case.

Nick