aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/eina/src/lib/Makefile.am10
-rw-r--r--libraries/eina/src/lib/Makefile.in68
-rw-r--r--libraries/eina/src/lib/eina_array.c4
-rw-r--r--libraries/eina/src/lib/eina_binbuf_template_c.x9
-rw-r--r--libraries/eina/src/lib/eina_cpu.c4
-rw-r--r--libraries/eina/src/lib/eina_file.c128
-rw-r--r--libraries/eina/src/lib/eina_hash.c6
-rw-r--r--libraries/eina/src/lib/eina_inarray.c777
-rw-r--r--libraries/eina/src/lib/eina_log.c145
-rw-r--r--libraries/eina/src/lib/eina_magic.c11
-rw-r--r--libraries/eina/src/lib/eina_main.c16
-rw-r--r--libraries/eina/src/lib/eina_mmap.c5
-rw-r--r--libraries/eina/src/lib/eina_module.c1
-rw-r--r--libraries/eina/src/lib/eina_prefix.c37
-rw-r--r--libraries/eina/src/lib/eina_private.h6
-rw-r--r--libraries/eina/src/lib/eina_rbtree.c10
-rw-r--r--libraries/eina/src/lib/eina_simple_xml_parser.c19
-rw-r--r--libraries/eina/src/lib/eina_strbuf.c6
-rw-r--r--libraries/eina/src/lib/eina_value.c4977
-rw-r--r--libraries/eina/src/lib/eina_xattr.c191
20 files changed, 6346 insertions, 84 deletions
diff --git a/libraries/eina/src/lib/Makefile.am b/libraries/eina/src/lib/Makefile.am
index 0537a61..d8c9d20 100644
--- a/libraries/eina/src/lib/Makefile.am
+++ b/libraries/eina/src/lib/Makefile.am
@@ -22,6 +22,7 @@ eina_error.c \
22eina_fp.c \ 22eina_fp.c \
23eina_hamster.c \ 23eina_hamster.c \
24eina_hash.c \ 24eina_hash.c \
25eina_inarray.c \
25eina_inlist.c \ 26eina_inlist.c \
26eina_iterator.c \ 27eina_iterator.c \
27eina_lalloc.c \ 28eina_lalloc.c \
@@ -130,12 +131,17 @@ eina_amalgamation.c: $(base_sources) Makefile
130 @echo "#include <stdio.h>" >> eina_amalgamation.c 131 @echo "#include <stdio.h>" >> eina_amalgamation.c
131 @echo "#include <stdlib.h>" >> eina_amalgamation.c 132 @echo "#include <stdlib.h>" >> eina_amalgamation.c
132 @echo "#include <string.h>" >> eina_amalgamation.c 133 @echo "#include <string.h>" >> eina_amalgamation.c
133 @echo "#include <dlfcn.h>" >> eina_amalgamation.c 134 @echo "#ifdef HAVE_DLOPEN" >> eina_amalgamation.c
135 @echo "# include <dlfcn.h>" >> eina_amalgamation.c
136 @echo "#endif" >> eina_amalgamation.c
134 @echo "#include <sys/types.h>" >> eina_amalgamation.c 137 @echo "#include <sys/types.h>" >> eina_amalgamation.c
135 @echo "#include <dirent.h>" >> eina_amalgamation.c 138 @echo "#ifdef HAVE_DIRENT_H" >> eina_amalgamation.c
139 @echo "# include <dirent.h>" >> eina_amalgamation.c
140 @echo "#endif" >> eina_amalgamation.c
136 @echo "#include <assert.h>" >> eina_amalgamation.c 141 @echo "#include <assert.h>" >> eina_amalgamation.c
137 @echo "#include <errno.h>" >> eina_amalgamation.c 142 @echo "#include <errno.h>" >> eina_amalgamation.c
138 @echo "#include <fnmatch.h>" >> eina_amalgamation.c 143 @echo "#include <fnmatch.h>" >> eina_amalgamation.c
144 @echo "#include <fcntl.h>" >> eina_amalgamation.c
139 145
140 @echo "#ifdef HAVE_EVIL" >> eina_amalgamation.c 146 @echo "#ifdef HAVE_EVIL" >> eina_amalgamation.c
141 @echo "# include <Evil.h>" >> eina_amalgamation.c 147 @echo "# include <Evil.h>" >> eina_amalgamation.c
diff --git a/libraries/eina/src/lib/Makefile.in b/libraries/eina/src/lib/Makefile.in
index 359aba0..878bcbe 100644
--- a/libraries/eina/src/lib/Makefile.in
+++ b/libraries/eina/src/lib/Makefile.in
@@ -96,15 +96,16 @@ libeina_la_DEPENDENCIES =
96am__libeina_la_SOURCES_DIST = eina_accessor.c eina_array.c \ 96am__libeina_la_SOURCES_DIST = eina_accessor.c eina_array.c \
97 eina_benchmark.c eina_binbuf.c eina_binshare.c eina_convert.c \ 97 eina_benchmark.c eina_binbuf.c eina_binshare.c eina_convert.c \
98 eina_counter.c eina_cpu.c eina_error.c eina_fp.c \ 98 eina_counter.c eina_cpu.c eina_error.c eina_fp.c \
99 eina_hamster.c eina_hash.c eina_inlist.c eina_iterator.c \ 99 eina_hamster.c eina_hash.c eina_inarray.c eina_inlist.c \
100 eina_lalloc.c eina_list.c eina_log.c eina_magic.c eina_main.c \ 100 eina_iterator.c eina_lalloc.c eina_list.c eina_log.c \
101 eina_matrixsparse.c eina_mempool.c eina_mmap.c eina_module.c \ 101 eina_magic.c eina_main.c eina_matrixsparse.c eina_mempool.c \
102 eina_prefix.c eina_quadtree.c eina_rbtree.c eina_rectangle.c \ 102 eina_mmap.c eina_module.c eina_prefix.c eina_quadtree.c \
103 eina_safety_checks.c eina_sched.c eina_share_common.c \ 103 eina_rbtree.c eina_rectangle.c eina_safety_checks.c \
104 eina_simple_xml_parser.c eina_str.c eina_strbuf.c \ 104 eina_sched.c eina_share_common.c eina_simple_xml_parser.c \
105 eina_strbuf_common.c eina_stringshare.c eina_tiler.c \ 105 eina_str.c eina_strbuf.c eina_strbuf_common.c \
106 eina_unicode.c eina_ustrbuf.c eina_ustringshare.c eina_value.c \ 106 eina_stringshare.c eina_tiler.c eina_unicode.c eina_ustrbuf.c \
107 eina_xattr.c eina_file_win32.c eina_file.c \ 107 eina_ustringshare.c eina_value.c eina_xattr.c \
108 eina_file_win32.c eina_file.c \
108 $(top_srcdir)/src/modules/mp/buddy/eina_buddy.c \ 109 $(top_srcdir)/src/modules/mp/buddy/eina_buddy.c \
109 $(top_srcdir)/src/modules/mp/chained_pool/eina_chained_mempool.c \ 110 $(top_srcdir)/src/modules/mp/chained_pool/eina_chained_mempool.c \
110 $(top_srcdir)/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c \ 111 $(top_srcdir)/src/modules/mp/ememoa_fixed/eina_ememoa_fixed.c \
@@ -129,15 +130,16 @@ am__objects_10 = libeina_la-eina_accessor.lo libeina_la-eina_array.lo \
129 libeina_la-eina_counter.lo libeina_la-eina_cpu.lo \ 130 libeina_la-eina_counter.lo libeina_la-eina_cpu.lo \
130 libeina_la-eina_error.lo libeina_la-eina_fp.lo \ 131 libeina_la-eina_error.lo libeina_la-eina_fp.lo \
131 libeina_la-eina_hamster.lo libeina_la-eina_hash.lo \ 132 libeina_la-eina_hamster.lo libeina_la-eina_hash.lo \
132 libeina_la-eina_inlist.lo libeina_la-eina_iterator.lo \ 133 libeina_la-eina_inarray.lo libeina_la-eina_inlist.lo \
133 libeina_la-eina_lalloc.lo libeina_la-eina_list.lo \ 134 libeina_la-eina_iterator.lo libeina_la-eina_lalloc.lo \
134 libeina_la-eina_log.lo libeina_la-eina_magic.lo \ 135 libeina_la-eina_list.lo libeina_la-eina_log.lo \
135 libeina_la-eina_main.lo libeina_la-eina_matrixsparse.lo \ 136 libeina_la-eina_magic.lo libeina_la-eina_main.lo \
136 libeina_la-eina_mempool.lo libeina_la-eina_mmap.lo \ 137 libeina_la-eina_matrixsparse.lo libeina_la-eina_mempool.lo \
137 libeina_la-eina_module.lo libeina_la-eina_prefix.lo \ 138 libeina_la-eina_mmap.lo libeina_la-eina_module.lo \
138 libeina_la-eina_quadtree.lo libeina_la-eina_rbtree.lo \ 139 libeina_la-eina_prefix.lo libeina_la-eina_quadtree.lo \
139 libeina_la-eina_rectangle.lo libeina_la-eina_safety_checks.lo \ 140 libeina_la-eina_rbtree.lo libeina_la-eina_rectangle.lo \
140 libeina_la-eina_sched.lo libeina_la-eina_share_common.lo \ 141 libeina_la-eina_safety_checks.lo libeina_la-eina_sched.lo \
142 libeina_la-eina_share_common.lo \
141 libeina_la-eina_simple_xml_parser.lo libeina_la-eina_str.lo \ 143 libeina_la-eina_simple_xml_parser.lo libeina_la-eina_str.lo \
142 libeina_la-eina_strbuf.lo libeina_la-eina_strbuf_common.lo \ 144 libeina_la-eina_strbuf.lo libeina_la-eina_strbuf_common.lo \
143 libeina_la-eina_stringshare.lo libeina_la-eina_tiler.lo \ 145 libeina_la-eina_stringshare.lo libeina_la-eina_tiler.lo \
@@ -231,7 +233,9 @@ EFL_SIMD_FLAGS = @EFL_SIMD_FLAGS@
231EGREP = @EGREP@ 233EGREP = @EGREP@
232EINA_CFLAGS = @EINA_CFLAGS@ 234EINA_CFLAGS = @EINA_CFLAGS@
233EINA_CONFIGURE_DEFAULT_MEMPOOL = @EINA_CONFIGURE_DEFAULT_MEMPOOL@ 235EINA_CONFIGURE_DEFAULT_MEMPOOL = @EINA_CONFIGURE_DEFAULT_MEMPOOL@
236EINA_CONFIGURE_ENABLE_LOG = @EINA_CONFIGURE_ENABLE_LOG@
234EINA_CONFIGURE_HAVE_DEBUG_THREADS = @EINA_CONFIGURE_HAVE_DEBUG_THREADS@ 237EINA_CONFIGURE_HAVE_DEBUG_THREADS = @EINA_CONFIGURE_HAVE_DEBUG_THREADS@
238EINA_CONFIGURE_HAVE_DIRENT_H = @EINA_CONFIGURE_HAVE_DIRENT_H@
235EINA_CONFIGURE_HAVE_INTTYPES_H = @EINA_CONFIGURE_HAVE_INTTYPES_H@ 239EINA_CONFIGURE_HAVE_INTTYPES_H = @EINA_CONFIGURE_HAVE_INTTYPES_H@
236EINA_CONFIGURE_HAVE_ON_OFF_THREADS = @EINA_CONFIGURE_HAVE_ON_OFF_THREADS@ 240EINA_CONFIGURE_HAVE_ON_OFF_THREADS = @EINA_CONFIGURE_HAVE_ON_OFF_THREADS@
237EINA_CONFIGURE_HAVE_STDINT_H = @EINA_CONFIGURE_HAVE_STDINT_H@ 241EINA_CONFIGURE_HAVE_STDINT_H = @EINA_CONFIGURE_HAVE_STDINT_H@
@@ -283,8 +287,6 @@ PACKAGE_URL = @PACKAGE_URL@
283PACKAGE_VERSION = @PACKAGE_VERSION@ 287PACKAGE_VERSION = @PACKAGE_VERSION@
284PATH_SEPARATOR = @PATH_SEPARATOR@ 288PATH_SEPARATOR = @PATH_SEPARATOR@
285PKG_CONFIG = @PKG_CONFIG@ 289PKG_CONFIG = @PKG_CONFIG@
286PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
287PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
288RANLIB = @RANLIB@ 290RANLIB = @RANLIB@
289SED = @SED@ 291SED = @SED@
290SET_MAKE = @SET_MAKE@ 292SET_MAKE = @SET_MAKE@
@@ -371,10 +373,10 @@ AM_CPPFLAGS = \
371base_sources = eina_accessor.c eina_array.c eina_benchmark.c \ 373base_sources = eina_accessor.c eina_array.c eina_benchmark.c \
372 eina_binbuf.c eina_binshare.c eina_convert.c eina_counter.c \ 374 eina_binbuf.c eina_binshare.c eina_convert.c eina_counter.c \
373 eina_cpu.c eina_error.c eina_fp.c eina_hamster.c eina_hash.c \ 375 eina_cpu.c eina_error.c eina_fp.c eina_hamster.c eina_hash.c \
374 eina_inlist.c eina_iterator.c eina_lalloc.c eina_list.c \ 376 eina_inarray.c eina_inlist.c eina_iterator.c eina_lalloc.c \
375 eina_log.c eina_magic.c eina_main.c eina_matrixsparse.c \ 377 eina_list.c eina_log.c eina_magic.c eina_main.c \
376 eina_mempool.c eina_mmap.c eina_module.c eina_prefix.c \ 378 eina_matrixsparse.c eina_mempool.c eina_mmap.c eina_module.c \
377 eina_quadtree.c eina_rbtree.c eina_rectangle.c \ 379 eina_prefix.c eina_quadtree.c eina_rbtree.c eina_rectangle.c \
378 eina_safety_checks.c eina_sched.c eina_share_common.c \ 380 eina_safety_checks.c eina_sched.c eina_share_common.c \
379 eina_simple_xml_parser.c eina_str.c eina_strbuf.c \ 381 eina_simple_xml_parser.c eina_str.c eina_strbuf.c \
380 eina_strbuf_common.c eina_stringshare.c eina_tiler.c \ 382 eina_strbuf_common.c eina_stringshare.c eina_tiler.c \
@@ -489,6 +491,7 @@ distclean-compile:
489@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_fp.Plo@am__quote@ 491@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_fp.Plo@am__quote@
490@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_hamster.Plo@am__quote@ 492@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_hamster.Plo@am__quote@
491@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_hash.Plo@am__quote@ 493@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_hash.Plo@am__quote@
494@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_inarray.Plo@am__quote@
492@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_inlist.Plo@am__quote@ 495@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_inlist.Plo@am__quote@
493@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_iterator.Plo@am__quote@ 496@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_iterator.Plo@am__quote@
494@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_lalloc.Plo@am__quote@ 497@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libeina_la-eina_lalloc.Plo@am__quote@
@@ -641,6 +644,14 @@ libeina_la-eina_hash.lo: eina_hash.c
641@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 644@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
642@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libeina_la_CFLAGS) $(CFLAGS) -c -o libeina_la-eina_hash.lo `test -f 'eina_hash.c' || echo '$(srcdir)/'`eina_hash.c 645@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libeina_la_CFLAGS) $(CFLAGS) -c -o libeina_la-eina_hash.lo `test -f 'eina_hash.c' || echo '$(srcdir)/'`eina_hash.c
643 646
647libeina_la-eina_inarray.lo: eina_inarray.c
648@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libeina_la_CFLAGS) $(CFLAGS) -MT libeina_la-eina_inarray.lo -MD -MP -MF $(DEPDIR)/libeina_la-eina_inarray.Tpo -c -o libeina_la-eina_inarray.lo `test -f 'eina_inarray.c' || echo '$(srcdir)/'`eina_inarray.c
649@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libeina_la-eina_inarray.Tpo $(DEPDIR)/libeina_la-eina_inarray.Plo
650@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
651@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='eina_inarray.c' object='libeina_la-eina_inarray.lo' libtool=yes @AMDEPBACKSLASH@
652@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
653@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libeina_la_CFLAGS) $(CFLAGS) -c -o libeina_la-eina_inarray.lo `test -f 'eina_inarray.c' || echo '$(srcdir)/'`eina_inarray.c
654
644libeina_la-eina_inlist.lo: eina_inlist.c 655libeina_la-eina_inlist.lo: eina_inlist.c
645@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libeina_la_CFLAGS) $(CFLAGS) -MT libeina_la-eina_inlist.lo -MD -MP -MF $(DEPDIR)/libeina_la-eina_inlist.Tpo -c -o libeina_la-eina_inlist.lo `test -f 'eina_inlist.c' || echo '$(srcdir)/'`eina_inlist.c 656@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libeina_la_CFLAGS) $(CFLAGS) -MT libeina_la-eina_inlist.lo -MD -MP -MF $(DEPDIR)/libeina_la-eina_inlist.Tpo -c -o libeina_la-eina_inlist.lo `test -f 'eina_inlist.c' || echo '$(srcdir)/'`eina_inlist.c
646@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libeina_la-eina_inlist.Tpo $(DEPDIR)/libeina_la-eina_inlist.Plo 657@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libeina_la-eina_inlist.Tpo $(DEPDIR)/libeina_la-eina_inlist.Plo
@@ -1189,12 +1200,17 @@ uninstall-am: uninstall-libLTLIBRARIES
1189@EINA_AMALGAMATION_TRUE@ @echo "#include <stdio.h>" >> eina_amalgamation.c 1200@EINA_AMALGAMATION_TRUE@ @echo "#include <stdio.h>" >> eina_amalgamation.c
1190@EINA_AMALGAMATION_TRUE@ @echo "#include <stdlib.h>" >> eina_amalgamation.c 1201@EINA_AMALGAMATION_TRUE@ @echo "#include <stdlib.h>" >> eina_amalgamation.c
1191@EINA_AMALGAMATION_TRUE@ @echo "#include <string.h>" >> eina_amalgamation.c 1202@EINA_AMALGAMATION_TRUE@ @echo "#include <string.h>" >> eina_amalgamation.c
1192@EINA_AMALGAMATION_TRUE@ @echo "#include <dlfcn.h>" >> eina_amalgamation.c 1203@EINA_AMALGAMATION_TRUE@ @echo "#ifdef HAVE_DLOPEN" >> eina_amalgamation.c
1204@EINA_AMALGAMATION_TRUE@ @echo "# include <dlfcn.h>" >> eina_amalgamation.c
1205@EINA_AMALGAMATION_TRUE@ @echo "#endif" >> eina_amalgamation.c
1193@EINA_AMALGAMATION_TRUE@ @echo "#include <sys/types.h>" >> eina_amalgamation.c 1206@EINA_AMALGAMATION_TRUE@ @echo "#include <sys/types.h>" >> eina_amalgamation.c
1194@EINA_AMALGAMATION_TRUE@ @echo "#include <dirent.h>" >> eina_amalgamation.c 1207@EINA_AMALGAMATION_TRUE@ @echo "#ifdef HAVE_DIRENT_H" >> eina_amalgamation.c
1208@EINA_AMALGAMATION_TRUE@ @echo "# include <dirent.h>" >> eina_amalgamation.c
1209@EINA_AMALGAMATION_TRUE@ @echo "#endif" >> eina_amalgamation.c
1195@EINA_AMALGAMATION_TRUE@ @echo "#include <assert.h>" >> eina_amalgamation.c 1210@EINA_AMALGAMATION_TRUE@ @echo "#include <assert.h>" >> eina_amalgamation.c
1196@EINA_AMALGAMATION_TRUE@ @echo "#include <errno.h>" >> eina_amalgamation.c 1211@EINA_AMALGAMATION_TRUE@ @echo "#include <errno.h>" >> eina_amalgamation.c
1197@EINA_AMALGAMATION_TRUE@ @echo "#include <fnmatch.h>" >> eina_amalgamation.c 1212@EINA_AMALGAMATION_TRUE@ @echo "#include <fnmatch.h>" >> eina_amalgamation.c
1213@EINA_AMALGAMATION_TRUE@ @echo "#include <fcntl.h>" >> eina_amalgamation.c
1198 1214
1199@EINA_AMALGAMATION_TRUE@ @echo "#ifdef HAVE_EVIL" >> eina_amalgamation.c 1215@EINA_AMALGAMATION_TRUE@ @echo "#ifdef HAVE_EVIL" >> eina_amalgamation.c
1200@EINA_AMALGAMATION_TRUE@ @echo "# include <Evil.h>" >> eina_amalgamation.c 1216@EINA_AMALGAMATION_TRUE@ @echo "# include <Evil.h>" >> eina_amalgamation.c
diff --git a/libraries/eina/src/lib/eina_array.c b/libraries/eina/src/lib/eina_array.c
index 5a850ac..4bcab61 100644
--- a/libraries/eina/src/lib/eina_array.c
+++ b/libraries/eina/src/lib/eina_array.c
@@ -119,7 +119,7 @@ eina_array_iterator_next(Eina_Iterator_Array *it, void **data)
119{ 119{
120 EINA_MAGIC_CHECK_ARRAY_ITERATOR(it, EINA_FALSE); 120 EINA_MAGIC_CHECK_ARRAY_ITERATOR(it, EINA_FALSE);
121 121
122 if (!(it->index < eina_array_count_get(it->array))) 122 if (!(it->index < eina_array_count(it->array)))
123 return EINA_FALSE; 123 return EINA_FALSE;
124 124
125 if (data) 125 if (data)
@@ -150,7 +150,7 @@ eina_array_accessor_get_at(Eina_Accessor_Array *it,
150{ 150{
151 EINA_MAGIC_CHECK_ARRAY_ACCESSOR(it, EINA_FALSE); 151 EINA_MAGIC_CHECK_ARRAY_ACCESSOR(it, EINA_FALSE);
152 152
153 if (!(idx < eina_array_count_get(it->array))) 153 if (!(idx < eina_array_count(it->array)))
154 return EINA_FALSE; 154 return EINA_FALSE;
155 155
156 if (data) 156 if (data)
diff --git a/libraries/eina/src/lib/eina_binbuf_template_c.x b/libraries/eina/src/lib/eina_binbuf_template_c.x
index 613a715..7e0c539 100644
--- a/libraries/eina/src/lib/eina_binbuf_template_c.x
+++ b/libraries/eina/src/lib/eina_binbuf_template_c.x
@@ -65,6 +65,15 @@ _FUNC_EXPAND(new)(void)
65 return buf; 65 return buf;
66} 66}
67 67
68EAPI _STRBUF_STRUCT_NAME *
69_FUNC_EXPAND(manage_new_length)(_STRBUF_DATA_TYPE *str, size_t length)
70{
71 _STRBUF_STRUCT_NAME *buf =
72 eina_strbuf_common_manage_new(_STRBUF_CSIZE, (void *) str, length);
73 EINA_MAGIC_SET(buf, _STRBUF_MAGIC);
74 return buf;
75}
76
68EAPI void 77EAPI void
69_FUNC_EXPAND(free)(_STRBUF_STRUCT_NAME *buf) 78_FUNC_EXPAND(free)(_STRBUF_STRUCT_NAME *buf)
70{ 79{
diff --git a/libraries/eina/src/lib/eina_cpu.c b/libraries/eina/src/lib/eina_cpu.c
index 8af550d..5b190e4 100644
--- a/libraries/eina/src/lib/eina_cpu.c
+++ b/libraries/eina/src/lib/eina_cpu.c
@@ -24,7 +24,7 @@
24# ifdef _WIN32 24# ifdef _WIN32
25# define WIN32_LEAN_AND_MEAN 25# define WIN32_LEAN_AND_MEAN
26# include <windows.h> 26# include <windows.h>
27# elif defined (__SUNPRO_C) || defined(__GNU__) 27# elif defined (__sun) || defined(__GNU__)
28# include <unistd.h> 28# include <unistd.h>
29# elif defined (__FreeBSD__) || defined (__OpenBSD__) || \ 29# elif defined (__FreeBSD__) || defined (__OpenBSD__) || \
30 defined (__NetBSD__) || defined (__DragonFly__) || defined (__MacOSX__) || \ 30 defined (__NetBSD__) || defined (__DragonFly__) || defined (__MacOSX__) || \
@@ -140,7 +140,7 @@ EAPI int eina_cpu_count(void)
140 GetSystemInfo(&sysinfo); 140 GetSystemInfo(&sysinfo);
141 return sysinfo.dwNumberOfProcessors; 141 return sysinfo.dwNumberOfProcessors;
142 142
143# elif defined (__SUNPRO_C) || defined(__GNU__) 143# elif defined (__sun) || defined(__GNU__)
144 /* 144 /*
145 * _SC_NPROCESSORS_ONLN: number of processors that are online, that 145 * _SC_NPROCESSORS_ONLN: number of processors that are online, that
146 is available when sysconf is called. The number 146 is available when sysconf is called. The number
diff --git a/libraries/eina/src/lib/eina_file.c b/libraries/eina/src/lib/eina_file.c
index 84b9e78..0b836b3 100644
--- a/libraries/eina/src/lib/eina_file.c
+++ b/libraries/eina/src/lib/eina_file.c
@@ -38,13 +38,18 @@ extern "C"
38void *alloca (size_t); 38void *alloca (size_t);
39#endif 39#endif
40 40
41#include <stdlib.h>
41#include <string.h> 42#include <string.h>
42#include <stddef.h> 43#include <stddef.h>
43#include <dirent.h> 44#ifdef HAVE_DIRENT_H
45# include <dirent.h>
46#endif
44#include <sys/types.h> 47#include <sys/types.h>
45#include <sys/stat.h> 48#include <sys/stat.h>
46#include <unistd.h> 49#include <unistd.h>
47#include <sys/mman.h> 50#ifdef HAVE_SYS_MMAN_H
51# include <sys/mman.h>
52#endif
48#include <fcntl.h> 53#include <fcntl.h>
49 54
50#define PATH_DELIM '/' 55#define PATH_DELIM '/'
@@ -60,6 +65,8 @@ void *alloca (size_t);
60#include "eina_list.h" 65#include "eina_list.h"
61#include "eina_lock.h" 66#include "eina_lock.h"
62#include "eina_mmap.h" 67#include "eina_mmap.h"
68#include "eina_log.h"
69#include "eina_xattr.h"
63 70
64#ifdef HAVE_ESCAPE_H 71#ifdef HAVE_ESCAPE_H
65# include <Escape.h> 72# include <Escape.h>
@@ -95,9 +102,8 @@ void *alloca (size_t);
95#define EINA_SMALL_PAGE 4096 102#define EINA_SMALL_PAGE 4096
96# define EINA_HUGE_PAGE 16 * 1024 * 1024 103# define EINA_HUGE_PAGE 16 * 1024 * 1024
97 104
105#ifdef HAVE_DIRENT_H
98typedef struct _Eina_File_Iterator Eina_File_Iterator; 106typedef struct _Eina_File_Iterator Eina_File_Iterator;
99typedef struct _Eina_File_Map Eina_File_Map;
100
101struct _Eina_File_Iterator 107struct _Eina_File_Iterator
102{ 108{
103 Eina_Iterator iterator; 109 Eina_Iterator iterator;
@@ -107,6 +113,7 @@ struct _Eina_File_Iterator
107 113
108 char dir[1]; 114 char dir[1];
109}; 115};
116#endif
110 117
111struct _Eina_File 118struct _Eina_File
112{ 119{
@@ -132,8 +139,10 @@ struct _Eina_File
132 139
133 Eina_Bool shared : 1; 140 Eina_Bool shared : 1;
134 Eina_Bool delete_me : 1; 141 Eina_Bool delete_me : 1;
142 Eina_Bool global_faulty : 1;
135}; 143};
136 144
145typedef struct _Eina_File_Map Eina_File_Map;
137struct _Eina_File_Map 146struct _Eina_File_Map
138{ 147{
139 void *map; 148 void *map;
@@ -144,6 +153,7 @@ struct _Eina_File_Map
144 int refcount; 153 int refcount;
145 154
146 Eina_Bool hugetlb : 1; 155 Eina_Bool hugetlb : 1;
156 Eina_Bool faulty : 1;
147}; 157};
148 158
149static Eina_Hash *_eina_file_cache = NULL; 159static Eina_Hash *_eina_file_cache = NULL;
@@ -156,6 +166,7 @@ static int _eina_file_log_dom = -1;
156 * The code and description of the issue can be found at : 166 * The code and description of the issue can be found at :
157 * http://womble.decadent.org.uk/readdir_r-advisory.html 167 * http://womble.decadent.org.uk/readdir_r-advisory.html
158 */ 168 */
169#ifdef HAVE_DIRENT_H
159static long 170static long
160_eina_name_max(DIR *dirp) 171_eina_name_max(DIR *dirp)
161{ 172{
@@ -390,6 +401,7 @@ _eina_file_stat_ls_iterator_next(Eina_File_Direct_Iterator *it, void **data)
390 401
391 return EINA_TRUE; 402 return EINA_TRUE;
392} 403}
404#endif
393 405
394static void 406static void
395_eina_file_real_close(Eina_File *file) 407_eina_file_real_close(Eina_File *file)
@@ -511,8 +523,8 @@ slprintf(char *str, size_t size, const char *format, ...)
511 va_end(ap); 523 va_end(ap);
512} 524}
513 525
514static char* 526static char *
515_eina_file_escape(const char* path, int* length) 527_eina_file_escape(const char *path, int *length)
516{ 528{
517 char *result = strdup(path ? path : ""); 529 char *result = strdup(path ? path : "");
518 char *p = result; 530 char *p = result;
@@ -738,6 +750,7 @@ eina_file_split(char *path)
738EAPI Eina_Iterator * 750EAPI Eina_Iterator *
739eina_file_ls(const char *dir) 751eina_file_ls(const char *dir)
740{ 752{
753#ifdef HAVE_DIRENT_H
741 Eina_File_Iterator *it; 754 Eina_File_Iterator *it;
742 size_t length; 755 size_t length;
743 756
@@ -773,11 +786,16 @@ eina_file_ls(const char *dir)
773 it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_ls_iterator_free); 786 it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_ls_iterator_free);
774 787
775 return &it->iterator; 788 return &it->iterator;
789#else
790 (void) dir;
791 return NULL;
792#endif
776} 793}
777 794
778EAPI Eina_Iterator * 795EAPI Eina_Iterator *
779eina_file_direct_ls(const char *dir) 796eina_file_direct_ls(const char *dir)
780{ 797{
798#ifdef HAVE_DIRENT_H
781 Eina_File_Direct_Iterator *it; 799 Eina_File_Direct_Iterator *it;
782 size_t length; 800 size_t length;
783 801
@@ -825,11 +843,16 @@ eina_file_direct_ls(const char *dir)
825 it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_direct_ls_iterator_free); 843 it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_direct_ls_iterator_free);
826 844
827 return &it->iterator; 845 return &it->iterator;
846#else
847 (void) dir;
848 return NULL;
849#endif
828} 850}
829 851
830EAPI Eina_Iterator * 852EAPI Eina_Iterator *
831eina_file_stat_ls(const char *dir) 853eina_file_stat_ls(const char *dir)
832{ 854{
855#ifdef HAVE_DIRENT_H
833 Eina_File_Direct_Iterator *it; 856 Eina_File_Direct_Iterator *it;
834 size_t length; 857 size_t length;
835 858
@@ -877,6 +900,10 @@ eina_file_stat_ls(const char *dir)
877 it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_direct_ls_iterator_free); 900 it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_direct_ls_iterator_free);
878 901
879 return &it->iterator; 902 return &it->iterator;
903#else
904 (void) dir;
905 return NULL;
906#endif
880} 907}
881 908
882EAPI Eina_File * 909EAPI Eina_File *
@@ -887,7 +914,9 @@ eina_file_open(const char *path, Eina_Bool shared)
887 char *filename; 914 char *filename;
888 struct stat file_stat; 915 struct stat file_stat;
889 int fd = -1; 916 int fd = -1;
917#ifdef HAVE_EXECVP
890 int flags; 918 int flags;
919#endif
891 920
892 EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); 921 EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL);
893 922
@@ -1184,4 +1213,91 @@ eina_file_map_free(Eina_File *file, void *map)
1184 eina_lock_release(&file->lock); 1213 eina_lock_release(&file->lock);
1185} 1214}
1186 1215
1216EAPI Eina_Bool
1217eina_file_map_faulted(Eina_File *file, void *map)
1218{
1219 Eina_File_Map *em;
1220
1221 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
1222
1223 eina_lock_take(&file->lock);
1224
1225 if (file->global_map == map) return file->global_faulty;
1226
1227 em = eina_hash_find(file->rmap, &map);
1228 if (!em) return EINA_FALSE;
1229
1230 return em->faulty;
1231}
1232
1233EAPI Eina_Iterator *
1234eina_file_xattr_get(Eina_File *file)
1235{
1236 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
1237
1238 return eina_xattr_fd_ls(file->fd);
1239}
1240
1241EAPI Eina_Iterator *
1242eina_file_xattr_value_get(Eina_File *file)
1243{
1244 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
1245
1246 return eina_xattr_value_fd_ls(file->fd);
1247}
1248
1249void
1250eina_file_mmap_faulty(void *addr, long page_size)
1251{
1252 Eina_File_Map *m;
1253 Eina_File *f;
1254 Eina_Iterator *itf;
1255 Eina_Iterator *itm;
1256
1257 /* NOTE: I actually don't know if other thread are running, I will try to take the lock.
1258 It may be possible that if other thread are not running and they were in the middle of
1259 accessing an Eina_File this lock are still taken and we will result as a deadlock. */
1260 eina_lock_take(&_eina_file_lock_cache);
1261
1262 itf = eina_hash_iterator_data_new(_eina_file_cache);
1263 EINA_ITERATOR_FOREACH(itf, f)
1264 {
1265 Eina_Bool faulty = EINA_FALSE;
1266
1267 eina_lock_take(&f->lock);
1268
1269 if (f->global_map)
1270 {
1271 if ((unsigned char *) addr < (((unsigned char *)f->global_map) + f->length) &&
1272 (((unsigned char *) addr) + page_size) >= (unsigned char *) f->global_map)
1273 {
1274 f->global_faulty = EINA_TRUE;
1275 faulty = EINA_TRUE;
1276 }
1277 }
1278
1279 if (!faulty)
1280 {
1281 itm = eina_hash_iterator_data_new(f->map);
1282 EINA_ITERATOR_FOREACH(itm, m)
1283 {
1284 if ((unsigned char *) addr < (((unsigned char *)m->map) + m->length) &&
1285 (((unsigned char *) addr) + page_size) >= (unsigned char *) m->map)
1286 {
1287 m->faulty = EINA_TRUE;
1288 faulty = EINA_TRUE;
1289 break;
1290 }
1291 }
1292 eina_iterator_free(itm);
1293 }
1294
1295 eina_lock_release(&f->lock);
1296
1297 if (faulty) break;
1298 }
1299 eina_iterator_free(itf);
1300
1301 eina_lock_release(&_eina_file_lock_cache);
1302}
1187 1303
diff --git a/libraries/eina/src/lib/eina_hash.c b/libraries/eina/src/lib/eina_hash.c
index 5df20aa..5196894 100644
--- a/libraries/eina/src/lib/eina_hash.c
+++ b/libraries/eina/src/lib/eina_hash.c
@@ -854,8 +854,9 @@ eina_hash_free(Eina_Hash *hash)
854{ 854{
855 int i; 855 int i;
856 856
857 if (!hash) return ;
858
857 EINA_MAGIC_CHECK_HASH(hash); 859 EINA_MAGIC_CHECK_HASH(hash);
858 EINA_SAFETY_ON_NULL_RETURN(hash);
859 860
860 if (hash->buckets) 861 if (hash->buckets)
861 { 862 {
@@ -871,8 +872,9 @@ eina_hash_free_buckets(Eina_Hash *hash)
871{ 872{
872 int i; 873 int i;
873 874
875 if (!hash) return ;
876
874 EINA_MAGIC_CHECK_HASH(hash); 877 EINA_MAGIC_CHECK_HASH(hash);
875 EINA_SAFETY_ON_NULL_RETURN(hash);
876 878
877 if (hash->buckets) 879 if (hash->buckets)
878 { 880 {
diff --git a/libraries/eina/src/lib/eina_inarray.c b/libraries/eina/src/lib/eina_inarray.c
new file mode 100644
index 0000000..dc95bc6
--- /dev/null
+++ b/libraries/eina/src/lib/eina_inarray.c
@@ -0,0 +1,777 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2012 - ProFUSION embedded systems
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <stdlib.h>
24#include <string.h>
25
26#include "eina_config.h"
27#include "eina_private.h"
28#include "eina_error.h"
29#include "eina_log.h"
30
31/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
32#include "eina_safety_checks.h"
33#include "eina_inarray.h"
34
35/*============================================================================*
36* Local *
37*============================================================================*/
38
39/**
40 * @cond LOCAL
41 */
42
43static const char EINA_MAGIC_INARRAY_STR[] = "Eina Inline Array";
44static const char EINA_MAGIC_INARRAY_ITERATOR_STR[] = "Eina Inline Array Iterator";
45static const char EINA_MAGIC_INARRAY_ACCESSOR_STR[] = "Eina Inline Array Accessor";
46
47typedef struct _Eina_Iterator_Inarray Eina_Iterator_Inarray;
48typedef struct _Eina_Accessor_Inarray Eina_Accessor_Inarray;
49
50struct _Eina_Iterator_Inarray
51{
52 Eina_Iterator iterator;
53 const Eina_Inarray *array;
54 unsigned int pos;
55 EINA_MAGIC
56};
57
58struct _Eina_Accessor_Inarray
59{
60 Eina_Accessor accessor;
61 const Eina_Inarray *array;
62 EINA_MAGIC
63};
64
65static int _eina_inarray_log_dom = -1;
66
67#ifdef ERR
68#undef ERR
69#endif
70#define ERR(...) EINA_LOG_DOM_ERR(_eina_inarray_log_dom, __VA_ARGS__)
71
72#ifdef DBG
73#undef DBG
74#endif
75#define DBG(...) EINA_LOG_DOM_DBG(_eina_inarray_log_dom, __VA_ARGS__)
76
77#define EINA_MAGIC_CHECK_INARRAY(d, ...) \
78 do \
79 { \
80 if (!EINA_MAGIC_CHECK(d, EINA_MAGIC_INARRAY)) \
81 { \
82 EINA_MAGIC_FAIL(d, EINA_MAGIC_INARRAY); \
83 return __VA_ARGS__; \
84 } \
85 eina_error_set(0); \
86 } \
87 while(0)
88
89#define EINA_MAGIC_CHECK_INARRAY_ITERATOR(d, ...) \
90 do \
91 { \
92 if (!EINA_MAGIC_CHECK(d, EINA_MAGIC_INARRAY_ITERATOR)) \
93 { \
94 EINA_MAGIC_FAIL(d, EINA_MAGIC_INARRAY_ITERATOR); \
95 return __VA_ARGS__; \
96 } \
97 eina_error_set(0); \
98 } \
99 while(0)
100
101#define EINA_MAGIC_CHECK_INARRAY_ACCESSOR(d, ...) \
102 do \
103 { \
104 if (!EINA_MAGIC_CHECK(d, EINA_MAGIC_INARRAY_ACCESSOR)) \
105 { \
106 EINA_MAGIC_FAIL(d, EINA_MAGIC_INARRAY_ACCESSOR); \
107 return __VA_ARGS__; \
108 } \
109 eina_error_set(0); \
110 } \
111 while(0)
112
113static void
114_eina_inarray_setup(Eina_Inarray *array, unsigned int member_size, unsigned int step)
115{
116 EINA_MAGIC_SET(array, EINA_MAGIC_INARRAY);
117 array->member_size = member_size;
118 array->len = 0;
119 array->max = 0;
120 array->step = (step > 0) ? step : 32;
121 array->members = NULL;
122}
123
124static Eina_Bool
125_eina_inarray_resize(Eina_Inarray *array, unsigned int new_size)
126{
127 unsigned int new_max;
128 void *tmp;
129
130 if (new_size < array->max)
131 return EINA_TRUE;
132
133 if (new_size % array->step == 0)
134 new_max = new_size;
135 else
136 new_max = ((new_size / array->step) + 1) * array->step;
137
138 tmp = realloc(array->members, new_max * array->member_size);
139 if ((!tmp) && (new_max > 0))
140 {
141 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
142 return EINA_FALSE;
143 }
144
145 array->members = tmp;
146 array->max = new_max;
147 return EINA_TRUE;
148}
149
150static inline void *
151_eina_inarray_get(const Eina_Inarray *array, unsigned int position)
152{
153 unsigned int offset = position * array->member_size;
154 return (unsigned char *)array->members + offset;
155}
156
157static int
158_eina_inarray_search(const Eina_Inarray *array, const void *data, Eina_Compare_Cb compare)
159{
160 const unsigned char *start, *found;
161 start = array->members;
162 found = bsearch(data, start, array->len, array->member_size, compare);
163 if (!found)
164 return -1;
165 return (found - start) / array->member_size;
166}
167
168static unsigned int
169_eina_inarray_search_sorted_near(const Eina_Inarray *array, const void *data, Eina_Compare_Cb compare, int *cmp)
170{
171 unsigned int start, last, middle;
172
173 if (array->len == 0)
174 {
175 *cmp = -1;
176 return 0;
177 }
178 else if (array->len == 1)
179 {
180 *cmp = compare(data, array->members);
181 return 0;
182 }
183
184 start = 0;
185 last = array->len - 1; /* inclusive */
186 do
187 {
188 void *p;
189 middle = start + (last - start) / 2; /* avoid overflow */
190 p = _eina_inarray_get(array, middle);
191 *cmp = compare(data, p);
192 if (*cmp == 0)
193 return middle;
194 else if (*cmp > 0)
195 start = middle + 1;
196 else if (middle > 0)
197 last = middle - 1;
198 else
199 break;
200 }
201 while (start <= last);
202 return middle;
203}
204
205
206static Eina_Bool
207_eina_inarray_iterator_next(Eina_Iterator_Inarray *it, void **data)
208{
209 EINA_MAGIC_CHECK_INARRAY_ITERATOR(it, EINA_FALSE);
210
211 if (it->pos >= it->array->len)
212 return EINA_FALSE;
213
214 *data = _eina_inarray_get(it->array, it->pos);
215 it->pos++;
216
217 return EINA_TRUE;
218}
219
220static Eina_Bool
221_eina_inarray_iterator_prev(Eina_Iterator_Inarray *it, void **data)
222{
223 EINA_MAGIC_CHECK_INARRAY_ITERATOR(it, EINA_FALSE);
224
225 if (it->pos == 0)
226 return EINA_FALSE;
227
228 it->pos--;
229 *data = _eina_inarray_get(it->array, it->pos);
230
231 return EINA_TRUE;
232}
233
234static Eina_Inarray *
235_eina_inarray_iterator_get_container(Eina_Iterator_Inarray *it)
236{
237 EINA_MAGIC_CHECK_INARRAY_ITERATOR(it, NULL);
238 return (Eina_Inarray *)it->array;
239}
240
241static void
242_eina_inarray_iterator_free(Eina_Iterator_Inarray *it)
243{
244 EINA_MAGIC_CHECK_INARRAY_ITERATOR(it);
245 MAGIC_FREE(it);
246}
247
248static Eina_Bool
249_eina_inarray_accessor_get_at(Eina_Accessor_Inarray *it, unsigned int pos, void **data)
250{
251 EINA_MAGIC_CHECK_INARRAY_ACCESSOR(it, EINA_FALSE);
252
253 if (pos >= it->array->len)
254 return EINA_FALSE;
255
256 *data = _eina_inarray_get(it->array, pos);
257 return EINA_TRUE;
258}
259
260static Eina_Inarray *
261_eina_inarray_accessor_get_container(Eina_Accessor_Inarray *it)
262{
263 EINA_MAGIC_CHECK_INARRAY_ACCESSOR(it, NULL);
264 return (Eina_Inarray *)it->array;
265}
266
267static void
268_eina_inarray_accessor_free(Eina_Accessor_Inarray *it)
269{
270 EINA_MAGIC_CHECK_INARRAY_ACCESSOR(it);
271 MAGIC_FREE(it);
272}
273
274/**
275 * @endcond
276 */
277
278
279/*============================================================================*
280* Global *
281*============================================================================*/
282
283/**
284 * @internal
285 * @brief Initialize the inline array module.
286 *
287 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
288 *
289 * This function sets up the inline array module of Eina. It is called
290 * by eina_init().
291 *
292 * @see eina_init()
293 */
294Eina_Bool
295eina_inarray_init(void)
296{
297 _eina_inarray_log_dom = eina_log_domain_register("eina_inarray",
298 EINA_LOG_COLOR_DEFAULT);
299 if (_eina_inarray_log_dom < 0)
300 {
301 EINA_LOG_ERR("Could not register log domain: eina_inarray");
302 return EINA_FALSE;
303 }
304
305#define EMS(n) eina_magic_string_static_set(n, n ## _STR)
306 EMS(EINA_MAGIC_INARRAY);
307 EMS(EINA_MAGIC_INARRAY_ITERATOR);
308 EMS(EINA_MAGIC_INARRAY_ACCESSOR);
309#undef EMS
310
311 return EINA_TRUE;
312}
313
314/**
315 * @internal
316 * @brief Shut down the inline array module.
317 *
318 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
319 *
320 * This function shuts down the inline array module set up by
321 * eina_inarray_init(). It is called by eina_shutdown().
322 *
323 * @see eina_shutdown()
324 */
325Eina_Bool
326eina_inarray_shutdown(void)
327{
328 eina_log_domain_unregister(_eina_inarray_log_dom);
329 _eina_inarray_log_dom = -1;
330 return EINA_TRUE;
331}
332
333/*============================================================================*
334* API *
335*============================================================================*/
336EAPI Eina_Inarray *
337eina_inarray_new(unsigned int member_size, unsigned int step)
338{
339 Eina_Inarray *ret;
340
341 EINA_SAFETY_ON_TRUE_RETURN_VAL(member_size == 0, NULL);
342
343 ret = malloc(sizeof(*ret));
344 if (!ret)
345 {
346 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
347 return NULL;
348 }
349 eina_error_set(0);
350 _eina_inarray_setup(ret, member_size, step);
351 return ret;
352}
353
354EAPI void
355eina_inarray_free(Eina_Inarray *array)
356{
357 EINA_MAGIC_CHECK_INARRAY(array);
358 free(array->members);
359 free(array);
360}
361
362EAPI void
363eina_inarray_setup(Eina_Inarray *array, unsigned int member_size, unsigned int step)
364{
365 EINA_SAFETY_ON_NULL_RETURN(array);
366 EINA_SAFETY_ON_TRUE_RETURN(member_size == 0);
367 _eina_inarray_setup(array, member_size, step);
368}
369
370EAPI void
371eina_inarray_flush(Eina_Inarray *array)
372{
373 EINA_MAGIC_CHECK_INARRAY(array);
374 free(array->members);
375 array->len = 0;
376 array->max = 0;
377 array->members = NULL;
378}
379
380EAPI int
381eina_inarray_append(Eina_Inarray *array, const void *data)
382{
383 void *p;
384
385 EINA_MAGIC_CHECK_INARRAY(array, -1);
386 EINA_SAFETY_ON_NULL_RETURN_VAL(data, -1);
387
388 if (!_eina_inarray_resize(array, array->len + 1))
389 return -1;
390
391 p = _eina_inarray_get(array, array->len);
392 memcpy(p, data, array->member_size);
393
394 array->len++;
395 return array->len - 1;
396}
397
398EAPI int
399eina_inarray_insert(Eina_Inarray *array, const void *data, Eina_Compare_Cb compare)
400{
401 const unsigned char *itr, *itr_end;
402 unsigned int sz;
403
404 EINA_MAGIC_CHECK_INARRAY(array, -1);
405 EINA_SAFETY_ON_NULL_RETURN_VAL(data, -1);
406 EINA_SAFETY_ON_NULL_RETURN_VAL(compare, -1);
407
408 sz = array->member_size;
409 itr = array->members;
410 itr_end = itr + array->len * sz;
411 for (; itr < itr_end; itr += sz)
412 {
413 unsigned int offset, position;
414 int cmp = compare(itr, data);
415 if (cmp <= 0)
416 continue;
417
418 offset = itr - (unsigned char *)array->members;
419 position = offset / sz;
420 if (!eina_inarray_insert_at(array, position, data))
421 return -1;
422 return position;
423 }
424 return eina_inarray_append(array, data);
425}
426
427EAPI int
428eina_inarray_insert_sorted(Eina_Inarray *array, const void *data, Eina_Compare_Cb compare)
429{
430 unsigned int pos;
431 int cmp;
432
433 EINA_MAGIC_CHECK_INARRAY(array, -1);
434 EINA_SAFETY_ON_NULL_RETURN_VAL(data, -1);
435 EINA_SAFETY_ON_NULL_RETURN_VAL(compare, -1);
436
437 pos = _eina_inarray_search_sorted_near(array, data, compare, &cmp);
438 if (cmp > 0)
439 pos++;
440
441 if (!eina_inarray_insert_at(array, pos, data))
442 return -1;
443 return pos;
444}
445
446EAPI int
447eina_inarray_remove(Eina_Inarray *array, const void *data)
448{
449 const unsigned char *itr, *itr_end;
450 unsigned int position, sz;
451
452 EINA_MAGIC_CHECK_INARRAY(array, -1);
453 EINA_SAFETY_ON_NULL_RETURN_VAL(data, -1);
454
455 sz = array->member_size;
456 if ((data >= array->members) &&
457 (data < _eina_inarray_get(array, array->len)))
458 {
459 unsigned int offset = ((unsigned char *)data -
460 (unsigned char *)array->members);
461 position = offset / sz;
462 goto found;
463 }
464
465 itr = array->members;
466 itr_end = itr + array->len * sz;
467 for (; itr < itr_end; itr += sz)
468 {
469 if (memcmp(data, itr, sz) == 0)
470 {
471 unsigned int offset = itr - (unsigned char *)array->members;
472 position = offset / sz;
473 goto found;
474 }
475 }
476 return -1;
477
478found:
479 if (!eina_inarray_remove_at(array, position))
480 return -1;
481 return position;
482}
483
484EAPI int
485eina_inarray_pop(Eina_Inarray *array)
486{
487 EINA_MAGIC_CHECK_INARRAY(array, -1);
488 EINA_SAFETY_ON_TRUE_RETURN_VAL(array->len == 0, -1);
489 if (!_eina_inarray_resize(array, array->len - 1))
490 return -1;
491 array->len--;
492 return array->len + 1;
493}
494
495EAPI void *
496eina_inarray_nth(const Eina_Inarray *array, unsigned int position)
497{
498 EINA_MAGIC_CHECK_INARRAY(array, NULL);
499 EINA_SAFETY_ON_TRUE_RETURN_VAL(position >= array->len, NULL);
500 return _eina_inarray_get(array, position);
501}
502
503EAPI Eina_Bool
504eina_inarray_insert_at(Eina_Inarray *array, unsigned int position, const void *data)
505{
506 unsigned int sz;
507 unsigned char *p;
508
509 EINA_MAGIC_CHECK_INARRAY(array, EINA_FALSE);
510 EINA_SAFETY_ON_TRUE_RETURN_VAL(position > array->len, EINA_FALSE);
511
512 if (!_eina_inarray_resize(array, array->len + 1))
513 return EINA_FALSE;
514
515 p = _eina_inarray_get(array, position);
516 sz = array->member_size;
517 if (array->len > position)
518 memmove(p + sz, p, (array->len - position) * sz);
519 memcpy(p, data, sz);
520
521 array->len++;
522 return EINA_TRUE;
523}
524
525EAPI void *
526eina_inarray_alloc_at(Eina_Inarray *array, unsigned int position, unsigned int member_count)
527{
528 unsigned int sz;
529 unsigned char *p;
530
531 EINA_MAGIC_CHECK_INARRAY(array, NULL);
532 EINA_SAFETY_ON_TRUE_RETURN_VAL(position > array->len, NULL);
533 EINA_SAFETY_ON_TRUE_RETURN_VAL(member_count == 0, NULL);
534
535 if (!_eina_inarray_resize(array, array->len + member_count))
536 return NULL;
537
538 p = _eina_inarray_get(array, position);
539 sz = array->member_size;
540 if (array->len > position)
541 memmove(p + member_count * sz, p, (array->len - position) * sz);
542
543 array->len += member_count;
544 return p;
545}
546
547EAPI Eina_Bool
548eina_inarray_replace_at(Eina_Inarray *array, unsigned int position, const void *data)
549{
550 unsigned char *p;
551
552 EINA_MAGIC_CHECK_INARRAY(array, EINA_FALSE);
553 EINA_SAFETY_ON_TRUE_RETURN_VAL(position >= array->len, EINA_FALSE);
554
555 p = _eina_inarray_get(array, position);
556 memcpy(p, data, array->member_size);
557
558 return EINA_TRUE;
559}
560
561EAPI Eina_Bool
562eina_inarray_remove_at(Eina_Inarray *array, unsigned int position)
563{
564 EINA_MAGIC_CHECK_INARRAY(array, EINA_FALSE);
565 EINA_SAFETY_ON_TRUE_RETURN_VAL(position >= array->len, EINA_FALSE);
566
567 if (position + 1 < array->len)
568 {
569 unsigned int sz = array->member_size;
570 unsigned char *p = _eina_inarray_get(array, position);
571 memmove(p, p + sz, (array->len - position - 1) * sz);
572 }
573
574 _eina_inarray_resize(array, array->len - 1);
575 array->len--;
576 return EINA_TRUE;
577}
578
579EAPI void
580eina_inarray_reverse(Eina_Inarray *array)
581{
582 size_t sz;
583 unsigned char *fwd, *rev, *fwd_end;
584 void *tmp;
585
586 EINA_MAGIC_CHECK_INARRAY(array);
587
588 if (array->len < 2)
589 return;
590
591 sz = array->member_size;
592
593 tmp = alloca(sz);
594 EINA_SAFETY_ON_NULL_RETURN(tmp);
595
596 fwd = array->members;
597 fwd_end = fwd + (array->len / 2) * sz;
598
599 rev = fwd + (array->len - 1) * sz;
600
601 for (; fwd < fwd_end; fwd += sz, rev -= sz)
602 {
603 memcpy(tmp, fwd, sz);
604 memcpy(fwd, rev, sz);
605 memcpy(rev, tmp, sz);
606 }
607}
608
609EAPI void
610eina_inarray_sort(Eina_Inarray *array, Eina_Compare_Cb compare)
611{
612 EINA_MAGIC_CHECK_INARRAY(array);
613 EINA_SAFETY_ON_NULL_RETURN(compare);
614 qsort(array->members, array->len, array->member_size, compare);
615}
616
617EAPI int
618eina_inarray_search(const Eina_Inarray *array, const void *data, Eina_Compare_Cb compare)
619{
620 EINA_MAGIC_CHECK_INARRAY(array, -1);
621 EINA_SAFETY_ON_NULL_RETURN_VAL(data, -1);
622 EINA_SAFETY_ON_NULL_RETURN_VAL(compare, -1);
623 return _eina_inarray_search(array, data, compare);
624}
625
626EAPI int
627eina_inarray_search_sorted(const Eina_Inarray *array, const void *data, Eina_Compare_Cb compare)
628{
629 unsigned int pos;
630 int cmp;
631
632 EINA_MAGIC_CHECK_INARRAY(array, -1);
633 EINA_SAFETY_ON_NULL_RETURN_VAL(data, -1);
634 EINA_SAFETY_ON_NULL_RETURN_VAL(compare, -1);
635
636 pos = _eina_inarray_search_sorted_near(array, data, compare, &cmp);
637 if (cmp == 0)
638 return pos;
639 return -1;
640}
641
642EAPI Eina_Bool
643eina_inarray_foreach(const Eina_Inarray *array, Eina_Each_Cb function, const void *user_data)
644{
645 unsigned char *itr, *itr_end;
646 unsigned int sz;
647 Eina_Bool ret = EINA_TRUE;
648
649 EINA_MAGIC_CHECK_INARRAY(array, EINA_FALSE);
650 EINA_SAFETY_ON_NULL_RETURN_VAL(function, EINA_FALSE);
651
652 sz = array->member_size;
653 itr = array->members;
654 itr_end = itr + array->len * sz;
655 for (; (itr < itr_end) && (ret); itr += sz)
656 ret = function(array, itr, (void *)user_data);
657 return ret;
658}
659
660EAPI int
661eina_inarray_foreach_remove(Eina_Inarray *array, Eina_Each_Cb match, const void *user_data)
662{
663 unsigned int i = 0, count = 0;
664
665 EINA_MAGIC_CHECK_INARRAY(array, -1);
666 EINA_SAFETY_ON_NULL_RETURN_VAL(match, -1);
667
668 while (i < array->len)
669 {
670 void *p = _eina_inarray_get(array, i);
671 if (match(array, p, (void *)user_data) == EINA_FALSE)
672 {
673 i++;
674 continue;
675 }
676
677 eina_inarray_remove_at(array, i);
678 count++;
679 }
680
681 return count;
682}
683
684EAPI unsigned int
685eina_inarray_count(const Eina_Inarray *array)
686{
687 EINA_MAGIC_CHECK_INARRAY(array, 0);
688 return array->len;
689}
690
691EAPI Eina_Iterator *
692eina_inarray_iterator_new(const Eina_Inarray *array)
693{
694 Eina_Iterator_Inarray *it;
695
696 EINA_MAGIC_CHECK_INARRAY(array, NULL);
697
698 eina_error_set(0);
699 it = calloc(1, sizeof(Eina_Iterator_Inarray));
700 if (!it)
701 {
702 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
703 return NULL;
704 }
705
706 EINA_MAGIC_SET(it, EINA_MAGIC_INARRAY_ITERATOR);
707 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
708
709 it->array = array;
710
711 it->iterator.version = EINA_ITERATOR_VERSION;
712 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_inarray_iterator_next);
713 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER
714 (_eina_inarray_iterator_get_container);
715 it->iterator.free = FUNC_ITERATOR_FREE(_eina_inarray_iterator_free);
716
717 return &it->iterator;
718}
719
720EAPI Eina_Iterator *
721eina_inarray_iterator_reversed_new(const Eina_Inarray *array)
722{
723 Eina_Iterator_Inarray *it;
724
725 EINA_MAGIC_CHECK_INARRAY(array, NULL);
726
727 eina_error_set(0);
728 it = calloc(1, sizeof(Eina_Iterator_Inarray));
729 if (!it)
730 {
731 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
732 return NULL;
733 }
734
735 EINA_MAGIC_SET(it, EINA_MAGIC_INARRAY_ITERATOR);
736 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
737
738 it->array = array;
739 it->pos = array->len;
740
741 it->iterator.version = EINA_ITERATOR_VERSION;
742 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_inarray_iterator_prev);
743 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER
744 (_eina_inarray_iterator_get_container);
745 it->iterator.free = FUNC_ITERATOR_FREE(_eina_inarray_iterator_free);
746
747 return &it->iterator;
748}
749
750EAPI Eina_Accessor *
751eina_inarray_accessor_new(const Eina_Inarray *array)
752{
753 Eina_Accessor_Inarray *ac;
754
755 EINA_MAGIC_CHECK_INARRAY(array, NULL);
756
757 eina_error_set(0);
758 ac = calloc(1, sizeof(Eina_Accessor_Inarray));
759 if (!ac)
760 {
761 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
762 return NULL;
763 }
764
765 EINA_MAGIC_SET(ac, EINA_MAGIC_INARRAY_ACCESSOR);
766 EINA_MAGIC_SET(&ac->accessor, EINA_MAGIC_ACCESSOR);
767
768 ac->array = array;
769
770 ac->accessor.version = EINA_ACCESSOR_VERSION;
771 ac->accessor.get_at = FUNC_ACCESSOR_GET_AT(_eina_inarray_accessor_get_at);
772 ac->accessor.get_container = FUNC_ACCESSOR_GET_CONTAINER
773 (_eina_inarray_accessor_get_container);
774 ac->accessor.free = FUNC_ACCESSOR_FREE(_eina_inarray_accessor_free);
775
776 return &ac->accessor;
777}
diff --git a/libraries/eina/src/lib/eina_log.c b/libraries/eina/src/lib/eina_log.c
index dd772d2..4e2bb6d 100644
--- a/libraries/eina/src/lib/eina_log.c
+++ b/libraries/eina/src/lib/eina_log.c
@@ -71,6 +71,7 @@
71#define EINA_LOG_ENV_FILE_DISABLE "EINA_LOG_FILE_DISABLE" 71#define EINA_LOG_ENV_FILE_DISABLE "EINA_LOG_FILE_DISABLE"
72#define EINA_LOG_ENV_FUNCTION_DISABLE "EINA_LOG_FUNCTION_DISABLE" 72#define EINA_LOG_ENV_FUNCTION_DISABLE "EINA_LOG_FUNCTION_DISABLE"
73 73
74#ifdef EINA_ENABLE_LOG
74 75
75// Structure for storing domain level settings passed from the command line 76// Structure for storing domain level settings passed from the command line
76// that will be matched with application-defined domains. 77// that will be matched with application-defined domains.
@@ -1294,6 +1295,8 @@ eina_log_print_unlocked(int domain,
1294 abort(); 1295 abort();
1295} 1296}
1296 1297
1298#endif
1299
1297/** 1300/**
1298 * @endcond 1301 * @endcond
1299 */ 1302 */
@@ -1321,6 +1324,7 @@ eina_log_print_unlocked(int domain,
1321Eina_Bool 1324Eina_Bool
1322eina_log_init(void) 1325eina_log_init(void)
1323{ 1326{
1327#ifdef EINA_ENABLE_LOG
1324 const char *level, *tmp; 1328 const char *level, *tmp;
1325 int color_disable; 1329 int color_disable;
1326 1330
@@ -1392,6 +1396,7 @@ eina_log_init(void)
1392 // Parse pending domains passed through EINA_LOG_LEVELS 1396 // Parse pending domains passed through EINA_LOG_LEVELS
1393 eina_log_domain_parse_pendings(); 1397 eina_log_domain_parse_pendings();
1394 1398
1399#endif
1395 return EINA_TRUE; 1400 return EINA_TRUE;
1396} 1401}
1397 1402
@@ -1413,6 +1418,7 @@ eina_log_init(void)
1413Eina_Bool 1418Eina_Bool
1414eina_log_shutdown(void) 1419eina_log_shutdown(void)
1415{ 1420{
1421#ifdef EINA_ENABLE_LOG
1416 Eina_Inlist *tmp; 1422 Eina_Inlist *tmp;
1417 1423
1418 while (_log_domains_count--) 1424 while (_log_domains_count--)
@@ -1443,6 +1449,7 @@ eina_log_shutdown(void)
1443 free(tmp); 1449 free(tmp);
1444 } 1450 }
1445 1451
1452#endif
1446 return EINA_TRUE; 1453 return EINA_TRUE;
1447} 1454}
1448 1455
@@ -1460,10 +1467,12 @@ eina_log_shutdown(void)
1460void 1467void
1461eina_log_threads_init(void) 1468eina_log_threads_init(void)
1462{ 1469{
1470#ifdef EINA_ENABLE_LOG
1463 if (_threads_inited) return; 1471 if (_threads_inited) return;
1464 _main_thread = SELF(); 1472 _main_thread = SELF();
1465 if (!INIT()) return; 1473 if (!INIT()) return;
1466 _threads_inited = EINA_TRUE; 1474 _threads_inited = EINA_TRUE;
1475#endif
1467} 1476}
1468 1477
1469/** 1478/**
@@ -1478,11 +1487,13 @@ eina_log_threads_init(void)
1478void 1487void
1479eina_log_threads_shutdown(void) 1488eina_log_threads_shutdown(void)
1480{ 1489{
1490#ifdef EINA_ENABLE_LOG
1481 if (!_threads_inited) return; 1491 if (!_threads_inited) return;
1482 CHECK_MAIN(); 1492 CHECK_MAIN();
1483 SHUTDOWN(); 1493 SHUTDOWN();
1484 _threads_enabled = EINA_FALSE; 1494 _threads_enabled = EINA_FALSE;
1485 _threads_inited = EINA_FALSE; 1495 _threads_inited = EINA_FALSE;
1496#endif
1486} 1497}
1487 1498
1488#endif 1499#endif
@@ -1504,7 +1515,7 @@ EAPI int EINA_LOG_DOMAIN_GLOBAL = 0;
1504EAPI void 1515EAPI void
1505eina_log_threads_enable(void) 1516eina_log_threads_enable(void)
1506{ 1517{
1507#ifdef EFL_HAVE_THREADS 1518#if defined (EFL_HAVE_THREADS) && defined (EINA_ENABLE_LOG)
1508 if (_threads_enabled) return; 1519 if (_threads_enabled) return;
1509 if (!_threads_inited) eina_log_threads_init(); 1520 if (!_threads_inited) eina_log_threads_init();
1510 _threads_enabled = EINA_TRUE; 1521 _threads_enabled = EINA_TRUE;
@@ -1515,32 +1526,45 @@ eina_log_threads_enable(void)
1515EAPI void 1526EAPI void
1516eina_log_print_cb_set(Eina_Log_Print_Cb cb, void *data) 1527eina_log_print_cb_set(Eina_Log_Print_Cb cb, void *data)
1517{ 1528{
1529#ifdef EINA_ENABLE_LOG
1518 LOG_LOCK(); 1530 LOG_LOCK();
1519 _print_cb = cb; 1531 _print_cb = cb;
1520 _print_cb_data = data; 1532 _print_cb_data = data;
1521 eina_log_print_prefix_update(); 1533 eina_log_print_prefix_update();
1522 LOG_UNLOCK(); 1534 LOG_UNLOCK();
1535#else
1536 (void) cb;
1537 (void) data;
1538#endif
1523} 1539}
1524 1540
1525EAPI void 1541EAPI void
1526eina_log_level_set(int level) 1542eina_log_level_set(int level)
1527{ 1543{
1544#ifdef EINA_ENABLE_LOG
1528 _log_level = level; 1545 _log_level = level;
1529 if (EINA_LIKELY((EINA_LOG_DOMAIN_GLOBAL >= 0) && 1546 if (EINA_LIKELY((EINA_LOG_DOMAIN_GLOBAL >= 0) &&
1530 ((unsigned int)EINA_LOG_DOMAIN_GLOBAL < _log_domains_count))) 1547 ((unsigned int)EINA_LOG_DOMAIN_GLOBAL < _log_domains_count)))
1531 _log_domains[EINA_LOG_DOMAIN_GLOBAL].level = level; 1548 _log_domains[EINA_LOG_DOMAIN_GLOBAL].level = level;
1549#else
1550 (void) level;
1551#endif
1532} 1552}
1533 1553
1534EAPI int 1554EAPI int
1535eina_log_level_get(void) 1555eina_log_level_get(void)
1536{ 1556{
1557#ifdef EINA_ENABLE_LOG
1537 return _log_level; 1558 return _log_level;
1559#else
1560 return 0;
1561#endif
1538} 1562}
1539 1563
1540EAPI Eina_Bool 1564EAPI Eina_Bool
1541eina_log_main_thread_check(void) 1565eina_log_main_thread_check(void)
1542{ 1566{
1543#ifdef EFL_HAVE_THREADS 1567#if defined (EFL_HAVE_THREADS) && defined (EINA_ENABLE_LOG)
1544 return ((!_threads_enabled) || IS_MAIN(SELF())); 1568 return ((!_threads_enabled) || IS_MAIN(SELF()));
1545#else 1569#else
1546 return EINA_TRUE; 1570 return EINA_TRUE;
@@ -1550,66 +1574,107 @@ eina_log_main_thread_check(void)
1550EAPI void 1574EAPI void
1551eina_log_color_disable_set(Eina_Bool disabled) 1575eina_log_color_disable_set(Eina_Bool disabled)
1552{ 1576{
1577#ifdef EINA_ENABLE_LOG
1553 _disable_color = disabled; 1578 _disable_color = disabled;
1579#else
1580 (void) disabled;
1581#endif
1554} 1582}
1555 1583
1556EAPI Eina_Bool 1584EAPI Eina_Bool
1557eina_log_color_disable_get(void) 1585eina_log_color_disable_get(void)
1558{ 1586{
1587#ifdef EINA_ENABLE_LOG
1559 return _disable_color; 1588 return _disable_color;
1589#else
1590 return EINA_TRUE;
1591#endif
1560} 1592}
1561 1593
1562EAPI void 1594EAPI void
1563eina_log_file_disable_set(Eina_Bool disabled) 1595eina_log_file_disable_set(Eina_Bool disabled)
1564{ 1596{
1597#ifdef EINA_ENABLE_LOG
1565 _disable_file = disabled; 1598 _disable_file = disabled;
1599#else
1600 (void) disabled;
1601#endif
1566} 1602}
1567 1603
1568EAPI Eina_Bool 1604EAPI Eina_Bool
1569eina_log_file_disable_get(void) 1605eina_log_file_disable_get(void)
1570{ 1606{
1607#ifdef EINA_ENABLE_LOG
1571 return _disable_file; 1608 return _disable_file;
1609#else
1610 return EINA_TRUE;
1611#endif
1572} 1612}
1573 1613
1574EAPI void 1614EAPI void
1575eina_log_function_disable_set(Eina_Bool disabled) 1615eina_log_function_disable_set(Eina_Bool disabled)
1576{ 1616{
1617#ifdef EINA_ENABLE_LOG
1577 _disable_function = disabled; 1618 _disable_function = disabled;
1619#else
1620 (void) disabled;
1621#endif
1578} 1622}
1579 1623
1580EAPI Eina_Bool 1624EAPI Eina_Bool
1581eina_log_function_disable_get(void) 1625eina_log_function_disable_get(void)
1582{ 1626{
1627#ifdef EINA_ENABLE_LOG
1583 return _disable_function; 1628 return _disable_function;
1629#else
1630 return EINA_TRUE;
1631#endif
1584} 1632}
1585 1633
1586EAPI void 1634EAPI void
1587eina_log_abort_on_critical_set(Eina_Bool abort_on_critical) 1635eina_log_abort_on_critical_set(Eina_Bool abort_on_critical)
1588{ 1636{
1637#ifdef EINA_ENABLE_LOG
1589 _abort_on_critical = abort_on_critical; 1638 _abort_on_critical = abort_on_critical;
1639#else
1640 (void) abort_on_critical;
1641#endif
1590} 1642}
1591 1643
1592EAPI Eina_Bool 1644EAPI Eina_Bool
1593eina_log_abort_on_critical_get(void) 1645eina_log_abort_on_critical_get(void)
1594{ 1646{
1647#ifdef EINA_ENABLE_LOG
1595 return _abort_on_critical; 1648 return _abort_on_critical;
1649#else
1650 return EINA_FALSE;
1651#endif
1596} 1652}
1597 1653
1598EAPI void 1654EAPI void
1599eina_log_abort_on_critical_level_set(int critical_level) 1655eina_log_abort_on_critical_level_set(int critical_level)
1600{ 1656{
1657#ifdef EINA_ENABLE_LOG
1601 _abort_level_on_critical = critical_level; 1658 _abort_level_on_critical = critical_level;
1659#else
1660 (void) critical_level;
1661#endif
1602} 1662}
1603 1663
1604EAPI int 1664EAPI int
1605eina_log_abort_on_critical_level_get(void) 1665eina_log_abort_on_critical_level_get(void)
1606{ 1666{
1667#ifdef EINA_ENABLE_LOG
1607 return _abort_level_on_critical; 1668 return _abort_level_on_critical;
1669#else
1670 return 0;
1671#endif
1608} 1672}
1609 1673
1610EAPI int 1674EAPI int
1611eina_log_domain_register(const char *name, const char *color) 1675eina_log_domain_register(const char *name, const char *color)
1612{ 1676{
1677#ifdef EINA_ENABLE_LOG
1613 int r; 1678 int r;
1614 1679
1615 EINA_SAFETY_ON_NULL_RETURN_VAL(name, -1); 1680 EINA_SAFETY_ON_NULL_RETURN_VAL(name, -1);
@@ -1618,20 +1683,30 @@ eina_log_domain_register(const char *name, const char *color)
1618 r = eina_log_domain_register_unlocked(name, color); 1683 r = eina_log_domain_register_unlocked(name, color);
1619 LOG_UNLOCK(); 1684 LOG_UNLOCK();
1620 return r; 1685 return r;
1686#else
1687 (void) name;
1688 (void) color;
1689 return 0;
1690#endif
1621} 1691}
1622 1692
1623EAPI void 1693EAPI void
1624eina_log_domain_unregister(int domain) 1694eina_log_domain_unregister(int domain)
1625{ 1695{
1696#ifdef EINA_ENABLE_LOG
1626 EINA_SAFETY_ON_FALSE_RETURN(domain >= 0); 1697 EINA_SAFETY_ON_FALSE_RETURN(domain >= 0);
1627 LOG_LOCK(); 1698 LOG_LOCK();
1628 eina_log_domain_unregister_unlocked(domain); 1699 eina_log_domain_unregister_unlocked(domain);
1629 LOG_UNLOCK(); 1700 LOG_UNLOCK();
1701#else
1702 (void) domain;
1703#endif
1630} 1704}
1631 1705
1632EAPI void 1706EAPI void
1633eina_log_domain_level_set(const char *domain_name, int level) 1707eina_log_domain_level_set(const char *domain_name, int level)
1634{ 1708{
1709#ifdef EINA_ENABLE_LOG
1635 Eina_Log_Domain_Level_Pending *pending; 1710 Eina_Log_Domain_Level_Pending *pending;
1636 size_t namelen; 1711 size_t namelen;
1637 unsigned int i; 1712 unsigned int i;
@@ -1672,11 +1747,16 @@ eina_log_domain_level_set(const char *domain_name, int level)
1672 memcpy(pending->name, domain_name, namelen + 1); 1747 memcpy(pending->name, domain_name, namelen + 1);
1673 1748
1674 _pending_list = eina_inlist_append(_pending_list, EINA_INLIST_GET(pending)); 1749 _pending_list = eina_inlist_append(_pending_list, EINA_INLIST_GET(pending));
1750#else
1751 (void) domain_name;
1752 (void) level;
1753#endif
1675} 1754}
1676 1755
1677EAPI int 1756EAPI int
1678eina_log_domain_level_get(const char *domain_name) 1757eina_log_domain_level_get(const char *domain_name)
1679{ 1758{
1759#ifdef EINA_ENABLE_LOG
1680 Eina_Log_Domain_Level_Pending *pending; 1760 Eina_Log_Domain_Level_Pending *pending;
1681 size_t namelen; 1761 size_t namelen;
1682 unsigned int i; 1762 unsigned int i;
@@ -1711,17 +1791,26 @@ eina_log_domain_level_get(const char *domain_name)
1711 } 1791 }
1712 1792
1713 return _log_level; 1793 return _log_level;
1794#else
1795 (void) domain_name;
1796 return 0;
1797#endif
1714} 1798}
1715 1799
1716EAPI int 1800EAPI int
1717eina_log_domain_registered_level_get(int domain) 1801eina_log_domain_registered_level_get(int domain)
1718{ 1802{
1803#ifdef EINA_ENABLE_LOG
1719 EINA_SAFETY_ON_FALSE_RETURN_VAL(domain >= 0, EINA_LOG_LEVEL_UNKNOWN); 1804 EINA_SAFETY_ON_FALSE_RETURN_VAL(domain >= 0, EINA_LOG_LEVEL_UNKNOWN);
1720 EINA_SAFETY_ON_FALSE_RETURN_VAL((unsigned int)domain < _log_domains_count, 1805 EINA_SAFETY_ON_FALSE_RETURN_VAL((unsigned int)domain < _log_domains_count,
1721 EINA_LOG_LEVEL_UNKNOWN); 1806 EINA_LOG_LEVEL_UNKNOWN);
1722 EINA_SAFETY_ON_TRUE_RETURN_VAL(_log_domains[domain].deleted, 1807 EINA_SAFETY_ON_TRUE_RETURN_VAL(_log_domains[domain].deleted,
1723 EINA_LOG_LEVEL_UNKNOWN); 1808 EINA_LOG_LEVEL_UNKNOWN);
1724 return _log_domains[domain].level; 1809 return _log_domains[domain].level;
1810#else
1811 (void) domain;
1812 return 0;
1813#endif
1725} 1814}
1726 1815
1727EAPI void 1816EAPI void
@@ -1734,9 +1823,20 @@ eina_log_print_cb_stderr(const Eina_Log_Domain *d,
1734 __UNUSED__ void *data, 1823 __UNUSED__ void *data,
1735 va_list args) 1824 va_list args)
1736{ 1825{
1826#ifdef EINA_ENABLE_LOG
1737 _eina_log_print_prefix(stderr, d, level, file, fnc, line); 1827 _eina_log_print_prefix(stderr, d, level, file, fnc, line);
1738 vfprintf(stderr, fmt, args); 1828 vfprintf(stderr, fmt, args);
1739 putc('\n', stderr); 1829 putc('\n', stderr);
1830#else
1831 (void) d;
1832 (void) level;
1833 (void) file;
1834 (void) fnc;
1835 (void) line;
1836 (void) fmt;
1837 (void) data;
1838 (void) args;
1839#endif
1740} 1840}
1741 1841
1742EAPI void 1842EAPI void
@@ -1749,9 +1849,20 @@ eina_log_print_cb_stdout(const Eina_Log_Domain *d,
1749 __UNUSED__ void *data, 1849 __UNUSED__ void *data,
1750 va_list args) 1850 va_list args)
1751{ 1851{
1852#ifdef EINA_ENABLE_LOG
1752 _eina_log_print_prefix(stdout, d, level, file, fnc, line); 1853 _eina_log_print_prefix(stdout, d, level, file, fnc, line);
1753 vprintf(fmt, args); 1854 vprintf(fmt, args);
1754 putchar('\n'); 1855 putchar('\n');
1856#else
1857 (void) d;
1858 (void) level;
1859 (void) file;
1860 (void) fnc;
1861 (void) line;
1862 (void) fmt;
1863 (void) data;
1864 (void) args;
1865#endif
1755} 1866}
1756 1867
1757EAPI void 1868EAPI void
@@ -1764,6 +1875,7 @@ eina_log_print_cb_file(const Eina_Log_Domain *d,
1764 void *data, 1875 void *data,
1765 va_list args) 1876 va_list args)
1766{ 1877{
1878#ifdef EINA_ENABLE_LOG
1767 FILE *f = data; 1879 FILE *f = data;
1768#ifdef EFL_HAVE_THREADS 1880#ifdef EFL_HAVE_THREADS
1769 if (_threads_enabled) 1881 if (_threads_enabled)
@@ -1787,12 +1899,22 @@ end:
1787#endif 1899#endif
1788 vfprintf(f, fmt, args); 1900 vfprintf(f, fmt, args);
1789 putc('\n', f); 1901 putc('\n', f);
1902#else
1903 (void) d;
1904 (void) file;
1905 (void) fnc;
1906 (void) line;
1907 (void) fmt;
1908 (void) data;
1909 (void) args;
1910#endif
1790} 1911}
1791 1912
1792EAPI void 1913EAPI void
1793eina_log_print(int domain, Eina_Log_Level level, const char *file, 1914eina_log_print(int domain, Eina_Log_Level level, const char *file,
1794 const char *fnc, int line, const char *fmt, ...) 1915 const char *fnc, int line, const char *fmt, ...)
1795{ 1916{
1917#ifdef EINA_ENABLE_LOG
1796 va_list args; 1918 va_list args;
1797 1919
1798#ifdef EINA_SAFETY_CHECKS 1920#ifdef EINA_SAFETY_CHECKS
@@ -1820,12 +1942,22 @@ eina_log_print(int domain, Eina_Log_Level level, const char *file,
1820 eina_log_print_unlocked(domain, level, file, fnc, line, fmt, args); 1942 eina_log_print_unlocked(domain, level, file, fnc, line, fmt, args);
1821 LOG_UNLOCK(); 1943 LOG_UNLOCK();
1822 va_end(args); 1944 va_end(args);
1945#else
1946 (void) domain;
1947 (void) level;
1948 (void) file;
1949 (void) fnc;
1950 (void) line;
1951 (void) fmt;
1952#endif
1823} 1953}
1824 1954
1825EAPI void 1955EAPI void
1826eina_log_vprint(int domain, Eina_Log_Level level, const char *file, 1956eina_log_vprint(int domain, Eina_Log_Level level, const char *file,
1827 const char *fnc, int line, const char *fmt, va_list args) 1957 const char *fnc, int line, const char *fmt, va_list args)
1828{ 1958{
1959#ifdef EINA_ENABLE_LOG
1960
1829#ifdef EINA_SAFETY_CHECKS 1961#ifdef EINA_SAFETY_CHECKS
1830 if (EINA_UNLIKELY(!file)) 1962 if (EINA_UNLIKELY(!file))
1831 { 1963 {
@@ -1849,4 +1981,13 @@ eina_log_vprint(int domain, Eina_Log_Level level, const char *file,
1849 LOG_LOCK(); 1981 LOG_LOCK();
1850 eina_log_print_unlocked(domain, level, file, fnc, line, fmt, args); 1982 eina_log_print_unlocked(domain, level, file, fnc, line, fmt, args);
1851 LOG_UNLOCK(); 1983 LOG_UNLOCK();
1984#else
1985 (void) domain;
1986 (void) level;
1987 (void) file;
1988 (void) fnc;
1989 (void) line;
1990 (void) fmt;
1991 (void) args;
1992#endif
1852} 1993}
diff --git a/libraries/eina/src/lib/eina_magic.c b/libraries/eina/src/lib/eina_magic.c
index 1adde92..d1f71cc 100644
--- a/libraries/eina/src/lib/eina_magic.c
+++ b/libraries/eina/src/lib/eina_magic.c
@@ -79,7 +79,7 @@ _eina_magic_strings_sort_cmp(const void *p1, const void *p2)
79static int 79static int
80_eina_magic_strings_find_cmp(const void *p1, const void *p2) 80_eina_magic_strings_find_cmp(const void *p1, const void *p2)
81{ 81{
82 Eina_Magic a = (Eina_Magic)p1; 82 Eina_Magic a = (Eina_Magic)(size_t)p1;
83 const Eina_Magic_String *b = p2; 83 const Eina_Magic_String *b = p2;
84 return a - b->magic; 84 return a - b->magic;
85} 85}
@@ -129,6 +129,10 @@ _eina_magic_strings_alloc(void)
129* Global * 129* Global *
130*============================================================================*/ 130*============================================================================*/
131 131
132EAPI Eina_Error EINA_ERROR_MAGIC_FAILED = 0;
133
134static const char EINA_ERROR_MAGIC_FAILED_STR[] = "Magic check failed.";
135
132/** 136/**
133 * @internal 137 * @internal
134 * @brief Initialize the magic string module. 138 * @brief Initialize the magic string module.
@@ -150,6 +154,8 @@ eina_magic_string_init(void)
150 EINA_LOG_ERR("Could not register log domain: eina_magic_string"); 154 EINA_LOG_ERR("Could not register log domain: eina_magic_string");
151 return EINA_FALSE; 155 return EINA_FALSE;
152 } 156 }
157 EINA_ERROR_MAGIC_FAILED = eina_error_msg_static_register(
158 EINA_ERROR_MAGIC_FAILED_STR);
153 159
154 return EINA_TRUE; 160 return EINA_TRUE;
155} 161}
@@ -206,7 +212,7 @@ eina_magic_string_get(Eina_Magic magic)
206 _eina_magic_strings_dirty = 0; 212 _eina_magic_strings_dirty = 0;
207 } 213 }
208 214
209 ems = bsearch((void *)magic, _eina_magic_strings, 215 ems = bsearch((void *)(size_t)magic, _eina_magic_strings,
210 _eina_magic_strings_count, sizeof(Eina_Magic_String), 216 _eina_magic_strings_count, sizeof(Eina_Magic_String),
211 _eina_magic_strings_find_cmp); 217 _eina_magic_strings_find_cmp);
212 if (ems) 218 if (ems)
@@ -271,6 +277,7 @@ eina_magic_fail(void *d,
271 const char *fnc, 277 const char *fnc,
272 int line) 278 int line)
273{ 279{
280 eina_error_set(EINA_ERROR_MAGIC_FAILED);
274 if (!d) 281 if (!d)
275 eina_log_print(EINA_LOG_DOMAIN_GLOBAL, EINA_LOG_LEVEL_CRITICAL, 282 eina_log_print(EINA_LOG_DOMAIN_GLOBAL, EINA_LOG_LEVEL_CRITICAL,
276 file, fnc, line, 283 file, fnc, line,
diff --git a/libraries/eina/src/lib/eina_main.c b/libraries/eina/src/lib/eina_main.c
index 8727f83..79f8a36 100644
--- a/libraries/eina/src/lib/eina_main.c
+++ b/libraries/eina/src/lib/eina_main.c
@@ -67,6 +67,8 @@
67#include "eina_rectangle.h" 67#include "eina_rectangle.h"
68#include "eina_safety_checks.h" 68#include "eina_safety_checks.h"
69#include "eina_inlist.h" 69#include "eina_inlist.h"
70#include "eina_inarray.h"
71#include "eina_value.h"
70 72
71/*============================================================================* 73/*============================================================================*
72* Local * 74* Local *
@@ -131,6 +133,7 @@ EAPI Eina_Inlist *_eina_tracking = NULL;
131 S(magic_string); 133 S(magic_string);
132 S(iterator); 134 S(iterator);
133 S(accessor); 135 S(accessor);
136 S(inarray);
134 S(array); 137 S(array);
135 S(module); 138 S(module);
136 S(mempool); 139 S(mempool);
@@ -149,6 +152,7 @@ EAPI Eina_Inlist *_eina_tracking = NULL;
149 S(simple_xml); 152 S(simple_xml);
150 S(file); 153 S(file);
151 S(prefix); 154 S(prefix);
155 S(value);
152#undef S 156#undef S
153 157
154struct eina_desc_setup 158struct eina_desc_setup
@@ -161,17 +165,18 @@ struct eina_desc_setup
161static const struct eina_desc_setup _eina_desc_setup[] = { 165static const struct eina_desc_setup _eina_desc_setup[] = {
162#define S(x) {# x, eina_ ## x ## _init, eina_ ## x ## _shutdown} 166#define S(x) {# x, eina_ ## x ## _init, eina_ ## x ## _shutdown}
163 /* log is a special case as it needs printf */ 167 /* log is a special case as it needs printf */
168 S(stringshare),
164 S(error), 169 S(error),
165 S(safety_checks), 170 S(safety_checks),
166 S(magic_string), 171 S(magic_string),
167 S(iterator), 172 S(iterator),
168 S(accessor), 173 S(accessor),
174 S(inarray),
169 S(array), 175 S(array),
170 S(module), 176 S(module),
171 S(mempool), 177 S(mempool),
172 S(list), 178 S(list),
173 S(binshare), 179 S(binshare),
174 S(stringshare),
175 S(ustringshare), 180 S(ustringshare),
176 S(matrixsparse), 181 S(matrixsparse),
177 S(convert), 182 S(convert),
@@ -183,7 +188,8 @@ static const struct eina_desc_setup _eina_desc_setup[] = {
183 S(quadtree), 188 S(quadtree),
184 S(simple_xml), 189 S(simple_xml),
185 S(file), 190 S(file),
186 S(prefix) 191 S(prefix),
192 S(value)
187#undef S 193#undef S
188}; 194};
189static const size_t _eina_desc_setup_len = sizeof(_eina_desc_setup) / 195static const size_t _eina_desc_setup_len = sizeof(_eina_desc_setup) /
@@ -236,8 +242,8 @@ eina_init(void)
236 _mt_enabled = 1; 242 _mt_enabled = 1;
237 mtrace(); 243 mtrace();
238 } 244 }
239#endif 245#endif
240 246
241 if (!eina_log_init()) 247 if (!eina_log_init())
242 { 248 {
243 fprintf(stderr, "Could not initialize eina logging system.\n"); 249 fprintf(stderr, "Could not initialize eina logging system.\n");
@@ -304,7 +310,7 @@ eina_shutdown(void)
304 muntrace(); 310 muntrace();
305 _mt_enabled = 0; 311 _mt_enabled = 0;
306 } 312 }
307#endif 313#endif
308 } 314 }
309 315
310 return _eina_main_count; 316 return _eina_main_count;
diff --git a/libraries/eina/src/lib/eina_mmap.c b/libraries/eina/src/lib/eina_mmap.c
index fb27bd7..7929f0e 100644
--- a/libraries/eina/src/lib/eina_mmap.c
+++ b/libraries/eina/src/lib/eina_mmap.c
@@ -110,6 +110,8 @@ _eina_mmap_safe_sigbus(int sig __UNUSED__,
110 errno = perrno; 110 errno = perrno;
111 abort(); 111 abort();
112 } 112 }
113 /* Look into mmaped Eina_File if it was one of them, just to remember for later request */
114 eina_file_mmap_faulty(addr, _eina_mmap_pagesize);
113 /* restore previous errno */ 115 /* restore previous errno */
114 errno = perrno; 116 errno = perrno;
115} 117}
@@ -162,6 +164,9 @@ eina_mmap_safety_enabled_set(Eina_Bool enabled)
162 sa.sa_sigaction = _eina_mmap_safe_sigbus; 164 sa.sa_sigaction = _eina_mmap_safe_sigbus;
163 sa.sa_flags = SA_RESTART | SA_SIGINFO; 165 sa.sa_flags = SA_RESTART | SA_SIGINFO;
164 sigemptyset(&sa.sa_mask); 166 sigemptyset(&sa.sa_mask);
167 /* FIXME: This is rubbish. We return EINA_FALSE whether sigaction
168 * fails or not. And we never set mmap_safe, so we always hit this
169 * code path. */
165 if (sigaction(SIGBUS, &sa, NULL) == 0) return EINA_FALSE; 170 if (sigaction(SIGBUS, &sa, NULL) == 0) return EINA_FALSE;
166 /* setup of SIGBUS handler failed, lets close zero page dev and fail */ 171 /* setup of SIGBUS handler failed, lets close zero page dev and fail */
167 close(_eina_mmap_zero_fd); 172 close(_eina_mmap_zero_fd);
diff --git a/libraries/eina/src/lib/eina_module.c b/libraries/eina/src/lib/eina_module.c
index 0dd19a6..26df980 100644
--- a/libraries/eina/src/lib/eina_module.c
+++ b/libraries/eina/src/lib/eina_module.c
@@ -37,6 +37,7 @@ extern "C"
37void *alloca (size_t); 37void *alloca (size_t);
38#endif 38#endif
39 39
40#include <stdlib.h>
40#include <stdio.h> 41#include <stdio.h>
41#include <sys/types.h> 42#include <sys/types.h>
42#include <string.h> 43#include <string.h>
diff --git a/libraries/eina/src/lib/eina_prefix.c b/libraries/eina/src/lib/eina_prefix.c
index 9445222..5b4b0c0 100644
--- a/libraries/eina/src/lib/eina_prefix.c
+++ b/libraries/eina/src/lib/eina_prefix.c
@@ -150,25 +150,24 @@ _fallback(Eina_Prefix *pfx, const char *pkg_bin, const char *pkg_lib,
150 STRDUP_REP(pfx->prefix_path_lib, pkg_lib); 150 STRDUP_REP(pfx->prefix_path_lib, pkg_lib);
151 STRDUP_REP(pfx->prefix_path_data, pkg_data); 151 STRDUP_REP(pfx->prefix_path_data, pkg_data);
152 STRDUP_REP(pfx->prefix_path_locale, pkg_locale); 152 STRDUP_REP(pfx->prefix_path_locale, pkg_locale);
153 fprintf(stderr, 153 WRN("Could not determine its installed prefix for '%s'\n"
154 "WARNING: Could not determine its installed prefix for '%s'\n" 154 " so am falling back on the compiled in default:\n"
155 " so am falling back on the compiled in default:\n" 155 " %s\n"
156 " %s\n" 156 " implied by the following:\n"
157 " implied by the following:\n" 157 " bindir = %s\n"
158 " bindir = %s\n" 158 " libdir = %s\n"
159 " libdir = %s\n" 159 " datadir = %s\n"
160 " datadir = %s\n" 160 " localedir = %s\n"
161 " localedir = %s\n" 161 " Try setting the following environment variables:\n"
162 " Try setting the following environment variables:\n" 162 " %s_PREFIX - points to the base prefix of install\n"
163 " %s_PREFIX - points to the base prefix of install\n" 163 " or the next 4 variables\n"
164 " or the next 4 variables\n" 164 " %s_BIN_DIR - provide a specific binary directory\n"
165 " %s_BIN_DIR - provide a specific binary directory\n" 165 " %s_LIB_DIR - provide a specific library directory\n"
166 " %s_LIB_DIR - provide a specific library directory\n" 166 " %s_DATA_DIR - provide a specific data directory\n"
167 " %s_DATA_DIR - provide a specific data directory\n" 167 " %s_LOCALE_DIR - provide a specific locale directory",
168 " %s_LOCALE_DIR - provide a specific locale directory\n" 168 envprefix,
169 , envprefix, 169 pfx->prefix_path, pkg_bin, pkg_lib, pkg_data, pkg_locale,
170 pfx->prefix_path, pkg_bin, pkg_lib, pkg_data, pkg_locale, 170 envprefix, envprefix, envprefix, envprefix, envprefix);
171 envprefix, envprefix, envprefix, envprefix, envprefix);
172 pfx->fallback = 1; 171 pfx->fallback = 1;
173 return 1; 172 return 1;
174} 173}
diff --git a/libraries/eina/src/lib/eina_private.h b/libraries/eina/src/lib/eina_private.h
index d390397..e31ab47 100644
--- a/libraries/eina/src/lib/eina_private.h
+++ b/libraries/eina/src/lib/eina_private.h
@@ -91,6 +91,10 @@
91#define EINA_MAGIC_SIMPLE_XML_DATA 0x98761261 91#define EINA_MAGIC_SIMPLE_XML_DATA 0x98761261
92#define EINA_MAGIC_SIMPLE_XML_ATTRIBUTE 0x98761262 92#define EINA_MAGIC_SIMPLE_XML_ATTRIBUTE 0x98761262
93 93
94#define EINA_MAGIC_INARRAY 0x98761270
95#define EINA_MAGIC_INARRAY_ITERATOR 0x98761271
96#define EINA_MAGIC_INARRAY_ACCESSOR 0x98761272
97
94#define EINA_MAGIC_CLASS 0x9877CB30 98#define EINA_MAGIC_CLASS 0x9877CB30
95 99
96/* undef the following, we want out version */ 100/* undef the following, we want out version */
@@ -136,5 +140,7 @@ void eina_log_threads_init(void);
136void eina_log_threads_shutdown(void); 140void eina_log_threads_shutdown(void);
137#endif 141#endif
138 142
143void eina_file_mmap_faulty(void *addr, long page_size);
144
139#endif /* EINA_PRIVATE_H_ */ 145#endif /* EINA_PRIVATE_H_ */
140 146
diff --git a/libraries/eina/src/lib/eina_rbtree.c b/libraries/eina/src/lib/eina_rbtree.c
index c0c9f9e..5f1232c 100644
--- a/libraries/eina/src/lib/eina_rbtree.c
+++ b/libraries/eina/src/lib/eina_rbtree.c
@@ -83,7 +83,7 @@ _eina_rbtree_iterator_list_new(const Eina_Rbtree *tree)
83static Eina_Rbtree * 83static Eina_Rbtree *
84_eina_rbtree_iterator_get_content(Eina_Iterator_Rbtree *it) 84_eina_rbtree_iterator_get_content(Eina_Iterator_Rbtree *it)
85{ 85{
86 if (eina_array_count_get(it->stack) <= 0) 86 if (eina_array_count(it->stack) <= 0)
87 return NULL; 87 return NULL;
88 88
89 return eina_array_data_get(it->stack, 0); 89 return eina_array_data_get(it->stack, 0);
@@ -110,10 +110,10 @@ _eina_rbtree_iterator_next(Eina_Iterator_Rbtree *it, void **data)
110 Eina_Iterator_Rbtree_List *new; 110 Eina_Iterator_Rbtree_List *new;
111 Eina_Rbtree *tree; 111 Eina_Rbtree *tree;
112 112
113 if (eina_array_count_get(it->stack) <= 0) 113 if (eina_array_count(it->stack) <= 0)
114 return EINA_FALSE; 114 return EINA_FALSE;
115 115
116 last = eina_array_data_get(it->stack, eina_array_count_get(it->stack) - 1); 116 last = eina_array_data_get(it->stack, eina_array_count(it->stack) - 1);
117 tree = last->tree; 117 tree = last->tree;
118 118
119 if (!last->tree || last->up == EINA_TRUE) 119 if (!last->tree || last->up == EINA_TRUE)
@@ -128,10 +128,10 @@ _eina_rbtree_iterator_next(Eina_Iterator_Rbtree *it, void **data)
128 { 128 {
129 free(last); 129 free(last);
130 130
131 if (eina_array_count_get(it->stack) > 0) 131 if (eina_array_count(it->stack) > 0)
132 { 132 {
133 last = eina_array_data_get(it->stack, 133 last = eina_array_data_get(it->stack,
134 eina_array_count_get( 134 eina_array_count(
135 it-> 135 it->
136 stack) 136 stack)
137 - 1); 137 - 1);
diff --git a/libraries/eina/src/lib/eina_simple_xml_parser.c b/libraries/eina/src/lib/eina_simple_xml_parser.c
index 08a8259..4e357ba 100644
--- a/libraries/eina/src/lib/eina_simple_xml_parser.c
+++ b/libraries/eina/src/lib/eina_simple_xml_parser.c
@@ -38,7 +38,10 @@ extern "C"
38void *alloca (size_t); 38void *alloca (size_t);
39#endif 39#endif
40 40
41#include <strings.h> 41#ifdef HAVE_STRINGS_H
42# include <strings.h>
43#endif
44#include <stdlib.h>
42#include <string.h> 45#include <string.h>
43#include <ctype.h> 46#include <ctype.h>
44 47
@@ -121,7 +124,7 @@ static inline const char *
121_eina_simple_xml_whitespace_find(const char *itr, const char *itr_end) 124_eina_simple_xml_whitespace_find(const char *itr, const char *itr_end)
122{ 125{
123 for (; itr < itr_end; itr++) 126 for (; itr < itr_end; itr++)
124 if (isspace(*itr)) break; 127 if (isspace((unsigned char)*itr)) break;
125 return itr; 128 return itr;
126} 129}
127 130
@@ -129,7 +132,7 @@ static inline const char *
129_eina_simple_xml_whitespace_skip(const char *itr, const char *itr_end) 132_eina_simple_xml_whitespace_skip(const char *itr, const char *itr_end)
130{ 133{
131 for (; itr < itr_end; itr++) 134 for (; itr < itr_end; itr++)
132 if (!isspace(*itr)) break; 135 if (!isspace((unsigned char)*itr)) break;
133 return itr; 136 return itr;
134} 137}
135 138
@@ -137,7 +140,7 @@ static inline const char *
137_eina_simple_xml_whitespace_unskip(const char *itr, const char *itr_start) 140_eina_simple_xml_whitespace_unskip(const char *itr, const char *itr_start)
138{ 141{
139 for (itr--; itr > itr_start; itr--) 142 for (itr--; itr > itr_start; itr--)
140 if (!isspace(*itr)) break; 143 if (!isspace((unsigned char)*itr)) break;
141 return itr + 1; 144 return itr + 1;
142} 145}
143 146
@@ -309,7 +312,7 @@ eina_simple_xml_parse(const char *buf, unsigned buflen, Eina_Bool strip, Eina_Si
309 (!memcmp(itr + 2, "DOCTYPE", 312 (!memcmp(itr + 2, "DOCTYPE",
310 sizeof("DOCTYPE") - 1)) && 313 sizeof("DOCTYPE") - 1)) &&
311 ((itr[2 + sizeof("DOCTYPE") - 1] == '>') || 314 ((itr[2 + sizeof("DOCTYPE") - 1] == '>') ||
312 (isspace(itr[2 + sizeof("DOCTYPE") - 1])))) 315 (isspace((unsigned char)itr[2 + sizeof("DOCTYPE") - 1]))))
313 { 316 {
314 type = EINA_SIMPLE_XML_DOCTYPE; 317 type = EINA_SIMPLE_XML_DOCTYPE;
315 toff = sizeof("!DOCTYPE") - 1; 318 toff = sizeof("!DOCTYPE") - 1;
@@ -455,7 +458,7 @@ eina_simple_xml_tag_attributes_find(const char *buf, unsigned buflen)
455 458
456 for (; itr < itr_end; itr++) 459 for (; itr < itr_end; itr++)
457 { 460 {
458 if (!isspace(*itr)) 461 if (!isspace((unsigned char)*itr))
459 { 462 {
460 /* user skip tagname and already gave it the attributes */ 463 /* user skip tagname and already gave it the attributes */
461 if (*itr == '=') 464 if (*itr == '=')
@@ -492,7 +495,7 @@ eina_simple_xml_attributes_parse(const char *buf, unsigned buflen, Eina_Simple_X
492 495
493 key = p; 496 key = p;
494 for (key_end = key; key_end < itr_end; key_end++) 497 for (key_end = key; key_end < itr_end; key_end++)
495 if ((*key_end == '=') || (isspace(*key_end))) break; 498 if ((*key_end == '=') || (isspace((unsigned char)*key_end))) break;
496 if (key_end == itr_end) return EINA_FALSE; 499 if (key_end == itr_end) return EINA_FALSE;
497 if (key_end == key) continue; 500 if (key_end == key) continue;
498 501
@@ -504,7 +507,7 @@ eina_simple_xml_attributes_parse(const char *buf, unsigned buflen, Eina_Simple_X
504 value++; 507 value++;
505 } 508 }
506 for (; value < itr_end; value++) 509 for (; value < itr_end; value++)
507 if (!isspace(*value)) break; 510 if (!isspace((unsigned char)*value)) break;
508 if (value == itr_end) return EINA_FALSE; 511 if (value == itr_end) return EINA_FALSE;
509 512
510 if ((*value == '"') || (*value == '\'')) 513 if ((*value == '"') || (*value == '\''))
diff --git a/libraries/eina/src/lib/eina_strbuf.c b/libraries/eina/src/lib/eina_strbuf.c
index 74b1eb9..828d842 100644
--- a/libraries/eina/src/lib/eina_strbuf.c
+++ b/libraries/eina/src/lib/eina_strbuf.c
@@ -162,9 +162,9 @@ eina_strbuf_insert_vprintf(Eina_Strbuf *buf,
162EAPI void 162EAPI void
163eina_strbuf_trim(Eina_Strbuf *buf) 163eina_strbuf_trim(Eina_Strbuf *buf)
164{ 164{
165 char *c = buf->buf; 165 unsigned char *c = buf->buf;
166 166
167 while (buf->len > 0 && isspace(((unsigned char*)(buf->buf))[buf->len - 1])) 167 while (buf->len > 0 && isspace(c[buf->len - 1]))
168 buf->len--; 168 buf->len--;
169 while (buf->len > 0 && isspace(*c)) 169 while (buf->len > 0 && isspace(*c))
170 { 170 {
@@ -178,7 +178,7 @@ eina_strbuf_trim(Eina_Strbuf *buf)
178EAPI void 178EAPI void
179eina_strbuf_ltrim(Eina_Strbuf *buf) 179eina_strbuf_ltrim(Eina_Strbuf *buf)
180{ 180{
181 char *c = buf->buf; 181 unsigned char *c = buf->buf;
182 182
183 while (buf->len > 0 && isspace(*c)) 183 while (buf->len > 0 && isspace(*c))
184 { 184 {
diff --git a/libraries/eina/src/lib/eina_value.c b/libraries/eina/src/lib/eina_value.c
index 554f907..ba8af52 100644
--- a/libraries/eina/src/lib/eina_value.c
+++ b/libraries/eina/src/lib/eina_value.c
@@ -28,8 +28,4762 @@
28# include "config.h" 28# include "config.h"
29#endif 29#endif
30 30
31#ifdef HAVE_ALLOCA_H
32# include <alloca.h>
33#elif defined __GNUC__
34# define alloca __builtin_alloca
35#elif defined _AIX
36# define alloca __alloca
37#elif defined _MSC_VER
38# include <malloc.h>
39# define alloca _alloca
40#else
41# include <stddef.h>
42# ifdef __cplusplus
43extern "C"
44# endif
45void *alloca (size_t);
46#endif
47
48#include <stdio.h> /* asprintf() */
49#include <inttypes.h> /* PRId64 and PRIu64 */
50#include <sys/time.h> /* struct timeval */
51
31#include "eina_config.h" 52#include "eina_config.h"
32#include "eina_private.h" 53#include "eina_private.h"
54#include "eina_error.h"
55#include "eina_log.h"
56#include "eina_strbuf.h"
57#include "eina_mempool.h"
58#include "eina_lock.h"
59
60/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
61#include "eina_safety_checks.h"
62#include "eina_value.h"
63
64/*============================================================================*
65* Local *
66*============================================================================*/
67
68/**
69 * @cond LOCAL
70 */
71
72static Eina_Mempool *_eina_value_mp = NULL;
73static Eina_Hash *_eina_value_inner_mps = NULL;
74static Eina_Lock _eina_value_inner_mps_lock;
75static char *_eina_value_mp_choice = NULL;
76static int _eina_value_log_dom = -1;
77
78#ifdef ERR
79#undef ERR
80#endif
81#define ERR(...) EINA_LOG_DOM_ERR(_eina_value_log_dom, __VA_ARGS__)
82
83#ifdef DBG
84#undef DBG
85#endif
86#define DBG(...) EINA_LOG_DOM_DBG(_eina_value_log_dom, __VA_ARGS__)
87
88static const unsigned char eina_value_uchar_max = 255U;
89static const char eina_value_char_max = 127;
90static const char eina_value_char_min = -127 - 1;
91
92static const unsigned short eina_value_ushort_max = 65535U;
93static const short eina_value_short_max = 32767;
94static const short eina_value_short_min = -32767 - 1;
95
96static const unsigned int eina_value_uint_max = 4294967295U;
97static const int eina_value_int_max = 2147483647;
98static const int eina_value_int_min = -2147483647 - 1;
99
100static const uint64_t eina_value_uint64_max = 18446744073709551615ULL;
101static const int64_t eina_value_int64_max = 9223372036854775807LL;
102static const int64_t eina_value_int64_min = -9223372036854775807LL - 1LL;
103
104#if __WORDSIZE == 64
105static const unsigned long eina_value_ulong_max = 18446744073709551615ULL;
106static const long eina_value_long_max = 9223372036854775807LL;
107static const long eina_value_long_min = -9223372036854775807LL - 1LL;
108#else
109static const unsigned long eina_value_ulong_max = 4294967295U;
110static const long eina_value_long_max = 2147483647;
111static const long eina_value_long_min = -2147483647 - 1;
112#endif
113
114
115static Eina_Bool
116_eina_value_type_uchar_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
117{
118 unsigned char *tmem = mem;
119 *tmem = 0;
120 return EINA_TRUE;
121}
122
123static Eina_Bool
124_eina_value_type_uchar_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
125{
126 return EINA_TRUE;
127}
128
129static Eina_Bool
130_eina_value_type_uchar_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
131{
132 const unsigned char *s = src;
133 unsigned char *d = dst;
134 *d = *s;
135 return EINA_TRUE;
136}
137
138static int
139_eina_value_type_uchar_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
140{
141 const unsigned char *ta = a, *tb = b;
142 if (*ta < *tb)
143 return -1;
144 else if (*ta > *tb)
145 return 1;
146 return 0;
147}
148
149static Eina_Bool
150_eina_value_type_uchar_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
151{
152 const unsigned char v = *(const unsigned char *)type_mem;
153
154 eina_error_set(0);
155
156 if (convert == EINA_VALUE_TYPE_UCHAR)
157 {
158 unsigned char other_mem = v;
159 return eina_value_type_pset(convert, convert_mem, &other_mem);
160 }
161 else if (convert == EINA_VALUE_TYPE_USHORT)
162 {
163 unsigned short other_mem = v;
164 return eina_value_type_pset(convert, convert_mem, &other_mem);
165 }
166 else if (convert == EINA_VALUE_TYPE_UINT)
167 {
168 unsigned int other_mem = v;
169 return eina_value_type_pset(convert, convert_mem, &other_mem);
170 }
171 else if (convert == EINA_VALUE_TYPE_ULONG)
172 {
173 unsigned long other_mem = v;
174 return eina_value_type_pset(convert, convert_mem, &other_mem);
175 }
176 else if (convert == EINA_VALUE_TYPE_UINT64)
177 {
178 uint64_t other_mem = v;
179 return eina_value_type_pset(convert, convert_mem, &other_mem);
180 }
181 else if (convert == EINA_VALUE_TYPE_CHAR)
182 {
183 char other_mem = v;
184 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
185 return EINA_FALSE;
186 return eina_value_type_pset(convert, convert_mem, &other_mem);
187 }
188 else if (convert == EINA_VALUE_TYPE_SHORT)
189 {
190 short other_mem = v;
191 return eina_value_type_pset(convert, convert_mem, &other_mem);
192 }
193 else if (convert == EINA_VALUE_TYPE_INT)
194 {
195 int other_mem = v;
196 return eina_value_type_pset(convert, convert_mem, &other_mem);
197 }
198 else if (convert == EINA_VALUE_TYPE_LONG)
199 {
200 long other_mem = v;
201 return eina_value_type_pset(convert, convert_mem, &other_mem);
202 }
203 else if (convert == EINA_VALUE_TYPE_INT64)
204 {
205 int64_t other_mem = v;
206 return eina_value_type_pset(convert, convert_mem, &other_mem);
207 }
208 else if (convert == EINA_VALUE_TYPE_FLOAT)
209 {
210 float other_mem = v;
211 return eina_value_type_pset(convert, convert_mem, &other_mem);
212 }
213 else if (convert == EINA_VALUE_TYPE_DOUBLE)
214 {
215 double other_mem = v;
216 return eina_value_type_pset(convert, convert_mem, &other_mem);
217 }
218 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
219 convert == EINA_VALUE_TYPE_STRING)
220 {
221 const char *other_mem;
222 char buf[64];
223 snprintf(buf, sizeof(buf), "%hhu", v);
224 other_mem = buf; /* required due &buf == buf */
225 return eina_value_type_pset(convert, convert_mem, &other_mem);
226 }
227 else
228 {
229 eina_error_set(EINA_ERROR_VALUE_FAILED);
230 return EINA_FALSE;
231 }
232
233 return EINA_TRUE;
234}
235
236static Eina_Bool
237_eina_value_type_uchar_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
238{
239 unsigned char *tmem = mem;
240 *tmem = va_arg(args, unsigned int); /* char is promoted to int for va_arg */
241 return EINA_TRUE;
242}
243
244static Eina_Bool
245_eina_value_type_uchar_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
246{
247 unsigned char *tmem = mem;
248 const unsigned char *p = ptr;
249 *tmem = *p;
250 return EINA_TRUE;
251}
252
253static Eina_Bool
254_eina_value_type_uchar_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
255{
256 const unsigned char *tmem = mem;
257 unsigned char *p = ptr;
258 *p = *tmem;
259 return EINA_TRUE;
260}
261
262static Eina_Bool
263_eina_value_type_ushort_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
264{
265 unsigned short *tmem = mem;
266 *tmem = 0;
267 return EINA_TRUE;
268}
269
270static Eina_Bool
271_eina_value_type_ushort_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
272{
273 return EINA_TRUE;
274}
275
276static Eina_Bool
277_eina_value_type_ushort_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
278{
279 const unsigned short *s = src;
280 unsigned short *d = dst;
281 *d = *s;
282 return EINA_TRUE;
283}
284
285static int
286_eina_value_type_ushort_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
287{
288 const unsigned short *ta = a, *tb = b;
289 if (*ta < *tb)
290 return -1;
291 else if (*ta > *tb)
292 return 1;
293 return 0;
294}
295
296static Eina_Bool
297_eina_value_type_ushort_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
298{
299 const unsigned short v = *(const unsigned short *)type_mem;
300
301 eina_error_set(0);
302
303 if (convert == EINA_VALUE_TYPE_UCHAR)
304 {
305 unsigned char other_mem = v;
306 if (EINA_UNLIKELY(v > eina_value_uchar_max))
307 return EINA_FALSE;
308 return eina_value_type_pset(convert, convert_mem, &other_mem);
309 }
310 else if (convert == EINA_VALUE_TYPE_USHORT)
311 {
312 unsigned short other_mem = v;
313 return eina_value_type_pset(convert, convert_mem, &other_mem);
314 }
315 else if (convert == EINA_VALUE_TYPE_UINT)
316 {
317 unsigned int other_mem = v;
318 return eina_value_type_pset(convert, convert_mem, &other_mem);
319 }
320 else if (convert == EINA_VALUE_TYPE_ULONG)
321 {
322 unsigned long other_mem = v;
323 return eina_value_type_pset(convert, convert_mem, &other_mem);
324 }
325 else if (convert == EINA_VALUE_TYPE_UINT64)
326 {
327 uint64_t other_mem = v;
328 return eina_value_type_pset(convert, convert_mem, &other_mem);
329 }
330 else if (convert == EINA_VALUE_TYPE_CHAR)
331 {
332 char other_mem = v;
333 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
334 return EINA_FALSE;
335 return eina_value_type_pset(convert, convert_mem, &other_mem);
336 }
337 else if (convert == EINA_VALUE_TYPE_SHORT)
338 {
339 short other_mem = v;
340 if (EINA_UNLIKELY(v > (unsigned short)eina_value_short_max))
341 return EINA_FALSE;
342 return eina_value_type_pset(convert, convert_mem, &other_mem);
343 }
344 else if (convert == EINA_VALUE_TYPE_INT)
345 {
346 int other_mem = v;
347 return eina_value_type_pset(convert, convert_mem, &other_mem);
348 }
349 else if (convert == EINA_VALUE_TYPE_LONG)
350 {
351 long other_mem = v;
352 return eina_value_type_pset(convert, convert_mem, &other_mem);
353 }
354 else if (convert == EINA_VALUE_TYPE_INT64)
355 {
356 int64_t other_mem = v;
357 return eina_value_type_pset(convert, convert_mem, &other_mem);
358 }
359 else if (convert == EINA_VALUE_TYPE_FLOAT)
360 {
361 float other_mem = v;
362 return eina_value_type_pset(convert, convert_mem, &other_mem);
363 }
364 else if (convert == EINA_VALUE_TYPE_DOUBLE)
365 {
366 double other_mem = v;
367 return eina_value_type_pset(convert, convert_mem, &other_mem);
368 }
369 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
370 convert == EINA_VALUE_TYPE_STRING)
371 {
372 const char *other_mem;
373 char buf[64];
374 snprintf(buf, sizeof(buf), "%hu", v);
375 other_mem = buf; /* required due &buf == buf */
376 return eina_value_type_pset(convert, convert_mem, &other_mem);
377 }
378 else
379 {
380 eina_error_set(EINA_ERROR_VALUE_FAILED);
381 return EINA_FALSE;
382 }
383
384 return EINA_TRUE;
385}
386
387static Eina_Bool
388_eina_value_type_ushort_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
389{
390 unsigned short *tmem = mem;
391 *tmem = va_arg(args, unsigned int); /* short is promoted to int for va_arg */
392 return EINA_TRUE;
393}
394
395static Eina_Bool
396_eina_value_type_ushort_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
397{
398 unsigned short *tmem = mem;
399 const unsigned short *p = ptr;
400 *tmem = *p;
401 return EINA_TRUE;
402}
403
404static Eina_Bool
405_eina_value_type_ushort_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
406{
407 const unsigned short *tmem = mem;
408 unsigned short *p = ptr;
409 *p = *tmem;
410 return EINA_TRUE;
411}
412
413static Eina_Bool
414_eina_value_type_uint_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
415{
416 unsigned int *tmem = mem;
417 *tmem = 0;
418 return EINA_TRUE;
419}
420
421static Eina_Bool
422_eina_value_type_uint_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
423{
424 return EINA_TRUE;
425}
426
427static Eina_Bool
428_eina_value_type_uint_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
429{
430 const unsigned int *s = src;
431 unsigned int *d = dst;
432 *d = *s;
433 return EINA_TRUE;
434}
435
436static int
437_eina_value_type_uint_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
438{
439 const unsigned int *ta = a, *tb = b;
440 if (*ta < *tb)
441 return -1;
442 else if (*ta > *tb)
443 return 1;
444 return 0;
445}
446
447static Eina_Bool
448_eina_value_type_uint_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
449{
450 const unsigned int v = *(const unsigned int *)type_mem;
451
452 eina_error_set(0);
453
454 if (convert == EINA_VALUE_TYPE_UCHAR)
455 {
456 unsigned char other_mem = v;
457 if (EINA_UNLIKELY(v > eina_value_uchar_max))
458 return EINA_FALSE;
459 return eina_value_type_pset(convert, convert_mem, &other_mem);
460 }
461 else if (convert == EINA_VALUE_TYPE_USHORT)
462 {
463 unsigned short other_mem = v;
464 if (EINA_UNLIKELY(v > eina_value_ushort_max))
465 return EINA_FALSE;
466 return eina_value_type_pset(convert, convert_mem, &other_mem);
467 }
468 else if (convert == EINA_VALUE_TYPE_UINT)
469 {
470 unsigned int other_mem = v;
471 return eina_value_type_pset(convert, convert_mem, &other_mem);
472 }
473 else if (convert == EINA_VALUE_TYPE_ULONG)
474 {
475 unsigned long other_mem = v;
476 return eina_value_type_pset(convert, convert_mem, &other_mem);
477 }
478 else if (convert == EINA_VALUE_TYPE_UINT64)
479 {
480 uint64_t other_mem = v;
481 return eina_value_type_pset(convert, convert_mem, &other_mem);
482 }
483 else if (convert == EINA_VALUE_TYPE_CHAR)
484 {
485 char other_mem = v;
486 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
487 return EINA_FALSE;
488 return eina_value_type_pset(convert, convert_mem, &other_mem);
489 }
490 else if (convert == EINA_VALUE_TYPE_SHORT)
491 {
492 short other_mem = v;
493 if (EINA_UNLIKELY(v > (unsigned short)eina_value_short_max))
494 return EINA_FALSE;
495 return eina_value_type_pset(convert, convert_mem, &other_mem);
496 }
497 else if (convert == EINA_VALUE_TYPE_INT)
498 {
499 int other_mem = v;
500 if (EINA_UNLIKELY(v > (unsigned int)eina_value_int_max))
501 return EINA_FALSE;
502 return eina_value_type_pset(convert, convert_mem, &other_mem);
503 }
504 else if (convert == EINA_VALUE_TYPE_LONG)
505 {
506 long other_mem = v;
507 return eina_value_type_pset(convert, convert_mem, &other_mem);
508 }
509 else if (convert == EINA_VALUE_TYPE_INT64)
510 {
511 int64_t other_mem = v;
512 return eina_value_type_pset(convert, convert_mem, &other_mem);
513 }
514 else if (convert == EINA_VALUE_TYPE_FLOAT)
515 {
516 float other_mem = v;
517 return eina_value_type_pset(convert, convert_mem, &other_mem);
518 }
519 else if (convert == EINA_VALUE_TYPE_DOUBLE)
520 {
521 double other_mem = v;
522 return eina_value_type_pset(convert, convert_mem, &other_mem);
523 }
524 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
525 convert == EINA_VALUE_TYPE_STRING)
526 {
527 const char *other_mem;
528 char buf[64];
529 snprintf(buf, sizeof(buf), "%u", v);
530 other_mem = buf; /* required due &buf == buf */
531 return eina_value_type_pset(convert, convert_mem, &other_mem);
532 }
533 else
534 {
535 eina_error_set(EINA_ERROR_VALUE_FAILED);
536 return EINA_FALSE;
537 }
538
539 return EINA_TRUE;
540}
541
542static Eina_Bool
543_eina_value_type_uint_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
544{
545 unsigned int *tmem = mem;
546 *tmem = va_arg(args, unsigned int);
547 return EINA_TRUE;
548}
549
550static Eina_Bool
551_eina_value_type_uint_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
552{
553 unsigned int *tmem = mem;
554 const unsigned int *p = ptr;
555 *tmem = *p;
556 return EINA_TRUE;
557}
558
559static Eina_Bool
560_eina_value_type_uint_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
561{
562 const unsigned int *tmem = mem;
563 unsigned int *p = ptr;
564 *p = *tmem;
565 return EINA_TRUE;
566}
567
568static Eina_Bool
569_eina_value_type_ulong_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
570{
571 unsigned long *tmem = mem;
572 *tmem = 0;
573 return EINA_TRUE;
574}
575
576static Eina_Bool
577_eina_value_type_ulong_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
578{
579 return EINA_TRUE;
580}
581
582static Eina_Bool
583_eina_value_type_ulong_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
584{
585 const unsigned long *s = src;
586 unsigned long *d = dst;
587 *d = *s;
588 return EINA_TRUE;
589}
590
591static int
592_eina_value_type_ulong_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
593{
594 const unsigned long *ta = a, *tb = b;
595 if (*ta < *tb)
596 return -1;
597 else if (*ta > *tb)
598 return 1;
599 return 0;
600}
601
602static Eina_Bool
603_eina_value_type_ulong_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
604{
605 const unsigned long v = *(const unsigned long *)type_mem;
606
607 eina_error_set(0);
608
609 if (convert == EINA_VALUE_TYPE_UCHAR)
610 {
611 unsigned char other_mem = v;
612 if (EINA_UNLIKELY(v > eina_value_uchar_max))
613 return EINA_FALSE;
614 return eina_value_type_pset(convert, convert_mem, &other_mem);
615 }
616 else if (convert == EINA_VALUE_TYPE_USHORT)
617 {
618 unsigned short other_mem = v;
619 if (EINA_UNLIKELY(v > eina_value_ushort_max))
620 return EINA_FALSE;
621 return eina_value_type_pset(convert, convert_mem, &other_mem);
622 }
623 else if (convert == EINA_VALUE_TYPE_UINT)
624 {
625 unsigned int other_mem = v;
626 if (EINA_UNLIKELY(v > eina_value_uint_max))
627 return EINA_FALSE;
628 return eina_value_type_pset(convert, convert_mem, &other_mem);
629 }
630 else if (convert == EINA_VALUE_TYPE_ULONG)
631 {
632 unsigned long other_mem = v;
633 return eina_value_type_pset(convert, convert_mem, &other_mem);
634 }
635 else if (convert == EINA_VALUE_TYPE_UINT64)
636 {
637 uint64_t other_mem = v;
638 return eina_value_type_pset(convert, convert_mem, &other_mem);
639 }
640 else if (convert == EINA_VALUE_TYPE_CHAR)
641 {
642 char other_mem = v;
643 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
644 return EINA_FALSE;
645 return eina_value_type_pset(convert, convert_mem, &other_mem);
646 }
647 else if (convert == EINA_VALUE_TYPE_SHORT)
648 {
649 short other_mem = v;
650 if (EINA_UNLIKELY(v > (unsigned short)eina_value_short_max))
651 return EINA_FALSE;
652 return eina_value_type_pset(convert, convert_mem, &other_mem);
653 }
654 else if (convert == EINA_VALUE_TYPE_INT)
655 {
656 int other_mem = v;
657 if (EINA_UNLIKELY(v > (unsigned int)eina_value_int_max))
658 return EINA_FALSE;
659 return eina_value_type_pset(convert, convert_mem, &other_mem);
660 }
661 else if (convert == EINA_VALUE_TYPE_LONG)
662 {
663 long other_mem = v;
664 if (EINA_UNLIKELY(v > (unsigned long)eina_value_long_max))
665 return EINA_FALSE;
666 return eina_value_type_pset(convert, convert_mem, &other_mem);
667 }
668 else if (convert == EINA_VALUE_TYPE_INT64)
669 {
670 int64_t other_mem = v;
671 return eina_value_type_pset(convert, convert_mem, &other_mem);
672 }
673 else if (convert == EINA_VALUE_TYPE_FLOAT)
674 {
675 float other_mem = v;
676 return eina_value_type_pset(convert, convert_mem, &other_mem);
677 }
678 else if (convert == EINA_VALUE_TYPE_DOUBLE)
679 {
680 double other_mem = v;
681 return eina_value_type_pset(convert, convert_mem, &other_mem);
682 }
683 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
684 convert == EINA_VALUE_TYPE_STRING)
685 {
686 const char *other_mem;
687 char buf[64];
688 snprintf(buf, sizeof(buf), "%lu", v);
689 other_mem = buf; /* required due &buf == buf */
690 return eina_value_type_pset(convert, convert_mem, &other_mem);
691 }
692 else
693 {
694 eina_error_set(EINA_ERROR_VALUE_FAILED);
695 return EINA_FALSE;
696 }
697
698 return EINA_TRUE;
699}
700
701static Eina_Bool
702_eina_value_type_ulong_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
703{
704 unsigned long *tmem = mem;
705 *tmem = va_arg(args, unsigned long);
706 return EINA_TRUE;
707}
708
709static Eina_Bool
710_eina_value_type_ulong_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
711{
712 unsigned long *tmem = mem;
713 const unsigned long *p = ptr;
714 *tmem = *p;
715 return EINA_TRUE;
716}
717
718static Eina_Bool
719_eina_value_type_ulong_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
720{
721 const unsigned long *tmem = mem;
722 unsigned long *p = ptr;
723 *p = *tmem;
724 return EINA_TRUE;
725}
726
727static Eina_Bool
728_eina_value_type_uint64_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
729{
730 uint64_t *tmem = mem;
731 *tmem = 0;
732 return EINA_TRUE;
733}
734
735static Eina_Bool
736_eina_value_type_uint64_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
737{
738 return EINA_TRUE;
739}
740
741static Eina_Bool
742_eina_value_type_uint64_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
743{
744 const uint64_t *s = src;
745 uint64_t *d = dst;
746 *d = *s;
747 return EINA_TRUE;
748}
749
750static int
751_eina_value_type_uint64_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
752{
753 const uint64_t *ta = a, *tb = b;
754 if (*ta < *tb)
755 return -1;
756 else if (*ta > *tb)
757 return 1;
758 return 0;
759}
760
761static Eina_Bool
762_eina_value_type_uint64_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
763{
764 const uint64_t v = *(const uint64_t *)type_mem;
765
766 eina_error_set(0);
767
768 if (convert == EINA_VALUE_TYPE_UCHAR)
769 {
770 unsigned char other_mem = v;
771 if (EINA_UNLIKELY(v > eina_value_uchar_max))
772 return EINA_FALSE;
773 return eina_value_type_pset(convert, convert_mem, &other_mem);
774 }
775 else if (convert == EINA_VALUE_TYPE_USHORT)
776 {
777 unsigned short other_mem = v;
778 if (EINA_UNLIKELY(v > eina_value_ushort_max))
779 return EINA_FALSE;
780 return eina_value_type_pset(convert, convert_mem, &other_mem);
781 }
782 else if (convert == EINA_VALUE_TYPE_UINT)
783 {
784 unsigned int other_mem = v;
785 if (EINA_UNLIKELY(v > eina_value_uint_max))
786 return EINA_FALSE;
787 return eina_value_type_pset(convert, convert_mem, &other_mem);
788 }
789 else if (convert == EINA_VALUE_TYPE_ULONG)
790 {
791 unsigned long other_mem = v;
792 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
793 (v > eina_value_ulong_max)))
794 return EINA_FALSE;
795 return eina_value_type_pset(convert, convert_mem, &other_mem);
796 }
797 else if (convert == EINA_VALUE_TYPE_UINT64)
798 {
799 uint64_t other_mem = v;
800 return eina_value_type_pset(convert, convert_mem, &other_mem);
801 }
802 else if (convert == EINA_VALUE_TYPE_CHAR)
803 {
804 char other_mem = v;
805 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
806 return EINA_FALSE;
807 return eina_value_type_pset(convert, convert_mem, &other_mem);
808 }
809 else if (convert == EINA_VALUE_TYPE_SHORT)
810 {
811 short other_mem = v;
812 if (EINA_UNLIKELY(v > (unsigned short)eina_value_short_max))
813 return EINA_FALSE;
814 return eina_value_type_pset(convert, convert_mem, &other_mem);
815 }
816 else if (convert == EINA_VALUE_TYPE_INT)
817 {
818 int other_mem = v;
819 if (EINA_UNLIKELY(v > (unsigned int)eina_value_int_max))
820 return EINA_FALSE;
821 return eina_value_type_pset(convert, convert_mem, &other_mem);
822 }
823 else if (convert == EINA_VALUE_TYPE_LONG)
824 {
825 long other_mem = v;
826 if (EINA_UNLIKELY(v > (unsigned long)eina_value_long_max))
827 return EINA_FALSE;
828 return eina_value_type_pset(convert, convert_mem, &other_mem);
829 }
830 else if (convert == EINA_VALUE_TYPE_INT64)
831 {
832 int64_t other_mem = v;
833 if (EINA_UNLIKELY(v > (uint64_t)eina_value_int64_max))
834 return EINA_FALSE;
835 return eina_value_type_pset(convert, convert_mem, &other_mem);
836 }
837 else if (convert == EINA_VALUE_TYPE_FLOAT)
838 {
839 float other_mem = v;
840 return eina_value_type_pset(convert, convert_mem, &other_mem);
841 }
842 else if (convert == EINA_VALUE_TYPE_DOUBLE)
843 {
844 double other_mem = v;
845 return eina_value_type_pset(convert, convert_mem, &other_mem);
846 }
847 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
848 convert == EINA_VALUE_TYPE_STRING)
849 {
850 const char *other_mem;
851 char buf[64];
852 snprintf(buf, sizeof(buf), "%"PRIu64, v);
853 other_mem = buf; /* required due &buf == buf */
854 return eina_value_type_pset(convert, convert_mem, &other_mem);
855 }
856 else
857 {
858 eina_error_set(EINA_ERROR_VALUE_FAILED);
859 return EINA_FALSE;
860 }
861
862 return EINA_TRUE;
863}
864
865static Eina_Bool
866_eina_value_type_uint64_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
867{
868 uint64_t *tmem = mem;
869 *tmem = va_arg(args, uint64_t);
870 return EINA_TRUE;
871}
872
873static Eina_Bool
874_eina_value_type_uint64_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
875{
876 uint64_t *tmem = mem;
877 const uint64_t *p = ptr;
878 *tmem = *p;
879 return EINA_TRUE;
880}
881
882static Eina_Bool
883_eina_value_type_uint64_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
884{
885 const uint64_t *tmem = mem;
886 uint64_t *p = ptr;
887 *p = *tmem;
888 return EINA_TRUE;
889}
890
891static Eina_Bool
892_eina_value_type_char_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
893{
894 char *tmem = mem;
895 *tmem = 0;
896 return EINA_TRUE;
897}
898
899static Eina_Bool
900_eina_value_type_char_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
901{
902 return EINA_TRUE;
903}
904
905static Eina_Bool
906_eina_value_type_char_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
907{
908 const char *s = src;
909 char *d = dst;
910 *d = *s;
911 return EINA_TRUE;
912}
913
914static int
915_eina_value_type_char_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
916{
917 const char *ta = a, *tb = b;
918 if (*ta < *tb)
919 return -1;
920 else if (*ta > *tb)
921 return 1;
922 return 0;
923}
924
925static Eina_Bool
926_eina_value_type_char_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
927{
928 const signed char v = *(const signed char *)type_mem;
929
930 eina_error_set(0);
931
932 if (convert == EINA_VALUE_TYPE_UCHAR)
933 {
934 unsigned char other_mem = v;
935 if (EINA_UNLIKELY(v < 0))
936 return EINA_FALSE;
937 return eina_value_type_pset(convert, convert_mem, &other_mem);
938 }
939 else if (convert == EINA_VALUE_TYPE_USHORT)
940 {
941 unsigned short other_mem = v;
942 if (EINA_UNLIKELY(v < 0))
943 return EINA_FALSE;
944 return eina_value_type_pset(convert, convert_mem, &other_mem);
945 }
946 else if (convert == EINA_VALUE_TYPE_UINT)
947 {
948 unsigned int other_mem = v;
949 if (EINA_UNLIKELY(v < 0))
950 return EINA_FALSE;
951 return eina_value_type_pset(convert, convert_mem, &other_mem);
952 }
953 else if (convert == EINA_VALUE_TYPE_ULONG)
954 {
955 unsigned long other_mem = v;
956 if (EINA_UNLIKELY(v < 0))
957 return EINA_FALSE;
958 return eina_value_type_pset(convert, convert_mem, &other_mem);
959 }
960 else if (convert == EINA_VALUE_TYPE_UINT64)
961 {
962 uint64_t other_mem = v;
963 if (EINA_UNLIKELY(v < 0))
964 return EINA_FALSE;
965 return eina_value_type_pset(convert, convert_mem, &other_mem);
966 }
967 else if (convert == EINA_VALUE_TYPE_CHAR)
968 {
969 char other_mem = v;
970 return eina_value_type_pset(convert, convert_mem, &other_mem);
971 }
972 else if (convert == EINA_VALUE_TYPE_SHORT)
973 {
974 short other_mem = v;
975 return eina_value_type_pset(convert, convert_mem, &other_mem);
976 }
977 else if (convert == EINA_VALUE_TYPE_INT)
978 {
979 int other_mem = v;
980 return eina_value_type_pset(convert, convert_mem, &other_mem);
981 }
982 else if (convert == EINA_VALUE_TYPE_LONG)
983 {
984 long other_mem = v;
985 return eina_value_type_pset(convert, convert_mem, &other_mem);
986 }
987 else if (convert == EINA_VALUE_TYPE_INT64)
988 {
989 int64_t other_mem = v;
990 return eina_value_type_pset(convert, convert_mem, &other_mem);
991 }
992 else if (convert == EINA_VALUE_TYPE_FLOAT)
993 {
994 float other_mem = v;
995 return eina_value_type_pset(convert, convert_mem, &other_mem);
996 }
997 else if (convert == EINA_VALUE_TYPE_DOUBLE)
998 {
999 double other_mem = v;
1000 return eina_value_type_pset(convert, convert_mem, &other_mem);
1001 }
1002 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1003 convert == EINA_VALUE_TYPE_STRING)
1004 {
1005 const char *other_mem;
1006 char buf[64];
1007 snprintf(buf, sizeof(buf), "%hhd", v);
1008 other_mem = buf; /* required due &buf == buf */
1009 return eina_value_type_pset(convert, convert_mem, &other_mem);
1010 }
1011 else
1012 {
1013 eina_error_set(EINA_ERROR_VALUE_FAILED);
1014 return EINA_FALSE;
1015 }
1016
1017 return EINA_TRUE;
1018}
1019
1020static Eina_Bool
1021_eina_value_type_char_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1022{
1023 char *tmem = mem;
1024 *tmem = va_arg(args, int); /* char is promoted to int for va_arg */
1025 return EINA_TRUE;
1026}
1027
1028static Eina_Bool
1029_eina_value_type_char_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1030{
1031 char *tmem = mem;
1032 const char *p = ptr;
1033 *tmem = *p;
1034 return EINA_TRUE;
1035}
1036
1037static Eina_Bool
1038_eina_value_type_char_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1039{
1040 const char *tmem = mem;
1041 char *p = ptr;
1042 *p = *tmem;
1043 return EINA_TRUE;
1044}
1045
1046static Eina_Bool
1047_eina_value_type_short_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1048{
1049 short *tmem = mem;
1050 *tmem = 0;
1051 return EINA_TRUE;
1052}
1053
1054static Eina_Bool
1055_eina_value_type_short_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1056{
1057 return EINA_TRUE;
1058}
1059
1060static Eina_Bool
1061_eina_value_type_short_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1062{
1063 const short *s = src;
1064 short *d = dst;
1065 *d = *s;
1066 return EINA_TRUE;
1067}
1068
1069static int
1070_eina_value_type_short_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1071{
1072 const short *ta = a, *tb = b;
1073 if (*ta < *tb)
1074 return -1;
1075 else if (*ta > *tb)
1076 return 1;
1077 return 0;
1078}
1079
1080static Eina_Bool
1081_eina_value_type_short_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1082{
1083 const short v = *(const short *)type_mem;
1084
1085 eina_error_set(0);
1086
1087 if (convert == EINA_VALUE_TYPE_UCHAR)
1088 {
1089 unsigned char other_mem = v;
1090 if (EINA_UNLIKELY(v < 0))
1091 return EINA_FALSE;
1092 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1093 return EINA_FALSE;
1094 return eina_value_type_pset(convert, convert_mem, &other_mem);
1095 }
1096 else if (convert == EINA_VALUE_TYPE_USHORT)
1097 {
1098 unsigned short other_mem = v;
1099 if (EINA_UNLIKELY(v < 0))
1100 return EINA_FALSE;
1101 return eina_value_type_pset(convert, convert_mem, &other_mem);
1102 }
1103 else if (convert == EINA_VALUE_TYPE_UINT)
1104 {
1105 unsigned int other_mem = v;
1106 if (EINA_UNLIKELY(v < 0))
1107 return EINA_FALSE;
1108 return eina_value_type_pset(convert, convert_mem, &other_mem);
1109 }
1110 else if (convert == EINA_VALUE_TYPE_ULONG)
1111 {
1112 unsigned long other_mem = v;
1113 if (EINA_UNLIKELY(v < 0))
1114 return EINA_FALSE;
1115 return eina_value_type_pset(convert, convert_mem, &other_mem);
1116 }
1117 else if (convert == EINA_VALUE_TYPE_UINT64)
1118 {
1119 uint64_t other_mem = v;
1120 if (EINA_UNLIKELY(v < 0))
1121 return EINA_FALSE;
1122 return eina_value_type_pset(convert, convert_mem, &other_mem);
1123 }
1124 else if (convert == EINA_VALUE_TYPE_CHAR)
1125 {
1126 char other_mem = v;
1127 if (EINA_UNLIKELY(v < eina_value_char_min))
1128 return EINA_FALSE;
1129 if (EINA_UNLIKELY(v > eina_value_char_max))
1130 return EINA_FALSE;
1131 return eina_value_type_pset(convert, convert_mem, &other_mem);
1132 }
1133 else if (convert == EINA_VALUE_TYPE_SHORT)
1134 {
1135 short other_mem = v;
1136 return eina_value_type_pset(convert, convert_mem, &other_mem);
1137 }
1138 else if (convert == EINA_VALUE_TYPE_INT)
1139 {
1140 int other_mem = v;
1141 return eina_value_type_pset(convert, convert_mem, &other_mem);
1142 }
1143 else if (convert == EINA_VALUE_TYPE_LONG)
1144 {
1145 long other_mem = v;
1146 return eina_value_type_pset(convert, convert_mem, &other_mem);
1147 }
1148 else if (convert == EINA_VALUE_TYPE_INT64)
1149 {
1150 int64_t other_mem = v;
1151 return eina_value_type_pset(convert, convert_mem, &other_mem);
1152 }
1153 else if (convert == EINA_VALUE_TYPE_FLOAT)
1154 {
1155 float other_mem = v;
1156 return eina_value_type_pset(convert, convert_mem, &other_mem);
1157 }
1158 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1159 {
1160 double other_mem = v;
1161 return eina_value_type_pset(convert, convert_mem, &other_mem);
1162 }
1163 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1164 convert == EINA_VALUE_TYPE_STRING)
1165 {
1166 const char *other_mem;
1167 char buf[64];
1168 snprintf(buf, sizeof(buf), "%hd", v);
1169 other_mem = buf; /* required due &buf == buf */
1170 return eina_value_type_pset(convert, convert_mem, &other_mem);
1171 }
1172 else
1173 {
1174 eina_error_set(EINA_ERROR_VALUE_FAILED);
1175 return EINA_FALSE;
1176 }
1177
1178 return EINA_TRUE;
1179}
1180
1181static Eina_Bool
1182_eina_value_type_short_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1183{
1184 short *tmem = mem;
1185 *tmem = va_arg(args, int); /* short int is promoted to int for va_arg */
1186 return EINA_TRUE;
1187}
1188
1189static Eina_Bool
1190_eina_value_type_short_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1191{
1192 short *tmem = mem;
1193 const short *p = ptr;
1194 *tmem = *p;
1195 return EINA_TRUE;
1196}
1197
1198static Eina_Bool
1199_eina_value_type_short_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1200{
1201 const short *tmem = mem;
1202 short *p = ptr;
1203 *p = *tmem;
1204 return EINA_TRUE;
1205}
1206
1207static Eina_Bool
1208_eina_value_type_int_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1209{
1210 int *tmem = mem;
1211 *tmem = 0;
1212 return EINA_TRUE;
1213}
1214
1215static Eina_Bool
1216_eina_value_type_int_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1217{
1218 return EINA_TRUE;
1219}
1220
1221static Eina_Bool
1222_eina_value_type_int_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1223{
1224 const int *s = src;
1225 int *d = dst;
1226 *d = *s;
1227 return EINA_TRUE;
1228}
1229
1230static int
1231_eina_value_type_int_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1232{
1233 const int *ta = a, *tb = b;
1234 if (*ta < *tb)
1235 return -1;
1236 else if (*ta > *tb)
1237 return 1;
1238 return 0;
1239}
1240
1241static Eina_Bool
1242_eina_value_type_int_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1243{
1244 const int v = *(const int *)type_mem;
1245
1246 eina_error_set(0);
1247
1248 if (convert == EINA_VALUE_TYPE_UCHAR)
1249 {
1250 unsigned char other_mem = v;
1251 if (EINA_UNLIKELY(v < 0))
1252 return EINA_FALSE;
1253 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1254 return EINA_FALSE;
1255 return eina_value_type_pset(convert, convert_mem, &other_mem);
1256 }
1257 else if (convert == EINA_VALUE_TYPE_USHORT)
1258 {
1259 unsigned short other_mem = v;
1260 if (EINA_UNLIKELY(v < 0))
1261 return EINA_FALSE;
1262 if (EINA_UNLIKELY(v > eina_value_ushort_max))
1263 return EINA_FALSE;
1264 return eina_value_type_pset(convert, convert_mem, &other_mem);
1265 }
1266 else if (convert == EINA_VALUE_TYPE_UINT)
1267 {
1268 unsigned int other_mem = v;
1269 if (EINA_UNLIKELY(v < 0))
1270 return EINA_FALSE;
1271 return eina_value_type_pset(convert, convert_mem, &other_mem);
1272 }
1273 else if (convert == EINA_VALUE_TYPE_ULONG)
1274 {
1275 unsigned long other_mem = v;
1276 if (EINA_UNLIKELY(v < 0))
1277 return EINA_FALSE;
1278 return eina_value_type_pset(convert, convert_mem, &other_mem);
1279 }
1280 else if (convert == EINA_VALUE_TYPE_UINT64)
1281 {
1282 uint64_t other_mem = v;
1283 if (EINA_UNLIKELY(v < 0))
1284 return EINA_FALSE;
1285 return eina_value_type_pset(convert, convert_mem, &other_mem);
1286 }
1287 else if (convert == EINA_VALUE_TYPE_CHAR)
1288 {
1289 char other_mem = v;
1290 if (EINA_UNLIKELY(v < eina_value_char_min))
1291 return EINA_FALSE;
1292 if (EINA_UNLIKELY(v > eina_value_char_max))
1293 return EINA_FALSE;
1294 return eina_value_type_pset(convert, convert_mem, &other_mem);
1295 }
1296 else if (convert == EINA_VALUE_TYPE_SHORT)
1297 {
1298 short other_mem = v;
1299 if (EINA_UNLIKELY(v < eina_value_short_min))
1300 return EINA_FALSE;
1301 if (EINA_UNLIKELY(v > eina_value_short_max))
1302 return EINA_FALSE;
1303 return eina_value_type_pset(convert, convert_mem, &other_mem);
1304 }
1305 else if (convert == EINA_VALUE_TYPE_INT)
1306 {
1307 int other_mem = v;
1308 return eina_value_type_pset(convert, convert_mem, &other_mem);
1309 }
1310 else if (convert == EINA_VALUE_TYPE_LONG)
1311 {
1312 long other_mem = v;
1313 return eina_value_type_pset(convert, convert_mem, &other_mem);
1314 }
1315 else if (convert == EINA_VALUE_TYPE_INT64)
1316 {
1317 int64_t other_mem = v;
1318 return eina_value_type_pset(convert, convert_mem, &other_mem);
1319 }
1320 else if (convert == EINA_VALUE_TYPE_FLOAT)
1321 {
1322 float other_mem = v;
1323 return eina_value_type_pset(convert, convert_mem, &other_mem);
1324 }
1325 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1326 {
1327 double other_mem = v;
1328 return eina_value_type_pset(convert, convert_mem, &other_mem);
1329 }
1330 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1331 convert == EINA_VALUE_TYPE_STRING)
1332 {
1333 const char *other_mem;
1334 char buf[64];
1335 snprintf(buf, sizeof(buf), "%d", v);
1336 other_mem = buf; /* required due &buf == buf */
1337 return eina_value_type_pset(convert, convert_mem, &other_mem);
1338 }
1339 else
1340 {
1341 eina_error_set(EINA_ERROR_VALUE_FAILED);
1342 return EINA_FALSE;
1343 }
1344
1345 return EINA_TRUE;
1346}
1347
1348static Eina_Bool
1349_eina_value_type_int_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1350{
1351 int *tmem = mem;
1352 *tmem = va_arg(args, int);
1353 return EINA_TRUE;
1354}
1355
1356static Eina_Bool
1357_eina_value_type_int_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1358{
1359 int *tmem = mem;
1360 const int *p = ptr;
1361 *tmem = *p;
1362 return EINA_TRUE;
1363}
1364
1365static Eina_Bool
1366_eina_value_type_int_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1367{
1368 const int *tmem = mem;
1369 int *p = ptr;
1370 *p = *tmem;
1371 return EINA_TRUE;
1372}
1373
1374static Eina_Bool
1375_eina_value_type_long_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1376{
1377 long *tmem = mem;
1378 *tmem = 0;
1379 return EINA_TRUE;
1380}
1381
1382static Eina_Bool
1383_eina_value_type_long_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1384{
1385 return EINA_TRUE;
1386}
1387
1388static Eina_Bool
1389_eina_value_type_long_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1390{
1391 const long *s = src;
1392 long *d = dst;
1393 *d = *s;
1394 return EINA_TRUE;
1395}
1396
1397static int
1398_eina_value_type_long_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1399{
1400 const long *ta = a, *tb = b;
1401 if (*ta < *tb)
1402 return -1;
1403 else if (*ta > *tb)
1404 return 1;
1405 return 0;
1406}
1407
1408static Eina_Bool
1409_eina_value_type_long_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1410{
1411 const long v = *(const long *)type_mem;
1412
1413 eina_error_set(0);
1414
1415 if (convert == EINA_VALUE_TYPE_UCHAR)
1416 {
1417 unsigned char other_mem = v;
1418 if (EINA_UNLIKELY(v < 0))
1419 return EINA_FALSE;
1420 if (EINA_UNLIKELY((unsigned long) v > eina_value_uchar_max))
1421 return EINA_FALSE;
1422 return eina_value_type_pset(convert, convert_mem, &other_mem);
1423 }
1424 else if (convert == EINA_VALUE_TYPE_USHORT)
1425 {
1426 unsigned short other_mem = v;
1427 if (EINA_UNLIKELY(v < 0))
1428 return EINA_FALSE;
1429 if (EINA_UNLIKELY((unsigned long) v > eina_value_ushort_max))
1430 return EINA_FALSE;
1431 return eina_value_type_pset(convert, convert_mem, &other_mem);
1432 }
1433 else if (convert == EINA_VALUE_TYPE_UINT)
1434 {
1435 unsigned int other_mem = v;
1436 if (EINA_UNLIKELY(v < 0))
1437 return EINA_FALSE;
1438 if (EINA_UNLIKELY((unsigned long) v > eina_value_uint_max))
1439 return EINA_FALSE;
1440 return eina_value_type_pset(convert, convert_mem, &other_mem);
1441 }
1442 else if (convert == EINA_VALUE_TYPE_ULONG)
1443 {
1444 unsigned long other_mem = v;
1445 if (EINA_UNLIKELY(v < 0))
1446 return EINA_FALSE;
1447 return eina_value_type_pset(convert, convert_mem, &other_mem);
1448 }
1449 else if (convert == EINA_VALUE_TYPE_UINT64)
1450 {
1451 uint64_t other_mem = v;
1452 if (EINA_UNLIKELY(v < 0))
1453 return EINA_FALSE;
1454 return eina_value_type_pset(convert, convert_mem, &other_mem);
1455 }
1456 else if (convert == EINA_VALUE_TYPE_CHAR)
1457 {
1458 char other_mem = v;
1459 if (EINA_UNLIKELY(v < eina_value_char_min))
1460 return EINA_FALSE;
1461 if (EINA_UNLIKELY(v > eina_value_char_max))
1462 return EINA_FALSE;
1463 return eina_value_type_pset(convert, convert_mem, &other_mem);
1464 }
1465 else if (convert == EINA_VALUE_TYPE_SHORT)
1466 {
1467 short other_mem = v;
1468 if (EINA_UNLIKELY(v < eina_value_short_min))
1469 return EINA_FALSE;
1470 if (EINA_UNLIKELY(v > eina_value_short_max))
1471 return EINA_FALSE;
1472 return eina_value_type_pset(convert, convert_mem, &other_mem);
1473 }
1474 else if (convert == EINA_VALUE_TYPE_INT)
1475 {
1476 int other_mem = v;
1477 if (EINA_UNLIKELY(v < eina_value_int_min))
1478 return EINA_FALSE;
1479 if (EINA_UNLIKELY(v > eina_value_int_max))
1480 return EINA_FALSE;
1481 return eina_value_type_pset(convert, convert_mem, &other_mem);
1482 }
1483 else if (convert == EINA_VALUE_TYPE_LONG)
1484 {
1485 long other_mem = v;
1486 return eina_value_type_pset(convert, convert_mem, &other_mem);
1487 }
1488 else if (convert == EINA_VALUE_TYPE_INT64)
1489 {
1490 int64_t other_mem = v;
1491 return eina_value_type_pset(convert, convert_mem, &other_mem);
1492 }
1493 else if (convert == EINA_VALUE_TYPE_FLOAT)
1494 {
1495 float other_mem = v;
1496 return eina_value_type_pset(convert, convert_mem, &other_mem);
1497 }
1498 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1499 {
1500 double other_mem = v;
1501 return eina_value_type_pset(convert, convert_mem, &other_mem);
1502 }
1503 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1504 convert == EINA_VALUE_TYPE_STRING)
1505 {
1506 const char *other_mem;
1507 char buf[64];
1508 snprintf(buf, sizeof(buf), "%ld", v);
1509 other_mem = buf; /* required due &buf == buf */
1510 return eina_value_type_pset(convert, convert_mem, &other_mem);
1511 }
1512 else
1513 {
1514 eina_error_set(EINA_ERROR_VALUE_FAILED);
1515 return EINA_FALSE;
1516 }
1517
1518 return EINA_TRUE;
1519}
1520
1521static Eina_Bool
1522_eina_value_type_long_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1523{
1524 long *tmem = mem;
1525 *tmem = va_arg(args, long);
1526 return EINA_TRUE;
1527}
1528
1529static Eina_Bool
1530_eina_value_type_long_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1531{
1532 long *tmem = mem;
1533 const long *p = ptr;
1534 *tmem = *p;
1535 return EINA_TRUE;
1536}
1537
1538static Eina_Bool
1539_eina_value_type_long_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1540{
1541 const long *tmem = mem;
1542 long *p = ptr;
1543 *p = *tmem;
1544 return EINA_TRUE;
1545}
1546
1547static Eina_Bool
1548_eina_value_type_int64_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1549{
1550 int64_t *tmem = mem;
1551 *tmem = 0;
1552 return EINA_TRUE;
1553}
1554
1555static Eina_Bool
1556_eina_value_type_int64_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1557{
1558 return EINA_TRUE;
1559}
1560
1561static Eina_Bool
1562_eina_value_type_int64_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1563{
1564 const int64_t *s = src;
1565 int64_t *d = dst;
1566 *d = *s;
1567 return EINA_TRUE;
1568}
1569
1570static int
1571_eina_value_type_int64_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1572{
1573 const int64_t *ta = a, *tb = b;
1574 if (*ta < *tb)
1575 return -1;
1576 else if (*ta > *tb)
1577 return 1;
1578 return 0;
1579}
1580
1581static Eina_Bool
1582_eina_value_type_int64_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1583{
1584 const int64_t v = *(const int64_t *)type_mem;
1585
1586 eina_error_set(0);
1587
1588 if (convert == EINA_VALUE_TYPE_UCHAR)
1589 {
1590 unsigned char other_mem = v;
1591 if (EINA_UNLIKELY(v < 0))
1592 return EINA_FALSE;
1593 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1594 return EINA_FALSE;
1595 return eina_value_type_pset(convert, convert_mem, &other_mem);
1596 }
1597 else if (convert == EINA_VALUE_TYPE_USHORT)
1598 {
1599 unsigned short other_mem = v;
1600 if (EINA_UNLIKELY(v < 0))
1601 return EINA_FALSE;
1602 if (EINA_UNLIKELY(v > eina_value_ushort_max))
1603 return EINA_FALSE;
1604 return eina_value_type_pset(convert, convert_mem, &other_mem);
1605 }
1606 else if (convert == EINA_VALUE_TYPE_UINT)
1607 {
1608 unsigned int other_mem = v;
1609 if (EINA_UNLIKELY(v < 0))
1610 return EINA_FALSE;
1611 if (EINA_UNLIKELY(v > eina_value_uint_max))
1612 return EINA_FALSE;
1613 return eina_value_type_pset(convert, convert_mem, &other_mem);
1614 }
1615 else if (convert == EINA_VALUE_TYPE_ULONG)
1616 {
1617 unsigned long other_mem = v;
1618 if (EINA_UNLIKELY(v < 0))
1619 return EINA_FALSE;
1620 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
1621 (v > eina_value_ulong_max)))
1622 return EINA_FALSE;
1623 return eina_value_type_pset(convert, convert_mem, &other_mem);
1624 }
1625 else if (convert == EINA_VALUE_TYPE_UINT64)
1626 {
1627 uint64_t other_mem = v;
1628 if (EINA_UNLIKELY(v < 0))
1629 return EINA_FALSE;
1630 return eina_value_type_pset(convert, convert_mem, &other_mem);
1631 }
1632 else if (convert == EINA_VALUE_TYPE_CHAR)
1633 {
1634 char other_mem = v;
1635 if (EINA_UNLIKELY(v < eina_value_char_min))
1636 return EINA_FALSE;
1637 if (EINA_UNLIKELY(v > eina_value_char_max))
1638 return EINA_FALSE;
1639 return eina_value_type_pset(convert, convert_mem, &other_mem);
1640 }
1641 else if (convert == EINA_VALUE_TYPE_SHORT)
1642 {
1643 short other_mem = v;
1644 if (EINA_UNLIKELY(v < eina_value_short_min))
1645 return EINA_FALSE;
1646 if (EINA_UNLIKELY(v > eina_value_short_max))
1647 return EINA_FALSE;
1648 return eina_value_type_pset(convert, convert_mem, &other_mem);
1649 }
1650 else if (convert == EINA_VALUE_TYPE_INT)
1651 {
1652 int other_mem = v;
1653 if (EINA_UNLIKELY(v < eina_value_int_min))
1654 return EINA_FALSE;
1655 if (EINA_UNLIKELY(v > eina_value_int_max))
1656 return EINA_FALSE;
1657 return eina_value_type_pset(convert, convert_mem, &other_mem);
1658 }
1659 else if (convert == EINA_VALUE_TYPE_LONG)
1660 {
1661 long other_mem = v;
1662 if (EINA_UNLIKELY(v < eina_value_long_min))
1663 return EINA_FALSE;
1664 if (EINA_UNLIKELY(v > eina_value_long_max))
1665 return EINA_FALSE;
1666 return eina_value_type_pset(convert, convert_mem, &other_mem);
1667 }
1668 else if (convert == EINA_VALUE_TYPE_INT64)
1669 {
1670 int64_t other_mem = v;
1671 return eina_value_type_pset(convert, convert_mem, &other_mem);
1672 }
1673 else if (convert == EINA_VALUE_TYPE_FLOAT)
1674 {
1675 float other_mem = v;
1676 return eina_value_type_pset(convert, convert_mem, &other_mem);
1677 }
1678 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1679 {
1680 double other_mem = v;
1681 return eina_value_type_pset(convert, convert_mem, &other_mem);
1682 }
1683 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1684 convert == EINA_VALUE_TYPE_STRING)
1685 {
1686 const char *other_mem;
1687 char buf[64];
1688 snprintf(buf, sizeof(buf), "%"PRId64, v);
1689 other_mem = buf; /* required due &buf == buf */
1690 return eina_value_type_pset(convert, convert_mem, &other_mem);
1691 }
1692 else
1693 {
1694 eina_error_set(EINA_ERROR_VALUE_FAILED);
1695 return EINA_FALSE;
1696 }
1697
1698 return EINA_TRUE;
1699}
1700
1701static Eina_Bool
1702_eina_value_type_int64_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1703{
1704 int64_t *tmem = mem;
1705 *tmem = va_arg(args, int64_t);
1706 return EINA_TRUE;
1707}
1708
1709static Eina_Bool
1710_eina_value_type_int64_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1711{
1712 int64_t *tmem = mem;
1713 const int64_t *p = ptr;
1714 *tmem = *p;
1715 return EINA_TRUE;
1716}
1717
1718static Eina_Bool
1719_eina_value_type_int64_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1720{
1721 const int64_t *tmem = mem;
1722 int64_t *p = ptr;
1723 *p = *tmem;
1724 return EINA_TRUE;
1725}
1726
1727static Eina_Bool
1728_eina_value_type_float_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1729{
1730 float *tmem = mem;
1731 *tmem = 0;
1732 return EINA_TRUE;
1733}
1734
1735static Eina_Bool
1736_eina_value_type_float_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1737{
1738 return EINA_TRUE;
1739}
1740
1741static Eina_Bool
1742_eina_value_type_float_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1743{
1744 const float *s = src;
1745 float *d = dst;
1746 *d = *s;
1747 return EINA_TRUE;
1748}
1749
1750static int
1751_eina_value_type_float_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1752{
1753 const float *ta = a, *tb = b;
1754 if (*ta < *tb)
1755 return -1;
1756 else if (*ta > *tb)
1757 return 1;
1758 return 0;
1759}
1760
1761static Eina_Bool
1762_eina_value_type_float_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1763{
1764 const float v = *(const float *)type_mem;
1765
1766 eina_error_set(0);
1767
1768 if (convert == EINA_VALUE_TYPE_UCHAR)
1769 {
1770 unsigned char other_mem = v;
1771 if (EINA_UNLIKELY(v < 0))
1772 return EINA_FALSE;
1773 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1774 return EINA_FALSE;
1775 return eina_value_type_pset(convert, convert_mem, &other_mem);
1776 }
1777 else if (convert == EINA_VALUE_TYPE_USHORT)
1778 {
1779 unsigned short other_mem = v;
1780 if (EINA_UNLIKELY(v < 0))
1781 return EINA_FALSE;
1782 if (EINA_UNLIKELY(v > eina_value_ushort_max))
1783 return EINA_FALSE;
1784 return eina_value_type_pset(convert, convert_mem, &other_mem);
1785 }
1786 else if (convert == EINA_VALUE_TYPE_UINT)
1787 {
1788 unsigned int other_mem = v;
1789 if (EINA_UNLIKELY(v < 0))
1790 return EINA_FALSE;
1791 if (EINA_UNLIKELY(v > eina_value_uint_max))
1792 return EINA_FALSE;
1793 return eina_value_type_pset(convert, convert_mem, &other_mem);
1794 }
1795 else if (convert == EINA_VALUE_TYPE_ULONG)
1796 {
1797 unsigned long other_mem = v;
1798 if (EINA_UNLIKELY(v < 0))
1799 return EINA_FALSE;
1800 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
1801 (v > eina_value_ulong_max)))
1802 return EINA_FALSE;
1803 return eina_value_type_pset(convert, convert_mem, &other_mem);
1804 }
1805 else if (convert == EINA_VALUE_TYPE_UINT64)
1806 {
1807 uint64_t other_mem = v;
1808 if (EINA_UNLIKELY(v < 0))
1809 return EINA_FALSE;
1810 if (EINA_UNLIKELY(v > eina_value_uint64_max))
1811 return EINA_FALSE;
1812 return eina_value_type_pset(convert, convert_mem, &other_mem);
1813 }
1814 else if (convert == EINA_VALUE_TYPE_CHAR)
1815 {
1816 char other_mem = v;
1817 if (EINA_UNLIKELY(v < eina_value_char_min))
1818 return EINA_FALSE;
1819 if (EINA_UNLIKELY(v > eina_value_char_max))
1820 return EINA_FALSE;
1821 return eina_value_type_pset(convert, convert_mem, &other_mem);
1822 }
1823 else if (convert == EINA_VALUE_TYPE_SHORT)
1824 {
1825 short other_mem = v;
1826 if (EINA_UNLIKELY(v < eina_value_short_min))
1827 return EINA_FALSE;
1828 if (EINA_UNLIKELY(v > eina_value_short_max))
1829 return EINA_FALSE;
1830 return eina_value_type_pset(convert, convert_mem, &other_mem);
1831 }
1832 else if (convert == EINA_VALUE_TYPE_INT)
1833 {
1834 int other_mem = v;
1835 if (EINA_UNLIKELY(v < eina_value_int_min))
1836 return EINA_FALSE;
1837 if (EINA_UNLIKELY(v > eina_value_int_max))
1838 return EINA_FALSE;
1839 return eina_value_type_pset(convert, convert_mem, &other_mem);
1840 }
1841 else if (convert == EINA_VALUE_TYPE_LONG)
1842 {
1843 long other_mem = v;
1844 if (EINA_UNLIKELY(v < eina_value_long_min))
1845 return EINA_FALSE;
1846 if (EINA_UNLIKELY(v > eina_value_long_max))
1847 return EINA_FALSE;
1848 return eina_value_type_pset(convert, convert_mem, &other_mem);
1849 }
1850 else if (convert == EINA_VALUE_TYPE_INT64)
1851 {
1852 int64_t other_mem = v;
1853 if (EINA_UNLIKELY(v < eina_value_int64_min))
1854 return EINA_FALSE;
1855 if (EINA_UNLIKELY(v > eina_value_int64_max))
1856 return EINA_FALSE;
1857 return eina_value_type_pset(convert, convert_mem, &other_mem);
1858 }
1859 else if (convert == EINA_VALUE_TYPE_FLOAT)
1860 {
1861 float other_mem = v;
1862 return eina_value_type_pset(convert, convert_mem, &other_mem);
1863 }
1864 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1865 {
1866 double other_mem = v;
1867 return eina_value_type_pset(convert, convert_mem, &other_mem);
1868 }
1869 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1870 convert == EINA_VALUE_TYPE_STRING)
1871 {
1872 const char *other_mem;
1873 char buf[64];
1874 snprintf(buf, sizeof(buf), "%f", v);
1875 other_mem = buf; /* required due &buf == buf */
1876 return eina_value_type_pset(convert, convert_mem, &other_mem);
1877 }
1878 else
1879 {
1880 eina_error_set(EINA_ERROR_VALUE_FAILED);
1881 return EINA_FALSE;
1882 }
1883
1884 return EINA_TRUE;
1885}
1886
1887static Eina_Bool
1888_eina_value_type_float_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1889{
1890 float *tmem = mem;
1891 *tmem = va_arg(args, double); /* float is promoted to double for va_args */
1892 return EINA_TRUE;
1893}
1894
1895static Eina_Bool
1896_eina_value_type_float_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1897{
1898 float *tmem = mem;
1899 const float *p = ptr;
1900 *tmem = *p;
1901 return EINA_TRUE;
1902}
1903
1904static Eina_Bool
1905_eina_value_type_float_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1906{
1907 const float *tmem = mem;
1908 float *p = ptr;
1909 *p = *tmem;
1910 return EINA_TRUE;
1911}
1912
1913static Eina_Bool
1914_eina_value_type_double_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1915{
1916 double *tmem = mem;
1917 *tmem = 0;
1918 return EINA_TRUE;
1919}
1920
1921static Eina_Bool
1922_eina_value_type_double_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1923{
1924 return EINA_TRUE;
1925}
1926
1927static Eina_Bool
1928_eina_value_type_double_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1929{
1930 const double *s = src;
1931 double *d = dst;
1932 *d = *s;
1933 return EINA_TRUE;
1934}
1935
1936static int
1937_eina_value_type_double_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1938{
1939 const double *ta = a, *tb = b;
1940 if (*ta < *tb)
1941 return -1;
1942 else if (*ta > *tb)
1943 return 1;
1944 return 0;
1945}
1946
1947static Eina_Bool
1948_eina_value_type_double_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1949{
1950 const double v = *(const double *)type_mem;
1951
1952 eina_error_set(0);
1953
1954 if (convert == EINA_VALUE_TYPE_UCHAR)
1955 {
1956 unsigned char other_mem = v;
1957 if (EINA_UNLIKELY(v < 0))
1958 return EINA_FALSE;
1959 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1960 return EINA_FALSE;
1961 return eina_value_type_pset(convert, convert_mem, &other_mem);
1962 }
1963 else if (convert == EINA_VALUE_TYPE_USHORT)
1964 {
1965 unsigned short other_mem = v;
1966 if (EINA_UNLIKELY(v < 0))
1967 return EINA_FALSE;
1968 if (EINA_UNLIKELY(v > eina_value_ushort_max))
1969 return EINA_FALSE;
1970 return eina_value_type_pset(convert, convert_mem, &other_mem);
1971 }
1972 else if (convert == EINA_VALUE_TYPE_UINT)
1973 {
1974 unsigned int other_mem = v;
1975 if (EINA_UNLIKELY(v < 0))
1976 return EINA_FALSE;
1977 if (EINA_UNLIKELY(v > eina_value_uint_max))
1978 return EINA_FALSE;
1979 return eina_value_type_pset(convert, convert_mem, &other_mem);
1980 }
1981 else if (convert == EINA_VALUE_TYPE_ULONG)
1982 {
1983 unsigned long other_mem = v;
1984 if (EINA_UNLIKELY(v < 0))
1985 return EINA_FALSE;
1986 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
1987 (v > eina_value_ulong_max)))
1988 return EINA_FALSE;
1989 return eina_value_type_pset(convert, convert_mem, &other_mem);
1990 }
1991 else if (convert == EINA_VALUE_TYPE_UINT64)
1992 {
1993 uint64_t other_mem = v;
1994 if (EINA_UNLIKELY(v < 0))
1995 return EINA_FALSE;
1996 return eina_value_type_pset(convert, convert_mem, &other_mem);
1997 }
1998 else if (convert == EINA_VALUE_TYPE_CHAR)
1999 {
2000 char other_mem = v;
2001 if (EINA_UNLIKELY(v < eina_value_char_min))
2002 return EINA_FALSE;
2003 if (EINA_UNLIKELY(v > eina_value_char_max))
2004 return EINA_FALSE;
2005 return eina_value_type_pset(convert, convert_mem, &other_mem);
2006 }
2007 else if (convert == EINA_VALUE_TYPE_SHORT)
2008 {
2009 short other_mem = v;
2010 if (EINA_UNLIKELY(v < eina_value_short_min))
2011 return EINA_FALSE;
2012 if (EINA_UNLIKELY(v > eina_value_short_max))
2013 return EINA_FALSE;
2014 return eina_value_type_pset(convert, convert_mem, &other_mem);
2015 }
2016 else if (convert == EINA_VALUE_TYPE_INT)
2017 {
2018 int other_mem = v;
2019 if (EINA_UNLIKELY(v < eina_value_int_min))
2020 return EINA_FALSE;
2021 if (EINA_UNLIKELY(v > eina_value_int_max))
2022 return EINA_FALSE;
2023 return eina_value_type_pset(convert, convert_mem, &other_mem);
2024 }
2025 else if (convert == EINA_VALUE_TYPE_LONG)
2026 {
2027 long other_mem = v;
2028 if (EINA_UNLIKELY(v < eina_value_long_min))
2029 return EINA_FALSE;
2030 if (EINA_UNLIKELY(v > eina_value_long_max))
2031 return EINA_FALSE;
2032 return eina_value_type_pset(convert, convert_mem, &other_mem);
2033 }
2034 else if (convert == EINA_VALUE_TYPE_INT64)
2035 {
2036 int64_t other_mem = v;
2037 return eina_value_type_pset(convert, convert_mem, &other_mem);
2038 }
2039 else if (convert == EINA_VALUE_TYPE_FLOAT)
2040 {
2041 float other_mem = v;
2042 return eina_value_type_pset(convert, convert_mem, &other_mem);
2043 }
2044 else if (convert == EINA_VALUE_TYPE_DOUBLE)
2045 {
2046 double other_mem = v;
2047 return eina_value_type_pset(convert, convert_mem, &other_mem);
2048 }
2049 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
2050 convert == EINA_VALUE_TYPE_STRING)
2051 {
2052 const char *other_mem;
2053 char buf[64];
2054 snprintf(buf, sizeof(buf), "%g", (double)v);
2055 other_mem = buf; /* required due &buf == buf */
2056 return eina_value_type_pset(convert, convert_mem, &other_mem);
2057 }
2058 else
2059 {
2060 eina_error_set(EINA_ERROR_VALUE_FAILED);
2061 return EINA_FALSE;
2062 }
2063
2064 return EINA_TRUE;
2065}
2066
2067static Eina_Bool
2068_eina_value_type_double_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
2069{
2070 double *tmem = mem;
2071 *tmem = va_arg(args, double);
2072 return EINA_TRUE;
2073}
2074
2075static Eina_Bool
2076_eina_value_type_double_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
2077{
2078 double *tmem = mem;
2079 const double *p = ptr;
2080 *tmem = *p;
2081 return EINA_TRUE;
2082}
2083
2084static Eina_Bool
2085_eina_value_type_double_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
2086{
2087 const double *tmem = mem;
2088 double *p = ptr;
2089 *p = *tmem;
2090 return EINA_TRUE;
2091}
2092
2093static Eina_Bool
2094_eina_value_type_string_common_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
2095{
2096 const char **tmem = mem;
2097 *tmem = NULL;
2098 return EINA_TRUE;
2099}
2100
2101static int
2102_eina_value_type_string_common_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
2103{
2104 const char *sa = *(const char **)a;
2105 const char *sb = *(const char **)b;
2106 if (sa == sb)
2107 return 0;
2108 if (sa == NULL)
2109 return -1;
2110 if (sb == NULL)
2111 return 1;
2112 return strcmp(sa, sb);
2113}
2114
2115static Eina_Bool
2116_eina_value_type_string_common_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
2117{
2118 const char *v = *(const char **)type_mem;
2119
2120 eina_error_set(0);
2121
2122 if (convert == EINA_VALUE_TYPE_UCHAR)
2123 {
2124 unsigned char other_mem;
2125 if ((sscanf(v, "%hhu", &other_mem) != 1) &&
2126 (sscanf(v, "%hhx", &other_mem) != 1) &&
2127 (sscanf(v, "%hho", &other_mem) != 1))
2128 return EINA_FALSE;
2129 return eina_value_type_pset(convert, convert_mem, &other_mem);
2130 }
2131 else if (convert == EINA_VALUE_TYPE_USHORT)
2132 {
2133 unsigned short other_mem;
2134 if ((sscanf(v, "%hu", &other_mem) != 1) &&
2135 (sscanf(v, "%hx", &other_mem) != 1) &&
2136 (sscanf(v, "%ho", &other_mem) != 1))
2137 return EINA_FALSE;
2138 return eina_value_type_pset(convert, convert_mem, &other_mem);
2139 }
2140 else if (convert == EINA_VALUE_TYPE_UINT)
2141 {
2142 unsigned int other_mem;
2143 if ((sscanf(v, "%u", &other_mem) != 1) &&
2144 (sscanf(v, "%x", &other_mem) != 1) &&
2145 (sscanf(v, "%o", &other_mem) != 1))
2146 return EINA_FALSE;
2147 return eina_value_type_pset(convert, convert_mem, &other_mem);
2148 }
2149 else if (convert == EINA_VALUE_TYPE_ULONG)
2150 {
2151 unsigned long other_mem;
2152 if ((sscanf(v, "%lu", &other_mem) != 1) &&
2153 (sscanf(v, "%lx", &other_mem) != 1) &&
2154 (sscanf(v, "%lo", &other_mem) != 1))
2155 return EINA_FALSE;
2156 return eina_value_type_pset(convert, convert_mem, &other_mem);
2157 }
2158 else if (convert == EINA_VALUE_TYPE_UINT64)
2159 {
2160 uint64_t other_mem;
2161 if ((sscanf(v, "%"SCNu64, &other_mem) != 1) &&
2162 (sscanf(v, "%"SCNx64, &other_mem) != 1) &&
2163 (sscanf(v, "%"SCNo64, &other_mem) != 1))
2164 return EINA_FALSE;
2165 return eina_value_type_pset(convert, convert_mem, &other_mem);
2166 }
2167 else if (convert == EINA_VALUE_TYPE_CHAR)
2168 {
2169 char other_mem;
2170 if ((sscanf(v, "%hhd", &other_mem) != 1) &&
2171 (sscanf(v, "%hhx", &other_mem) != 1) &&
2172 (sscanf(v, "%hho", &other_mem) != 1))
2173 return EINA_FALSE;
2174 return eina_value_type_pset(convert, convert_mem, &other_mem);
2175 }
2176 else if (convert == EINA_VALUE_TYPE_SHORT)
2177 {
2178 short other_mem;
2179 if ((sscanf(v, "%hd", &other_mem) != 1) &&
2180 (sscanf(v, "%hx", &other_mem) != 1) &&
2181 (sscanf(v, "%ho", &other_mem) != 1))
2182 return EINA_FALSE;
2183 return eina_value_type_pset(convert, convert_mem, &other_mem);
2184 }
2185 else if (convert == EINA_VALUE_TYPE_INT)
2186 {
2187 int other_mem;
2188 if ((sscanf(v, "%d", &other_mem) != 1) &&
2189 (sscanf(v, "%x", &other_mem) != 1) &&
2190 (sscanf(v, "%o", &other_mem) != 1))
2191 return EINA_FALSE;
2192 return eina_value_type_pset(convert, convert_mem, &other_mem);
2193 }
2194 else if (convert == EINA_VALUE_TYPE_LONG)
2195 {
2196 long other_mem;
2197 if ((sscanf(v, "%ld", &other_mem) != 1) &&
2198 (sscanf(v, "%lx", &other_mem) != 1) &&
2199 (sscanf(v, "%lo", &other_mem) != 1))
2200 return EINA_FALSE;
2201 return eina_value_type_pset(convert, convert_mem, &other_mem);
2202 }
2203 else if (convert == EINA_VALUE_TYPE_INT64)
2204 {
2205 int64_t other_mem;
2206 if ((sscanf(v, "%"SCNd64, &other_mem) != 1) &&
2207 (sscanf(v, "%"SCNx64, &other_mem) != 1) &&
2208 (sscanf(v, "%"SCNo64, &other_mem) != 1))
2209 return EINA_FALSE;
2210 return eina_value_type_pset(convert, convert_mem, &other_mem);
2211 }
2212 else if (convert == EINA_VALUE_TYPE_FLOAT)
2213 {
2214 float other_mem;
2215 if (sscanf(v, "%f", &other_mem) != 1)
2216 return EINA_FALSE;
2217 return eina_value_type_pset(convert, convert_mem, &other_mem);
2218 }
2219 else if (convert == EINA_VALUE_TYPE_DOUBLE)
2220 {
2221 double other_mem;
2222 if (sscanf(v, "%lf", &other_mem) != 1)
2223 return EINA_FALSE;
2224 return eina_value_type_pset(convert, convert_mem, &other_mem);
2225 }
2226 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
2227 convert == EINA_VALUE_TYPE_STRING)
2228 {
2229 return eina_value_type_pset(convert, convert_mem, &v);
2230 }
2231 else
2232 {
2233 eina_error_set(EINA_ERROR_VALUE_FAILED);
2234 return EINA_FALSE;
2235 }
2236
2237 return EINA_TRUE;
2238}
2239
2240static Eina_Bool
2241_eina_value_type_string_common_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
2242{
2243 memcpy(ptr, mem, sizeof(const char *));
2244 return EINA_TRUE;
2245}
2246
2247static Eina_Bool
2248_eina_value_type_stringshare_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
2249{
2250 const char **tmem = mem;
2251 if (*tmem) eina_stringshare_del(*tmem);
2252 return EINA_TRUE;
2253}
2254
2255static Eina_Bool
2256_eina_value_type_stringshare_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
2257{
2258 const char * const*s = src;
2259 const char **d = dst;
2260 *d = *s;
2261 eina_stringshare_ref(*d);
2262 return EINA_TRUE;
2263}
2264
2265static Eina_Bool
2266_eina_value_type_stringshare_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
2267{
2268 const char *str = va_arg(args, const char *);
2269 return eina_stringshare_replace((const char **)mem, str);
2270}
2271
2272static Eina_Bool
2273_eina_value_type_stringshare_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
2274{
2275 const char * const *str = ptr;
2276 return eina_stringshare_replace((const char **)mem, *str);
2277}
2278
2279static Eina_Bool
2280_eina_value_type_string_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
2281{
2282 char **tmem = mem;
2283 if (*tmem) free(*tmem);
2284 return EINA_TRUE;
2285}
2286
2287static Eina_Bool
2288_eina_value_type_string_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
2289{
2290 const char * const *s = src;
2291 char **d = dst;
2292 if (*s == NULL)
2293 *d = NULL;
2294 else
2295 {
2296 *d = strdup(*s);
2297 if (*d == NULL)
2298 {
2299 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
2300 return EINA_FALSE;
2301 }
2302 }
2303 return EINA_TRUE;
2304}
2305
2306static Eina_Bool
2307_eina_value_type_string_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
2308{
2309 char **tmem = mem;
2310 const char *str = va_arg(args, const char *);
2311 free(*tmem);
2312 if (str == NULL)
2313 *tmem = NULL;
2314 else
2315 {
2316 *tmem = strdup(str);
2317 if (*tmem == NULL)
2318 {
2319 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
2320 return EINA_FALSE;
2321 }
2322 }
2323 eina_error_set(0);
2324 return EINA_TRUE;
2325}
2326
2327static Eina_Bool
2328_eina_value_type_string_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
2329{
2330 char **tmem = mem;
2331 const char * const *str = ptr;
2332 free(*tmem);
2333 if (*str == NULL)
2334 *tmem = NULL;
2335 else
2336 {
2337 *tmem = strdup(*str);
2338 if (*tmem == NULL)
2339 {
2340 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
2341 return EINA_FALSE;
2342 }
2343 }
2344 eina_error_set(0);
2345 return EINA_TRUE;
2346}
2347
2348static Eina_Bool
2349_eina_value_type_array_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
2350{
2351 memset(mem, 0, sizeof(Eina_Value_Array));
2352 return EINA_TRUE;
2353}
2354
2355static Eina_Bool
2356_eina_value_type_array_flush_elements(Eina_Value_Array *tmem)
2357{
2358 const Eina_Value_Type *subtype = tmem->subtype;
2359 Eina_Bool ret = EINA_TRUE;
2360 unsigned char sz;
2361 char *ptr, *ptr_end;
2362
2363 if (!tmem->array) return EINA_TRUE;
2364
2365 sz = tmem->array->member_size;
2366 ptr = tmem->array->members;
2367 ptr_end = ptr + tmem->array->len * sz;
2368
2369 for (; ptr < ptr_end; ptr += sz)
2370 ret &= eina_value_type_flush(subtype, ptr);
2371
2372 eina_inarray_flush(tmem->array);
2373 return ret;
2374}
2375
2376static Eina_Bool
2377_eina_value_type_array_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
2378{
2379 Eina_Value_Array *tmem = mem;
2380 Eina_Bool ret =_eina_value_type_array_flush_elements(tmem);
2381
2382 if (tmem->array) eina_inarray_free(tmem->array);
2383 tmem->array = NULL;
2384 tmem->subtype = NULL;
2385 return ret;
2386}
2387
2388static Eina_Bool
2389_eina_value_type_array_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
2390{
2391 const Eina_Value_Type *subtype;
2392 const Eina_Value_Array *s = src;
2393 Eina_Value_Array *d = dst;
2394 unsigned int i, count, sz;
2395 char *ptr, *ptr_end;
2396
2397 d->subtype = subtype = s->subtype;
2398 d->step = s->step;
2399
2400 if ((!s->array) || (!s->subtype))
2401 {
2402 d->array = NULL;
2403 return EINA_TRUE;
2404 }
2405
2406 if (!subtype->copy)
2407 {
2408 eina_error_set(EINA_ERROR_VALUE_FAILED);
2409 return EINA_FALSE;
2410 }
2411
2412 d->array = eina_inarray_new(subtype->value_size, s->step);
2413 if (!d->array)
2414 return EINA_FALSE;
2415
2416 sz = s->array->member_size;
2417
2418 count = eina_inarray_count(s->array);
2419 ptr = s->array->members;
2420 ptr_end = ptr + (count * sz);
2421
2422 for (i = 0; ptr < ptr_end; ptr += sz, i++)
2423 {
2424 void *imem = eina_inarray_alloc_at(d->array, i, 1);
2425 if (!imem) goto error;
2426 if (!subtype->copy(subtype, ptr, imem))
2427 {
2428 eina_inarray_pop(d->array);
2429 goto error;
2430 }
2431 }
2432
2433 return EINA_TRUE;
2434
2435 error:
2436 _eina_value_type_array_flush_elements(d);
2437 return EINA_FALSE;
2438}
2439
2440static int
2441_eina_value_type_array_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
2442{
2443 const Eina_Value_Type *subtype;
2444 const Eina_Value_Array *eva_a = a, *eva_b = b;
2445 const char *a_ptr, *a_ptr_end, *b_ptr;
2446 unsigned int count_a, count_b, count, sz;
2447 int cmp = 0;
2448
2449 if (eva_a->subtype != eva_b->subtype)
2450 {
2451 eina_error_set(EINA_ERROR_VALUE_FAILED);
2452 return -1;
2453 }
2454
2455 subtype = eva_a->subtype;
2456 if (!subtype->compare)
2457 {
2458 eina_error_set(EINA_ERROR_VALUE_FAILED);
2459 return 0;
2460 }
2461
2462 if ((!eva_a->array) && (!eva_b->array))
2463 return 0;
2464 else if (!eva_a->array)
2465 return -1;
2466 else if (!eva_b->array)
2467 return 1;
2468
2469 count_a = eina_inarray_count(eva_a->array);
2470 count_b = eina_inarray_count(eva_b->array);
2471
2472 if (count_a <= count_b)
2473 count = count_a;
2474 else
2475 count = count_b;
2476
2477 sz = eva_a->array->member_size;
2478
2479 a_ptr = eva_a->array->members;
2480 a_ptr_end = a_ptr + (count * sz);
2481 b_ptr = eva_b->array->members;
2482
2483 for (; (cmp == 0) && (a_ptr < a_ptr_end); a_ptr += sz, b_ptr += sz)
2484 cmp = subtype->compare(subtype, a_ptr, b_ptr);
2485
2486 if (cmp == 0)
2487 {
2488 if (count_a < count_b)
2489 return -1;
2490 else if (count_a > count_b)
2491 return 1;
2492 return 0;
2493 }
2494
2495 return cmp;
2496}
2497
2498static Eina_Bool
2499_eina_value_type_array_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
2500{
2501 const Eina_Value_Array *tmem = type_mem;
2502 Eina_Bool ret = EINA_FALSE;
2503
2504 if ((convert == EINA_VALUE_TYPE_STRING) ||
2505 (convert == EINA_VALUE_TYPE_STRINGSHARE))
2506 {
2507 Eina_Strbuf *str = eina_strbuf_new();
2508 if (!tmem->array) eina_strbuf_append(str, "[]");
2509 else
2510 {
2511 const Eina_Value_Type *subtype = tmem->subtype;
2512 unsigned char sz;
2513 const char *ptr, *ptr_end;
2514 Eina_Value tmp;
2515 Eina_Bool first = EINA_TRUE;
2516
2517 eina_value_setup(&tmp, EINA_VALUE_TYPE_STRING);
2518
2519 eina_strbuf_append_char(str, '[');
2520
2521 sz = tmem->array->member_size;
2522 ptr = tmem->array->members;
2523 ptr_end = ptr + tmem->array->len * sz;
2524 for (; ptr < ptr_end; ptr += sz)
2525 {
2526 Eina_Bool r = EINA_FALSE;
2527 if (subtype->convert_to)
2528 {
2529 r = subtype->convert_to(subtype, EINA_VALUE_TYPE_STRING,
2530 ptr, tmp.value.buf);
2531 if (r)
2532 {
2533 if (first) first = EINA_FALSE;
2534 else eina_strbuf_append_length(str, ", ", 2);
2535 eina_strbuf_append(str, tmp.value.ptr);
2536 free(tmp.value.ptr);
2537 tmp.value.ptr = NULL;
2538 }
2539 }
2540
2541 if (!r)
2542 {
2543 if (first)
2544 {
2545 first = EINA_FALSE;
2546 eina_strbuf_append_char(str, '?');
2547 }
2548 else
2549 eina_strbuf_append_length(str, ", ?", 3);
2550 }
2551 }
2552
2553 eina_strbuf_append_char(str, ']');
2554 ptr = eina_strbuf_string_get(str);
2555 ret = eina_value_type_pset(convert, convert_mem, &ptr);
2556 eina_strbuf_free(str);
2557 }
2558 }
2559 else if ((tmem->array) && (tmem->array->len == 1))
2560 {
2561 const Eina_Value_Type *subtype = tmem->subtype;
2562 void *imem = tmem->array->members;
2563
2564 if (subtype->convert_to)
2565 ret = subtype->convert_to(subtype, convert, imem, convert_mem);
2566 if ((!ret) && (convert->convert_from))
2567 ret = convert->convert_from(convert, subtype, convert_mem, imem);
2568 }
2569
2570 if (!ret)
2571 {
2572 eina_error_set(EINA_ERROR_VALUE_FAILED);
2573 return EINA_FALSE;
2574 }
2575 return EINA_TRUE;
2576}
2577
2578static Eina_Bool
2579_eina_value_type_array_convert_from(const Eina_Value_Type *type, const Eina_Value_Type *convert, void *type_mem, const void *convert_mem)
2580{
2581 Eina_Value_Array *tmem = type_mem;
2582 Eina_Value_Array desc = {convert, tmem->step, NULL};
2583 char *buf;
2584 void *imem;
2585
2586 if (!eina_value_type_pset(type, tmem, &desc))
2587 return EINA_FALSE;
2588
2589 buf = alloca(convert->value_size);
2590 if (!eina_value_type_pget(convert, convert_mem, &buf))
2591 return EINA_FALSE;
2592
2593 imem = eina_inarray_alloc_at(tmem->array, 0, 1);
2594 if (!imem)
2595 return EINA_FALSE;
2596
2597 if (!eina_value_type_setup(convert, imem)) goto error_setup;
2598 if (!eina_value_type_pset(convert, imem, &buf)) goto error_set;
2599 return EINA_TRUE;
2600
2601 error_set:
2602 eina_value_type_flush(convert, imem);
2603 error_setup:
2604 eina_inarray_remove_at(tmem->array, 0);
2605 return EINA_FALSE;
2606}
2607
2608static Eina_Bool
2609_eina_value_type_array_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
2610{
2611 Eina_Value_Array *tmem = mem;
2612 const Eina_Value_Array *desc = ptr;
2613 Eina_Inarray *desc_array;
2614
2615 if ((!tmem->subtype) && (!desc->subtype))
2616 return EINA_TRUE;
2617
2618 desc_array = desc->array;
2619 if (desc_array)
2620 {
2621 EINA_SAFETY_ON_FALSE_RETURN_VAL
2622 (desc_array->member_size == desc->subtype->value_size, EINA_FALSE);
2623 }
2624
2625 if (tmem->array)
2626 {
2627 _eina_value_type_array_flush_elements(tmem);
2628 if (desc_array)
2629 eina_inarray_free(tmem->array);
2630 else
2631 eina_inarray_setup(tmem->array, desc->subtype->value_size,
2632 desc->step);
2633 }
2634 else if (!desc_array)
2635 {
2636 tmem->array = eina_inarray_new(desc->subtype->value_size, desc->step);
2637 if (!tmem->array)
2638 return EINA_FALSE;
2639 }
2640
2641 if (desc_array)
2642 tmem->array = desc_array;
2643
2644 tmem->subtype = desc->subtype;
2645
2646 return EINA_TRUE;
2647}
2648
2649static Eina_Bool
2650_eina_value_type_array_vset(const Eina_Value_Type *type, void *mem, va_list args)
2651{
2652 const Eina_Value_Array desc = va_arg(args, Eina_Value_Array);
2653 _eina_value_type_array_pset(type, mem, &desc);
2654 return EINA_TRUE;
2655}
2656
2657static Eina_Bool
2658_eina_value_type_array_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
2659{
2660 memcpy(ptr, mem, sizeof(Eina_Value_Array));
2661 return EINA_TRUE;
2662}
2663
2664static const Eina_Value_Type _EINA_VALUE_TYPE_ARRAY = {
2665 EINA_VALUE_TYPE_VERSION,
2666 sizeof(Eina_Value_Array),
2667 "Eina_Value_Array",
2668 _eina_value_type_array_setup,
2669 _eina_value_type_array_flush,
2670 _eina_value_type_array_copy,
2671 _eina_value_type_array_compare,
2672 _eina_value_type_array_convert_to,
2673 _eina_value_type_array_convert_from,
2674 _eina_value_type_array_vset,
2675 _eina_value_type_array_pset,
2676 _eina_value_type_array_pget
2677};
2678
2679static Eina_Bool
2680_eina_value_type_list_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
2681{
2682 memset(mem, 0, sizeof(Eina_Value_List));
2683 return EINA_TRUE;
2684}
2685
2686static Eina_Bool
2687_eina_value_type_list_flush_elements(Eina_Value_List *tmem)
2688{
2689 const Eina_Value_Type *subtype = tmem->subtype;
2690 Eina_Bool ret = EINA_TRUE;
2691
2692 if (!tmem->list) return EINA_TRUE;
2693
2694 while (tmem->list)
2695 {
2696 void *mem = eina_value_list_node_memory_get(tmem->subtype, tmem->list);
2697 ret &= eina_value_type_flush(subtype, mem);
2698 eina_value_list_node_memory_flush(tmem->subtype, tmem->list);
2699 tmem->list = eina_list_remove_list(tmem->list, tmem->list);
2700 }
2701
2702 return ret;
2703}
2704
2705static Eina_Bool
2706_eina_value_type_list_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
2707{
2708 Eina_Value_List *tmem = mem;
2709 Eina_Bool ret =_eina_value_type_list_flush_elements(tmem);
2710
2711 if (tmem->list) eina_list_free(tmem->list);
2712 tmem->list = NULL;
2713 tmem->subtype = NULL;
2714 return ret;
2715}
2716
2717static Eina_Bool
2718_eina_value_type_list_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
2719{
2720 const Eina_Value_Type *subtype;
2721 const Eina_Value_List *s = src;
2722 Eina_Value_List *d = dst;
2723 const Eina_List *snode;
2724
2725 d->subtype = subtype = s->subtype;
2726 if ((!s->list) || (!s->subtype))
2727 {
2728 d->list = NULL;
2729 return EINA_TRUE;
2730 }
2731
2732 if (!subtype->copy)
2733 {
2734 eina_error_set(EINA_ERROR_VALUE_FAILED);
2735 return EINA_FALSE;
2736 }
2737
2738 d->list = NULL;
2739 for (snode = s->list; snode != NULL; snode = snode->next)
2740 {
2741 const void *ptr = eina_value_list_node_memory_get(subtype, snode);
2742 Eina_List *dnode;
2743 void *imem;
2744
2745 d->list = eina_list_append(d->list, (void*)1L);
2746 dnode = eina_list_last(d->list);
2747 EINA_SAFETY_ON_NULL_GOTO(dnode, error);
2748 EINA_SAFETY_ON_FALSE_GOTO(dnode->data == (void*)1L, error);
2749
2750 imem = eina_value_list_node_memory_setup(subtype, dnode);
2751 if (!subtype->copy(subtype, ptr, imem))
2752 {
2753 eina_value_list_node_memory_flush(subtype, dnode);
2754 d->list = eina_list_remove_list(d->list, dnode);
2755 goto error;
2756 }
2757 }
2758 return EINA_TRUE;
2759
2760 error:
2761 _eina_value_type_list_flush_elements(d);
2762 return EINA_FALSE;
2763}
2764
2765static int
2766_eina_value_type_list_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
2767{
2768 const Eina_Value_Type *subtype;
2769 const Eina_Value_List *eva_a = a, *eva_b = b;
2770 const Eina_List *anode, *bnode;
2771 int cmp = 0;
2772
2773 if (eva_a->subtype != eva_b->subtype)
2774 {
2775 eina_error_set(EINA_ERROR_VALUE_FAILED);
2776 return -1;
2777 }
2778
2779 subtype = eva_a->subtype;
2780 if (!subtype->compare)
2781 {
2782 eina_error_set(EINA_ERROR_VALUE_FAILED);
2783 return 0;
2784 }
2785
2786 if ((!eva_a->list) && (!eva_b->list))
2787 return 0;
2788 else if (!eva_a->list)
2789 return -1;
2790 else if (!eva_b->list)
2791 return 1;
2792
2793 for (anode = eva_a->list, bnode = eva_b->list;
2794 (cmp == 0) && (anode) && (bnode);
2795 anode = anode->next, bnode = bnode->next)
2796 {
2797 const void *amem = eina_value_list_node_memory_get(subtype, anode);
2798 const void *bmem = eina_value_list_node_memory_get(subtype, bnode);
2799 cmp = subtype->compare(subtype, amem, bmem);
2800 }
2801
2802 if (cmp == 0)
2803 {
2804 if ((!anode) && (bnode))
2805 return -1;
2806 else if ((anode) && (!bnode))
2807 return 1;
2808 return 0;
2809 }
2810
2811 return cmp;
2812}
2813
2814static Eina_Bool
2815_eina_value_type_list_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
2816{
2817 const Eina_Value_List *tmem = type_mem;
2818 Eina_Bool ret = EINA_FALSE;
2819
2820 if ((convert == EINA_VALUE_TYPE_STRING) ||
2821 (convert == EINA_VALUE_TYPE_STRINGSHARE))
2822 {
2823 Eina_Strbuf *str = eina_strbuf_new();
2824 if (!tmem->list) eina_strbuf_append(str, "[]");
2825 else
2826 {
2827 const Eina_Value_Type *subtype = tmem->subtype;
2828 const Eina_List *node;
2829 Eina_Value tmp;
2830 const char *s;
2831 Eina_Bool first = EINA_TRUE;
2832
2833 eina_value_setup(&tmp, EINA_VALUE_TYPE_STRING);
2834
2835 eina_strbuf_append_char(str, '[');
2836
2837 for (node = tmem->list; node != NULL; node = node->next)
2838 {
2839 Eina_Bool r = EINA_FALSE;
2840
2841 if (subtype->convert_to)
2842 {
2843 const void *ptr;
2844 ptr = eina_value_list_node_memory_get(subtype, node);
2845 r = subtype->convert_to(subtype, EINA_VALUE_TYPE_STRING,
2846 ptr, tmp.value.buf);
2847 if (r)
2848 {
2849 if (first) first = EINA_FALSE;
2850 else eina_strbuf_append_length(str, ", ", 2);
2851 eina_strbuf_append(str, tmp.value.ptr);
2852 free(tmp.value.ptr);
2853 tmp.value.ptr = NULL;
2854 }
2855 }
2856
2857 if (!r)
2858 {
2859 if (first)
2860 {
2861 first = EINA_FALSE;
2862 eina_strbuf_append_char(str, '?');
2863 }
2864 else
2865 eina_strbuf_append_length(str, ", ?", 3);
2866 }
2867 }
2868
2869 eina_strbuf_append_char(str, ']');
2870 s = eina_strbuf_string_get(str);
2871 ret = eina_value_type_pset(convert, convert_mem, &s);
2872 eina_strbuf_free(str);
2873 }
2874 }
2875 else if ((tmem->list) && (tmem->list->next == NULL))
2876 {
2877 const Eina_Value_Type *subtype = tmem->subtype;
2878 void *imem = eina_value_list_node_memory_get(subtype, tmem->list);
2879
2880 if (subtype->convert_to)
2881 ret = subtype->convert_to(subtype, convert, imem, convert_mem);
2882 if ((!ret) && (convert->convert_from))
2883 ret = convert->convert_from(convert, subtype, convert_mem, imem);
2884 }
2885
2886 if (!ret)
2887 {
2888 eina_error_set(EINA_ERROR_VALUE_FAILED);
2889 return EINA_FALSE;
2890 }
2891 return EINA_TRUE;
2892}
2893
2894static Eina_Bool
2895_eina_value_type_list_convert_from(const Eina_Value_Type *type, const Eina_Value_Type *convert, void *type_mem, const void *convert_mem)
2896{
2897 Eina_Value_List *tmem = type_mem;
2898 Eina_Value_List desc = {convert, NULL};
2899 Eina_List *node;
2900 char *buf;
2901 void *imem;
2902
2903 if (!eina_value_type_pset(type, tmem, &desc))
2904 return EINA_FALSE;
2905
2906 buf = alloca(convert->value_size);
2907 if (!eina_value_type_pget(convert, convert_mem, &buf))
2908 return EINA_FALSE;
2909
2910 tmem->list = eina_list_append(tmem->list, (void*)1L);
2911 node = eina_list_last(tmem->list);
2912 EINA_SAFETY_ON_NULL_RETURN_VAL(node, EINA_FALSE);
2913 EINA_SAFETY_ON_FALSE_RETURN_VAL(node->data == (void*)1L, EINA_FALSE);
2914
2915 imem = eina_value_list_node_memory_setup(tmem->subtype, node);
2916 if (!imem)
2917 {
2918 tmem->list = eina_list_remove_list(tmem->list, node);
2919 return EINA_FALSE;
2920 }
2921
2922 if (!eina_value_type_setup(tmem->subtype, imem)) goto error_setup;
2923 if (!eina_value_type_pset(tmem->subtype, imem, &buf)) goto error_set;
2924 return EINA_TRUE;
2925
2926 error_set:
2927 eina_value_type_flush(tmem->subtype, imem);
2928 error_setup:
2929 eina_value_list_node_memory_flush(tmem->subtype, node);
2930 tmem->list = eina_list_remove_list(tmem->list, node);
2931 return EINA_FALSE;
2932}
2933
2934static Eina_Bool
2935_eina_value_type_list_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
2936{
2937 Eina_Value_List *tmem = mem;
2938 const Eina_Value_List *desc = ptr;
2939
2940 if ((!tmem->subtype) && (!desc->subtype))
2941 return EINA_TRUE;
2942
2943 _eina_value_type_list_flush_elements(tmem);
2944 tmem->subtype = desc->subtype;
2945 tmem->list = desc->list;
2946
2947 return EINA_TRUE;
2948}
2949
2950static Eina_Bool
2951_eina_value_type_list_vset(const Eina_Value_Type *type, void *mem, va_list args)
2952{
2953 const Eina_Value_List desc = va_arg(args, Eina_Value_List);
2954 _eina_value_type_list_pset(type, mem, &desc);
2955 return EINA_TRUE;
2956}
2957
2958static Eina_Bool
2959_eina_value_type_list_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
2960{
2961 memcpy(ptr, mem, sizeof(Eina_Value_List));
2962 return EINA_TRUE;
2963}
2964
2965static const Eina_Value_Type _EINA_VALUE_TYPE_LIST = {
2966 EINA_VALUE_TYPE_VERSION,
2967 sizeof(Eina_Value_List),
2968 "Eina_Value_List",
2969 _eina_value_type_list_setup,
2970 _eina_value_type_list_flush,
2971 _eina_value_type_list_copy,
2972 _eina_value_type_list_compare,
2973 _eina_value_type_list_convert_to,
2974 _eina_value_type_list_convert_from,
2975 _eina_value_type_list_vset,
2976 _eina_value_type_list_pset,
2977 _eina_value_type_list_pget
2978};
2979
2980static Eina_Bool
2981_eina_value_type_hash_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
2982{
2983 memset(mem, 0, sizeof(Eina_Value_Hash));
2984 return EINA_TRUE;
2985}
2986
2987struct _eina_value_type_hash_flush_each_ctx
2988{
2989 const Eina_Value_Type *subtype;
2990 Eina_Bool ret;
2991};
2992
2993static Eina_Bool
2994_eina_value_type_hash_flush_each(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *mem, void *user_data)
2995{
2996 struct _eina_value_type_hash_flush_each_ctx *ctx = user_data;
2997 ctx->ret &= eina_value_type_flush(ctx->subtype, mem);
2998 return EINA_TRUE;
2999}
3000
3001static Eina_Bool
3002_eina_value_type_hash_flush_elements(Eina_Value_Hash *tmem)
3003{
3004 struct _eina_value_type_hash_flush_each_ctx ctx = {
3005 tmem->subtype,
3006 EINA_TRUE
3007 };
3008
3009 if (!tmem->hash) return EINA_TRUE;
3010
3011 eina_hash_foreach(tmem->hash, _eina_value_type_hash_flush_each, &ctx);
3012 eina_hash_free(tmem->hash);
3013 tmem->hash = NULL;
3014 return ctx.ret;
3015}
3016
3017static Eina_Bool
3018_eina_value_type_hash_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
3019{
3020 Eina_Value_Hash *tmem = mem;
3021 Eina_Bool ret =_eina_value_type_hash_flush_elements(tmem);
3022 tmem->subtype = NULL;
3023 return ret;
3024}
3025
3026static unsigned int
3027_eina_value_hash_key_length(const void *key)
3028{
3029 if (!key)
3030 return 0;
3031 return (int)strlen(key) + 1;
3032}
3033
3034static int
3035_eina_value_hash_key_cmp(const void *key1, int key1_len, const void *key2, int key2_len)
3036{
3037 int r = key1_len - key2_len;
3038 if (r != 0)
3039 return r;
3040 return strcmp(key1, key2);
3041}
3042
3043static Eina_Bool
3044_eina_value_type_hash_create(Eina_Value_Hash *desc)
3045{
3046 if (!desc->buckets_power_size)
3047 desc->buckets_power_size = 5;
3048
3049 desc->hash = eina_hash_new(_eina_value_hash_key_length,
3050 _eina_value_hash_key_cmp,
3051 EINA_KEY_HASH(eina_hash_superfast),
3052 NULL, desc->buckets_power_size);
3053 return !!desc->hash;
3054}
3055
3056struct _eina_value_type_hash_copy_each_ctx
3057{
3058 const Eina_Value_Type *subtype;
3059 Eina_Value_Hash *dest;
3060 Eina_Bool ret;
3061};
3062
3063static Eina_Bool
3064_eina_value_type_hash_copy_each(const Eina_Hash *hash __UNUSED__, const void *key, void *_ptr, void *user_data)
3065{
3066 struct _eina_value_type_hash_copy_each_ctx *ctx = user_data;
3067 const void *ptr = _ptr;
3068 void *imem = malloc(ctx->subtype->value_size);
3069 if (!imem)
3070 {
3071 ctx->ret = EINA_FALSE;
3072 return EINA_FALSE;
3073 }
3074 if (!ctx->subtype->copy(ctx->subtype, ptr, imem))
3075 {
3076 free(imem);
3077 ctx->ret = EINA_FALSE;
3078 return EINA_FALSE;
3079 }
3080 if (!eina_hash_add(ctx->dest->hash, key, imem))
3081 {
3082 eina_value_type_flush(ctx->subtype, imem);
3083 free(imem);
3084 ctx->ret = EINA_FALSE;
3085 return EINA_FALSE;
3086 }
3087 return EINA_TRUE;
3088}
3089
3090static Eina_Bool
3091_eina_value_type_hash_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
3092{
3093 const Eina_Value_Hash *s = src;
3094 Eina_Value_Hash *d = dst;
3095 struct _eina_value_type_hash_copy_each_ctx ctx = {s->subtype, d, EINA_TRUE};
3096
3097 d->subtype = s->subtype;
3098 d->buckets_power_size = s->buckets_power_size;
3099
3100 if ((!s->hash) || (!s->subtype))
3101 {
3102 d->hash = NULL;
3103 return EINA_TRUE;
3104 }
3105
3106 if (!s->subtype->copy)
3107 {
3108 eina_error_set(EINA_ERROR_VALUE_FAILED);
3109 return EINA_FALSE;
3110 }
3111
3112 if (!_eina_value_type_hash_create(d))
3113 return EINA_FALSE;
3114
3115 eina_hash_foreach(s->hash, _eina_value_type_hash_copy_each, &ctx);
3116 if (!ctx.ret)
3117 {
3118 _eina_value_type_hash_flush_elements(d);
3119 return EINA_FALSE;
3120 }
3121 return EINA_TRUE;
3122}
3123
3124struct _eina_value_type_hash_compare_each_ctx
3125{
3126 const Eina_Value_Type *subtype;
3127 const Eina_Hash *other;
3128 int cmp;
3129};
3130
3131static Eina_Bool
3132_eina_value_type_hash_compare_each(const Eina_Hash *hash __UNUSED__, const void *key, void *_ptr, void *user_data)
3133{
3134 struct _eina_value_type_hash_compare_each_ctx *ctx = user_data;
3135 const void *self_ptr = _ptr;
3136 const void *other_ptr = eina_hash_find(ctx->other, key);
3137 if (!other_ptr) return EINA_TRUE;
3138 ctx->cmp = ctx->subtype->compare(ctx->subtype, self_ptr, other_ptr);
3139 return ctx->cmp == 0;
3140}
3141
3142static int
3143_eina_value_type_hash_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
3144{
3145 const Eina_Value_Hash *eva_a = a, *eva_b = b;
3146 struct _eina_value_type_hash_compare_each_ctx ctx = {
3147 eva_a->subtype, eva_b->hash, 0
3148 };
3149
3150 if (eva_a->subtype != eva_b->subtype)
3151 {
3152 eina_error_set(EINA_ERROR_VALUE_FAILED);
3153 return -1;
3154 }
3155
3156 if (!eva_a->subtype->compare)
3157 {
3158 eina_error_set(EINA_ERROR_VALUE_FAILED);
3159 return 0;
3160 }
3161
3162 if ((!eva_a->hash) && (!eva_b->hash))
3163 return 0;
3164 else if (!eva_a->hash)
3165 return -1;
3166 else if (!eva_b->hash)
3167 return 1;
3168
3169 eina_hash_foreach(eva_a->hash, _eina_value_type_hash_compare_each, &ctx);
3170 if (ctx.cmp == 0)
3171 {
3172 unsigned int count_a = eina_hash_population(eva_a->hash);
3173 unsigned int count_b = eina_hash_population(eva_b->hash);
3174 if (count_a < count_b)
3175 return -1;
3176 else if (count_a > count_b)
3177 return 1;
3178 return 0;
3179 }
3180
3181 return ctx.cmp;
3182}
3183
3184static Eina_Bool
3185_eina_value_type_hash_find_first(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *ptr, void *user_data)
3186{
3187 void **ret = user_data;
3188 *ret = ptr;
3189 return EINA_FALSE;
3190}
3191
3192struct _eina_value_type_hash_convert_to_string_each_ctx
3193{
3194 const Eina_Value_Type *subtype;
3195 Eina_Strbuf *str;
3196 Eina_Value tmp;
3197 Eina_Bool first;
3198};
3199
3200static Eina_Bool
3201_eina_value_type_hash_convert_to_string_each(const Eina_Hash *hash __UNUSED__, const void *_key, void *_ptr, void *user_data)
3202{
3203 struct _eina_value_type_hash_convert_to_string_each_ctx *ctx = user_data;
3204 const char *key = _key;
3205 const void *ptr = _ptr;
3206 Eina_Bool r = EINA_FALSE;
3207
3208 if (ctx->first) ctx->first = EINA_FALSE;
3209 else eina_strbuf_append_length(ctx->str, ", ", 2);
3210
3211 eina_strbuf_append(ctx->str, key);
3212 eina_strbuf_append_length(ctx->str, ": ", 2);
3213
3214 if (ctx->subtype->convert_to)
3215 {
3216 r = ctx->subtype->convert_to(ctx->subtype, EINA_VALUE_TYPE_STRING,
3217 ptr, ctx->tmp.value.buf);
3218 if (r)
3219 {
3220 eina_strbuf_append(ctx->str, ctx->tmp.value.ptr);
3221 free(ctx->tmp.value.ptr);
3222 ctx->tmp.value.ptr = NULL;
3223 }
3224 }
3225
3226 if (!r)
3227 eina_strbuf_append_char(ctx->str, '?');
3228
3229 return EINA_TRUE;
3230}
3231
3232static Eina_Bool
3233_eina_value_type_hash_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
3234{
3235 const Eina_Value_Hash *tmem = type_mem;
3236 Eina_Bool ret = EINA_FALSE;
3237
3238 if ((convert == EINA_VALUE_TYPE_STRING) ||
3239 (convert == EINA_VALUE_TYPE_STRINGSHARE))
3240 {
3241 Eina_Strbuf *str = eina_strbuf_new();
3242 if (!tmem->hash) eina_strbuf_append(str, "{}");
3243 else
3244 {
3245 struct _eina_value_type_hash_convert_to_string_each_ctx ctx;
3246 const char *s;
3247
3248 ctx.subtype = tmem->subtype;
3249 ctx.str = str;
3250 ctx.first = EINA_TRUE;
3251 eina_value_setup(&ctx.tmp, EINA_VALUE_TYPE_STRING);
3252
3253 eina_strbuf_append_char(str, '{');
3254
3255 eina_hash_foreach(tmem->hash,
3256 _eina_value_type_hash_convert_to_string_each,
3257 &ctx);
3258
3259 eina_strbuf_append_char(str, '}');
3260 s = eina_strbuf_string_get(str);
3261 ret = eina_value_type_pset(convert, convert_mem, &s);
3262 eina_strbuf_free(str);
3263 }
3264 }
3265 else if ((tmem->hash) && (eina_hash_population(tmem->hash) == 1))
3266 {
3267 const Eina_Value_Type *subtype = tmem->subtype;
3268 void *imem = NULL;
3269
3270 eina_hash_foreach(tmem->hash, _eina_value_type_hash_find_first, &imem);
3271 if (!imem) /* shouldn't happen... */
3272 ret = EINA_FALSE;
3273 else
3274 {
3275 if (subtype->convert_to)
3276 ret = subtype->convert_to(subtype, convert, imem, convert_mem);
3277 if ((!ret) && (convert->convert_from))
3278 ret = convert->convert_from(convert, subtype, convert_mem, imem);
3279 }
3280 }
3281
3282 if (!ret)
3283 {
3284 eina_error_set(EINA_ERROR_VALUE_FAILED);
3285 return EINA_FALSE;
3286 }
3287 return EINA_TRUE;
3288}
3289
3290static Eina_Bool
3291_eina_value_type_hash_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
3292{
3293 Eina_Value_Hash *tmem = mem;
3294 const Eina_Value_Hash *desc = ptr;
3295
3296 if ((!tmem->subtype) && (!desc->subtype))
3297 return EINA_TRUE;
3298
3299 if (tmem->hash) _eina_value_type_hash_flush_elements(tmem);
3300
3301 if (desc->hash)
3302 tmem->hash = desc->hash;
3303 else if (!_eina_value_type_hash_create(tmem))
3304 return EINA_FALSE;
3305
3306 tmem->subtype = desc->subtype;
3307
3308 return EINA_TRUE;
3309}
3310
3311static Eina_Bool
3312_eina_value_type_hash_vset(const Eina_Value_Type *type, void *mem, va_list args)
3313{
3314 const Eina_Value_Hash desc = va_arg(args, Eina_Value_Hash);
3315 _eina_value_type_hash_pset(type, mem, &desc);
3316 return EINA_TRUE;
3317}
3318
3319static Eina_Bool
3320_eina_value_type_hash_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
3321{
3322 memcpy(ptr, mem, sizeof(Eina_Value_Hash));
3323 return EINA_TRUE;
3324}
3325
3326static const Eina_Value_Type _EINA_VALUE_TYPE_HASH = {
3327 EINA_VALUE_TYPE_VERSION,
3328 sizeof(Eina_Value_Hash),
3329 "Eina_Value_Hash",
3330 _eina_value_type_hash_setup,
3331 _eina_value_type_hash_flush,
3332 _eina_value_type_hash_copy,
3333 _eina_value_type_hash_compare,
3334 _eina_value_type_hash_convert_to,
3335 NULL, /* no convert from */
3336 _eina_value_type_hash_vset,
3337 _eina_value_type_hash_pset,
3338 _eina_value_type_hash_pget
3339};
3340
3341static Eina_Bool
3342_eina_value_type_timeval_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
3343{
3344 memset(mem, 0, sizeof(struct timeval));
3345 return EINA_TRUE;
3346}
3347
3348static Eina_Bool
3349_eina_value_type_timeval_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
3350{
3351 return EINA_TRUE;
3352}
3353
3354static Eina_Bool
3355_eina_value_type_timeval_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
3356{
3357 const struct timeval *s = src;
3358 struct timeval *d = dst;
3359 *d = *s;
3360 return EINA_TRUE;
3361}
3362
3363static inline struct timeval _eina_value_type_timeval_fix(const struct timeval *input)
3364{
3365 struct timeval ret = *input;
3366 if (EINA_UNLIKELY(ret.tv_usec < 0))
3367 {
3368 ret.tv_sec -= 1;
3369 ret.tv_usec += 1e6;
3370 }
3371 return ret;
3372}
3373
3374static int
3375_eina_value_type_timeval_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
3376{
3377 struct timeval va = _eina_value_type_timeval_fix(a);
3378 struct timeval vb = _eina_value_type_timeval_fix(b);
3379
3380 if (va.tv_sec < vb.tv_sec)
3381 return -1;
3382 else if (va.tv_sec > vb.tv_sec)
3383 return 1;
3384
3385 if (va.tv_usec < vb.tv_usec)
3386 return -1;
3387 else if (va.tv_usec > vb.tv_usec)
3388 return 1;
3389
3390 return 0;
3391}
3392
3393static Eina_Bool
3394_eina_value_type_timeval_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
3395{
3396 struct timeval v = _eina_value_type_timeval_fix(type_mem);
3397
3398 eina_error_set(0);
3399
3400 if (convert == EINA_VALUE_TYPE_UCHAR)
3401 {
3402 unsigned char other_mem = v.tv_sec;
3403 if (EINA_UNLIKELY(v.tv_sec < 0))
3404 return EINA_FALSE;
3405 if (EINA_UNLIKELY(v.tv_sec > eina_value_uchar_max))
3406 return EINA_FALSE;
3407 return eina_value_type_pset(convert, convert_mem, &other_mem);
3408 }
3409 else if (convert == EINA_VALUE_TYPE_USHORT)
3410 {
3411 unsigned short other_mem = v.tv_sec;
3412 if (EINA_UNLIKELY(v.tv_sec < 0))
3413 return EINA_FALSE;
3414 if (EINA_UNLIKELY(v.tv_sec > eina_value_ushort_max))
3415 return EINA_FALSE;
3416 return eina_value_type_pset(convert, convert_mem, &other_mem);
3417 }
3418 else if (convert == EINA_VALUE_TYPE_UINT)
3419 {
3420 unsigned int other_mem = v.tv_sec;
3421 if (EINA_UNLIKELY(v.tv_sec < 0))
3422 return EINA_FALSE;
3423 if (EINA_UNLIKELY((unsigned long) v.tv_sec > eina_value_uint_max))
3424 return EINA_FALSE;
3425 return eina_value_type_pset(convert, convert_mem, &other_mem);
3426 }
3427 else if (convert == EINA_VALUE_TYPE_ULONG)
3428 {
3429 unsigned long other_mem = v.tv_sec;
3430 if (EINA_UNLIKELY(v.tv_sec < 0))
3431 return EINA_FALSE;
3432 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
3433 ((unsigned long)v.tv_sec > eina_value_ulong_max)))
3434 return EINA_FALSE;
3435 return eina_value_type_pset(convert, convert_mem, &other_mem);
3436 }
3437 else if (convert == EINA_VALUE_TYPE_UINT64)
3438 {
3439 uint64_t other_mem = v.tv_sec;
3440 if (EINA_UNLIKELY(v.tv_sec < 0))
3441 return EINA_FALSE;
3442 return eina_value_type_pset(convert, convert_mem, &other_mem);
3443 }
3444 else if (convert == EINA_VALUE_TYPE_CHAR)
3445 {
3446 char other_mem = v.tv_sec;
3447 if (EINA_UNLIKELY(v.tv_sec < eina_value_char_min))
3448 return EINA_FALSE;
3449 if (EINA_UNLIKELY(v.tv_sec > eina_value_char_max))
3450 return EINA_FALSE;
3451 return eina_value_type_pset(convert, convert_mem, &other_mem);
3452 }
3453 else if (convert == EINA_VALUE_TYPE_SHORT)
3454 {
3455 short other_mem = v.tv_sec;
3456 if (EINA_UNLIKELY(v.tv_sec < eina_value_short_min))
3457 return EINA_FALSE;
3458 if (EINA_UNLIKELY(v.tv_sec > eina_value_short_max))
3459 return EINA_FALSE;
3460 return eina_value_type_pset(convert, convert_mem, &other_mem);
3461 }
3462 else if (convert == EINA_VALUE_TYPE_INT)
3463 {
3464 int other_mem = v.tv_sec;
3465 if (EINA_UNLIKELY(v.tv_sec < eina_value_int_min))
3466 return EINA_FALSE;
3467 if (EINA_UNLIKELY(v.tv_sec > eina_value_int_max))
3468 return EINA_FALSE;
3469 return eina_value_type_pset(convert, convert_mem, &other_mem);
3470 }
3471 else if (convert == EINA_VALUE_TYPE_LONG)
3472 {
3473 long other_mem = v.tv_sec;
3474 if (EINA_UNLIKELY(v.tv_sec < eina_value_long_min))
3475 return EINA_FALSE;
3476 if (EINA_UNLIKELY(v.tv_sec > eina_value_long_max))
3477 return EINA_FALSE;
3478 return eina_value_type_pset(convert, convert_mem, &other_mem);
3479 }
3480 else if (convert == EINA_VALUE_TYPE_INT64)
3481 {
3482 int64_t other_mem = v.tv_sec;
3483 return eina_value_type_pset(convert, convert_mem, &other_mem);
3484 }
3485 else if (convert == EINA_VALUE_TYPE_FLOAT)
3486 {
3487 float other_mem = (float)v.tv_sec + (float)v.tv_usec / 1.0e6;
3488 return eina_value_type_pset(convert, convert_mem, &other_mem);
3489 }
3490 else if (convert == EINA_VALUE_TYPE_DOUBLE)
3491 {
3492 double other_mem = (double)v.tv_sec + (double)v.tv_usec / 1.0e6;
3493 return eina_value_type_pset(convert, convert_mem, &other_mem);
3494 }
3495 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
3496 convert == EINA_VALUE_TYPE_STRING)
3497 {
3498 const char *other_mem;
3499 char buf[64];
3500 snprintf(buf, sizeof(buf), "%ld.%06ld", v.tv_sec, v.tv_usec);
3501 other_mem = buf; /* required due &buf == buf */
3502 return eina_value_type_pset(convert, convert_mem, &other_mem);
3503 }
3504 else
3505 {
3506 eina_error_set(EINA_ERROR_VALUE_FAILED);
3507 return EINA_FALSE;
3508 }
3509}
3510
3511static Eina_Bool
3512_eina_value_type_timeval_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
3513{
3514 struct timeval *tmem = mem;
3515 *tmem = _eina_value_type_timeval_fix(ptr);
3516 return EINA_TRUE;
3517}
3518
3519static Eina_Bool
3520_eina_value_type_timeval_vset(const Eina_Value_Type *type, void *mem, va_list args)
3521{
3522 const struct timeval desc = va_arg(args, struct timeval);
3523 _eina_value_type_timeval_pset(type, mem, &desc);
3524 return EINA_TRUE;
3525}
3526
3527static Eina_Bool
3528_eina_value_type_timeval_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
3529{
3530 memcpy(ptr, mem, sizeof(struct timeval));
3531 return EINA_TRUE;
3532}
3533
3534static const Eina_Value_Type _EINA_VALUE_TYPE_TIMEVAL = {
3535 EINA_VALUE_TYPE_VERSION,
3536 sizeof(struct timeval),
3537 "struct timeval",
3538 _eina_value_type_timeval_setup,
3539 _eina_value_type_timeval_flush,
3540 _eina_value_type_timeval_copy,
3541 _eina_value_type_timeval_compare,
3542 _eina_value_type_timeval_convert_to,
3543 NULL, /* no convert from */
3544 _eina_value_type_timeval_vset,
3545 _eina_value_type_timeval_pset,
3546 _eina_value_type_timeval_pget
3547};
3548
3549static Eina_Bool
3550_eina_value_type_blob_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
3551{
3552 memset(mem, 0, sizeof(Eina_Value_Blob));
3553 return EINA_TRUE;
3554}
3555
3556static inline const Eina_Value_Blob_Operations *
3557_eina_value_type_blob_ops_get(const Eina_Value_Blob *blob)
3558{
3559 if (!blob) return NULL;
3560 if (!blob->ops) return NULL;
3561 EINA_SAFETY_ON_FALSE_RETURN_VAL
3562 (blob->ops->version == EINA_VALUE_BLOB_OPERATIONS_VERSION, NULL);
3563 return blob->ops;
3564}
3565
3566static Eina_Bool
3567_eina_value_type_blob_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
3568{
3569 const Eina_Value_Blob_Operations *ops = _eina_value_type_blob_ops_get(mem);
3570 Eina_Value_Blob *tmem = mem;
3571 if ((ops) && (ops->free))
3572 ops->free(ops, (void *)tmem->memory, tmem->size);
3573 return EINA_TRUE;
3574}
3575
3576static Eina_Bool
3577_eina_value_type_blob_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
3578{
3579 const Eina_Value_Blob_Operations *ops = _eina_value_type_blob_ops_get(src);
3580 const Eina_Value_Blob *s = src;
3581 Eina_Value_Blob *d = dst;
3582
3583 *d = *s;
3584
3585 if ((ops) && (ops->copy))
3586 {
3587 d->memory = ops->copy(ops, s->memory, s->size);
3588 if ((d->memory == NULL) && (s->size > 0))
3589 return EINA_FALSE;
3590 }
3591
3592 return EINA_TRUE;
3593}
3594
3595static int
3596_eina_value_type_blob_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
3597{
3598 const Eina_Value_Blob_Operations *ops = _eina_value_type_blob_ops_get(a);
3599 const Eina_Value_Blob *ta = a, *tb = b;
3600 size_t minsize;
3601 if (ta->ops != tb->ops)
3602 {
3603 eina_error_set(EINA_ERROR_VALUE_FAILED);
3604 return -1;
3605 }
3606 if ((ops) && (ops->compare))
3607 return ops->compare(ops, ta->memory, ta->size, tb->memory, tb->size);
3608
3609 if (ta->size < tb->size)
3610 minsize = ta->size;
3611 else
3612 minsize = tb->size;
3613
3614 return memcmp(ta->memory, tb->memory, minsize);
3615}
3616
3617static Eina_Bool
3618_eina_value_type_blob_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
3619{
3620 const Eina_Value_Blob *tmem = type_mem;
3621
3622 eina_error_set(0);
3623 if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
3624 convert == EINA_VALUE_TYPE_STRING)
3625 {
3626 const Eina_Value_Blob_Operations *ops;
3627 Eina_Strbuf *str;
3628 const char *other_mem;
3629 Eina_Bool ret = EINA_FALSE, first = EINA_TRUE;
3630 const unsigned char *ptr, *ptr_end;
3631
3632 ops = _eina_value_type_blob_ops_get(tmem);
3633 if ((ops) && (ops->to_string))
3634 {
3635 char *x = ops->to_string(ops, tmem->memory, tmem->size);
3636 if (x)
3637 {
3638 ret = eina_value_type_pset(convert, convert_mem, &x);
3639 free(x);
3640 }
3641 return ret;
3642 }
3643
3644 str = eina_strbuf_new();
3645 if (!str)
3646 return EINA_FALSE;
3647
3648 if (!eina_strbuf_append_printf(str, "BLOB(%u, [", tmem->size))
3649 goto error;
3650
3651 ptr = tmem->memory;
3652 ptr_end = ptr + tmem->size;
3653 for (; ptr < ptr_end; ptr++)
3654 {
3655 if (first)
3656 {
3657 first = EINA_FALSE;
3658 if (!eina_strbuf_append_printf(str, "%02hhx", *ptr))
3659 goto error;
3660 }
3661 else
3662 {
3663 if (!eina_strbuf_append_printf(str, " %02hhx", *ptr))
3664 goto error;
3665 }
3666 }
3667
3668 if (!eina_strbuf_append(str, "])"))
3669 goto error;
3670
3671 other_mem = eina_strbuf_string_get(str);
3672 ret = eina_value_type_pset(convert, convert_mem, &other_mem);
3673
3674 error:
3675 eina_strbuf_free(str);
3676 return ret;
3677 }
3678 else
3679 {
3680 eina_error_set(EINA_ERROR_VALUE_FAILED);
3681 return EINA_FALSE;
3682 }
3683}
3684
3685static Eina_Bool
3686_eina_value_type_blob_convert_from(const Eina_Value_Type *type, const Eina_Value_Type *convert, void *type_mem, const void *convert_mem)
3687{
3688 Eina_Value_Blob desc;
3689 char *buf;
3690
3691 desc.ops = EINA_VALUE_BLOB_OPERATIONS_MALLOC;
3692
3693 if ((convert == EINA_VALUE_TYPE_STRING) ||
3694 (convert == EINA_VALUE_TYPE_STRINGSHARE))
3695 {
3696 const char *str = *(const char **)convert_mem;
3697 if (!str)
3698 {
3699 desc.size = 0;
3700 desc.memory = NULL;
3701 }
3702 else
3703 {
3704 desc.size = strlen(str) + 1;
3705 desc.memory = buf = malloc(desc.size);
3706 if (!desc.memory)
3707 {
3708 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
3709 return EINA_FALSE;
3710 }
3711 memcpy(buf, str, desc.size);
3712 }
3713 }
3714 else if (convert == EINA_VALUE_TYPE_ARRAY)
3715 {
3716 const Eina_Value_Array *a = convert_mem;
3717 if ((!a->array) || (a->array->len == 0))
3718 {
3719 desc.size = 0;
3720 desc.memory = NULL;
3721 }
3722 else
3723 {
3724 desc.size = a->array->len * a->array->member_size;
3725 desc.memory = buf = malloc(desc.size);
3726 if (!desc.memory)
3727 {
3728 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
3729 return EINA_FALSE;
3730 }
3731 memcpy(buf, a->array->members, desc.size);
3732 }
3733 }
3734 else if (convert == EINA_VALUE_TYPE_BLOB)
3735 {
3736 const Eina_Value_Blob *b = convert_mem;
3737 if (b->size == 0)
3738 {
3739 desc.size = 0;
3740 desc.memory = NULL;
3741 }
3742 else
3743 {
3744 desc.size = b->size;
3745 desc.memory = buf = malloc(desc.size);
3746 if (!desc.memory)
3747 {
3748 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
3749 return EINA_FALSE;
3750 }
3751 memcpy(buf, b->memory, desc.size);
3752 }
3753 }
3754 else
3755 {
3756 desc.size = convert->value_size;
3757 desc.memory = buf = malloc(convert->value_size);
3758 if (!desc.memory)
3759 {
3760 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
3761 return EINA_FALSE;
3762 }
3763 if (!eina_value_type_pget(convert, convert_mem, buf))
3764 {
3765 free(buf);
3766 return EINA_FALSE;
3767 }
3768 }
3769 return eina_value_type_pset(type, type_mem, &desc);
3770}
3771
3772static Eina_Bool
3773_eina_value_type_blob_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
3774{
3775 const Eina_Value_Blob_Operations *ops = _eina_value_type_blob_ops_get(mem);
3776 Eina_Value_Blob *tmem = mem;
3777 const Eina_Value_Blob *desc = ptr;
3778
3779 if ((ops) && (ops->free))
3780 ops->free(ops, (void *)tmem->memory, tmem->size);
3781
3782 *tmem = *desc;
3783 return EINA_TRUE;
3784}
3785
3786static Eina_Bool
3787_eina_value_type_blob_vset(const Eina_Value_Type *type, void *mem, va_list args)
3788{
3789 const Eina_Value_Blob desc = va_arg(args, Eina_Value_Blob);
3790 _eina_value_type_blob_pset(type, mem, &desc);
3791 return EINA_TRUE;
3792}
3793
3794static Eina_Bool
3795_eina_value_type_blob_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
3796{
3797 memcpy(ptr, mem, sizeof(Eina_Value_Blob));
3798 return EINA_TRUE;
3799}
3800
3801static const Eina_Value_Type _EINA_VALUE_TYPE_BLOB = {
3802 EINA_VALUE_TYPE_VERSION,
3803 sizeof(Eina_Value_Blob),
3804 "Eina_Value_Blob",
3805 _eina_value_type_blob_setup,
3806 _eina_value_type_blob_flush,
3807 _eina_value_type_blob_copy,
3808 _eina_value_type_blob_compare,
3809 _eina_value_type_blob_convert_to,
3810 _eina_value_type_blob_convert_from,
3811 _eina_value_type_blob_vset,
3812 _eina_value_type_blob_pset,
3813 _eina_value_type_blob_pget
3814};
3815
3816static int
3817_eina_value_struct_operations_binsearch_cmp(const void *pa, const void *pb)
3818{
3819 const Eina_Value_Struct_Member *a = pa, *b = pb;
3820 return strcmp(a->name, b->name);
3821}
3822
3823static const Eina_Value_Struct_Member *
3824_eina_value_struct_operations_binsearch_find_member(const Eina_Value_Struct_Operations *ops __UNUSED__, const Eina_Value_Struct_Desc *desc, const char *name)
3825{
3826 unsigned int count = desc->member_count;
3827 Eina_Value_Struct_Member search;
3828 if (count == 0)
3829 {
3830 const Eina_Value_Struct_Member *itr = desc->members;
3831 for (; itr->name != NULL; itr++)
3832 count++;
3833 }
3834
3835 search.name = name;
3836 return bsearch(&search, desc->members, count,
3837 sizeof(Eina_Value_Struct_Member),
3838 _eina_value_struct_operations_binsearch_cmp);
3839}
3840
3841static Eina_Value_Struct_Operations _EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH = {
3842 EINA_VALUE_STRUCT_OPERATIONS_VERSION,
3843 NULL, /* default alloc */
3844 NULL, /* default free */
3845 NULL, /* default copy */
3846 NULL, /* default compare */
3847 _eina_value_struct_operations_binsearch_find_member
3848};
3849
3850static const Eina_Value_Struct_Member *
3851_eina_value_struct_operations_stringshare_find_member(const Eina_Value_Struct_Operations *ops __UNUSED__, const Eina_Value_Struct_Desc *desc, const char *name)
3852{
3853 const Eina_Value_Struct_Member *itr = desc->members;
3854
3855 /* assumes name is stringshared.
3856 *
3857 * we do this because it's the recommended usage pattern, moreover
3858 * we expect to find the member, as users shouldn't look for
3859 * non-existent members!
3860 */
3861 if (desc->member_count > 0)
3862 {
3863 const Eina_Value_Struct_Member *itr_end = itr + desc->member_count;
3864 for (; itr < itr_end; itr++)
3865 if (itr->name == name)
3866 return itr;
3867 }
3868 else
3869 {
3870 for (; itr->name != NULL; itr++)
3871 if (itr->name == name)
3872 return itr;
3873 }
3874
3875 name = eina_stringshare_add(name);
3876 eina_stringshare_del(name); /* we'll not use the contents, this is fine */
3877 /* stringshare and look again */
3878 if (desc->member_count > 0)
3879 {
3880 const Eina_Value_Struct_Member *itr_end = itr + desc->member_count;
3881 for (; itr < itr_end; itr++)
3882 if (itr->name == name)
3883 return itr;
3884 }
3885 else
3886 {
3887 for (; itr->name != NULL; itr++)
3888 if (itr->name == name)
3889 return itr;
3890 }
3891
3892 return NULL;
3893}
3894
3895static Eina_Value_Struct_Operations _EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE = {
3896 EINA_VALUE_STRUCT_OPERATIONS_VERSION,
3897 NULL, /* default alloc */
3898 NULL, /* default free */
3899 NULL, /* default copy */
3900 NULL, /* default compare */
3901 _eina_value_struct_operations_stringshare_find_member
3902};
3903
3904static inline const Eina_Value_Struct_Operations *
3905_eina_value_type_struct_ops_get(const Eina_Value_Struct *st)
3906{
3907 if (!st) return NULL;
3908 if (!st->desc) return NULL;
3909 if (!st->desc->ops) return NULL;
3910 EINA_SAFETY_ON_FALSE_RETURN_VAL
3911 (st->desc->ops->version == EINA_VALUE_STRUCT_OPERATIONS_VERSION, NULL);
3912 return st->desc->ops;
3913}
3914
3915EAPI const Eina_Value_Struct_Member *
3916eina_value_struct_member_find(const Eina_Value_Struct *st, const char *name)
3917{
3918 const Eina_Value_Struct_Operations *ops;
3919 const Eina_Value_Struct_Member *itr;
3920
3921 EINA_SAFETY_ON_NULL_RETURN_VAL(st, NULL);
3922 EINA_SAFETY_ON_NULL_RETURN_VAL(st->desc, NULL);
3923
3924 ops = _eina_value_type_struct_ops_get(st);
3925 if ((ops) && (ops->find_member))
3926 return ops->find_member(ops, st->desc, name);
3927
3928 itr = st->desc->members;
3929 if (st->desc->member_count)
3930 {
3931 const Eina_Value_Struct_Member *itr_end = itr + st->desc->member_count;
3932 for (; itr < itr_end; itr++)
3933 {
3934 if (strcmp(name, itr->name) == 0)
3935 return itr;
3936 }
3937 return NULL;
3938 }
3939 else
3940 {
3941 for (; itr->name != NULL; itr++)
3942 {
3943 if (strcmp(name, itr->name) == 0)
3944 return itr;
3945 }
3946 return NULL;
3947 }
3948}
3949
3950static Eina_Bool
3951_eina_value_type_struct_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
3952{
3953 memset(mem, 0, sizeof(Eina_Value_Struct));
3954 return EINA_TRUE;
3955}
3956
3957static Eina_Bool
3958_eina_value_type_struct_flush_member(const Eina_Value_Struct_Member *member, Eina_Value_Struct *st)
3959{
3960 unsigned char *base = st->memory;
3961 return eina_value_type_flush(member->type, base + member->offset);
3962}
3963
3964static Eina_Bool
3965_eina_value_type_struct_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
3966{
3967 const Eina_Value_Struct_Operations *ops;
3968 const Eina_Value_Struct_Member *itr;
3969 Eina_Value_Struct *tmem = mem;
3970 Eina_Bool ret = EINA_TRUE;
3971
3972 itr = tmem->desc->members;
3973 if (tmem->desc->member_count > 0)
3974 {
3975 const Eina_Value_Struct_Member *itr_end;
3976 itr_end = itr + tmem->desc->member_count;
3977 for (; itr < itr_end; itr++)
3978 ret &= _eina_value_type_struct_flush_member(itr, tmem);
3979 }
3980 else
3981 {
3982 for (; itr->name != NULL; itr++)
3983 ret &= _eina_value_type_struct_flush_member(itr, tmem);
3984 }
3985
3986 ops = _eina_value_type_struct_ops_get(mem);
3987 if ((ops) && (ops->free))
3988 ops->free(ops, tmem->desc, tmem->memory);
3989 else
3990 free(tmem->memory);
3991
3992 return ret;
3993}
3994
3995static Eina_Bool
3996_eina_value_type_struct_copy_member(const Eina_Value_Struct_Member *member, const Eina_Value_Struct *s, Eina_Value_Struct *d)
3997{
3998 const unsigned char *base_s = s->memory;
3999 unsigned char *base_d = d->memory;
4000 return eina_value_type_copy(member->type,
4001 base_s + member->offset,
4002 base_d + member->offset);
4003}
4004
4005static Eina_Bool
4006_eina_value_type_struct_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
4007{
4008 const Eina_Value_Struct_Operations *ops;
4009 const Eina_Value_Struct_Member *itr;
4010 const Eina_Value_Struct *s = src;
4011 Eina_Value_Struct *d = dst;
4012
4013 *d = *s;
4014
4015 ops = _eina_value_type_struct_ops_get(src);
4016 if ((ops) && (ops->copy))
4017 {
4018 d->memory = ops->copy(ops, s->desc, s->memory);
4019 if (d->memory == NULL)
4020 return EINA_FALSE;
4021 return EINA_TRUE;
4022 }
4023
4024 d->memory = malloc(s->desc->size);
4025 if (!d->memory)
4026 {
4027 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
4028 return EINA_FALSE;
4029 }
4030
4031 itr = s->desc->members;
4032 if (s->desc->member_count > 0)
4033 {
4034 const Eina_Value_Struct_Member *itr_end = itr + s->desc->member_count;
4035 for (; itr < itr_end; itr++)
4036 if (!_eina_value_type_struct_copy_member(itr, s, d))
4037 goto error;
4038 }
4039 else
4040 {
4041 for (; itr->name != NULL; itr++)
4042 if (!_eina_value_type_struct_copy_member(itr, s, d))
4043 goto error;
4044 }
4045
4046
4047 return EINA_TRUE;
4048
4049 error:
4050 itr--;
4051 for (; itr >= s->desc->members; itr--)
4052 _eina_value_type_struct_flush_member(itr, d);
4053 free(d->memory);
4054 return EINA_FALSE;
4055}
4056
4057static inline int
4058_eina_value_type_struct_compare_member(const Eina_Value_Struct_Member *member, const Eina_Value_Struct *ta, const Eina_Value_Struct *tb)
4059{
4060 const unsigned char *base_a = ta->memory;
4061 const unsigned char *base_b = tb->memory;
4062 return eina_value_type_compare(member->type,
4063 base_a + member->offset,
4064 base_b + member->offset);
4065}
4066
4067static int
4068_eina_value_type_struct_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
4069{
4070 const Eina_Value_Struct_Operations *ops = _eina_value_type_struct_ops_get(a);
4071 const Eina_Value_Struct *ta = a, *tb = b;
4072 const Eina_Value_Struct_Member *itr;
4073 int cmp = 0;
4074
4075 if (ta->desc != tb->desc)
4076 {
4077 eina_error_set(EINA_ERROR_VALUE_FAILED);
4078 return -1;
4079 }
4080 if (ta->desc->ops != tb->desc->ops)
4081 {
4082 eina_error_set(EINA_ERROR_VALUE_FAILED);
4083 return -1;
4084 }
4085 if ((!ta->memory) && (!tb->memory))
4086 return 0;
4087 else if (!ta->memory)
4088 return -1;
4089 else if (!tb->memory)
4090 return 1;
4091
4092 if ((ops) && (ops->compare))
4093 return ops->compare(ops, ta->desc, ta->memory, tb->memory);
4094
4095 itr = ta->desc->members;
4096 if (ta->desc->member_count > 0)
4097 {
4098 const Eina_Value_Struct_Member *itr_end = itr + ta->desc->member_count;
4099 for (; (cmp == 0) && (itr < itr_end); itr++)
4100 cmp = _eina_value_type_struct_compare_member(itr, ta, tb);
4101 }
4102 else
4103 {
4104 for (; (cmp == 0) && (itr->name != NULL); itr++)
4105 cmp = _eina_value_type_struct_compare_member(itr, ta, tb);
4106 }
4107 return cmp;
4108}
4109
4110static void
4111_eina_value_type_struct_convert_to_string_member(const Eina_Value_Struct *st, const Eina_Value_Struct_Member *member, Eina_Strbuf *str)
4112{
4113 const unsigned char *p = st->memory;
4114 Eina_Bool first = st->desc->members == member;
4115 Eina_Bool r = EINA_FALSE;
4116
4117 if (first) eina_strbuf_append_printf(str, "%s: ", member->name);
4118 else eina_strbuf_append_printf(str, ", %s: ", member->name);
4119
4120 if ((member->type) && (member->type->convert_to))
4121 {
4122 const Eina_Value_Type *type = member->type;
4123 char *conv = NULL;
4124
4125 r = eina_value_type_convert_to(type, EINA_VALUE_TYPE_STRING,
4126 p + member->offset, &conv);
4127 if (r)
4128 {
4129 eina_strbuf_append(str, conv);
4130 free(conv);
4131 }
4132 }
4133
4134 if (!r)
4135 eina_strbuf_append_char(str, '?');
4136}
4137
4138static Eina_Bool
4139_eina_value_type_struct_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
4140{
4141 const Eina_Value_Struct *tmem = type_mem;
4142
4143 eina_error_set(0);
4144 if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
4145 convert == EINA_VALUE_TYPE_STRING)
4146 {
4147 Eina_Strbuf *str = eina_strbuf_new();
4148 const char *s;
4149 Eina_Bool ret;
4150
4151 if (!tmem->memory) eina_strbuf_append(str, "{}");
4152 else
4153 {
4154 const Eina_Value_Struct_Member *itr = tmem->desc->members;
4155
4156 eina_strbuf_append_char(str, '{');
4157
4158 if (tmem->desc->member_count > 0)
4159 {
4160 const Eina_Value_Struct_Member *itr_end;
4161
4162 itr_end = itr + tmem->desc->member_count;
4163 for (; itr < itr_end; itr++)
4164 _eina_value_type_struct_convert_to_string_member
4165 (tmem, itr, str);
4166 }
4167 else
4168 {
4169 for (; itr->name != NULL; itr++)
4170 _eina_value_type_struct_convert_to_string_member
4171 (tmem, itr, str);
4172 }
4173
4174 eina_strbuf_append_char(str, '}');
4175 }
4176 s = eina_strbuf_string_get(str);
4177 ret = eina_value_type_pset(convert, convert_mem, &s);
4178 eina_strbuf_free(str);
4179 return ret;
4180 }
4181 else
4182 {
4183 eina_error_set(EINA_ERROR_VALUE_FAILED);
4184 return EINA_FALSE;
4185 }
4186}
4187
4188static Eina_Bool
4189_eina_value_type_struct_desc_check(const Eina_Value_Struct_Desc *desc)
4190{
4191 unsigned int minsize = 0;
4192 const Eina_Value_Struct_Member *itr;
4193
4194 EINA_SAFETY_ON_NULL_RETURN_VAL(desc, EINA_FALSE);
4195 EINA_SAFETY_ON_FALSE_RETURN_VAL
4196 (desc->version == EINA_VALUE_STRUCT_DESC_VERSION, EINA_FALSE);
4197
4198 itr = desc->members;
4199 if (desc->member_count > 0)
4200 {
4201 const Eina_Value_Struct_Member *itr_end = itr + desc->member_count;
4202 for (; itr < itr_end; itr++)
4203 {
4204 unsigned int member_end;
4205
4206 EINA_SAFETY_ON_FALSE_RETURN_VAL
4207 (eina_value_type_check(itr->type), EINA_FALSE);
4208 EINA_SAFETY_ON_FALSE_RETURN_VAL
4209 (itr->type->value_size > 0, EINA_FALSE);
4210
4211 member_end = itr->offset + itr->type->value_size;
4212 if (minsize < member_end)
4213 minsize = member_end;
4214 }
4215 }
4216 else
4217 {
4218 for (; itr->name != NULL; itr++)
4219 {
4220 unsigned int member_end;
4221
4222 EINA_SAFETY_ON_FALSE_RETURN_VAL
4223 (eina_value_type_check(itr->type), EINA_FALSE);
4224 EINA_SAFETY_ON_FALSE_RETURN_VAL
4225 (itr->type->value_size > 0, EINA_FALSE);
4226
4227 member_end = itr->offset + itr->type->value_size;
4228 if (minsize < member_end)
4229 minsize = member_end;
4230 }
4231 }
4232
4233 EINA_SAFETY_ON_FALSE_RETURN_VAL(minsize > 0, EINA_FALSE);
4234 EINA_SAFETY_ON_FALSE_RETURN_VAL(desc->size >= minsize, EINA_FALSE);
4235 return EINA_TRUE;
4236}
4237
4238static Eina_Bool
4239_eina_value_type_struct_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
4240{
4241 const Eina_Value_Struct_Operations *ops = _eina_value_type_struct_ops_get(mem);
4242 Eina_Value_Struct *tmem = mem;
4243 const Eina_Value_Struct *desc = ptr;
4244
4245 if (!_eina_value_type_struct_desc_check(desc->desc))
4246 {
4247 eina_error_set(EINA_ERROR_VALUE_FAILED);
4248 return EINA_FALSE;
4249 }
4250
4251 if ((ops) && (ops->free))
4252 ops->free(ops, tmem->desc, tmem->memory);
4253 else
4254 free(tmem->memory);
4255
4256 *tmem = *desc;
4257
4258 ops = _eina_value_type_struct_ops_get(desc);
4259 if (!tmem->memory)
4260 {
4261 if ((ops) && (ops->alloc))
4262 tmem->memory = ops->alloc(ops, tmem->desc);
4263 else
4264 tmem->memory = malloc(tmem->desc->size);
4265
4266 if (!tmem->memory)
4267 {
4268 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
4269 return EINA_FALSE;
4270 }
4271 }
4272
4273 eina_error_set(0);
4274 return EINA_TRUE;
4275}
4276
4277static Eina_Bool
4278_eina_value_type_struct_vset(const Eina_Value_Type *type, void *mem, va_list args)
4279{
4280 const Eina_Value_Struct desc = va_arg(args, Eina_Value_Struct);
4281 _eina_value_type_struct_pset(type, mem, &desc);
4282 return EINA_TRUE;
4283}
4284
4285static Eina_Bool
4286_eina_value_type_struct_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
4287{
4288 memcpy(ptr, mem, sizeof(Eina_Value_Struct));
4289 return EINA_TRUE;
4290}
4291
4292static const Eina_Value_Type _EINA_VALUE_TYPE_STRUCT = {
4293 EINA_VALUE_TYPE_VERSION,
4294 sizeof(Eina_Value_Struct),
4295 "Eina_Value_Struct",
4296 _eina_value_type_struct_setup,
4297 _eina_value_type_struct_flush,
4298 _eina_value_type_struct_copy,
4299 _eina_value_type_struct_compare,
4300 _eina_value_type_struct_convert_to,
4301 NULL, /* no convert from */
4302 _eina_value_type_struct_vset,
4303 _eina_value_type_struct_pset,
4304 _eina_value_type_struct_pget
4305};
4306
4307/* keep all basic types inlined in an array so we can compare if it's
4308 * a basic type using pointer arithmetic.
4309 *
4310 * NOTE-1: JUST BASIC TYPES, DO NOT ADD MORE TYPES HERE!!!
4311 * NOTE-2: KEEP ORDER, see eina_value_init()
4312 */
4313static const Eina_Value_Type _EINA_VALUE_TYPE_BASICS[] = {
4314 {
4315 EINA_VALUE_TYPE_VERSION,
4316 sizeof(unsigned char),
4317 "unsigned char",
4318 _eina_value_type_uchar_setup,
4319 _eina_value_type_uchar_flush,
4320 _eina_value_type_uchar_copy,
4321 _eina_value_type_uchar_compare,
4322 _eina_value_type_uchar_convert_to,
4323 NULL, /* no convert from */
4324 _eina_value_type_uchar_vset,
4325 _eina_value_type_uchar_pset,
4326 _eina_value_type_uchar_pget
4327 },
4328 {
4329 EINA_VALUE_TYPE_VERSION,
4330 sizeof(unsigned short),
4331 "unsigned short",
4332 _eina_value_type_ushort_setup,
4333 _eina_value_type_ushort_flush,
4334 _eina_value_type_ushort_copy,
4335 _eina_value_type_ushort_compare,
4336 _eina_value_type_ushort_convert_to,
4337 NULL, /* no convert from */
4338 _eina_value_type_ushort_vset,
4339 _eina_value_type_ushort_pset,
4340 _eina_value_type_ushort_pget
4341 },
4342 {
4343 EINA_VALUE_TYPE_VERSION,
4344 sizeof(unsigned int),
4345 "unsigned int",
4346 _eina_value_type_uint_setup,
4347 _eina_value_type_uint_flush,
4348 _eina_value_type_uint_copy,
4349 _eina_value_type_uint_compare,
4350 _eina_value_type_uint_convert_to,
4351 NULL, /* no convert from */
4352 _eina_value_type_uint_vset,
4353 _eina_value_type_uint_pset,
4354 _eina_value_type_uint_pget
4355 },
4356 {
4357 EINA_VALUE_TYPE_VERSION,
4358 sizeof(unsigned long),
4359 "unsigned long",
4360 _eina_value_type_ulong_setup,
4361 _eina_value_type_ulong_flush,
4362 _eina_value_type_ulong_copy,
4363 _eina_value_type_ulong_compare,
4364 _eina_value_type_ulong_convert_to,
4365 NULL, /* no convert from */
4366 _eina_value_type_ulong_vset,
4367 _eina_value_type_ulong_pset,
4368 _eina_value_type_ulong_pget
4369 },
4370 {
4371 EINA_VALUE_TYPE_VERSION,
4372 sizeof(uint64_t),
4373 "uint64_t",
4374 _eina_value_type_uint64_setup,
4375 _eina_value_type_uint64_flush,
4376 _eina_value_type_uint64_copy,
4377 _eina_value_type_uint64_compare,
4378 _eina_value_type_uint64_convert_to,
4379 NULL, /* no convert from */
4380 _eina_value_type_uint64_vset,
4381 _eina_value_type_uint64_pset,
4382 _eina_value_type_uint64_pget
4383 },
4384 {
4385 EINA_VALUE_TYPE_VERSION,
4386 sizeof(char),
4387 "char",
4388 _eina_value_type_char_setup,
4389 _eina_value_type_char_flush,
4390 _eina_value_type_char_copy,
4391 _eina_value_type_char_compare,
4392 _eina_value_type_char_convert_to,
4393 NULL, /* no convert from */
4394 _eina_value_type_char_vset,
4395 _eina_value_type_char_pset,
4396 _eina_value_type_char_pget
4397 },
4398 {
4399 EINA_VALUE_TYPE_VERSION,
4400 sizeof(short),
4401 "short",
4402 _eina_value_type_short_setup,
4403 _eina_value_type_short_flush,
4404 _eina_value_type_short_copy,
4405 _eina_value_type_short_compare,
4406 _eina_value_type_short_convert_to,
4407 NULL, /* no convert from */
4408 _eina_value_type_short_vset,
4409 _eina_value_type_short_pset,
4410 _eina_value_type_short_pget
4411 },
4412 {
4413 EINA_VALUE_TYPE_VERSION,
4414 sizeof(int),
4415 "int",
4416 _eina_value_type_int_setup,
4417 _eina_value_type_int_flush,
4418 _eina_value_type_int_copy,
4419 _eina_value_type_int_compare,
4420 _eina_value_type_int_convert_to,
4421 NULL, /* no convert from */
4422 _eina_value_type_int_vset,
4423 _eina_value_type_int_pset,
4424 _eina_value_type_int_pget
4425 },
4426 {
4427 EINA_VALUE_TYPE_VERSION,
4428 sizeof(long),
4429 "long",
4430 _eina_value_type_long_setup,
4431 _eina_value_type_long_flush,
4432 _eina_value_type_long_copy,
4433 _eina_value_type_long_compare,
4434 _eina_value_type_long_convert_to,
4435 NULL, /* no convert from */
4436 _eina_value_type_long_vset,
4437 _eina_value_type_long_pset,
4438 _eina_value_type_long_pget
4439 },
4440 {
4441 EINA_VALUE_TYPE_VERSION,
4442 sizeof(int64_t),
4443 "int64_t",
4444 _eina_value_type_int64_setup,
4445 _eina_value_type_int64_flush,
4446 _eina_value_type_int64_copy,
4447 _eina_value_type_int64_compare,
4448 _eina_value_type_int64_convert_to,
4449 NULL, /* no convert from */
4450 _eina_value_type_int64_vset,
4451 _eina_value_type_int64_pset,
4452 _eina_value_type_int64_pget
4453 },
4454 {
4455 EINA_VALUE_TYPE_VERSION,
4456 sizeof(float),
4457 "float",
4458 _eina_value_type_float_setup,
4459 _eina_value_type_float_flush,
4460 _eina_value_type_float_copy,
4461 _eina_value_type_float_compare,
4462 _eina_value_type_float_convert_to,
4463 NULL, /* no convert from */
4464 _eina_value_type_float_vset,
4465 _eina_value_type_float_pset,
4466 _eina_value_type_float_pget
4467 },
4468 {
4469 EINA_VALUE_TYPE_VERSION,
4470 sizeof(double),
4471 "double",
4472 _eina_value_type_double_setup,
4473 _eina_value_type_double_flush,
4474 _eina_value_type_double_copy,
4475 _eina_value_type_double_compare,
4476 _eina_value_type_double_convert_to,
4477 NULL, /* no convert from */
4478 _eina_value_type_double_vset,
4479 _eina_value_type_double_pset,
4480 _eina_value_type_double_pget
4481 },
4482 {
4483 EINA_VALUE_TYPE_VERSION,
4484 sizeof(const char *),
4485 "stringshare",
4486 _eina_value_type_string_common_setup,
4487 _eina_value_type_stringshare_flush,
4488 _eina_value_type_stringshare_copy,
4489 _eina_value_type_string_common_compare,
4490 _eina_value_type_string_common_convert_to,
4491 NULL, /* no convert from */
4492 _eina_value_type_stringshare_vset,
4493 _eina_value_type_stringshare_pset,
4494 _eina_value_type_string_common_pget
4495 },
4496 {
4497 EINA_VALUE_TYPE_VERSION,
4498 sizeof(char *),
4499 "string",
4500 _eina_value_type_string_common_setup,
4501 _eina_value_type_string_flush,
4502 _eina_value_type_string_copy,
4503 _eina_value_type_string_common_compare,
4504 _eina_value_type_string_common_convert_to,
4505 NULL, /* no convert from */
4506 _eina_value_type_string_vset,
4507 _eina_value_type_string_pset,
4508 _eina_value_type_string_common_pget
4509 }
4510};
4511
4512static void
4513_eina_value_blob_operations_malloc_free(const Eina_Value_Blob_Operations *ops __UNUSED__, void *memory, size_t size __UNUSED__)
4514{
4515 free(memory);
4516}
4517
4518static void *
4519_eina_value_blob_operations_malloc_copy(const Eina_Value_Blob_Operations *ops __UNUSED__, const void *memory, size_t size)
4520{
4521 void *ret = malloc(size);
4522 if (!ret)
4523 {
4524 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
4525 return NULL;
4526 }
4527 memcpy(ret, memory, size);
4528 return ret;
4529}
4530
4531static const Eina_Value_Blob_Operations _EINA_VALUE_BLOB_OPERATIONS_MALLOC = {
4532 EINA_VALUE_BLOB_OPERATIONS_VERSION,
4533 _eina_value_blob_operations_malloc_free,
4534 _eina_value_blob_operations_malloc_copy,
4535 NULL,
4536 NULL
4537};
4538
4539typedef struct _Eina_Value_Inner_Mp Eina_Value_Inner_Mp;
4540struct _Eina_Value_Inner_Mp
4541{
4542 Eina_Mempool *mempool;
4543 int references;
4544};
4545
4546/**
4547 * @endcond
4548 */
4549
4550static const char EINA_ERROR_VALUE_FAILED_STR[] = "Value check failed.";
4551
4552/**
4553 */
4554
4555static inline void
4556_eina_value_inner_mp_dispose(int size, Eina_Value_Inner_Mp *imp)
4557{
4558 EINA_SAFETY_ON_FALSE_RETURN(imp->references == 0);
4559
4560 eina_hash_del_by_key(_eina_value_inner_mps, &size);
4561 eina_mempool_del(imp->mempool);
4562 free(imp);
4563}
4564
4565static inline Eina_Value_Inner_Mp *
4566_eina_value_inner_mp_get(int size)
4567{
4568 Eina_Value_Inner_Mp *imp = eina_hash_find(_eina_value_inner_mps, &size);
4569 if (imp) return imp;
4570
4571 imp = malloc(sizeof(Eina_Value_Inner_Mp));
4572 if (!imp)
4573 return NULL;
4574
4575 imp->references = 0;
4576
4577 imp->mempool = eina_mempool_add(_eina_value_mp_choice,
4578 "Eina_Value_Inner_Mp", NULL, size, 128);
4579 if (!imp->mempool)
4580 {
4581 free(imp);
4582 return NULL;
4583 }
4584
4585 if (!eina_hash_add(_eina_value_inner_mps, &size, imp))
4586 {
4587 eina_mempool_del(imp->mempool);
4588 free(imp);
4589 return NULL;
4590 }
4591
4592 return imp;
4593}
4594
4595static inline void *
4596_eina_value_inner_alloc_internal(int size)
4597{
4598 Eina_Value_Inner_Mp *imp;
4599 void *mem;
4600
4601 imp = _eina_value_inner_mp_get(size);
4602 if (!imp) return NULL;
4603
4604 mem = eina_mempool_malloc(imp->mempool, size);
4605 if (mem) imp->references++;
4606 else if (imp->references == 0) _eina_value_inner_mp_dispose(size, imp);
4607
4608 return mem;
4609}
4610
4611static inline void
4612_eina_value_inner_free_internal(int size, void *mem)
4613{
4614 Eina_Value_Inner_Mp *imp = eina_hash_find(_eina_value_inner_mps, &size);
4615 EINA_SAFETY_ON_NULL_RETURN(imp);
4616
4617 eina_mempool_free(imp->mempool, mem);
4618
4619 imp->references--;
4620 if (imp->references > 0) return;
4621 _eina_value_inner_mp_dispose(size, imp);
4622}
4623
4624EAPI void *
4625eina_value_inner_alloc(size_t size)
4626{
4627 void *mem;
4628
4629 if (size > 256) return malloc(size);
4630
4631 eina_lock_take(&_eina_value_inner_mps_lock);
4632 mem = _eina_value_inner_alloc_internal(size);
4633 eina_lock_release(&_eina_value_inner_mps_lock);
4634
4635 return mem;
4636}
4637
4638EAPI void
4639eina_value_inner_free(size_t size, void *mem)
4640{
4641 if (size > 256)
4642 {
4643 free(mem);
4644 return;
4645 }
4646
4647 eina_lock_take(&_eina_value_inner_mps_lock);
4648 _eina_value_inner_free_internal(size, mem);
4649 eina_lock_release(&_eina_value_inner_mps_lock);
4650}
4651
4652/**
4653 * @internal
4654 * @brief Initialize the value module.
4655 *
4656 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
4657 *
4658 * This function sets up the value module of Eina. It is called
4659 * by eina_init().
4660 *
4661 * @see eina_init()
4662 */
4663Eina_Bool
4664eina_value_init(void)
4665{
4666 const char *choice, *tmp;
4667
4668 _eina_value_log_dom = eina_log_domain_register("eina_value",
4669 EINA_LOG_COLOR_DEFAULT);
4670 if (_eina_value_log_dom < 0)
4671 {
4672 EINA_LOG_ERR("Could not register log domain: eina_value");
4673 return EINA_FALSE;
4674 }
4675
4676#ifdef EINA_DEFAULT_MEMPOOL
4677 choice = "pass_through";
4678#else
4679 choice = "chained_mempool";
4680#endif
4681 tmp = getenv("EINA_MEMPOOL");
4682 if (tmp && tmp[0])
4683 choice = tmp;
4684
4685 if (choice)
4686 _eina_value_mp_choice = strdup(choice);
4687
4688 _eina_value_mp = eina_mempool_add
4689 (_eina_value_mp_choice, "value", NULL, sizeof(Eina_Value), 320);
4690 if (!_eina_value_mp)
4691 {
4692 ERR("Mempool for value cannot be allocated in value init.");
4693 goto on_init_fail_mp;
4694 }
4695
4696 if (!eina_lock_new(&_eina_value_inner_mps_lock))
4697 {
4698 ERR("Cannot create lock in value init.");
4699 goto on_init_fail_lock;
4700 }
4701 _eina_value_inner_mps = eina_hash_int32_new(NULL);
4702 if (!_eina_value_inner_mps)
4703 {
4704 ERR("Cannot create hash for inner mempools in value init.");
4705 goto on_init_fail_hash;
4706 }
4707
4708 EINA_ERROR_VALUE_FAILED = eina_error_msg_static_register(
4709 EINA_ERROR_VALUE_FAILED_STR);
4710
4711 EINA_VALUE_TYPE_UCHAR = _EINA_VALUE_TYPE_BASICS + 0;
4712 EINA_VALUE_TYPE_USHORT = _EINA_VALUE_TYPE_BASICS + 1;
4713 EINA_VALUE_TYPE_UINT = _EINA_VALUE_TYPE_BASICS + 2;
4714 EINA_VALUE_TYPE_ULONG = _EINA_VALUE_TYPE_BASICS + 3;
4715 EINA_VALUE_TYPE_UINT64 = _EINA_VALUE_TYPE_BASICS + 4;
4716 EINA_VALUE_TYPE_CHAR = _EINA_VALUE_TYPE_BASICS + 5;
4717 EINA_VALUE_TYPE_SHORT = _EINA_VALUE_TYPE_BASICS + 6;
4718 EINA_VALUE_TYPE_INT = _EINA_VALUE_TYPE_BASICS + 7;
4719 EINA_VALUE_TYPE_LONG = _EINA_VALUE_TYPE_BASICS + 8;
4720 EINA_VALUE_TYPE_INT64 = _EINA_VALUE_TYPE_BASICS + 9;
4721 EINA_VALUE_TYPE_FLOAT = _EINA_VALUE_TYPE_BASICS + 10;
4722 EINA_VALUE_TYPE_DOUBLE = _EINA_VALUE_TYPE_BASICS + 11;
4723 EINA_VALUE_TYPE_STRINGSHARE = _EINA_VALUE_TYPE_BASICS + 12;
4724 EINA_VALUE_TYPE_STRING = _EINA_VALUE_TYPE_BASICS + 13;
4725
4726 _EINA_VALUE_TYPE_BASICS_START = _EINA_VALUE_TYPE_BASICS + 0;
4727 _EINA_VALUE_TYPE_BASICS_END = _EINA_VALUE_TYPE_BASICS + 13;
4728
4729 EINA_SAFETY_ON_FALSE_RETURN_VAL((sizeof(_EINA_VALUE_TYPE_BASICS)/sizeof(_EINA_VALUE_TYPE_BASICS[0])) == 14, EINA_FALSE);
4730
4731
4732 EINA_VALUE_TYPE_ARRAY = &_EINA_VALUE_TYPE_ARRAY;
4733 EINA_VALUE_TYPE_LIST = &_EINA_VALUE_TYPE_LIST;
4734 EINA_VALUE_TYPE_HASH = &_EINA_VALUE_TYPE_HASH;
4735 EINA_VALUE_TYPE_TIMEVAL = &_EINA_VALUE_TYPE_TIMEVAL;
4736 EINA_VALUE_TYPE_BLOB = &_EINA_VALUE_TYPE_BLOB;
4737 EINA_VALUE_TYPE_STRUCT = &_EINA_VALUE_TYPE_STRUCT;
4738
4739 EINA_VALUE_BLOB_OPERATIONS_MALLOC = &_EINA_VALUE_BLOB_OPERATIONS_MALLOC;
4740
4741 EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH = &_EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH;
4742 EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE = &_EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE;
4743
4744 return EINA_TRUE;
4745
4746 on_init_fail_hash:
4747 eina_lock_free(&_eina_value_inner_mps_lock);
4748 on_init_fail_lock:
4749 eina_mempool_del(_eina_value_mp);
4750 on_init_fail_mp:
4751 free(_eina_value_mp_choice);
4752 _eina_value_mp_choice = NULL;
4753 eina_log_domain_unregister(_eina_value_log_dom);
4754 _eina_value_log_dom = -1;
4755 return EINA_FALSE;
4756}
4757
4758/**
4759 * @internal
4760 * @brief Shut down the value module.
4761 *
4762 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
4763 *
4764 * This function shuts down the value module set up by
4765 * eina_value_init(). It is called by eina_shutdown().
4766 *
4767 * @see eina_shutdown()
4768 */
4769Eina_Bool
4770eina_value_shutdown(void)
4771{
4772 eina_lock_take(&_eina_value_inner_mps_lock);
4773 if (eina_hash_population(_eina_value_inner_mps) != 0)
4774 ERR("Cannot free eina_value internal memory pools -- still in use!");
4775 else
4776 eina_hash_free(_eina_value_inner_mps);
4777 eina_lock_release(&_eina_value_inner_mps_lock);
4778 eina_lock_free(&_eina_value_inner_mps_lock);
4779
4780 free(_eina_value_mp_choice);
4781 _eina_value_mp_choice = NULL;
4782 eina_mempool_del(_eina_value_mp);
4783 eina_log_domain_unregister(_eina_value_log_dom);
4784 _eina_value_log_dom = -1;
4785 return EINA_TRUE;
4786}
33 4787
34/*============================================================================* 4788/*============================================================================*
35* Global * 4789* Global *
@@ -39,9 +4793,232 @@
39* API * 4793* API *
40*============================================================================*/ 4794*============================================================================*/
41 4795
4796EAPI const Eina_Value_Type *_EINA_VALUE_TYPE_BASICS_START = NULL;
4797EAPI const Eina_Value_Type *_EINA_VALUE_TYPE_BASICS_END = NULL;
4798
4799EAPI const Eina_Value_Type *EINA_VALUE_TYPE_UCHAR = NULL;
4800EAPI const Eina_Value_Type *EINA_VALUE_TYPE_USHORT = NULL;
4801EAPI const Eina_Value_Type *EINA_VALUE_TYPE_UINT = NULL;
4802EAPI const Eina_Value_Type *EINA_VALUE_TYPE_ULONG = NULL;
4803EAPI const Eina_Value_Type *EINA_VALUE_TYPE_UINT64 = NULL;
4804EAPI const Eina_Value_Type *EINA_VALUE_TYPE_CHAR = NULL;
4805EAPI const Eina_Value_Type *EINA_VALUE_TYPE_SHORT = NULL;
4806EAPI const Eina_Value_Type *EINA_VALUE_TYPE_INT = NULL;
4807EAPI const Eina_Value_Type *EINA_VALUE_TYPE_LONG = NULL;
4808EAPI const Eina_Value_Type *EINA_VALUE_TYPE_INT64 = NULL;
4809EAPI const Eina_Value_Type *EINA_VALUE_TYPE_FLOAT = NULL;
4810EAPI const Eina_Value_Type *EINA_VALUE_TYPE_DOUBLE = NULL;
4811EAPI const Eina_Value_Type *EINA_VALUE_TYPE_STRINGSHARE = NULL;
4812EAPI const Eina_Value_Type *EINA_VALUE_TYPE_STRING = NULL;
4813EAPI const Eina_Value_Type *EINA_VALUE_TYPE_ARRAY = NULL;
4814EAPI const Eina_Value_Type *EINA_VALUE_TYPE_LIST = NULL;
4815EAPI const Eina_Value_Type *EINA_VALUE_TYPE_HASH = NULL;
4816EAPI const Eina_Value_Type *EINA_VALUE_TYPE_TIMEVAL = NULL;
4817EAPI const Eina_Value_Type *EINA_VALUE_TYPE_BLOB = NULL;
4818EAPI const Eina_Value_Type *EINA_VALUE_TYPE_STRUCT = NULL;
4819
4820EAPI const Eina_Value_Blob_Operations *EINA_VALUE_BLOB_OPERATIONS_MALLOC = NULL;
4821
4822EAPI const Eina_Value_Struct_Operations *EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH = NULL;
4823EAPI const Eina_Value_Struct_Operations *EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE = NULL;
4824
4825EAPI Eina_Error EINA_ERROR_VALUE_FAILED = 0;
4826
42EAPI const unsigned int eina_prime_table[] = 4827EAPI const unsigned int eina_prime_table[] =
43{ 4828{
44 17, 31, 61, 127, 257, 509, 1021, 4829 17, 31, 61, 127, 257, 509, 1021,
45 2053, 4093, 8191, 16381, 32771, 65537, 131071, 262147, 524287, 1048573, 4830 2053, 4093, 8191, 16381, 32771, 65537, 131071, 262147, 524287, 1048573,
46 2097143, 4194301, 8388617, 16777213 4831 2097143, 4194301, 8388617, 16777213
47}; 4832};
4833
4834EAPI Eina_Value *
4835eina_value_new(const Eina_Value_Type *type)
4836{
4837 Eina_Value *value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
4838 if (!value)
4839 {
4840 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
4841 return NULL;
4842 }
4843 if (!eina_value_setup(value, type))
4844 {
4845 free(value);
4846 return NULL;
4847 }
4848 return value;
4849}
4850
4851EAPI void
4852eina_value_free(Eina_Value *value)
4853{
4854 EINA_SAFETY_ON_NULL_RETURN(value);
4855 eina_value_flush(value);
4856 eina_mempool_free(_eina_value_mp, value);
4857}
4858
4859
4860EAPI Eina_Bool
4861eina_value_copy(const Eina_Value *value, Eina_Value *copy)
4862{
4863 const Eina_Value_Type *type;
4864 const void *src;
4865 void *dst;
4866 Eina_Bool ret;
4867
4868 EINA_SAFETY_ON_NULL_RETURN_VAL(value, EINA_FALSE);
4869 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(value->type),
4870 EINA_FALSE);
4871 EINA_SAFETY_ON_NULL_RETURN_VAL(copy, EINA_FALSE);
4872 EINA_SAFETY_ON_NULL_RETURN_VAL(value->type->copy, EINA_FALSE);
4873
4874 type = value->type;
4875 if (!eina_value_setup(copy, type))
4876 return EINA_FALSE;
4877
4878 src = eina_value_memory_get(value);
4879 dst = eina_value_memory_get(copy);
4880 ret = type->copy(type, src, dst);
4881 if (!ret)
4882 eina_value_flush(copy);
4883
4884 return ret;
4885}
4886
4887EAPI Eina_Bool
4888eina_value_convert(const Eina_Value *value, Eina_Value *convert)
4889{
4890 Eina_Bool ret = EINA_FALSE;
4891 const Eina_Value_Type *type, *convert_type;
4892 const void *type_mem;
4893 void *convert_mem;
4894
4895 EINA_SAFETY_ON_NULL_RETURN_VAL(value, EINA_FALSE);
4896 EINA_SAFETY_ON_NULL_RETURN_VAL(convert, EINA_FALSE);
4897 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(value->type),
4898 EINA_FALSE);
4899 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(convert->type),
4900 EINA_FALSE);
4901
4902 type = value->type;
4903 convert_type = convert->type;
4904
4905 type_mem = eina_value_memory_get(value);
4906 convert_mem = eina_value_memory_get(convert);
4907
4908 if (type->convert_to)
4909 ret = type->convert_to(type, convert_type, type_mem, convert_mem);
4910
4911 if ((!ret) && (convert_type->convert_from))
4912 ret = convert_type->convert_from(convert_type, type, convert_mem,
4913 type_mem);
4914
4915 return ret;
4916}
4917
4918EAPI char *
4919eina_value_to_string(const Eina_Value *value)
4920{
4921 Eina_Value tmp;
4922
4923 EINA_SAFETY_ON_NULL_RETURN_VAL(value, NULL);
4924 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(value->type), NULL);
4925
4926 if (!eina_value_setup(&tmp, EINA_VALUE_TYPE_STRING))
4927 return NULL;
4928 if (!eina_value_convert(value, &tmp))
4929 return NULL;
4930
4931 return tmp.value.ptr; /* steal value */
4932}
4933
4934EAPI Eina_Value *
4935eina_value_array_new(const Eina_Value_Type *subtype, unsigned int step)
4936{
4937 Eina_Value *value;
4938
4939 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(subtype), EINA_FALSE);
4940
4941 value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
4942 if (!value)
4943 return NULL;
4944
4945 if (!eina_value_array_setup(value, subtype, step))
4946 {
4947 eina_mempool_free(_eina_value_mp, value);
4948 return NULL;
4949 }
4950
4951 return value;
4952}
4953
4954EAPI Eina_Value *
4955eina_value_list_new(const Eina_Value_Type *subtype)
4956{
4957 Eina_Value *value;
4958
4959 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(subtype), EINA_FALSE);
4960
4961 value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
4962 if (!value)
4963 return NULL;
4964
4965 if (!eina_value_list_setup(value, subtype))
4966 {
4967 eina_mempool_free(_eina_value_mp, value);
4968 return NULL;
4969 }
4970
4971 return value;
4972}
4973
4974EAPI Eina_Value *
4975eina_value_hash_new(const Eina_Value_Type *subtype, unsigned int buckets_power_size)
4976{
4977 Eina_Value *value;
4978
4979 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(subtype), EINA_FALSE);
4980
4981 value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
4982 if (!value)
4983 return NULL;
4984
4985 if (!eina_value_hash_setup(value, subtype, buckets_power_size))
4986 {
4987 eina_mempool_free(_eina_value_mp, value);
4988 return NULL;
4989 }
4990
4991 return value;
4992}
4993
4994EAPI Eina_Value *
4995eina_value_struct_new(const Eina_Value_Struct_Desc *desc)
4996{
4997 Eina_Value *value;
4998
4999 value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
5000 if (!value)
5001 return NULL;
5002
5003 if (!eina_value_struct_setup(value, desc))
5004 {
5005 eina_mempool_free(_eina_value_mp, value);
5006 return NULL;
5007 }
5008
5009 return value;
5010}
5011
5012EAPI Eina_Bool
5013eina_value_type_check(const Eina_Value_Type *type)
5014{
5015 EINA_SAFETY_ON_NULL_RETURN_VAL(type, EINA_FALSE);
5016 return type->version == EINA_VALUE_TYPE_VERSION;
5017}
5018
5019EAPI const char *
5020eina_value_type_name_get(const Eina_Value_Type *type)
5021{
5022 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(type), NULL);
5023 return type->name;
5024}
diff --git a/libraries/eina/src/lib/eina_xattr.c b/libraries/eina/src/lib/eina_xattr.c
index bd5b98e..d4ed139 100644
--- a/libraries/eina/src/lib/eina_xattr.c
+++ b/libraries/eina/src/lib/eina_xattr.c
@@ -20,6 +20,7 @@
20# include "config.h" 20# include "config.h"
21#endif 21#endif
22 22
23#include <stdlib.h>
23#include <sys/types.h> 24#include <sys/types.h>
24#include <string.h> 25#include <string.h>
25#include <math.h> 26#include <math.h>
@@ -34,6 +35,7 @@
34#include "eina_safety_checks.h" 35#include "eina_safety_checks.h"
35#include "eina_xattr.h" 36#include "eina_xattr.h"
36#include "eina_convert.h" 37#include "eina_convert.h"
38#include "eina_stringshare.h"
37 39
38/*============================================================================* 40/*============================================================================*
39 * Local * 41 * Local *
@@ -49,14 +51,83 @@ struct _Eina_Xattr_Iterator
49{ 51{
50 Eina_Iterator iterator; 52 Eina_Iterator iterator;
51 53
54 const char *file;
55 Eina_Xattr *attr;
56
52 ssize_t length; 57 ssize_t length;
53 ssize_t offset; 58 ssize_t offset;
54 59
60 int fd;
61
55 char xattr[1]; 62 char xattr[1];
56}; 63};
57 64
58#ifdef HAVE_XATTR 65#ifdef HAVE_XATTR
59static Eina_Bool 66static Eina_Bool
67_eina_xattr_value_ls_fd_iterator_next(Eina_Xattr_Iterator *it, void **data)
68{
69 char *tmp;
70
71 if (it->offset >= it->length)
72 return EINA_FALSE;
73
74 *data = it->attr;
75 it->attr->name = it->xattr + it->offset;
76
77 it->attr->length = fgetxattr(it->fd, it->attr->name, NULL, 0);
78 if (it->attr->length)
79 {
80 tmp = realloc((void*) it->attr->value, it->attr->length);
81 if (!tmp)
82 {
83 free((void*) it->attr->value);
84 it->attr->value = NULL;
85 it->attr->length = 0;
86 }
87 else
88 {
89 it->attr->length = fgetxattr(it->fd, it->attr->name,
90 (void *) it->attr->value,
91 it->attr->length);
92 }
93 }
94
95 return EINA_TRUE;
96}
97
98static Eina_Bool
99_eina_xattr_value_ls_iterator_next(Eina_Xattr_Iterator *it, void **data)
100{
101 char *tmp;
102
103 if (it->offset >= it->length)
104 return EINA_FALSE;
105
106 *data = it->attr;
107 it->attr->name = it->xattr + it->offset;
108
109 it->attr->length = getxattr(it->file, it->attr->name, NULL, 0);
110 if (it->attr->length)
111 {
112 tmp = realloc((void*) it->attr->value, it->attr->length);
113 if (!tmp)
114 {
115 free((void*) it->attr->value);
116 it->attr->value = NULL;
117 it->attr->length = 0;
118 }
119 else
120 {
121 it->attr->length = getxattr(it->file, it->attr->name,
122 (void*) it->attr->value,
123 it->attr->length);
124 }
125 }
126
127 return EINA_TRUE;
128}
129
130static Eina_Bool
60_eina_xattr_ls_iterator_next(Eina_Xattr_Iterator *it, void **data) 131_eina_xattr_ls_iterator_next(Eina_Xattr_Iterator *it, void **data)
61{ 132{
62 if (it->offset >= it->length) 133 if (it->offset >= it->length)
@@ -78,6 +149,9 @@ static void
78_eina_xattr_ls_iterator_free(Eina_Xattr_Iterator *it) 149_eina_xattr_ls_iterator_free(Eina_Xattr_Iterator *it)
79{ 150{
80 EINA_MAGIC_SET(&it->iterator, 0); 151 EINA_MAGIC_SET(&it->iterator, 0);
152 if (it->attr) free((void *) it->attr->value);
153 eina_stringshare_del(it->file);
154 free(it->attr);
81 free(it); 155 free(it);
82} 156}
83#endif 157#endif
@@ -96,6 +170,85 @@ _eina_xattr_ls_iterator_free(Eina_Xattr_Iterator *it)
96 * API * 170 * API *
97 *============================================================================*/ 171 *============================================================================*/
98 172
173EAPI Eina_Iterator *
174eina_xattr_value_fd_ls(int fd)
175{
176#ifdef HAVE_XATTR
177 Eina_Xattr_Iterator *it;
178 ssize_t length;
179
180 if (fd < 0) return NULL;
181
182 length = flistxattr(fd, NULL, 0);
183 if (length <= 0) return NULL;
184
185 it = calloc(1, sizeof (Eina_Xattr_Iterator) + length - 1);
186 if (!it) return NULL;
187
188 it->attr = calloc(1, sizeof (Eina_Xattr));
189 if (!it->attr)
190 {
191 free(it);
192 return NULL;
193 }
194
195 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
196
197 it->fd = fd;
198 it->length = flistxattr(fd, it->xattr, length);
199 if (it->length != length)
200 {
201 free(it);
202 return NULL;
203 }
204
205 it->iterator.version = EINA_ITERATOR_VERSION;
206 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_xattr_value_ls_fd_iterator_next);
207 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_eina_xattr_ls_iterator_container);
208 it->iterator.free = FUNC_ITERATOR_FREE(_eina_xattr_ls_iterator_free);
209
210 return &it->iterator;
211#else
212 return NULL;
213 (void)fd;
214#endif
215}
216
217EAPI Eina_Iterator *
218eina_xattr_fd_ls(int fd)
219{
220#ifdef HAVE_XATTR
221 Eina_Xattr_Iterator *it;
222 ssize_t length;
223
224 if (fd < 0) return NULL;
225
226 length = flistxattr(fd, NULL, 0);
227 if (length <= 0) return NULL;
228
229 it = calloc(1, sizeof (Eina_Xattr_Iterator) + length - 1);
230 if (!it) return NULL;
231
232 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
233
234 it->length = flistxattr(fd, it->xattr, length);
235 if (it->length != length)
236 {
237 free(it);
238 return NULL;
239 }
240
241 it->iterator.version = EINA_ITERATOR_VERSION;
242 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_xattr_ls_iterator_next);
243 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_eina_xattr_ls_iterator_container);
244 it->iterator.free = FUNC_ITERATOR_FREE(_eina_xattr_ls_iterator_free);
245
246 return &it->iterator;
247#else
248 return NULL;
249 (void)fd;
250#endif
251}
99 252
100EAPI Eina_Iterator * 253EAPI Eina_Iterator *
101eina_xattr_ls(const char *file) 254eina_xattr_ls(const char *file)
@@ -133,6 +286,44 @@ eina_xattr_ls(const char *file)
133#endif 286#endif
134} 287}
135 288
289EAPI Eina_Iterator *
290eina_xattr_value_ls(const char *file)
291{
292#ifdef HAVE_XATTR
293 Eina_Xattr_Iterator *it;
294 ssize_t length;
295
296 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
297
298 length = listxattr(file, NULL, 0);
299 if (length <= 0) return NULL;
300
301 it = calloc(1, sizeof (Eina_Xattr_Iterator) + length - 1);
302 if (!it) return NULL;
303
304 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
305
306 it->length = listxattr(file, it->xattr, length);
307 if (it->length != length)
308 {
309 free(it);
310 return NULL;
311 }
312
313 it->file = eina_stringshare_add(file);
314
315 it->iterator.version = EINA_ITERATOR_VERSION;
316 it->iterator.next = FUNC_ITERATOR_NEXT(_eina_xattr_value_ls_iterator_next);
317 it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_eina_xattr_ls_iterator_container);
318 it->iterator.free = FUNC_ITERATOR_FREE(_eina_xattr_ls_iterator_free);
319
320 return &it->iterator;
321#else
322 return NULL;
323 (void)file;
324#endif
325}
326
136EAPI void * 327EAPI void *
137eina_xattr_get(const char *file, const char *attribute, ssize_t *size) 328eina_xattr_get(const char *file, const char *attribute, ssize_t *size)
138{ 329{