Re: Patch for Scintillua style handling

"'Neil Hodgson' via scite-interest" <[email protected]>
Newsgroups gmane.editors.scite.general
Message-ID <[email protected]>
Mitchell:

> Before returning the name of a style, my Scintillua lexer stores it inside its own std::string and returns the c_str(), which is guaranteed to exist until the next call to NameOfStyle. Therefore, I didn't think lifetime was an issue here, as it is for most char* returns. If you prefer to use std::string, then that's fine with me.

   Its already using std::string. This is going through ScintillaCall,

std::string ScintillaCall::NameOfStyle(int style) {
    return CallReturnString(Message::NameOfStyle, style);
}

   This invokes CallReturnString which finds the string length then allocates a std::string and copies the value. Its calling your lexer twice. So, a std::string is being allocated, making a copy of the string from the Scintillua lexer and this new std::string is returned as a temporary to the caller. As Csaba points out, its OK to take a const reference to this temporary as the temporary's lifetime is extended.

   ScintillaCall also has a 2 argument form (int, char *) for copying into an already allocated buffer but that should be avoided as its safer to treat strings as values. I should convert more of the code in property handling to use std::string and avoid the potential for bugs with fixed size buffers.

   Neil

-- 
You received this message because you are subscribed to the Google Groups "scite-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/scite-interest/C9CC4891-E4B3-439B-8C13-4B19A2A8B690%40me.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.