Commit Graph

491 Commits

Author SHA1 Message Date
Gustavo Sverzut Barbieri 216e6e51e4 eo: better error reporting, always provide caller/source when available.
_eo_pointer_error() was kinda a bitch to debug as it provided a nice
breakpoint location, but did not provide a good output since the file,
line and function were always the same.

Change that to be a thin wrapper on top of eina_log_vprint(), then we
keep the breakpoint location yet provide useful information.

In that sense, change other error messages so they carry as much
information as possible.
2016-12-02 14:50:45 -02:00
Gustavo Sverzut Barbieri cf5aeb9804 eo: use log domain as soon as it's available. 2016-12-02 14:50:45 -02:00
Jean-Philippe Andre b6fae524ff eo: Improve debug for efl_isa errors from threads 2016-12-02 17:21:47 +09:00
Tom Hacohen 79d76fb25e Eo gdb: add a way to resolve Eo ids from GDB without a running process
Normally when debugging Eo with gdb you can just use any of the internal
eo functions to resolve the id to its internal pointer. However, when
loading a coredump you can't execute any code, not even the id resolve
code.

This change adds a gdb function that resolves the id to its pointer form
without executing any code in the process space. This plugin is
essentially the id resolve code written in python as a gdb function.

Usage:
 Print the pointer:
 (gdb) print $eo_resolve(obj)
 $1 = (_Eo_Object *) 0x5555559bbe70

 Use it directly (e.g. to print the class name):
 (gdb) $eo_resolve(obj)->klass->desc.name

