Could we use another name? Map is confusing. Call it mmap, memmap or something else. The eet_map reminds of a dict/hash access.
On Wednesday, January 2, 2013, Enlightenment SVN wrote: > Log: > efl: add eet_map and use it. > > > Author: cedric > Date: 2013-01-01 18:46:05 -0800 (Tue, 01 Jan 2013) > New Revision: 81970 > Trac: http://trac.enlightenment.org/e/changeset/81970 > > Modified: > trunk/efl/ChangeLog trunk/efl/NEWS trunk/efl/src/lib/eet/Eet.h > trunk/efl/src/lib/eet/Eet_private.h trunk/efl/src/lib/eet/eet_lib.c > trunk/efl/src/modules/evas/loaders/eet/evas_image_load_eet.c > > Modified: trunk/efl/ChangeLog > =================================================================== > --- trunk/efl/ChangeLog 2013-01-02 01:50:50 UTC (rev 81969) > +++ trunk/efl/ChangeLog 2013-01-02 02:46:05 UTC (rev 81970) > @@ -1,6 +1,7 @@ > 2013-01-02 Cedric Bail > > - * Use Eina_File for evas webp loader. > + * Use Eina_File for evas webp and eet loader. > + * Add eet_map to open an Eet file from an Eina_File. > > 2012-12-31 Gustavo Sverzut Barbieri (k-s) > > > Modified: trunk/efl/NEWS > =================================================================== > --- trunk/efl/NEWS 2013-01-02 01:50:50 UTC (rev 81969) > +++ trunk/efl/NEWS 2013-01-02 02:46:05 UTC (rev 81970) > @@ -47,6 +47,7 @@ > eina_xattr_del(), eina_xattr_fd_del(), eina_xattr_copy() and > eina_xattr_fd_copy() > * Added eina_file_copy() > + * Add eet_map. > > Deprecations: > * ecore_x: > @@ -68,7 +69,7 @@ > * Display more information with eet -l -v. > * eina_magic_fail() now throws error messages on NULL pointers > instead of critical > * all efl object-freeing functions now take NULL without crashing or > erroring > - * use Eina_File in webp loader > + * use Eina_File in webp and eet loader > > Fixes: > * Fix PPC (big endian) image codec bug. > > Modified: trunk/efl/src/lib/eet/Eet.h > =================================================================== > --- trunk/efl/src/lib/eet/Eet.h 2013-01-02 01:50:50 UTC (rev 81969) > +++ trunk/efl/src/lib/eet/Eet.h 2013-01-02 02:46:05 UTC (rev 81970) > @@ -558,6 +558,31 @@ > Eet_File_Mode mode); > > /** > + * Open an eet file on disk from an Eina_File handle, and returns a > handle to it. > + * @param file The Eina_File handle to map to an eet file. > + * @return An opened eet file handle. > + * @ingroup Eet_File_Group > + * > + * This function will open an exiting eet file for reading, and build > + * the directory table in memory and return a handle to the file, if it > + * exists and can be read, and no memory errors occur on the way, > otherwise > + * NULL will be returned. > + * > + * This function can't open file for writing only read only mode is > supported for now. > + * > + * If the same file is opened multiple times, then the same file handle > will > + * be returned as eet maintains an internal list of all currently open > + * files. That means opening a file for read only looks in the read only > set, > + * and returns a handle to that file handle and increments its reference > count. > + * You need to close an eet file handle as many times as it has been > opened to > + * maintain correct reference counts. > + * > + * @since 1.8.0 > + */ > +EAPI Eet_File * > +eet_map(Eina_File *file); > + > +/** > * Open an eet file directly from a memory location. The data is not > copied, > * so you must keep it around as long as the eet file is open. There is > * currently no cache for this kind of Eet_File, so it's reopened every > time > > Modified: trunk/efl/src/lib/eet/Eet_private.h > =================================================================== > --- trunk/efl/src/lib/eet/Eet_private.h 2013-01-02 01:50:50 UTC (rev 81969) > +++ trunk/efl/src/lib/eet/Eet_private.h 2013-01-02 02:46:05 UTC (rev 81970) > @@ -97,6 +97,7 @@ > > unsigned char writes_pending : 1; > unsigned char delete_me_now : 1; > + unsigned char readfp_owned : 1; > }; > > struct _Eet_File_Header > > Modified: trunk/efl/src/lib/eet/eet_lib.c > =================================================================== > --- trunk/efl/src/lib/eet/eet_lib.c 2013-01-02 01:50:50 UTC (rev 81969) > +++ trunk/efl/src/lib/eet/eet_lib.c 2013-01-02 02:46:05 UTC (rev 81970) > @@ -1346,7 +1346,7 @@ > if (ef->sha1) > free(ef->sha1); > > - if (ef->readfp) > + if (ef->readfp && ef->readfp_owned) > { > if (ef->data) > eina_file_map_free(ef->readfp, (void *)ef->data); > @@ -1396,6 +1396,7 @@ > ef->data_size = size; > ef->sha1 = NULL; > ef->sha1_length = 0; > + ef->readfp_owned = EINA_FALSE; > > /* eet_internal_read expects the cache lock to be held when it is > called */ > LOCK_CACHE; > @@ -1412,6 +1413,67 @@ > } > > EAPI Eet_File * > +eet_map(Eina_File *file) > +{ > + Eet_File *ef = NULL; > + const char *path; > + > + path = eina_file_filename_get(file); > + > + LOCK_CACHE; > + ef = eet_cache_find(path, eet_writers, eet_writers_num); > + if (ef) > + { > + eet_sync(ef); > + ef->references++; > + ef->delete_me_now = 1; > + eet_internal_close(ef, EINA_TRUE); > + } > + > + ef = eet_cache_find(path, eet_readers, eet_readers_num); > + if (ef->readfp == file) goto done; > + > + /* Allocate struct for eet file and have it zero'd out */ > + ef = eet_file_malloc(1); > + if (!ef) return NULL; > + > + /* fill some of the members */ > + INIT_FILE(ef); > + ef->key = NULL; > + ef->readfp = file; > + ef->path = eina_stringshare_add(path); > + ef->magic = EET_MAGIC_FILE; > + ef->references = 1; > + ef->mode = EET_FILE_MODE_READ; > + ef->header = NULL; > + ef->writes_pending = 0; > + ef->delete_me_now = 0; > + ef->data = NULL; > + ef->data_size = 0; > + ef->sha1 = NULL; > + ef->sha1_length = 0; > + ef->readfp_owned = EINA_FALSE; > + > + ef->data_size = eina_file_size_get(file); > + ef->data = eina_file_map_all(file, EINA_FILE_SEQUENTIAL); > + if (eet_test_close((ef->data == NULL), ef)) > + goto on_error; > + > + ef = eet_internal_read(ef); > + if (!ef) > + goto on_error; > + > + done: > + ef->references++; > + UNLOCK_CACHE; > + return ef; > + > + on_error: > + UNLOCK_CACHE; > + return NULL; > +} > + > +EAPI Eet_File * > eet_open(const char *file, > Eet_File_Mode mode) > { > @@ -1535,6 +1597,7 @@ > ef->data_size = 0; > ef->sha1 = NULL; > ef->sha1_length = 0; > + ef->readfp_owned = EINA_TRUE; > > ef->ed = (mode == EET_FILE_MODE_WRITE) > || (!ef->readfp && mode == EET_FILE_MODE_READ_WRITE) ? > > Modified: trunk/efl/src/modules/evas/loaders/eet/evas_image_load_eet.c > =================================================================== > --- trunk/efl/src/modules/evas/loaders/eet/evas_image_load_eet.c > 2013-01-02 01:50:50 UTC (rev 81969) > +++ trunk/efl/src/modules/evas/loaders/eet/evas_image_load_eet.c > 2013-01-02 02:46:05 UTC (rev 81970) > @@ -20,13 +20,13 @@ > EINA_FALSE > }; > > - > static Eina_Bool > evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const > char *key, int *error) > { > int alpha, compression, quality, lossy; > unsigned int w, h; > - Eet_File *ef; > + Eina_File *f = NULL; > + Eet_File *ef = NULL; > int ok; > Eina_Bool res = EINA_FALSE; > > @@ -36,11 +36,18 @@ > return EINA_FALSE; > } > > - ef = eet_open((char *)file, EET_FILE_MODE_READ); > + f = eina_file_open(file, EINA_FALSE); > + if (!f) > + { > + *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; > + return EINA_FALSE; > + } > + > + ef = eet_map(f); > if (!ef) > { > - *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; > - return EINA_FALSE; > + *error = EVAS_LOAD_ERROR_CORRUPT_FILE; > + goto on_error; > } > ok = eet_data_image_header_read(ef, key, > &w, &h, &alpha, &compression, &quality, > &lossy); > @@ -61,7 +68,8 @@ > *error = EVAS_LOAD_ERROR_NONE; > > on_error: > - eet_close(ef); > + if (ef) eet_close(ef); > + eina_file_close(f); > return res; > } > > @@ -70,6 +78,7 @@ > { > unsigned int w, h; > int alpha, compression, quality, lossy, ok; > + Eina_File *f; > Eet_File *ef; > DATA32 *body, *p, *end, *data; > DATA32 nas = 0; > @@ -85,11 +94,17 @@ > *error = EVAS_LOAD_ERROR_NONE; > return EINA_TRUE; > } > - ef = eet_open(file, EET_FILE_MODE_READ); > + f = eina_file_open(file, EINA_FALSE); > + if (!f) > + { > + *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; > + return EINA_FALSE; > + } > + ef = eet_map(f); > if (!ef) > { > - *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; > - return EINA_FALSE; > + *error = EVAS_LOAD_ERROR_CORRUPT_FILE; > + goto on_error; > } > ok = eet_data_image_header_read(ef, key, > &w, &h, &alpha, &compression, &quality, > &lossy); > @@ -148,7 +163,8 @@ > res = EINA_TRUE; > > on_error: > - eet_close(ef); > + if (ef) eet_close(ef); > + eina_file_close(f); > return res; > } > > > > > ------------------------------------------------------------------------------ > Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery > and much more. Keep your Java skills current with LearnJavaNow - > 200+ hours of step-by-step video tutorials by Java experts. > SALE $49.99 this month only -- learn more at: > http://p.sf.net/sfu/learnmore_122612 > _______________________________________________ > enlightenment-svn mailing list > enlightenment-...@lists.sourceforge.net <javascript:;> > https://lists.sourceforge.net/lists/listinfo/enlightenment-svn > -- Gustavo Sverzut Barbieri http://profusion.mobi embedded systems -------------------------------------- MSN: barbi...@gmail.com Skype: gsbarbieri Mobile: +55 (19) 9225-2202 ------------------------------------------------------------------------------ Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery and much more. Keep your Java skills current with LearnJavaNow - 200+ hours of step-by-step video tutorials by Java experts. SALE $49.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122612 _______________________________________________ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel