Commit Graph

746 Commits

Author SHA1 Message Date
Jean Guyomarc'h 3f79cf8748 eina: fix behaviour break of eina_error_msg_get()
eina_error_msg_get() must return NULL if an incorrect error is provided.
The XSI strerror_r() returns EINVAL when an invalid error is passed to
it, so we can end the function here. If we kept on, we would have tested
against the 'unknown_prefix' ("Unknown error ") which is implementation
defined, and registered a new error when the invalid error message
didn't match the 'unknown_prefix'. This new error message would have
been returned, which is not what we expected.

This case arised on Mac OS X where the 'unkwown prefix' is
"Unknown error: " instead of "Unknown error ".

It fixes eina test suite on Mac OS X.
2016-08-29 20:03:52 +02:00
Jean Guyomarc'h 5db3357f40 eina: overhaul Mac OS X semaphores
Mac OS X does not support POSIX unnamed semaphores, only named
semaphores, which are persistant IPC: when the program exits,
and if semaphores where not released, they stay forever...

All EFL programs were "leaking" a semaphore, due to how
eina_log_monitor manages its resources. Therefore, after building
EFL a lot (which run eolian_gen, eolian_cxx, elua, edje_cc, ...)
we were not able to create any semaphore...

Now, we get rid of these semaphores and use Mac OS X's own
semaphores. Code is less cumbersome, and we don't have any
disavantage of the named semaphores.

Fixes T4423

@fix
2016-08-26 21:16:39 +02:00
Cedric BAIL 0ef07d6095 eina: readdir_r has been deprecated.
So glibc has decided that readdir_r is hard to use safely and deprecated it
this summer. They recommand to use readdir, which was in the past unsafe to
use in a multi thread scenario, but is now on most system (and all system
we care, including our own implementation in evil). It is basically safe
as long the same DIRP is not accessed from another thread. This is true in
our code base, so we are fine to go with this.

For further reading: https://lwn.net/Articles/696474/
2016-08-25 15:23:14 -07:00
Gustavo Sverzut Barbieri 45c0002929 eina_slice: startswith and endswith.
these helpers around memcmp() make the code more readable.
2016-08-23 21:25:02 -03:00
Gustavo Sverzut Barbieri 9944c164bd eina_slice: fix multi-byte find function, add tests. 2016-08-23 20:17:13 -03:00
Jean Guyomarc'h 5d527fffc8 eina: remove references to win32 and winCE in threads 2016-08-23 21:15:25 +02:00
Jean Guyomarc'h 180b24f2a0 eina: fixtures on OSX semaphores
So actually there is quite a big issue with semaphores
on OSX. We use (named) POSIX semaphores, but this was
a (my) mistake... I'll fix it later...
The real issue is that named semaphore are persistants:
when the program dies, it stays alive. This is pretty
bad with eina_debug_monitor because we create a semaphore
we never release, due to a wild thread...

This leak of semaphores went unnoticed before commit
4a40ff95de because the
name of the semaphore was unique per process, and
overriden when another process was launched. This
was very bad, but saved us from overflowing the
semaphore pool. It is now overflowed pretty fast when
building a lot EFL, because of Eolian that runs A LOT!

So that's one problem that still needs to be fixed,
by using OSX' own semaphores (see T4423).
Another big issue, which is now fixed is that the
buffer in which we generated the semaphore ID was
too small, and therefore we were reduced to one shared
semaphore for a whole process... This buffer has been
now set to 31 characters, which seems to be the maximum
length of a semaphore ID.

So now things are better, but still with a deadly issue.
2016-08-23 21:15:25 +02:00
Gustavo Sverzut Barbieri 12850d4e25 remove EINA_ERROR_TIMEOUT
As pointed out in the mailing list, it was introduced in this release,
so it's better to remove the symbol instead of deprecating it.