This plugin requires that the coredump would be loaded with the exact
same libeo.so binary (or at least one that hasn't changed eo internals),
and that the debug symbols for libeo.so would be available for gdb to
use.

Note:
This feature is incomplete and only resolves IDs that are owned by the
main thread and in the main domain. This is not a big issue at the
moment, because almost all of our IDs are like that.

@feature
2016-11-18 11:48:07 +00:00
Carsten Haitzler 45771d47ab eo - use free queue for at least some eo core memory and pointers
this should help improve robusteness by keeping memory around for a
bit until the free queue flushes or is full

@feature
2016-11-06 13:13:10 +09:00
Tom Hacohen f736946d10 Eo: Add a method to mark objects for reuse.
This informas eo an object is going to get reused/cached, so eo can
reset the object appropriately.

@feature.
2016-10-28 13:19:10 +01:00
Tom Hacohen 25242e6af9 Eo: Fix references of objects 2016-10-21 15:29:39 +01:00
Tom Hacohen 5a659fafd2 Eo: Fix reference leak when failing to resolve function.
When resolving a function for an object the object would get reference,
and then in some failure cases won't be freed.

I suspect this is a regression following the reshuffling that was done
in that function recently.

Thanks to zmike for investigating and reporting this.

Fixes T4740

@fix
2016-10-19 16:32:16 +01:00
Jean-Philippe Andre 9c95eda748 eo: Fix deadlocks with composite objects
This happens with shared objects.

The situation seems to be:
1. object has composited object a of class A in thread 1
2. call something on object a from thread 2, deadlock
In fact, do anything from thread 2 on a shared object and you deadlock.
2016-10-06 17:57:45 +09:00
Carsten Haitzler 6a5ae00ffa eo - goto-ify a chunk iof code moving debug printfs out of hot paths
this moves a lot of error case handling into goto's so the code gets
out of the hot path and this should help expecially since variou
smacros do things like:

   do { char buf[256]; sprintf(buf, fmt, ptr); _eo_pointer_error(buf); } while (0)

   _Efl_Class *klass; \
   do { \
      klass = _eo_class_pointer_get(klass_id); \
      if (!klass) { \
         _EO_POINTER_ERR("Class (%p) is an invalid ref.", klass_id); \
      return ret; \
   } \
} while (0)

so putting quite a chunk of code inside a rare "if this errors"
handler that will cause l1 cache misses and this we don't want, thus
moving stuff in eo core out of hot paths to cut down on overhead. yes
it might not be pretty but it's kind of the right thing at such a core
level of efl. this also does the same to the eo base class as this is
also going to be relatively hot given it's the core of every other
object.
2016-09-29 17:45:47 +09:00
Carsten Haitzler f387818a55 eo - fix error case lock not unlocking with shared objects from coverity
this fixes CID 1363294
2016-09-29 17:45:47 +09:00
Carsten Haitzler edf6507b9f eo - remove pointless if found by coverity
fix CID 1363295
2016-09-29 17:45:47 +09:00
Carsten Haitzler c43308efb4 eo - silence coverit "leak" on eo init if eoid table tls alloc fails
creating a new tls for the eoid table should just never fail so this
is moot anyway, but it silences CID 1362735
2016-09-29 17:45:47 +09:00
Carsten Haitzler 0f929f5546 eo id and shared domain objects - do locking properly and better
so there were a few issues. one we had a spinlokc on the eoid table
for shared objects AND then had a mutex for accessing those objects
(released on return from any eo function). BUT this missed some funcs
like eo_ref, eo_unref and so on in eo.c ... oops. so fixed. but then i
realized there was a race condition. we locked the eoid table then
unlocked with our pointer THEN locked the sharted object mutex ...
then unlocked it. that was a race condtion gap. so we should share the
same lock anyway - if it's a shared object, grab the shared object
mutex then do a lookup and if the lookup does not fail, KEEP the lock
until it is released by the return from eo function or by some special
macro/funcs that released a matching lock. since its a recursive lock
this is all fine. as its also a universal single lock for all objects
we just need the eoid to know if it's shared and needs locking based
on the domain bits. so now do this locking properly with just a single
mutex, not both a spinlock and mutex and keep the lock around until
totally done with the object. this plugs the race condition holes and
goes from 1 spinlock lock and unlock then a mutex lock and unlokc to
just a single mutex lock and unlock. this means shared objects are
actually truly safe across threads and only have the overhead of a
single recursive mutex to lock and unlock in every api call.
2016-09-28 13:38:46 +09:00
Marcel Hollerbach f63cd63e54 eo: fix headr to header
if you enable EO_DEBUG you cannot build eo, since the field is called
header not headr
2016-09-19 13:25:23 +02:00
Marcel Hollerbach 907bbbf965 eo: fix callback cmp
Summary:
as told in _eina_stringshared_key_cmp in eina_hash.c:

originally we want to do this:
   return key1 - key2;
but since they are ptrs and an int can't store the different of 2 ptrs in
either 32 or 64bit (signed hasn't got enough range for the diff of 2
32bit values regardless of their type... we'd need 33bits or 65bits)

So changing this to the same logic.

Reviewers: tasn, raster

Subscribers: cedric, jpeg

Differential Revision: https://phab.enlightenment.org/D4298
2016-09-19 13:25:23 +02:00
Carsten Haitzler 50d508866e eo invalid err - make the thread self more useful like main. 2016-09-17 05:49:32 +09:00
Tom Hacohen cfcdacc5f7 Eo: Remove the EO_DEBUG env check. We have DBG for that. 2016-09-09 11:38:07 +01:00
Tom Hacohen 7ebf9d879d Eo: Change the way functions are registered to classes
This change lets us remove a field from the structure that leads to
around 20KiB more of saving in private dirty pages in elementary.

This also looks a bit better and feels a bit cleaner.

Breaks API and ABI.
2016-09-09 11:14:35 +01:00
Tom Hacohen 5ad71f1486 Eo: don't allow object override to introduce previously undefined functions. 2016-09-09 11:14:05 +01:00
Carsten Haitzler 8b159aab68 eo - move eoid lookup to ptr indir file and clean up some code
this improves the readability of some of the new domain related and
ptr indir code..
2016-09-09 18:53:20 +09:00
Carsten Haitzler 54c39aa564 eo class add - dont always call getenv as this is epxensive. get once
so class creation is possibly a little slower thanks to always calling
getenv. get once then store rsult from there on out.
2016-09-09 18:53:20 +09:00
Cedric BAIL 9a2ada6d87 eo: add abstract efl.future. 2016-09-08 14:58:05 -07:00
Tom Hacohen bd3801247e Eo: Make function overrides implicit.
Before this commit, function overrides were explicit. That is, you'd
have to explicitly state you were overriding a function instead of
creating a new one. This made the code a tad more complex, and was also
a bit more annoying to use. This commit removes this extra piece of
information.

This means we now store much less information per function, that will
let us further optimise out structures in the future.
2016-09-08 13:59:04 +01:00
Tom Hacohen 6b60560773 Eo class creation: Simplify code using recursive locks.
Now that we have recursive locks, the class creation code can be much simpler.
All the code there was essentially our own implementation of recursive locks,
or rather a special case of those.

This is no longer needed.
2016-09-08 11:14:32 +01:00
Carsten Haitzler 3ce5d1ebc7 eo_compatible - improve usability of err/warnings by duplication impl 2016-09-08 00:09:32 +09:00
Carsten Haitzler 9d2786896b eo - fix indenting in a file that was nuts and non-standard 2016-09-08 00:09:31 +09:00
Carsten Haitzler f695762d06 eo - add single global mutex for all shared eo objects to they are th-safe
this adds a signle mutex (recursive) mutex for all eo objects that is
auto-called by _efl_object_call_resolve() and _efl_object_call_end()
that wrap all eo method calls and since its recursive it can be
blindly called for sub-calls. this will lock all shared objects during
any call to any shared object so only the thread calling now has
access until it releases. not fine-grained but good enough and the
best we can do "simplistically".
2016-09-08 00:09:31 +09:00
Carsten Haitzler 09f19c3c73 eo - make eo id table TLS private data for thread safety and speed
This moved all the eoid tables, eoid lookup caches, generation count
information ad eo_isa cache into a TLS segment of memory that is
thread private. There is also a shared domain for EO objects that all
threads can access, but it has an added cost of a lock. This means
objects accessed outside the thread they were created in cannot be
accessed by another thread unless they are adopted in temporarily, or
create4d with the shared domain active at the time of creation. child
objects will use their parent object domain if created with a parent
object passed in. If you were accessing EO (EFL) objects across threads
before then this will actually now cause your code to fail as it was
invalid before to do this as no actual objects were threadsafe in EFL,
so this will force things to "fail early".
ecore_thread_main_loop_begin() and end() still work as this uses the
eo domain adoption features to temporarily adopt a domain during this
section and then return it when done.

This returns speed back to eo brining the overhead in my tests of
lookup for the elm genlist autobounce test in elementary from about
5-7% down to 2.5-2.6%. A steep drop.

This does not mean everything is perfect. Still to do are:

1. Tests in the test suite
2. Some API's to help for sending objects from thread to thread
3. Make the eo call cache TLS data to make it also safe
4. Look at other locks in eo and probably move them to TLS data
5. Make eo resolve and call wrappers that call the real method func do
   recursive mutex wrapping of the given object IF it is a shared object
   to provide threadsafety transparently for shared objects (but adding
   some overhead as a result)
6. Test test est, and that is why this commit is going in now for wider
   testing
7. Decide how to make this work with sending IPC (between threads)
8. Deciding what makes an object sendable (a sendable property in base?)
9. Deciding what makes an object shareable (a sharable property in base?)
2016-09-07 18:17:10 +09:00
Tom Hacohen 4aae224ef5 Efl object: change the way we set class's functions.
This is another follow up to the investigations of T4227. As stated
there, in any PIE (a shared library is one), structures, even const ones
end up being written to because of dynamic relocation. This means that
using static const structures has actually lead to no savings, only
waste. Since we never really needed them, using them made things even
worse than just having a different API that doesn't save them.

Thus, this commit changes the way we set the functions. Instead of
passing a pre-populated struct, we now just have an initialiser function
where you set the functions. This on its own doesn't significantly reduce
the amount of dirty memory pages for a reason I have yet to uncover,
though I believe it's done as a misguided compiler optimisation.
However, this design is flexible enough so we can change to another one
that is quite ugly, but I have already tested and proven that does that.
This patch series doesn't include the better improvement (passing
        everything on the stack as va_args) because the API was too ugly
for me to bear, and I would rather first make sure there is no way to
force the compiler to do the right thing here.

Unfortunately this commit gives up on useless stricter validation.
Before this commit we would make sure that we are only overriding
functions correctly defined in our hierarchy. With this one, we don't
anymore. This is not a big problem though because this is a check that
is also enforced by Eolian. So as long as you are using Eolian, you
should be fine.

Breaks API and ABI!

@feature
2016-09-05 16:03:17 +01:00
Cedric Bail 05f05dde5c eo: protect efl_isa from thread race condition. 2016-09-02 10:19:45 -07:00
Cedric BAIL 605fec91ee eo: improve speed of walking callback array by sorting them during creation.
This improve speed of processing events in genlist scrolling benchmark by 30%
inside the efl_object_event_callback_call code. Not a really big deal as it
goes from 0.9% to 0.6% of the total time spend. Welcome to micro optimization.
2016-09-02 10:19:45 -07:00
Carsten Haitzler 90acc0216b eo - make eoid table access threadsafe - was missing a lock around it
this now makes at least eoid deref and ojbect access safe across
threads. the downside is that oeid lookup goes from 2% to ~5% of cpu.
ugh.
2016-09-01 18:59:56 +09:00
Cedric BAIL aaa0e962b7 eo: speedup efl_isa by 50%.
Most of our use case of efl_isa is related to legacy Evas_Object_Image API,
that check the isa of the same object again and again. Caching help.
2016-08-26 12:14:14 -07:00
Tom Hacohen b3dd735be7 Efl Object: Change and rename the type we use for function pointers.
Rename the type to something more sensible and change it to remove the
last remanent of Eo1. This fixes a fixme that has been there for a
while.

The type doesn't really matter, it just looks nicer with the va_list.
2016-08-16 16:29:21 +01:00
Tom Hacohen 28c80f9122 Efl object: implement CoW for the function vtables
This commit implements a sort of CoW for the vtables. The vtables are
usually just linked to and refcounted. When we need to change them we
allocate new ones and copy them over so we can write to them.

I wrote some code to measure the effectiveness of this change. When
running elementary_test (and immediately exiting) I saw that out of the
total number of vtable chains (561) that were needed by the classes in
the EFL, 79 (14.08%) were reused. Considering that I had to add
refcounting (unsigned short, but let's consider it's the size of a word
because of alignment), I would calculate the saving as such (in bytes):

Number of items in a chain (refcounted block): 32

32 bit:
sizeof(chain_node) = 8
Mem wasted on refcounting: 561 * 4 = 2244
Mem saved because of sharing: 79 * (32 * 8) = 20224
Total save: 17980 bytes

64 bit:
sizeof(chain_node) = 16
Mem wasted on refcounting: 561 * 8 = 4488
Mem saved because of sharing: 79 * (32 * 16) = 40448
Total save: 35960 bytes

Wow, we use a lot of memory in Eo classes, I'm sure we can
save even more if we put our hearts into it (change the shareable units
        to be smaller to increase the chance of sharing).
This is internal and doesn't affect API/ABI so we can change this even
further with time.

This also improves efl_object_override(). This should now be quite
memory efficient (don't abuse, but it's not a big hogg as it was), so
feel free to abuse that one and rely on it in API.

@feature
2016-08-16 16:29:21 +01:00
Tom Hacohen e65aae994e Eo: Finish the renaming of Eo to the EFL.
This renames all the rest of the API to the EFL namespace except for
Eo_Event that will follow soon.

Obviously breaks both API and ABI.
2016-08-15 15:07:42 +01:00
Tom Hacohen c662934be8 Change the EFL to follow the new Eo rename. 2016-08-11 17:04:43 +01:00
Tom Hacohen e64e120a51 Eo: Rename most of Eo to the Efl prefix.
This includes Eo.Base -> Efl.Object and many (but not all) of the eo
functions. This commit is only for eo itself, not the rest of the EFL.
2016-08-11 17:04:43 +01:00
Carsten Haitzler 742fbc5717 evas canvas destruction - detect zombie objs and hack at them with axes
ok. so here's the issue at least now. we have eo objects in the canvas
and they have a refcount of 2 user_refcount is 0. the calls stack does
NOT show we are calling callbacks at that time on these objects. they
are not in the backtrace (the canvas is, the objects themselves are
not).

SOMETHING is keeping 2 eo "internal" refs on these objects and i have
no idea what/how/who. it's a royal pain in the butt to find out as the
only way is lots and lots of logging and you get drowned in the
logging...

so what I have now done is a super ugly workaround that detects these
zombie objects that refuse to die and just FORCES them to die when the
evas canvas frees and clears out layers.
ac10a00acc doesn't really cause the
issue, it just brings it out in the open for all to see far more
easily. but something is deeply wrong SOMEWHERE with SOME objects and
our refcounts.

this fixes T4187
2016-07-29 00:02:03 +09:00
Jean-Philippe Andre 6a559a6fff eo: Prevent eo_override to be called on an already overridden object
I don't see the point of it but can't be bothered to argue.
For Tom.
2016-07-21 13:49:37 +09:00
Jean-Philippe Andre 3029227fa1 eo: Change eo_override to avoid struct passing and GCC construct
This is a (minor) API & ABI break in Eo.h!

I say minor as eo_override shouldn't be used yet (EO is unstable
and this patch includes all the use cases in EFL).

