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)

// </smpl>



Lucas De Marchi

------------------------------------------------------------------------------
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