From cbe9b6f7700aaa3c87a203e69b5ab543cee68c20 Mon Sep 17 00:00:00 2001 From: Shinwoo Kim Date: Fri, 17 Aug 2018 12:42:18 -0400 Subject: [PATCH] eina_file: check copied using copied Summary: From (1) "the following commit" message, the changed condition in this patch should check if the virtualized file is copied or not. In eina_file_virtualize head_padded = 16 * ((sizeof(Eina_File) + slen + 15) / 16); file->global_map = ((char *)file) + head_padded; In eina_file_dup file->global_map != (void*)(file->filename + strlen(file->filename) + 1) Because of this discord condition makes eina_file_dup copies always. (1) This is "the following commit": commit 4766316935589b6191e047ad697ab10ae2027a43 Author: Cedric Bail Date: Wed Mar 8 10:13:36 2017 -0800 eina: force copy of not copied virtualized file while doing an eina_file_dup. The other way around is pretty much impossible as you don't know who does an eina_file_dup and for how long they keep there reference. T5234 Reviewers: zmike, Hermet Reviewed By: zmike Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D6857 --- src/lib/eina/eina_file_common.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c index 3de42523ca..c87b7d94aa 100644 --- a/src/lib/eina/eina_file_common.c +++ b/src/lib/eina/eina_file_common.c @@ -474,18 +474,16 @@ eina_file_dup(const Eina_File *f) { EINA_FILE_MAGIC_CHECK(f, NULL); eina_lock_take(&file->lock); - if (file->virtual) + + // For ease of use and safety of the API, if you dup a virtualized file, we prefer to make a copy + if (file->virtual && !file->copied) { - // For ease of use and safety of the API, if you dup a virtualized file, we prefer to make a copy - if (file->global_map != (void*)(file->filename + strlen(file->filename) + 1)) - { - Eina_File *r; + Eina_File *r; - r = eina_file_virtualize(file->filename, file->global_map, file->length, EINA_TRUE); - eina_lock_release(&file->lock); + r = eina_file_virtualize(file->filename, file->global_map, file->length, EINA_TRUE); + eina_lock_release(&file->lock); - return r; - } + return r; } file->refcount++; eina_lock_release(&file->lock);