I'm not very happy about the new form of the macro, but it avoids
two things:
- passing in a struct (valid in C, but never used in EFL)
- using a GCC construct to create structs on the fly

It was inspired by the event array define, but I don't think
we need the runtime memcpy here.

See also:
https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
2016-07-19 17:55:07 +09:00
Jean-Philippe Andre cae939e208 eo: Fix leak in eo_override and allow NULL to reset
eo_override would leak the vtable if called multiple times, this
fixes that. Also, it is now possible to revert back to the original
class' vtable by passing in { NULL, 0 }

I believe it is thus possible to incrementally override more
functions on an object. Absolutely not recommended, but should work.
But it is not possible to selectively revert back to the original
class implementation on a single method. Use eo_super for that,
or revert back the entire object overrides.

PS: Is it normal that we pass in a struct? We never do that in EFL...
2016-07-18 17:55:58 +09:00
Tom Hacohen fdc0eef770 Eo add ref: Fix a bug causing leaks and wrong refcount in some cases.
When using eo_add_ref, it was increasing the refcount before the user
context in the addition has fully ended. This means the object had its
reference increased while still not finalized, which means it was
sometimes passed with an increased refcount to unsuspecting class code.
The correct behaviour is to increase the reference count just before
returning the object to the user at the end of eo_add so the reference
count is only increased for whoever asked for it.

Breaks ABI!

@fix
2016-07-12 11:09:40 +01:00
Tom Hacohen a5eb66edd4 Eo refcount: Split the refcount to private and public (user).
This commit changes the way refcount is dealt with internally. Before
this commit, there was one refcount shared between Eo internals and
users. Now there is a refcount for eo operations (like for example,
function calls) and one for user refcount (eo_ref).

An example bug that this protects against (which is seemingly rather
common) is:
some_eo_func(obj);

// Inside the implementation of that func:
pd->a = 1; // The object's private data
eo_unref(obj); // To delete the object
eo_unref(obj); // A big one extra unref
pd->a = 2; // Segfault, this data has already been freed

This is a feature, but really just a fix for a class of bugs.

@feature
2016-07-12 11:09:40 +01:00
Jean-Philippe Andre 85a9bd5430 eo: Fix crash during eo_shutdown
I was getting a crash in eo_shutdown, inside
_efl_event_pointer_class_destructor as I was calling eo_del
from there. But the parent class was already destroyed.

Assuming class IDs can only go up, and child classes are only
instanciated after all their parents, it is safer to call the
class destructors in reverse order.

Obviously, still pretty sure eo_del() in a class_destructor
is not a good idea...
2016-07-05 19:15:13 +09:00
Stefan Schmidt ecdbde7493 eo: remove now longer needed EO_BASE_BETA define from code base
This was needed when the eo composite object was still in beta. Since commit
d7c45e41d4 this is no longer the case. No beta
part left in eo base so we can safely remove this define.
2016-06-20 10:07:30 +02:00
Tom Hacohen f122437dd6 Eo: fix reference hack when calling composite objects.
We used to keep a reference to the parent object and have it in the call
structure although we were actually calling the function on the embedded
object. This was needed because we wanted to unref the parent correctly.
This was incorrect (and marked as a hack) and now I finally gotten
around to implementing the (amazingly simple) fix to remove this
workaround.

Essentially we just ref the comp object, unref the parent, and let the
normal eo call flow to unref the comp object correctly later on, like it
would have unreffed the extra ref we had for the parent.
2016-06-05 15:22:53 +01:00
Tom Hacohen a6a2338962 Revert "Eo: Remove eo_del() and make eo_unref() the replacement."
This reverts commit 546ff7bbba.

It seems that eo_del() is useful and removing it was creating bugs.
The issue is that the way we defined parents in eo, both the parent and
the programmer share a reference to the object. When we eo_unref() that
reference as the programmer, eo has no way to know it's this specific
reference we are freeing, and not a general one, so in some
circumstances, for example:
eo_ref(child);
eo_unref(child); // trying to delete here
eo_unref(container); // container is deleted here
eo_unref(child); // child already has 0 refs before this point.

We would have an issue with references and objects being freed too soon
and in general, issue with the references.

Having eo_del() solves that, because this one explicitly unparents if
there is a parent, meaning the reference ownership is explicitly taken
by the programmer.

eo_del() is essentially a convenience function around "check if has
parent, and if so unparent, otherwise, unref". Which should be used when
you want to delete an object although it has a parent, and is equivalent
to eo_unref() when it doesn't have one.
2016-06-01 13:33:21 +01:00
Carsten Haitzler 11393cfee3 Revert "eo - now ref and unref objects on each eo call to keep things safe"
This reverts commit 4044fe6504.
2016-05-25 17:35:53 +09:00
Carsten Haitzler 4044fe6504 eo - now ref and unref objects on each eo call to keep things safe
so... i got this ... callback calls callback calls something calls
callback that deletes the original object at the top so when it comes
back ... things die as the object was destructed. in removing eo_do()
we removed the ref/unrefs that went with it. so this uses the
_EO_API_BEFORE_HOOK and _EO_API_AFTER_HOOK to call exposed "internal"
public functions _eo_real_ref() and _eo_real_unref().

this fixes a new segv i've noticed in several e dialogs where hitting
close does the above via callbacks and closes the window etc.
2016-05-24 09:20:49 +09:00
Tom Hacohen 83a2ed5e70 Eo: Fix wrong allocation.
We weren't allocating the correct amount. Oops.

CID 1355594.
2016-05-23 08:36:16 +01:00
Tom Hacohen 5e95d7f2d8 Eo super: Validate class in eo_super instead of call_reslove.
This is more correct and fixes a segfault that occurs when eo_id is
disabled.
2016-05-20 11:47:32 +01:00
Tom Hacohen 06f65ab2b1 Eo: Implement eo_override() to enable overriding functions of objects.
This change lets you override the functions of objects so that those
functions will be called instead of the functions of the class. This
lets you change objects on the fly and makes using the delegate pattern
easier (no need to create a class every time anymore).
You can see the newly added tests (in this commit) for usage examples.

@feature
2016-05-20 10:25:00 +01:00
Tom Hacohen c450efdcde Eo: Improve error message when overriding functions. 2016-05-20 10:25:00 +01:00
Tom Hacohen e1efe2e651 Eo: Reorganise the vtable in classes and add pointer from objects.
This is the first step towards supporting eo_override().
More details about eo_override() to follow.
2016-05-20 10:25:00 +01:00
Carsten Haitzler 72adab7222 eo datarefcount - only use in debug mode 2016-05-18 23:11:00 +09:00
Tom Hacohen 96624b9725 Eo: Fix singleton pattern and add a test to make sure it works. 2016-05-18 13:31:30 +01:00
Tom Hacohen 546ff7bbba Eo: Remove eo_del() and make eo_unref() the replacement.
We used to have eo_del() as the mirrored action to eo_add(). No longer,
now you just always eo_unref() to delete an object. This change makes it
so the reference of the parent is shared with the reference the
programmer has. So eo_parent_set(obj, NULL) can free an object, and so
does eo_unref() (even if there is a parent).

