From 3761d8ecf81e825ae318ba1f73f931e87c63b914 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Thu, 12 May 2011 08:28:25 +0000 Subject: [PATCH] Evas Smart: add ability to get usage count SVN revision: 59341 --- legacy/evas/ChangeLog | 6 ++++++ legacy/evas/src/lib/Evas.h | 22 ++++++++++++++++++++++ legacy/evas/src/lib/canvas/evas_smart.c | 10 ++++++++++ 3 files changed, 38 insertions(+) diff --git a/legacy/evas/ChangeLog b/legacy/evas/ChangeLog index 42c387657f..064411e05c 100644 --- a/legacy/evas/ChangeLog +++ b/legacy/evas/ChangeLog @@ -327,3 +327,9 @@ * Textblock: Added evas_textblock_node_format_list_get. This is very useful for edje_entry that uses anchors in the text. + +2011-05-12 Carsten Haitzler (The Rasterman) + + * Add smart instance usage count get function for ability to free + data from memory from a smart class if needed. + diff --git a/legacy/evas/src/lib/Evas.h b/legacy/evas/src/lib/Evas.h index 84676081ab..6589f933c4 100644 --- a/legacy/evas/src/lib/Evas.h +++ b/legacy/evas/src/lib/Evas.h @@ -6708,6 +6708,28 @@ EAPI const Evas_Smart_Cb_Description *evas_smart_callback_description_find(const * using regular memcpy(). */ EAPI Eina_Bool evas_smart_class_inherit_full (Evas_Smart_Class *sc, const Evas_Smart_Class *parent_sc, unsigned int parent_sc_size) EINA_ARG_NONNULL(1, 2); + +/** + * Get the number of users of the smart instance + * + * @param s The Evas_Smart to get the usage count of + * @return The number of uses of the smart instance + * + * This function tells you how many more uses of the smart instance are in + * existance. This should be used before freeing/clearing any of the + * Evas_Smart_Class that was used to create the smart instance. The smart + * instance will refer to data in the Evas_Smart_Class used to create it and + * thus you cannot remove the original data until all users of it are gone. + * When the usage count goes to 0, you can evas_smart_free() the smart + * instance @p s and remove from memory any of the Evas_Smart_Class that + * was used to create the smart instance, if you desire. Removing it from + * memory without doing this will cause problems (crashes, undefined + * behavior etc. etc.), so either never remove the original + * Evas_Smart_Class data from memory (have it be a constant structure and + * data), or use this API call and be very careful. + */ +EAPI int evas_smart_usage_get(const Evas_Smart *s); + /** * @def evas_smart_class_inherit * Easy to use version of evas_smart_class_inherit_full(). diff --git a/legacy/evas/src/lib/canvas/evas_smart.c b/legacy/evas/src/lib/canvas/evas_smart.c index 44cf9a0c04..eb48bb8576 100644 --- a/legacy/evas/src/lib/canvas/evas_smart.c +++ b/legacy/evas/src/lib/canvas/evas_smart.c @@ -112,6 +112,16 @@ evas_smart_class_inherit_full(Evas_Smart_Class *sc, const Evas_Smart_Class *pare return 1; } +EAPI int +evas_smart_usage_get(const Evas_Smart *s) +{ + MAGIC_CHECK(s, Evas_Smart, MAGIC_SMART); + return 0; + MAGIC_CHECK_END(); + return s->usage; +} + + /* internal funcs */ void evas_object_smart_use(Evas_Smart *s)