People should use ETIMEDOUT directly.
2016-08-23 10:14:17 -03:00
Gustavo Sverzut Barbieri 0d96ba9734 binbuf, strbuf and ustrbuf: add slice_get() and rw_slice_get(). 2016-08-22 18:25:14 -03:00
Gustavo Sverzut Barbieri 77faebde67 eina_stringshare: add slice_get() 2016-08-22 18:25:14 -03:00
Gustavo Sverzut Barbieri 9062bbd8e0 eina: introduce Eina_Slice and Eina_Rw_Slice.
A plain simple pointer + length describing a linear memory region.
2016-08-22 18:25:14 -03:00
Gustavo Sverzut Barbieri 602a98c8b9 eina_error: provide a fallback when strerror_r() is not available. 2016-08-22 18:25:14 -03:00
Jean Guyomarc'h 26a26f2304 eina: fix use of strerror_r()
So, first, the wrong strerror_r() was detected on
Mac OS X. Instead of using a complex set of macros
to try to detect which strerror_r() to use, when
it is defined, let the autotools handle that clerverness
for us.
2016-08-22 20:02:02 +02:00
Gustavo Sverzut Barbieri e56811ed4d eina_error: allow errno.h codes.
we have some duplication of errors between Eina_Error and errno.h,
however we should use Eina_Error to extend the traditional errno.h
system.

then change eina_error_msg_register() and
eina_error_msg_static_register() to return a magic bit to state the
number was registered, and on other functions test this bit in order
to operate on registered values, otherwise fallback to errno.h, such
as strerror().

It also deprecates 2 clear duplicated errors:

- EINA_ERROR_OUT_OF_MEMORY -> ENOMEM

- EINA_ERROR_TIMEOUT -> ETIMEDOUT

There are two details when using strerror():

 - old behavior did not return strings for non-error, such as
   "Success" or "Unknown error ${N}"

 - thread-safety issues: since we must be thread safe, then use
   strerror_r() and eina_stringshare_add() that value, keeping a hash
   of cached values
2016-08-18 13:36:05 -03:00
Jean-Philippe Andre cb24d5f489 eina: Set EINA_ERROR_TIMEOUT to cond_timedwait
This adds a new error code.

I'm using a weak symbol (were supported, ie GCC on linux) for
some kind of forward compatibility.

Fixes T1780

@feature
2016-08-16 16:14:21 +09:00
Jean-Philippe Andre 67ab4e3b4d eina: Move EWAPI and EAPI_WEAK to Eina.h from Eo.h
So it may be used outside EO (eina error is what I have in mind).
I believe it doesn't need to be redefined in all EFL libs, especially
since it's not used on Windows yet.
2016-08-16 16:14:21 +09:00
Carsten Haitzler 825e60e023 efl api release - fix @since in new eina iterator api 2016-08-12 18:04:54 +02:00
Stefan Schmidt d126107782 Revert "eina threadqueue - for paranoia lock+ulock+free in order locks taken"
This reverts commit d19cd4e63c.

This causes a SIGBUS error on OpenBSD when closing any application. As this
was safety patch only I will revert it for the 1.18 release and we can work
out what breaks OpenBSD here for 1.19

Fixes T4332
2016-08-11 15:25:32 +02:00
Stefan Schmidt 72b88e51f4 eina: add includes for getpid() to work on MacOSX
Without this I get errors from the clang compiler used on Travis for some OSX
builds:
../src/lib/eina/eina_inline_lock_posix.x:845:27: error: use of undeclared identifier 'getpid'
2016-08-08 16:49:55 +02:00
Stefan Schmidt a5fd63067d eina: safepointer: add since tags to new eina safepointer EAPI 2016-08-08 14:59:57 +02:00
Carsten Haitzler 933c0a6b04 eina_module - check result of module load from an array of modules
we don't give any debug or info if a module in a list fails to load.
we should at least offer debug info. do that. this fixes coverity
issue CID 1039687
2016-08-08 18:38:25 +09:00
Carsten Haitzler 83752435cf eina log - handle possible overflow from high mem (last few bytes) or env
fixes CID 1361219
if you had an env var a few gb in size or we had stuff in the last bit
of memory address space this might be an issue, but that won't happen.