This means Eo no longer complains if you have a parent during deletion.
2016-05-17 16:23:23 +01:00
Tom Hacohen 9ef65788f4 Eo: Rename an internal function to reduce confusion.
@raster added eo_id_get() which was confusing because we already had
_eo_id_get() that was used internally.
2016-05-17 10:29:16 +01:00
Tom Hacohen 6cacef2503 Eo abstract class: Rename to Eo.Class. 2016-05-12 14:33:40 +01:00
Tom Hacohen 106951a61d Eo: Make eo_del() an eo function.
This was done following a feature request by @raster. There was no real
reason for it not to be an eo function and this gives us more
flexibility.

The reason why this done was to provide a way for classes to do special
things when an object deletion was requested, for example in the case of
Evas, hide the object.
2016-04-26 16:29:18 +01:00
Carsten Haitzler 09cdd364f9 eo - class table - move to mmaped memory if possible and alloc chunks
so memory for class id -> ptrs is mallocs. this means it likely will
be next to other memory malloced. which means overrunning memory
someone mallocs could walk into the class table and corrupt it. we put
eo ids in mmaped regions to avoid this if possible in case of buggy
code. let's do it for classes too.

this also now allocs in larger chunks. for mmap its in page chunks
(which can hold either 1024 or 512 classes depending on 32 or 64bit).
reallocs still work if mmap is not there and we do them in chunks of
128 classes (it seems that we start at about 70 or so classes atm when
elm_test starts and it grows to ~100 or let's do 128 as that's pretty
much our base as a power of 2 and we now dont realloc much).
2016-04-24 12:07:42 +09:00
Tom Hacohen c9347b1ca2 Revert "Eo: Fix rare crash after call_resolve"
I'm reverting this because according to jpeg it was possibly fixed in
5284b62e93.
I reverted this patch after his fix and followed his reproduction cases
and it seems that his second patch does indeed fix this issue so this
patch is no longer needed.

This reverts commit 0862b9d083.
2016-04-06 11:18:36 +01:00
Jean-Philippe Andre 0862b9d083 Eo: Fix rare crash after call_resolve
It seems that calling a @class function with an EO object
(that was not the required Eo_Class) lead to a situation
where func->func was NULL. And that meant a crash after
call_resolve.

The proper fix is to properly call a @class function with a
class object.
2016-04-06 13:27:04 +09:00
Tom Hacohen 4a75116cb4 Eo: Implement the fallback eo_add implementation.
The current eo_add uses a (very useful) gcc extension that is only
available in gcc compatible compilers (e.g clang). Until this commit we
just temporarily ignored this fact. This adds a fallback implementation that
can be used interchangeably with the non portable one. This means that the
same binary can call either at any point in time and the code will work.

Breaks ABI.
2016-03-29 16:01:52 +01:00
Carsten Haitzler 3df71ab0f6 eo del interceptor: add the ability to intercept deletions of eo objects
Imagine this. You have an object. You pass this object handle as a
message to another thread. Let's say it's not a UI object, so
something you might expect to be able to be accessed from multiple
threads. In order to keep the object alive you eo_ref() it when
placing the message on a queue and eo_unref() it once the message is
"done" in the other thread. If the original sender unref()ed the
object before the message is done, then the object will be destroyed
in the reciever thread. This is bad for objects "expecting" not to be
destroyed outside their owning thread.

This allows thius situation to be fixed. A constructor in a class of
an object can set up a delete interceptor. For example if we have a
"loop ownership" class you multi-ple-inherit from/use as a mixin. This
class will set up the interceptor to ensure that on destruction if
pthread_self() != owning loop thread id, then add object to "delete
me" queue on the owning loop and wake it up. the owning loop thread
will wake up and then process this queue and delete the queued objects
nicely and safely within the "owning context".

This can also be used in this same manner to defer deletion within a
loop "until later" in the same delete_me queue.

You can even use this as a caching mechanism for objects to prevernt
their actual destruction and instead place them in a cached area to be
picked from at a later date.

The uses are many for this and this is a basic building block for
future EFL features like generic messages where a message payload
could be an eo object and thus the above loop onwership issue can
happen and needs fixing.

This adds APIs, implementation, documentation (doxy reference) and tests.

@feature
2016-03-08 16:57:22 +09:00
Tom Hacohen b55ec7a34e Eo: remove the long deprecated eo_data_get.
It has been deprecated for a while, and now it's time to actually stop
using it.
2016-03-04 14:23:02 +00:00
Tom Hacohen d2f799e4cb Eo: Remove useless safety checks.
Those can never happen, ever.
2016-03-04 14:09:34 +00:00
Tom Hacohen fc88037977 Eo: Migrate to the new syntax (Eo 4).
The syntax is described in: https://phab.enlightenment.org/w/eo/

Summary:
eo_do(obj, a_set(1)) -> a_set(obj, 1)
eo_do_super(obj, CLASS, a_set(1)) -> a_set(eo_super(obj, CLASS), 1)

eo_do_*_ret() set of functions are no longer needed.

This is the first step, the next step would be to also fix up eo_add()
which currently still uses the old syntax and is not 100% portable.

@feature
2016-03-03 09:53:23 +00:00
Tom Hacohen 668fd4a6e8 Eo: add support for initialising eo after it has been shut down.
Until now it wasn't allowed/possible to init (eo_init) eo after it has
been shut down (eo_shutdown). This commit fixes that, so now that is
fully legal to have as many init/shutdown cycles as you want.

There was a previous workaround for this issue:
e47edc250d.

This should allow more flexibility when using the EFL in loadable
modules and in various other scenarios.

The problem is that the class_get() functions cache the previously
created class for efficiency, but the class is freed if eo is shut down,
so the cached pointer is actually invalid.
The solution to the problem was to maintain a generation count
(incremented every time we shut down eo), and compare that to a locally
saved version in class_get(). If they don't match, recreate the class,
as it has already been freed.

@feature
2016-02-04 09:27:15 +00:00
Tom Hacohen 43d05a334d Revert "Eo: Prevent shutdown from actually doing anything"
This commit was a workaround to let us shutdown and then init eo without
any issues. It leaks and it's wrong. This will properly be fixed in the
next commit.

This reverts commit e47edc250d.
2016-02-04 09:27:15 +00:00
Tom Hacohen d01ed68825 Eo: fix eo_shutdown()'s return value to be FALSE on shutdown.
The return value of init/shutdown is true if eo is init, false otherwise.
This was broken until now.

@fix.
2016-02-03 16:56:15 +00:00
Tom Hacohen 0ff1646871 Eo: Rearrange class creation code a bit.
This is not really needed, I just did it to make it easier for coverity
(and future static analysers) to understand that the class id doesn't
need to be accessed with a lock.

CID1341854
2016-01-07 13:04:12 +00:00
Vincent Torri 47ed848a87 Evil: integrate the dlfcn code into Evil
This will remove some incompatibilities with other packages,
especially for win-builds
2015-12-29 22:13:58 +09:00
Jean-Philippe Andre e47edc250d Eo: Prevent shutdown from actually doing anything
Currently, eo_shutdown can't work.

Every Eo_Class ID is stored inside its class_get() function as a
static variable. This means any call to class_get() after eo_shutdown()
(even if eo_init was done properly) will lead to using an invalid ref
for the class id. In other words, the class is not valid anymore,
and objects can't be created.

Resetting the pointer to NULL would be possible, if we passed it
during the class creation. But this would lead to potential crashes
if a class was created from a now dlclosed library.

The only solution I can envision here is to check that class_get
actually returns a valid ref with the right class name. Most likely
the performance impact is not acceptable.

