On Tue, Oct 19, 2010 at 10:08 AM, Lucas De Marchi
<lucas.demar...@profusion.mobi> wrote:
> On Tue, Oct 19, 2010 at 9:54 AM, Gustavo Sverzut Barbieri
> <barbi...@profusion.mobi> wrote:
>> I guess it's hard if not impossible to know for sure, unfortunately we
>> have no way to tell from a const char* if it came from stringshare or
>> regular malloc :-/
>
>
> What about the following first attempt of a semantic patch? The
> assumption here is that if a pointer is used once as stringshare
> (therefore there's a call to eina_stringshare_add()) it will always be
> used as stringshare. It seems reasonable to me... I didn't check if it
> works across different compilation units though and it misses the case
> where the pointer is the return value of a function returning a
> stringshare (possibly just using eina_stringshare_ref()).
>
> It might not get all cases, but I can't think in a case where it would
> have a false positive. If anyone is interested in learning Coccinelle
> (there were so many at irc asking me about this), this is a good start
> point.
>
>
> // <smpl>
> // Prefer the use of eina_stringshare_strlen() over strlen()
> //
> // If a string is stringshared, use eina_stringshare_strlen() that is O(1)
> // instead of strlen();
> //
>
> @r1@
> expression x;
> @@
>
> x = eina_stringshare_add(...)
>
> @r2@
> expression r1.x;
> @@
> - strlen(x)
> + eina_stringshare_strlen(x)

This seems good, but would it handle the following cases?

1.

void name_set(struct my_struct *p, const char *name) {
    eina_stringshare_replace(&p->str, name); // could be a simple
eina_stringshare_add() as well
}
const char *name_get(const struct my_struct *p) {
    return p->str;
}
Eina_Bool use_it(const struct my_struct *p) {
     return strlen(p->str) % 2; // should be eina_stringshare_strlen()
}


2.
Eina_Bool use_it(const char *s) {
     return strlen(x) % 2; // should not be eina_stringshare_strlen()
}

use_it(name_get(p));
use_it("hello");

-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbi...@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202

------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to