I'm just guessing (that long function is a bit much for me to look  
over in depth at the moment), but it could be that you need to do this:
Change:
#define WHPRINTF_RETURN if( zExtra ) free(zExtra); return ResultString

To:
#define WHPRINTF_RETURN if( zExtra ) free(zExtra); return  
sentry.Close(ResultString);


But if I recall, you don't actually need handle scopes inside function  
callbacks (some people mentioned that v8 already had them in these  
situations, which makes sense), so the point may be moot. Other than  
that, you are probably handling memory alright; you aren't using  
persistent handles, and the handle scope is taken care of, so v8-wise,  
you shouldn't be leaking.

If you don't know what HandleScope::Close() does, I think I cover it  
in http://create.tpsitulsa.com/wiki/V8/Handles#Escaping_Scope , under  
"Escaping Scope."

Hope that helps,

Alex



On Mar 3, 2009, at 4:21 PM, Stephan Beal wrote:

>
> Hi, all!
>
> Just committed to the source tree: an implementation of sprintf() for
> JS. While much, in terms of string formatting, can be achieved via
> straightforward string concatenation in JS, sprintf() gives a bit more
> control in some situations (e.g. padding numbers and specifying the
> number of decimal places to output).
>
> The back-end is a much-hacked version of the public domain printf()
> implementation from the sqlite3 source tree. i've been using a variant
> of it quite heavily in other projects for over a year and i believe it
> to work quite well. It also inherits some formatting extensions from
> its sqlite3 heritage, like escaping HTML and SQL, and URL encoding/
> decoding.
>
> (Despite the sqlite3 source heritage, snprintf() does not need sqlite3
> to work.)
>
> The source repo is available via:
>
> http://wanderinghorse.net/computing/javascript/v8/
>
> To use this in your own code:
>
> the tarball i'll post on the above page in the next 1-2 hours will
> include this code (it'll have the version 20090304). It can be used
> standalone (it's independent of the other code in the tarball): fish
> out the files addons/v8-sprintf.cc and addons/include/v8/v8-sprintf.h.
>
> :)
>
> Example:
>
> {{{
> var obj = {hi:32};
> print(sprintf("hi, %s!","world"));
> print(sprintf("hi, %s!", obj));
> print(sprintf("%d %05d", 42, 42));
> }}}
>
> step...@jareth:~/cvs/fossil/v8-addons/addons$ ./shell js/sprintf.js
> hi, world!
> hi, [object Object]!
> 42 00042
>
>
> i would very much appreciate it if someone skilled in the ways of v8's
> garbage collection would look it over: just the sprintf() function
> itself, not the ancient, C-oriented framework around it (grep for
> NEXT_ARG). i have an odd feeling i'm failing to follow some important
> memory guideline or other. When i just slap a HandleScope in it, i get
> segfaults when the function exits.
>
> Happy hacking!
>
> --
> ----- stephan beal
> http://wanderinghorse.net/home/stephan/
>
>
> >

Alex Iskander, TPSi





--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to