This fixes make check for me (with systemd module for ecore).
2015-12-29 20:55:50 +09:00
Tom Hacohen 0bebaed0ac Eo do: use the __thread directive when available to manage call stack.
This is faster in most cases, and to be honest, should be much faster
than it is. I don't understand why there's no better directive to mark a
variable as *really* important thread storage that is used all the time.
2015-11-09 11:43:04 +00:00
Tom Hacohen 3e40b45be6 Eo: Remove extra paranoid-never could happen safety checks.
I was not able to reach those without arbitrary memory corruption, but
in that case we are in trouble anyway.
2015-11-09 11:43:04 +00:00
Tom Hacohen 6ed69b1d11 Eo: Reorganise some of the code and cleanup.
This is cleaner and makes more sense.
2015-11-09 11:43:04 +00:00
Tom Hacohen 3782931c50 Eo: Removed weird unneeded condition. 2015-11-09 11:43:04 +00:00
Tom Hacohen f28f6ecbfa Eo: Move op resolve check to where it belongs (out of hot path).
It was put in the wrong place. It should abort early if it detects we
can't resolve, and shouldn't check it if we already know it's OK.
2015-11-09 11:43:04 +00:00
Tom Hacohen f7f7fc69cf Eo: Split object checking from class checking and simplify.
The check there was wrong for objects anyway, and was ultra conservative
for classes.
2015-11-09 11:43:04 +00:00
Tom Hacohen 680388472e Eo: Reduce call stack memory footprint.
We don't really need the eo_id most of the time, and when we do, it's
very easy to get it. It's better if we just don't save the eo_id on the
stack, and just save if it's an object or a class instead.
2015-11-09 11:43:04 +00:00
Tom Hacohen adbc534703 Eo: Remove useless optimisation that is more harm than good.
It seems that the idea behind that optimisation, is to save object data
fetching when calling functions implemented by the object's class inside
functions implemented by the object's class. This should be rare enough
not to worth the upkeep, memory reads and memory writes, especially
since for all cases apart of mixins (for which this optimisation won't
work for anyway), the upkeep is more costly than fetching the data
again.
2015-11-09 11:43:04 +00:00
Tom Hacohen 748b90d295 Eo: use correct mask when checking if an id is a class 2015-11-09 11:43:04 +00:00
Tom Hacohen 44ca3a3669 Eo: Optimise object data fetching a bit more.
Removed safety check that is not necessary. This may seem small,
but this in addition to the previous commit, account for around
2% of CPU usage.
2015-11-09 11:43:04 +00:00
Tom Hacohen 1ed0edfb9e Eo: Optimise object data fetching (minor).
Pre-calculate object data offset for improved performance.
2015-11-09 11:43:04 +00:00
Carsten Haitzler c2b4137f77 eo - move cache lookup into the hot path if as it only is valid there
minor speedup ... really minor - but correct.
2015-10-24 12:23:53 +09:00
Carsten Haitzler 29884844d4 efl eo - pass test suite function overrides again after adding cache
removing the klass member meant removing hooks and keeping cache small
but that meant not using it. this meand if the object is not an obj...
i removed the:

call->obj = _eo_class_id_get(call->klass);

line - seemed harmless/pointless. apparently not. so put it back but
use the klass there in local vars and not in call as it's not there
(and not needed).

fix.
2015-10-22 09:35:11 +09:00
Carsten Haitzler 8b48906401 eo - oops remove warning cpp i accidentally put in! 2015-10-21 22:27:06 +09:00
Carsten Haitzler 9ef9f2deb8 eo resolv cache - remove params passed to resolv func for efficiency
we pass both the callcache and the op id - both are static and filled
in at runtime, so merge them into the same struct. this should lead to
better alignment/padding with the offset array and the next slot and
op fields, probably saving about 4-8 bytes of rame per method with no
downsides. also pass in only cache ptr, not both cache ptr and opid -
less passing of stuff around and should be better.
2015-10-21 22:23:18 +09:00
Carsten Haitzler 7cc41473a3 efl - eo - massively improve eo cal resolv and data scope get with cache
BEWARE! this breaks eo ABI. _eo_call_resolve and _eo_data_scope_get
are 2 of the biggest cpu users in eo. they easily consume like 10-15%
cpu between them on tests that drive a lot of api - like simply
scrolling a genlist around. this is a lot of overhead for efl. this
fixes that to make them far leaner. In fact this got an overall 10%
cpu usage drop and that includes all of the actual rendering, and code
work, so this would drop the eo overhead of these functions incredibly
low. using this much cpu just on doing call marshalling is a bug and
thus - this is a fix, but ... with an abi break to boot. more abi
breaks may happen before release to try and get them all in this
release so we don't have to do them again later.

note i actually tested 4, 3, 2, and 1 cache slots, and 1 was the
fastest. 2 was very close behind and then it got worse. all were
better than with no cache though.

benchmark test method:

export ELM_ENGINE=gl
export ELM_TEST_AUTOBOUNCE=1

while [ 1 ]; do sync; sync; sync; time elementary_test -to genlist;
sleep 1; done

take the 2nd to the 8th results (7 runs) and total up system and user
time. copmpare this to the same without the cache. with the cache cpu
time used is 90.3% of the cpu time used without - thus a win. at least
in my tests.

@fix
2015-10-21 20:16:06 +09:00
Carsten Haitzler 94ebd96df5 eo - another 1.5 percent speedup in eo_bench eo_do by removing err handl
so we do a bit of error handling like does a stack fail to allocate,
does setting the tls var fail, have the stack frames been nulled or
not allocated, etc. - these acutally cost every call because they mean
some extra compare and branches, but ore because they cause a lot fo
extra code to be generated, thus polluting instruction cache with code
and cacheline fetches of code that we rarely take - if ever.

every if () and DBG, ERR etc. does cost something. in really hotpath
code like this, i think it's best we realize that these checks will
basically never be triggered, because if a stack fails to grow... we
likely alreayd blew our REAL stack for the C/C++ side and that can't
allocate anymore and has already just crashed (no magic message there -
just segv). so in this case i think this checking is pointless and
just costs us rather than gets us anything.
2015-10-17 11:42:46 +09:00
Tom Hacohen 07ea62419a Eo do: Reuse stack fetching across eo functions.
This causes a significant speed up (around 10% here) and is definitely
worth it. The way it's done lets the compiler cache the value across
different eo_do calls, and across the parts of eo_do. Start and end.

This breaks ABI.
2015-10-16 16:38:46 +01:00
Tom Hacohen 3ee44dcef0 Eo do: optimise getting the thread call stack for the main loop thread.
This may look like an insignificant change, but it doubles the speed of
this function, and since this function is called so often, it actually
improves my benchmarks by around 8%.
2015-10-16 16:38:44 +01:00
Tom Hacohen b61556aa87 Eo: Move mainloop checks inside Eo.
This breaks ABI in a harmless way, and it will give us the ability to
drastically improve Eo in the future without breaking ABI again, thus
allowing us to declare Eo stable for this release if we choose to.
2015-10-16 14:53:22 +01:00
Tom Hacohen 535076f425 Eo: Fix confusing indentation and style. 2015-10-14 20:43:07 +01:00
Tom Hacohen fd61ff69b3 Eo: Fix Eo on Windows.
We use function names instead of function pointers of Windows, because
of dll import/export issues (more in a comment in eo.c). Before this
commit we were comparing the pointers to the strings instead of the
content in some of the places, which caused op desc lookup not to work.
This fixes that.

Thanks to vtorri for his assistance.

@fix
2015-10-09 12:18:30 +01:00
Tom Hacohen 6a4c603e0f Eo: Remove dead code.
This removes code that became dead in commit:
389c6d35f2
The commit doesn't explain why we don't shrink or grow when using mmap,
but this is how it is. No reason to keep old code there.

CID 1240224

@fix
2015-10-04 15:01:27 +01:00
Tom Hacohen 001aa98942 Eo: Clean up windows code a bit more.
Merge more parts of it with the non-windows code.
2015-09-30 08:38:47 +01:00
Tom Hacohen e2344b9b9e Eo: reduce memory usage across applications.
As described by Carsten in his email to edev ML titled:
"[E-devel] eo stability - i think we need to postpone that"
with the switch to Eo2 we significantly increased our usage of RW memory
pages, and thus significantly increased our memory usage when running
multiple applications.

The problem was that during the migration to Eo2 the op id cache and the
op description arrays were merged, causing the op description arrays to
no longer be RO. This patch enables users of Eo (mainly Eolian) to
declare those arrays as const (RO) again, saving that memory.

There might be performance implications with this patch. I had to remove
the op desc array sorting, and I used a hash table for the lookup. I
think the op desc sorting doesn't really affect performance because that
array is seldom accessed and is usually pretty short. The hash table
is not a problem either, because it's  behind the scenes, so it can be
changed to a more efficient data structure if the hash table is not good
enough. The hash table itself is also rarely accessed, so it's mostly
about memory.

Please keep an eye for any bugs, performance or excessive memory usage.
I believe this should be better on all fronts.

This commit *BREAKS ABI*.