@fix
2016-08-06 15:53:18 +09:00
Carsten Haitzler 20c6bd296b eina log - keep coverity happy with potential ptr comparison overflow
fixes CID 1361220

in theory yes end minus start could be insanely huge or end be very
high in memory thus causing an overflow. this would have to be in the
last few bytes of memory space, so it never going to happen. and the
input from the env var has to be sane anyway as its user controlled.

@fix
2016-08-06 15:50:17 +09:00
Carsten Haitzler d19cd4e63c eina threadqueue - for paranoia lock+ulock+free in order locks taken
so mimic order of locks taken to be paranoid ... this wouldnt be a
deadlock issue but just to be safe instead of sorry.
2016-08-06 09:56:02 +09:00
Carsten Haitzler 26db5d5056 eina thread queue - ensure blocks cannot be freed until lock+unlock
just in case... check blocks cannot be freed until locked and unlocked
just in case someone still is holding a lock.
2016-08-05 23:52:20 +09:00
Carsten Haitzler 4a40ff95de eina lock semaphores - do not use shared semaphores and fix osx names
the way eina does sempahores, they can NEVER be sensibly shared
cross-process portably. so enabling sharing is a pointless idea. in
fact some os's like openbsd check if the sempahore addres is in a
sharable mem region and deny init if it is not. on osx you dont use
shared memory but a sempahore name you share instead... and this is
not exposed thus it can't be shared either. if we did process sharable
semaphores we'd make shm segments and/or name them in a sharable way
were you can share the idenitifer of the shm segment and/or the offset
address or name from osx. but we don't, so making them
process-private is the right thing. sharable sempahores will need a
whole new api.

this also fixes osx naming to make the name pretty unguessable/private
and opened exclusive (or it fails) by using pid, sem counter, and 4
random numbers. it's not a security mechanism as the create will fail
if there is a clash. chances are low. we unlink before anyway. good
enough for osx for now.

@fix
2016-08-05 18:11:42 +09:00
Carsten Haitzler 8fd224b4d6 eina thread queue/semaphores - check even more unlikely errors + complain
check some really unlikely alloc errors and semaphore deadlock errors
and report if that has happened. just in case.
2016-08-05 17:38:02 +09:00
Carsten Haitzler 07924f26f1 eina thread queue - check returns fo semaphore new/lock/release to debug
so openbsd may have issues with semaphores - maybe. this would catch
them if it it. why - if sem_init/sem_wait are different... i dont know.
2016-08-05 17:09:34 +09:00
Carsten Haitzler 6b6823e5af eina_threadqueue - fix const ptr warning on spinlocks if atomic disabled
atomics SHOULDNT be disabled anyway, but if they are... fix this
warning. (no real bug)
2016-08-05 13:42:50 +09:00
Cedric BAIL dd1d3f0d2d autotools: since it has been broken for some times and nobody noticed, let's remove per directory support. 2016-08-01 13:36:47 -07:00
Stefan Schmidt 3bd4c19f55 eina: promise: fix memory leak in error path
If we would not get a promise back here the allocated array would leak when we
return. Make sure we also free it in this case.

CID: 1360468
2016-07-29 14:53:36 +02:00
Chris Michael 89234ce6bc eina: Fix null pointer derefernce
Coverity reports that eina_safepointer_get returns a NULL promise here
(checked 20 out of 21 times). As eina_safepointer_get can return NULL,
we should check the validity of 'promise' here before trying to
derefernce it later.

Fixes Coverity CID1356625

@fix

Signed-off-by: Chris Michael <cp.michael@samsung.com>
2016-07-21 13:07:26 -04:00
Carsten Haitzler ad1bfac960 eina rbtree iterator - fix leak found while debugging other problems
there was a leak of elements on  the itrator stack when the stack was
flushed still having some items on it, thus losing their pointers and
never freeing them.

