Re: [pypy-dev] Declaring a function that returns a string in CFFI

2014-09-26 Thread Vincent Legoll
Hello, maybe the code above / inside getstring already knows that string length, and you could exploit that fact to avoid the strlen calculation... On Fri, Sep 26, 2014 at 6:51 PM, Armin Rigo wrote: > Hi, > > On 25 September 2014 16:57, Eleytherios Stamatogiannakis > wrote: > > Wouldn't an "st

Re: [pypy-dev] Declaring a function that returns a string in CFFI

2014-09-26 Thread Armin Rigo
Hi, On 25 September 2014 16:57, Eleytherios Stamatogiannakis wrote: > Wouldn't an "strbuffer" that does this scan (opportunistically) be faster > for cases like above? No, it can't be faster than my last solution. There is no way we're going to add custom logic for a special case into the gener

Re: [pypy-dev] Declaring a function that returns a string in CFFI

2014-09-25 Thread Eleytherios Stamatogiannakis
On 25/09/14 15:10, Armin Rigo wrote: Hi, On 25 September 2014 09:06, Elefterios Stamatogiannakis wrote: Unfortunately, the C library that i use (libsqlite3) does not provide a function like that :( . It has a function that returns the size of the string, but in my tests the overhead of doing a

Re: [pypy-dev] Declaring a function that returns a string in CFFI

2014-09-25 Thread Armin Rigo
Hi, On 25 September 2014 09:06, Elefterios Stamatogiannakis wrote: > Unfortunately, the C library that i use (libsqlite3) does not provide a > function like that :( . It has a function that returns the size of the > string, but in my tests the overhead of doing another CFFI call (to find the > si

Re: [pypy-dev] Declaring a function that returns a string in CFFI

2014-09-25 Thread Elefterios Stamatogiannakis
On 24/09/14 20:13, Armin Rigo wrote: Hi, On 23 September 2014 14:54, Eleytherios Stamatogiannakis wrote: p = clib.getString(...)# a "char *" length = clib.strlen(p) # the standard strlen() function from C b = unicode(ffi.buffer(p, length), 'utf-8') I've tried that, and the overhe

Re: [pypy-dev] Declaring a function that returns a string in CFFI

2014-09-24 Thread Armin Rigo
Hi, On 23 September 2014 14:54, Eleytherios Stamatogiannakis wrote: >> p = clib.getString(...)# a "char *" >> length = clib.strlen(p) # the standard strlen() function from C >> b = unicode(ffi.buffer(p, length), 'utf-8') > > I've tried that, and the overhead of the second call is more

Re: [pypy-dev] Declaring a function that returns a string in CFFI

2014-09-23 Thread Yichao Yu
On Tue, Sep 23, 2014 at 8:54 AM, Eleytherios Stamatogiannakis < est...@gmail.com> wrote: > On 23/09/14 09:52, Armin Rigo wrote: > >> Hi Lefteris, >> >> On 22 September 2014 19:37, Eleytherios Stamatogiannakis >> wrote: >> >>> b = unicode( ffi.buffer( clib.getString(...) ) ,'utf-8') >>> >>> becaus

Re: [pypy-dev] Declaring a function that returns a string in CFFI

2014-09-23 Thread Eleytherios Stamatogiannakis
On 23/09/14 09:52, Armin Rigo wrote: Hi Lefteris, On 22 September 2014 19:37, Eleytherios Stamatogiannakis wrote: b = unicode( ffi.buffer( clib.getString(...) ) ,'utf-8') because it'll only return the first character of getString, due to being declared as a 'char*'. The issue is only that f

Re: [pypy-dev] Declaring a function that returns a string in CFFI

2014-09-22 Thread Armin Rigo
Hi Lefteris, On 22 September 2014 19:37, Eleytherios Stamatogiannakis wrote: > b = unicode( ffi.buffer( clib.getString(...) ) ,'utf-8') > > because it'll only return the first character of getString, due to being > declared as a 'char*'. The issue is only that ffi.buffer() tries to guess how lon