@fix
2015-09-28 18:39:15 +01:00
Tom Hacohen 9328524da4 Eo: Remove EO_SENTINEL.
This was never really needed because we always had the count.
Removing this now because we are already breaking API and ABI.
2015-09-28 15:52:50 +01:00
Tom Hacohen 35a482141d Eo: Clean up windows code.
We were keeping a struct member that wasn't really needed on windows.
Since we already broke ABI, we can afford to clean this up.
2015-09-28 15:26:51 +01:00
Tom Hacohen 12c3986866 Eo: Fix eo function name getter on windows. 2015-09-28 15:24:44 +01:00
Tom Hacohen 37f84b7e96 Eo: Drop doc field from ops and events.
This hasn't been used for a while. Since we are going to break Eo a bit anyway
it's a good opportunity to drop this.

This may cause a slight performance issues with legacy events, such as
smart callbacks. This shouldn't really be a problem as we've migrated away from
them. If it does, we need to migrate the remaining parts. Only relevant
for callbacks that are added before the classes are created, which
shouldn't be possible except for smart, only for old evas callbacks.
2015-09-28 15:09:16 +01:00
Tom Hacohen acc158a2bf Revert "Revert "Eo base: Change parent_set to be an assignment of ref.""
Had to revert it until I pushed the changes to elm, which I had issues
with. Now the patch can safely go back in.

This reverts commit 37abea3831.
2015-08-26 10:47:06 +01:00
Tom Hacohen 37abea3831 Revert "Eo base: Change parent_set to be an assignment of ref."
Damn, this breaks some things. Reverting until fixed.

This reverts commit 9c78ee0bf4.
2015-08-26 10:33:24 +01:00
Tom Hacohen 9c78ee0bf4 Eo base: Change parent_set to be an assignment of ref.
After this change, parent_set assigns a ref, so for example:
  obj = eo_add(CLASS, parent); /* Ref is 1 */
  eo_do(obj, eo_parent_set(parent2)); /* Ref is 1 */
  eo_ref(obj); /* Ref is 2 */
  eo_do(obj, eo_parent_set(NULL)); /* Ref is 1, giving the ref to NULL */
  eo_do(obj, eo_parent_set(parent)); /* Ref is 1 */

This is following a discussion on the ML about commit
8689d54471.

@feature
2015-08-26 10:11:18 +01:00
Carsten Haitzler c6011926ba eo - silence ERR logs on constructor fail - this is valid behavior
@fix

XXX: Given EFL usage of objects, construction is a perfectly valid thing
to do. we shouldn't complain about it as handling a NULL obj creation is
the job of the caller. a perfect example here is ecore_con and ecore_ipc
where you create a con or ipc obj then set up type/destination/port and
the finalize of the constructor does the actual connect and thus this
fails or succeeds based on if service is there.

until there is a better solution - don't complain here.
2015-06-24 19:28:04 +09:00
Tom Hacohen db6c17627f Eo: Fix windows support.
This is heavily based on a patch by Vincent Torri. I just refactored it
a bit so it doesn't break ABI on Linux, only on Windows (where it was
broken anyway).

This patch changes things so on Windows, functions are looked up only
based on their name. Because of the indirection (and export/import
tables) windows does, this is the only reasonable way to make it work.
2015-06-18 14:23:08 +01:00
Tom Hacohen d85029a5c0 Eo: Fix a potentially dangerous lack of {}.
You should always use curly brackets. Especially when the inside statement
has its own curlys. This can be confusing and has already lead to bugs in
many projects.
2015-06-18 14:23:08 +01:00
Tom Hacohen 293d286977 Eo: rename conflicting internal Eo_Base to Eo_Header
This name conflicts with the class Eo.Base and should have
been called Eo_Header from the start anyway.
2015-05-28 17:47:59 +01:00
Tom Hacohen 1d4c028034 Eo: Fix typo in error message.
Thanjs to q66 for reporting.
2015-05-21 10:52:36 +01:00
Tom Hacohen c02bab4149 Eo: Better handle object cleanup on failure.
While unrefing twice works, it's cleaner to unref the ref we
have and delete normally. It will handle parnet detachments in
a nicer way, and is just more correct.
2015-05-20 16:48:33 +01:00
Tom Hacohen 92fb2917cb Eo: Remove eo_error_set() and clean up finalizer()
This is another cleanup in perparation for the Eo stable release.
This is no longer needed thanks to the proper error reporting with
eo_constructor()'s new return value.

The finalizer change cleans it up a bit so it catches more cases/issues.
This also means that the finalizer cleans up the object in all cases,
and not only some.

@feature.
2015-05-20 16:25:38 +01:00
Tom Hacohen 6efbfe227a Eo: Add a return value to eo_constructor().
From now on, constructors should return a value, usually the object
being worked on, or NULL (if the constructor failed). This can also
be used for implementing singletons, by just always returning the same
object from the constructor.

This is one of the final steps towards stabilizing Eo.

@feature
2015-05-20 13:03:24 +01:00
Tom Hacohen e27f40111d Eo: Mark composite APIs as beta.
Until now we used @protected, but now we can finally properly use @beta.
2015-05-08 16:18:36 +01:00
Tom Hacohen 1506ec30ba Eo base: mark composite API as not ready. 2015-05-06 15:46:18 +01:00
Tom Hacohen e891c56f60 Revert "eo: add eo_error_get"
As discussed on IRC and ML. We are in a feature freeze phase, and this
patch is not essential. Furthermore, this patch was never discussed.

This reverts commit 537c7fe9e3.
2015-04-15 08:18:25 +01:00
Jaehwan Kim 537c7fe9e3 eo: add eo_error_get
This is pair of eo_error_set.
2015-04-15 13:57:42 +09:00
Tom Hacohen a791d97bfc Eo: Remove GCCism and make it more portable.
This affects eo_do() and eo_add() that used to use the ({}) GCCism.
Following a discussion with Peter de Ridder after my talk at FOSDEM,
we've decided to reopen the GCCism (works with other gcc compatible
compilers like clang and intelc) discussion, and after a bit of back and
forth it was decided to make things more portable, at the cost of ease
of use.

For example:
if (eo_do(obj, visible_get()))
is no longer allowed, the portable alternative
Eina_Bool tmp;
if (eo_do_ret(obj, tmp, visible_get()))
is to be used instead.

However:
eo_do(obj, a = a_get(), b = b_get(), bool_set(!bool_get))
are still allowed and OK.

eo_do(obj, if (a_get()) return;);
is no longer allowed, but:
eo_do(obj, if (a_get()) something());
is still allowed.

For clarity, this commit only incorporates the Eo changes, and not the
EFL changes to make the efl conform with this change.

Thanks again to Peter de Ridder for triggering this important discussion
which led to this change.
2015-02-23 17:16:02 +00:00
Tom Hacohen 40cb2cd3d4 Eo add: beef up error reporting.
In some cases object ceration would fail without an error,
this is bad and should not happen.

Thanks to cedric for reporting.
2015-01-23 16:51:18 +00:00
Nicolas Aguirre 2982b05288 Eo: use int for _eo_init_count intsead of Eina_Bool 2015-01-12 14:48:22 +01:00
Avi Levin b384cd3f62 eo: Fix bad addressing in _eo_classes array
The header.id was masked before using it as index in the _eo_classes
array and was not unmasked when used.
It hasn't caused segfault (by sheer luck) but was wrong.

@fix
2015-01-08 14:29:07 +00:00
Jérémy Zurcher 18ceed4daf Eo: protect against recursive object destruction calls, fixes T1741
Summary:
    Eo: semantic obj->del replaced by obj->destructed
    Eo: protect against recursive object destruction calls
    Eo: add tests for bfada4b

Reviewers: JackDanielZ, tasn

Reviewed By: tasn

Subscribers: cedric

Maniphest Tasks: T1741

Differential Revision: https://phab.enlightenment.org/D1675

Fixes T1741