@fix
2016-07-19 15:43:22 +09:00
Carsten Haitzler 4bbe5ee058 eina thread create - use pthread_sigmask as this can be called from thread
@fix
2016-07-14 08:39:31 +09:00
Jean-Philippe Andre 4d9de121d1 eina_safepointer: Fix coverity warning
I guess the overflow was badly handled. Fixing it by using
explicit int intermediate value.

Fixes CID 1356616 and 1356619:

Operands don't affect result
Logically dead code
2016-07-13 16:25:01 +09:00
Carsten Haitzler 25c63f726e eina thread - fix window build with sigprocmask
fixes T4048
2016-07-08 21:11:21 +09:00
Carsten Haitzler aeeda1f77d efl - threads and signals - make efl work on "insane" os's with signals
so. on linux signals are delivered to the main process thread/loop.
thats' where signal handlers are set up and always run. this is sane.
it's predicatble. but of course this is not the same in bsd land.
there "just send the signal to any old thread and call the signal
handler there" seems to tbe the order of the day. this explains why
wer are losing sigchld signals in edje_cc - it's heavily threaded and
bsd is just randombly picking a thread to call it on.

this fixes that. in theory. i hope. i can't test, but putting it in to
share

@fix
2016-07-04 23:47:25 +09:00
Jean Guyomarc'h e333175109 eina: fix typos in eina_rectangle doc 2016-06-26 18:48:15 +02:00
Jean Guyomarc'h 33bb4583b8 eina: fix compiling of safepointers on OSX
This is a reccurring compatibility issue...
MAP_ANONYMOUS is not defined on OSX, but MAP_ANON is.
I know MAP_ANON is marked as deprecated in the Linux man
pages, but it has the benefit of being more portable.
2016-06-15 22:33:39 +02:00
Carsten Haitzler fe9a9d8759 eina - alloca.h - include stdlib and stddef, usze size_t not long 2016-06-15 14:33:56 +09:00
Felipe Magno de Almeida f33b53e923 eina: Fix race wrong prototype for unref 2016-06-14 23:08:13 -03:00
Felipe Magno de Almeida 949af55947 eina: Add support for eina_safepointer in promises 2016-06-11 10:40:27 -03:00
Cedric BAIL 692b2c9fc9 eina: add generic infrastructure for a Eina_Safepointer
This is heavily inspired from Eo_Id infrastructure. Main change
are that the lower bit are always guaranteed to be zero and ignored
by all function. Also it may be a little bit less efficient in some
case, but we will tune it once we have real life usage of it.

Eo won't be migrated for 1.18 to it as Eo_Id is deeply integrated
and it is quite risky to touch it so close from a freeze. This can
wait.
2016-06-10 13:57:01 -07:00
Lauro Moura 2d2e57eccd eina: Smudge magic value on promise deletion 2016-06-09 22:39:25 -03:00
Lauro Moura 46843551c0 eina: Remove value type promises
All values in promises are now considered as by-pointer.
2016-06-09 22:38:54 -03:00
Lauro Moura 5a3331618e eolian: remove support for value-type promises 2016-06-09 19:14:18 -03:00
Lauro Moura 3b090b808b eina: Fixes on promises behavior when cancelling
- Free the cancel callbacks on promise delete
- Cancelling an ended promise should be a nop
- More tests to increase coverage
2016-06-09 19:14:14 -03:00
Jean Guyomarc'h dec1d251dc eina: ensure resource destruction on failure
In case of failure within eina_lock_new() (posix), a
pthread_mutexattr_t would have been left in an initialized state,
without any deinitialization being called.

Consequences would have been implementation defined.
2016-06-06 23:45:18 +02:00
Benjamin Jacobs 731e88061a eina_thread.c: fix include guard.
DragonFlyBSD has pthread_setname_np but no pthread_setaffinity_np;
we still need to include pthread_np though.

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
2016-06-06 12:05:43 -07:00
Larry Jr 2e441c3f5e eina: eina_promise_all callback cast removed 2016-06-06 03:30:42 -03:00