> -------- Original Message --------
> Subject: Re: [E-devel] [EGIT] [core/efl] master 02/03: eina: allow convertion 
> to BLOB from Eina_File Eina_Value by mmap the file.
> Local Time: September 13, 2017 6:18 PM
> UTC Time: September 14, 2017 1:18 AM
> From: [email protected]
> To: Enlightenment developer list <[email protected]>
>
> On Wed, Sep 13, 2017 at 2:41 PM, Cedric BAIL <[email protected]> wrote:
>> cedric pushed a commit to branch master.
>>
>> http://git.enlightenment.org/core/efl.git/commit/?id=430095d4f1aaad51ffbc30c7e323c200c896e926
>>
>> commit 430095d4f1aaad51ffbc30c7e323c200c896e926
>> Author: Cedric Bail <[email protected]>
>> Date: Wed Sep 13 10:38:36 2017 -0700
>>
>> eina: allow convertion to BLOB from Eina_File Eina_Value by mmap the file.
>> ---
>> src/lib/eina/eina_value.c | 18 ++++++++++++++++++
>> 1 file changed, 18 insertions(+)
>>
>> diff --git a/src/lib/eina/eina_value.c b/src/lib/eina/eina_value.c
>> index 59d54d8799..6088d63695 100644
>> --- a/src/lib/eina/eina_value.c
>> +++ b/src/lib/eina/eina_value.c
>> @@ -4722,7 +4722,25 @@ _eina_value_type_file_convert_to(const 
>> Eina_Value_Type *type EINA_UNUSED, const
>> filename = eina_file_filename_get(f);
>> ret = eina_value_type_pset(convert, convert_mem, &filename);
>> }
>> + else if (convert == EINA_VALUE_TYPE_BLOB)
>> + {
>> + Eina_Value_Blob *c = convert_mem;
>> + const void *m;
>> +
>> + m = eina_file_map_all((Eina_File*) f, EINA_FILE_WILLNEED);
>> + if (!m) goto end;
>> +
>> + c->ops = EINA_VALUE_BLOB_OPERATIONS_MALLOC;
>> + c->memory = malloc(eina_file_size_get(f));
>> + memcpy((void*)c->memory, m, eina_file_size_get(f));
>> + c->size = eina_file_size_get(f);
>> +
>> + eina_file_map_free((Eina_File*)f, (void*)m);
>
> do you dup the memory because of modifications? otherwise we could
> provide "ops" that would handle Eina_File, which we could
> eina_file_dup().

Yes, I was afraid of user of Eina_Value expecting to be able to mess with the 
memory directly (be accessing it or just copying the pointer and destroying the 
Eina_Value) and get a crash. If you think it won't be a problem, we could go 
with some optimisation and do the trick you described.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to