@fix
2014-11-18 15:25:34 +00:00
Tom Hacohen 2cd728373c Eo comp: Remove dead code following the composite fix.
This removes dead code resulting from Cedric's fix:
3550c38080.
2014-10-28 15:19:41 +00:00
Cedric BAIL 3550c38080 eo: fix composite to actually work.
So I don't really understand why the code was not there before, but it resulted
in my experiment of making a combobox for elementary just impossible. Now it
work at least.
2014-10-27 23:44:40 +01:00
Tom Hacohen 01a487d881 Eo composite: Fix composite object functions to be eo functions.
For some reason, they were normal functions instead of eo functions,
which makes them harder to bind, less safe, and just wrong.
This commit fixes that.
2014-10-21 12:37:00 +01:00
Tom Hacohen 5db7a70603 Revert "Revert "Eo: Move eo_add_ref logic inside the library.""
This reverts commit 11da942184.

Can't reproduce with the non-existent bug report, thus have no choice
but consider it as working.
2014-10-10 09:30:52 +01:00
Mike Blumenkrantz 11da942184 Revert "Eo: Move eo_add_ref logic inside the library."
This reverts commit 8d16d8eb57.

this broke child object deletion in all the cases that I tested and regular object deletion in some cases as well
2014-10-09 21:07:30 -04:00
Tom Hacohen 8d16d8eb57 Eo: Move eo_add_ref logic inside the library.
It was a stupid lazy decision to leave it outside. Having it inside is safer
and cleaner.
2014-10-02 15:02:48 +01:00
Tom Hacohen bc6b6aa457 Eo: Better define the relationship of eo_add/del/ref/unref.
Now it's more clear and consistent. This commit complements the previous
eo_add commit (a7560dbc61).

Now eo_add should be matched with eo_del
eo_ref with eo_unref
eo_add_ref with eo_unref + eo_del

Essentially, the change is that if you have the ref to an object, you
need to unref it. Thus making ref/unref unneeded for most people who use
things (carefully) in c. If however, you would like to delete an object
previously created by you, you should eo_del (counter-part to eo_add).

It's still recommended you ref/unref when dealing with objects in
scopes, as you can't know when an object might just get deleted as a
by-product of another call.

This fixes an issue found by JackDanielZ.
2014-09-30 14:53:09 +01:00
Tom Hacohen a7560dbc61 Eo: Change eo_add/del/unref behaviour.
Before this change eo_add() used to create an object with 1 ref, and if
the object had a parent, a second ref.
Now, eo_add() always returns an object with 1 ref, and eo_add_ref()
    preserves the old behaviour (for bindings).

eo_unref now un-parents if refcount is 0, and eo_del() is an alias for
eo_unref (will change to be a way to ensure an object is dead and goes
        to zombie-land even if still refed).
2014-09-25 17:38:45 +01:00
Tom Hacohen b33372b1f6 Eo do: simplify eo_do macro.
This moves the mainloop check inside the function. There was never need
for it to be in client code (i.e a header/macro).
This is better suited inside eo_do_start because this is a macro some
bindings have to re-implement, and we definitely don't want it to be any
more complicated than it has to be.

This breaks ABI and makes elm 1.12 depend on efl 1.11. This is not an issue
as because of eolian and interfaces it's already the case.
2014-09-23 14:36:20 +01:00
Jérémy Zurcher b3ffe9229a eo: call stack depth is 1024 2014-09-23 10:51:05 +02:00
Jérémy Zurcher 389c6d35f2 eo: call stack can grow/shrink when not using mmap
- if HAVE_MMAP call stack do not shrink and abort() when should grow
- otherwise it's a growing/shrinking stack using realloc
2014-09-23 10:47:24 +02:00
Jérémy Zurcher 88c5996dc1 eo: remove stack->max_size
- define EO_CALL_STACK_SIZE instead of stack->max_size
- we are talking about size here not maxsize
2014-09-23 10:43:36 +02:00
Jérémy Zurcher dc3add048f eo: remove XXX, it's ok now ... 2014-09-23 10:41:13 +02:00
Jérémy Zurcher a4c3299f41 eo: unify error msgs 2014-09-23 10:29:44 +02:00
Jérémy Zurcher 95e610d89a eo: call stack remove stack->dropcount
stack->shrink_frame does the same but more efficiently
change the value of EO_CALL_STACK_SHRINK_DROP if needed
2014-09-23 10:26:33 +02:00
Jérémy Zurcher 007efb5f05 eo: fix call stack shrink_frame
- do never shrink under EO_CALL_STACK_DEPTH_MIN size
- set shrink_frame at (current_size/2) - EO_CALL_STACK_SHRINK_OFFSET
2014-09-23 10:24:06 +02:00
Jérémy Zurcher 209a7506c3 eo: remove FIXME: Thread Local Storage
done in d39d7050
2014-09-23 10:21:26 +02:00
Cedric BAIL d86f094d67 eo: do not call eina_tls_get as often when in the main loop.
eina_tls_get is really slow, having a fast path for the main loop does really
help us right now. It is also unlikely that slowing down a little bit the use
of eo in thread is going to have any impact on application speed any time soon.

I win a +10% on expedite benchmark compared to without.

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
2014-09-04 18:11:45 +02:00
Cedric BAIL 68384fc7ef eo: let's be consistent and use the portable flag MAP_ANON. 2014-09-03 17:14:39 +02:00
Tom Hacohen 2a0937b889 Eo base: Add a property to indicate if the object is finalized;
This enables checking if an object is being created, or has already been
finalized. This is useful in functions that you want to allow
only during the creation phase (i.e inside the eo_add()).
2014-08-29 10:26:23 +01:00
Daniel Kolesa 78acf69e20 eo, autotools: check for mmap feature rather than OS (mmap is POSIX) 2014-08-21 11:54:17 +01:00
Jean Guyomarc'h dc8e006e4f eo: mmap()/unmap() are also supported on OSX
Reviewers: raster, raoulh
@feature

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D1240

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
2014-08-21 12:04:53 +02:00
Tom Hacohen 46b3643ff0 Revert "eo: replace composite_objects Eina_List with an array of Eo_Object*"
Comp objects are rare, and since we allow using classes as interfaces,
we end up allocating a lot of memory for something we don't even use.
That's why it was a linked list in the first place, and that's why it
should remain a list.

This is almost a complete revert. I reverted the code itself, and the
intent (use of array instead of list), but not the tests, or the new
return value added to comp_detach, which is useful.

This reverts commit ef09ef7489.
2014-06-13 18:20:24 +01:00
Jean-Philippe Andre 188ffd412c Eo: Fix crash on WIN32 (wrong check for NULL)
Thanks vtorri for the report
2014-06-10 14:57:58 +09:00
Cedric BAIL acc99074d1 eo: force zeroing memory on non Linux system.
@fix
2014-06-09 19:55:40 +02:00
Tom Hacohen 10626ff538 Eo: Fix and use the abstract class .eo file.
Until now it was just there, but never generated or used.
2014-06-03 09:19:19 +01:00
Tom Hacohen f92e5d50f9 Eo: Add eo_finalize. A func that's called at the end of eo_add.
This function lets you hook at the end of eo_add and override it for a
class. This is essentially the first step towards killing custom
constructors. Instead of having a custom constructor, you should just
do:
eo_add(CLASS, parent, a_set(3), b_set("eou"));
eo_constructor is called at the beginning for pre-init things.
eo_finalize is called at the end, for actually finalizing and doing
things. This cleans up the API and possibly saves a lot of things that
would have been stupid and slow in the past, like loading an elm widget
with an existing theme, and then changing the theme.

** This breaks Eo ABI, please recompile elementary and everything else that
creates eo objects.

@feature
2014-05-30 11:22:36 +01:00
Guillaume Friloux 949b51af24 Fix unused param warning when building on non linux. 2014-05-30 10:38:27 +02:00
Jean-Philippe Andre f4a0c8054f Win64: Fix a bunch of warnings
Fix invalid casts.
Use printf("%z") where appropriate.
Fix unused variables warnings.

Thanks vtorri for the patch.

@fix
2014-05-29 20:02:16 +09:00
Jean-Philippe Andre 02f24d76e1 Eo: Add function name to OP desc on Windows
Match function names when the API pointer is out of range.
Reviewed by TAsn and modified according to his comments :)

