From: Volker D. <v.d...@we...> - 2004-07-21 07:34:04
|
Ethan Merritt wrote: > Consider a typical call site, one of the 98 you counted: > > set.c (set_fontpath) line 1801: > > if (isstring(c_token)) { > int len; > char *ss = gp_alloc(token_len(c_token), "tmp storage"); > len = (collect? strlen(collect) : 0); > quote_str(ss,c_token,token_len(c_token)); > collect = gp_realloc(collect, len+1+strlen(ss)+1, "tmp fontpath"); > > I am not clever enough to re-write isstring() and quote_str() such > that the code at this call site works when the length of the string > changes mid-stream. So trying to be clever in isstring() and > quote_str() paradoxically makes *more* work, since every call site > would have to be inspected and re-written for compatibility. > Yes, but this I think this is easy: I took a look at my old `value substitution` patch (the python like syntax of "%(foo).2f"): There are two functions: quote_str and m_quote_capture. Using quote_str you will have to do memory allocation yourself, whereas m_quote_capture will do allocation for you if I remember correctly. My old patch replaced (hopfully) all the invocations of quote_str with m_quote_capture and did substitution there. > If the program were being re-written from scratch, then yes. > But in the interest of sanity and not introducing 98 possible > new bug sites, I would rather go for a solution that leaves the > input code intact ... > I think 98 sites which do memory allocation themself is more dangerous than replacing 98 call sites with one tested and correct call to m_quote_capture. Regarding the discussion about late evaluation: I would like to _object_ to late evaluation. Late evaluation will intruduce much more problems in user space than it will solve. If I construct a string (regardless if done by the '' + trick or sprintf or anyting else) I expect it to be the way I constructed it; at least that's the behavior of all programming languages I am familiar with. I do not see any problem which could be solved easier with late evaluation, at least not from user side: It is very easy to reconstruct the string if a variable change should be reflected in the string. IMHO the substitution should be done right during parsing, no late evaluation and m_quote_capture is a good place for it. Volker -- Volker Dobler _______________________________________________________ WEB.DE Video-Mail - Sagen Sie mehr mit bewegten Bildern Informationen unter: http://freemail.web.de/?mc=021199 |