Last Comment Bug 288786 - Add BeginWriting equivalent to frozen string API
: Add BeginWriting equivalent to frozen string API
Product: Core
Classification: Components
Component: String (show other bugs)
: Trunk
: All All
P1 enhancement (vote)
: mozilla1.8beta2
Assigned To: Darin Fisher
: Nathan Froyd [:froydnj]
: 242577 (view as bug list)
Depends on:
  Show dependency treegraph
Reported: 2005-04-02 11:30 PST by Benjamin Smedberg [:bsmedberg]
Modified: 2005-09-01 17:50 PDT (History)
4 users (show)
benjamin: blocking‑aviary1.5+
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

v1 patch (19.90 KB, patch)
2005-04-04 16:27 PDT, Darin Fisher
cbiesinger: review+
dbaron: superreview+
asa: approval1.8b2+
Details | Diff | Splinter Review

Description User image Benjamin Smedberg [:bsmedberg] 2005-04-02 11:30:21 PST
We need to add an equivalent for BeginWriting to the frozen string API for gecko
1.8.  Darin, if you won't have time for this reassign it back to me.
Comment 1 User image Darin Fisher 2005-04-02 11:37:40 PST
Yeah, this is something I really want to do as well.

This means adding NS_C?StringGetMutableData (or something like that) to the
frozen XPCOM exports.
Comment 2 User image Darin Fisher 2005-04-02 11:38:38 PST
We may also want a way to set the string buffer length.
Comment 3 User image Christian :Biesinger (don't email me, ping me on IRC) 2005-04-02 12:03:56 PST
(In reply to comment #2)
> We may also want a way to set the string buffer length.

Why not make that a single function?
Comment 4 User image Darin Fisher 2005-04-02 20:16:28 PST
Yes, that is exactly my plan.  Here's my suggestion:

  NS_StringGetMutableData(nsAString &aStr,
                          PRUint32 aDataLength,
                          PRUnichar **aData);

The idea here is that you could pass PR_UINT32_MAX as aDataLength to indicate
that you want the current length of the string.  The length of the data buffer
returned by aData is indicated by the return value of this function.  If the
function fails because it could not allocate memory, then aData is set to null,
and the function returns 0 or maybe PR_UINT32_MAX (not sure about what the
function should return if unable to allocate memory).

At any rate, I'm leaning toward this function signature over one that returns
the buffer itself for consistency (somewhat) with NS_StringGetData.

Comment 5 User image Benjamin Smedberg [:bsmedberg] 2005-04-03 08:20:29 PDT
Sounds fine, and it should return 0 if allocation was unsuccessful.
Comment 6 User image Darin Fisher 2005-04-03 13:18:42 PDT
Here's what I have so far:

 * NS_StringGetMutableData
 * This function provides mutable access to a string's internal buffer.  It
 * returns a pointer to an array of characters that may be modified.  The
 * returned pointer remains valid until the string object is passed to some
 * other string function.
 * Optionally, this function may be used to resize the string's internal
 * buffer.  The aDataLength parameter specifies the requested length of the
 * string's internal buffer.  By passing some value other than PR_UINT32_MAX,
 * the caller can request that the buffer be resized to the specified number of
 * characters before returning.  The caller is not responsible for writing
 * null-terminator.
 * @param aStr          abstract string reference
 * @param aDataLength   number of characters to resize the string's internal
 *                      buffer to or PR_UINT32_MAX if no resizing is needed
 * @param aData         out param that upon return holds the address of aStr's
 *                      internal buffer or null if the function failed
 * @return              number of characters or zero if the function failed
  (nsAString &aStr, PRUint32 aDataLength, PRUnichar **aData);

If you see any problems with this, please let me know.
Comment 7 User image Darin Fisher 2005-04-04 16:27:28 PDT
Created attachment 179628 [details] [diff] [review]
v1 patch
Comment 8 User image Christian :Biesinger (don't email me, ping me on IRC) 2005-04-05 11:45:15 PDT
Comment on attachment 179628 [details] [diff] [review]
v1 patch

+  return begin.size_forward();

that does not include the null terminator, right?

(hrm, this file has a lot of functions that only differ in data type. could we
use some template functions to avoid code duplication, at least source-wise?
not for this bug, certainly)
Comment 9 User image David Baron :dbaron: ⌚️UTC-8 2005-04-22 18:14:47 PDT
Comment on attachment 179628 [details] [diff] [review]
v1 patch

>Index: stub/nsXPComStub.cpp
>     &NS_Alloc_P,
>     &NS_Realloc_P,
>     &NS_Free_P,
>     &NS_StringContainerInit2_P,
>-    &NS_CStringContainerInit2_P
>+    &NS_CStringContainerInit2_P,
>+    &NS_StringGetMutableData,
>+    &NS_CStringGetMutableData

Any reason these don't use _P ?

Other than that, sr=dbaron.
Comment 10 User image Darin Fisher 2005-04-22 21:23:45 PDT
whoops.. yes!  thank you for catching that mistake.
Comment 11 User image Darin Fisher 2005-04-22 21:24:10 PDT
Comment on attachment 179628 [details] [diff] [review]
v1 patch

This is a new API that would be nice to have in the developer preview.
Comment 12 User image Asa Dotzler [:asa] 2005-04-23 23:59:45 PDT
Comment on attachment 179628 [details] [diff] [review]
v1 patch

Comment 13 User image Darin Fisher 2005-04-26 18:38:40 PDT
Comment 14 User image Darin Fisher 2005-09-01 17:50:24 PDT
*** Bug 242577 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.