subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject svn commit: r1130512 - in /subversion/trunk/subversion: include/svn_string.h libsvn_subr/svn_string.c
Date Thu, 02 Jun 2011 12:24:36 GMT
Author: stefan2
Date: Thu Jun  2 12:24:36 2011
New Revision: 1130512

URL: http://svn.apache.org/viewvc?rev=1130512&view=rev
Log:
Finally, make svn_string_from_stringbuf useful: This kind of conversion
usually takes place at the end of some internal processing using variable
sized strings and then returning a fixed-size result. So, it is acceptable
to "consume" the source svn_stringbuf_t.

* subversion/include/svn_string.h
  (svn_string_from_stringbuf): switch interface to modifiable structs
* subversion/libsvn_subr/svn_string.c
  (svn_string_from_stringbuf): make it harder to mis-use in debug mode;
   adapt to API change

Modified:
    subversion/trunk/subversion/include/svn_string.h
    subversion/trunk/subversion/libsvn_subr/svn_string.c

Modified: subversion/trunk/subversion/include/svn_string.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_string.h?rev=1130512&r1=1130511&r2=1130512&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_string.h (original)
+++ subversion/trunk/subversion/include/svn_string.h Thu Jun  2 12:24:36 2011
@@ -179,10 +179,11 @@ svn_string_find_char_backward(const svn_
 
 /** Returns the @a svn_string_t information contained in the data and
  * len members of @a strbuf. This is effectively a typecast, converting
- * @a strbuf into an svn_string_t.
+ * @a strbuf into an svn_string_t. This first will become invalid and must
+ * not be accessed after this function returned.
  */
-const svn_string_t *
-svn_string_from_stringbuf(const svn_stringbuf_t *strbuf);
+svn_string_t *
+svn_string_from_stringbuf(svn_stringbuf_t *strbuf);
 /** @} */
 
 

Modified: subversion/trunk/subversion/libsvn_subr/svn_string.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/svn_string.c?rev=1130512&r1=1130511&r2=1130512&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/svn_string.c (original)
+++ subversion/trunk/subversion/libsvn_subr/svn_string.c Thu Jun  2 12:24:36 2011
@@ -235,9 +235,16 @@ svn_string_find_char_backward(const svn_
   return find_char_backward(str->data, str->len, ch);
 }
 
-const svn_string_t *
-svn_string_from_stringbuf(const svn_stringbuf_t *strbuf)
+svn_string_t *
+svn_string_from_stringbuf(svn_stringbuf_t *strbuf)
 {
+  /* In debug mode, detect attempts to modify the original STRBUF object.
+   */
+#ifdef SVN_DEBUG
+  strbuf->pool = NULL;
+  strbuf->blocksize = strbuf->len;
+#endif
+
   /* Both, svn_string_t and svn_stringbuf_t are public API structures
    * since a couple of releases now. Thus, we can rely on their precise
    * layout not to change.
@@ -246,13 +253,12 @@ svn_string_from_stringbuf(const svn_stri
    * to the (data, len) sub-set of svn_stringbuf_t. There is also no
    * difference in alignment and padding. So, we can just re-interpret
    * that part of STRBUF as a svn_string_t.
-   * 
+   *
    * However, since svn_string_t does not know about the blocksize
-   * member in svn_stringbuf_t, the returned svn_string_t must not
-   * try to re-allocate its data member. It would possibly be inconsistent
-   * with STRBUF's blocksize member. Hence, the result is a const
-   * structure.
-   * 
+   * member in svn_stringbuf_t, any attempt to re-size the returned
+   * svn_string_t might invalidate the STRBUF struct. Hence, we consider
+   * the source STRBUF "consumed".
+   *
    * Modifying the string character content is fine, though.
    */
   return (const svn_string_t *)&strbuf->data;



Mime
View raw message