Differential Revision: https://phab.enlightenment.org/D876
2014-05-21 18:03:53 +09:00
Tom Hacohen 8784685120 Eo: Rename descs2 to descs (remnant of the Eo2 change). 2014-05-09 08:26:25 +01:00
Jérémy Zurcher 0b97c11ea2 eo: improve error reporting, update tests 2014-05-08 13:44:47 +02:00
Jérémy Zurcher 0ce3154656 eo: improve error reporting for _eo_api_op_id_get() 2014-05-08 00:15:53 +02:00
Tom Hacohen e699087521 Eo: fixed misleading indentation. 2014-05-01 13:28:30 +01:00
Carsten Haitzler 1ed6e2cf9c improve eo call stack
it now does up to 8192 entries and madvise unused upper pages when
dropping. also delay dropping to avoi too many syscalls
2014-04-22 20:24:27 +09:00
Carsten Haitzler f21cfc0554 eo - callstack. realloc is a bad idea. use mmap and keep addr fixed
this fixes and eo2 problem where when callstack grows (or shrinks)
and realloc nas to relocate memory, the frame ptrs like fptr become
invalid and all sorts of hell ensues.

this uses mmap so blowing the stack will segv, not scribble over
memory, also its separated from malloc heap, and now big enough to not
need to size ... ever (1024 entries).
2014-04-22 19:19:24 +09:00
Cedric Bail cb43636bd1 eo: do not risk dereferencing NULL.
CID 1199563.
2014-04-17 21:10:34 +02:00
Carsten Haitzler 08484aa646 formatting fix (spacing) 2014-04-17 16:35:43 +09:00
Tom Hacohen d77a7ce468 Eo: eo_do now returns called func's value + default ret fix.
It's now completely valid to do:
a = eo_do(obj, a_get());

or:
b = eo_do(obj, a_set(1), b_get());

Also, the default return value for eo2 functions is now also returned
when the object is invalid, not just when the object does not match
class.

It's a small refactor that fixed both issues at once.

@feature
@fix
2014-04-14 10:54:08 +01:00
Tom Hacohen 68a1f1941a Eo: Fix class checking.
Without this patch, NULL, and random garbage are detected as classes.
This fixes is.
2014-04-14 10:54:08 +01:00
Daniel Zaoui 1a895149e7 Eo: fix warning on printf 2014-04-10 11:42:54 +03:00
Tom Hacohen a77f090256 Eo2: Make internal function static + improved debug output. 2014-04-10 04:20:21 +01:00
Tom Hacohen c32bb4fe95 Eo2: Updated naming Eo2->Eo. 2014-04-10 04:20:21 +01:00
Tom Hacohen 80faa56ed3 Eo2: Removed more Eo1 code. 2014-04-10 04:20:21 +01:00
Tom Hacohen 3c46e7dab8 Eo2: Removed a lot of Eo1 code. 2014-04-10 04:20:21 +01:00
Tom Hacohen 9d332da1f8 Eo2: Adjust to composite object changes. 2014-04-10 04:20:21 +01:00
Jérémy Zurcher d39d705087 eo2: call stack is now thread safe
create/destroy tls key (_eo2_call_stack_key) at eo_init()/eo_shutdown().
use _eo2_call_stack_get() to allocate the stack when required.
register _eo2_call_stack_free() as eina_tls_cb_new() delete callback.
2014-04-10 04:20:21 +01:00
Jérémy Zurcher f812b38a66 eo2: do not allow ill formed class creation
eo_class_new() returns NULL on error in _eo2_class_funcs_set().
it covers: NULL API func, API redefined, dich func override,
overriding non-existing fct.
2014-04-10 04:20:20 +01:00
Jérémy Zurcher 70fe1398fd eo2: if _eo2_class_funcs_set() fails eo_class_new() returns NULL
call to _eo2_class_funcs_set() is moved out of _eo_class_constructor()
into eo_class_new().
2014-04-10 04:20:20 +01:00
Jérémy Zurcher a0d761cfa9 eo2: _eo2_call_resolve() fails if op is EO_NOOP 2014-04-10 04:20:20 +01:00
Jérémy Zurcher 9d2eeb7a8b eo2: improve _eo2_class_funcs_set() errors support
as op descs are sorted, we can't output fct indexes in error msgs, but
as they are sorted using api_fct as key, we can detect multiple usage of
the same api_fct which leads to an unpredictable call to whatever is
returned by _eo2_api_op_id_get()->_eo2_api_desc_get().

it is still possible to instanciate an object of a not well defined class.
2014-04-10 04:20:20 +01:00
Jérémy Zurcher a9c325c124 eo2: normalize ERR msgs 2014-04-10 04:20:20 +01:00
Jérémy Zurcher c506ce2e1f eo2: fix err msg in _dich_func_set() 2014-04-10 04:20:20 +01:00
Jérémy Zurcher 82af591b83 eo2: improve _eo_op_id_name_get() to support eo1/2 2014-04-10 04:20:20 +01:00
Jérémy Zurcher 19245b48f8 eo2: add _eo2_op_id_desc_get() 2014-04-10 04:20:20 +01:00
Jérémy Zurcher e41f2804b4 eo2: improve err msg in _eo2_api_op_id_get() and _eo2_call_resolve() 2014-04-10 04:20:20 +01:00
Jérémy Zurcher 63c271dc5e eo2: fix indentation 2014-04-10 04:20:20 +01:00
Jérémy Zurcher d3cd7cd63c eo2: do not try to unref classes in eo2_do_end() 2014-04-10 04:20:20 +01:00
Jérémy Zurcher 56ae6cf32e eo2: remove memset() in _eo2_do_end() as all stack fields are set in _eo2_do_start() 2014-04-10 04:20:20 +01:00
Jérémy Zurcher adb5b8776d eo2: no need to resolve eo_id when we reuse previous stack frame 2014-04-10 04:20:20 +01:00
Jérémy Zurcher ae536bdd84 eo2: call stack grows and shrinks 2014-04-10 04:20:20 +01:00
Jérémy Zurcher 1834e3ff12 eo2: remove dead code 2014-04-10 04:20:20 +01:00
Tom Hacohen 0dc70153e5 eo2: optimize eo2_do_super func relove a bit.
no need to call dich_func_get twice, just reuse the value previously
fetched.
2014-04-10 04:20:20 +01:00
Tom Hacohen 08aca96bc3 eo2: get rid of eo2_stack_depth_get.
This is super internal, no reason why it should be exposed.

We should just implement automatic stack growth.
2014-04-10 04:20:20 +01:00
Tom Hacohen 2fe10219c0 eo2: prefixed internal functions with _.
This is done to prevent code completion from picking them up.
2014-04-10 04:20:19 +01:00
Tom Hacohen ebae305a9e eo2: fixed validity checks for eo2_do_super.
The class should be checked to be valid and non-null.
This fixes the issues with eo_suite.
2014-04-10 04:20:19 +01:00
Tom Hacohen 1890fdf27f eo2: fixed eo2_do call order.
This fixes the mixin test and general calling order.
"Next class" can only be known per op. That's why super should be
restricted to only one op.
2014-04-10 04:20:19 +01:00
Tom Hacohen d9ceddf63a eo2: fixed formatting. 2014-04-10 04:20:19 +01:00
Tom Hacohen b8ae43b464 eo2: prefix all the eo2_*internal* functions with an underscore.
This prevents them from being auto-completed by IDEs which makes
development nicer.
2014-04-10 04:20:19 +01:00
Tom Hacohen a588c7d99e eo2: correctly handle eo2_do(NULL, ...). 2014-04-10 04:20:19 +01:00
Jérémy Zurcher b08ae598a8 eo2: do not restrict search for api in class extensions to some class types 2014-04-10 04:20:19 +01:00
Jérémy Zurcher ca1f245366 eo2: _eo2_api_desc_get can look into interfaces extensions too 2014-04-10 04:20:19 +01:00
Jérémy Zurcher 541cf25723 eo2: eo2_add_internal_end() return NULL if do_error is set 2014-04-10 04:20:19 +01:00
Jérémy Zurcher 9c1856bf82 eo2: support NULL op_descs 2014-04-10 04:20:19 +01:00
Jérémy Zurcher 11595dc40c eo2: fix mixim elaboration
a mixin class must not inherit
- _eo2_api_desc_get()
      accept NULL klass param
      EO_CLASS_TYPE_REGULAR_NO_INSTANT is an acceptable extension class type for
- _eo2_class_funcs_set() do not shout if parent is NULL
2014-04-10 04:20:18 +01:00