[svn:parrot] r46371 - in trunk: include/parrot src/ops src/string

NotFound at svn.parrot.org NotFound at svn.parrot.org
Thu May 6 21:23:24 UTC 2010


Author: NotFound
Date: Thu May  6 21:23:24 2010
New Revision: 46371
URL: https://trac.parrot.org/parrot/changeset/46371

Log:
some sanity in Parrot_str_length and Parrot_str_byte_length meaning and usages

Modified:
   trunk/include/parrot/string_funcs.h
   trunk/src/ops/string.ops
   trunk/src/string/api.c

Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h	Thu May  6 20:53:51 2010	(r46370)
+++ trunk/include/parrot/string_funcs.h	Thu May  6 21:23:24 2010	(r46371)
@@ -236,8 +236,7 @@
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
-INTVAL Parrot_str_length(SHIM_INTERP, ARGIN(const STRING *s))
-        __attribute__nonnull__(2);
+INTVAL Parrot_str_length(SHIM_INTERP, ARGIN_NULLOK(const STRING *s));
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
@@ -550,8 +549,7 @@
 #define ASSERT_ARGS_Parrot_str_join __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(ar))
-#define ASSERT_ARGS_Parrot_str_length __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(s))
+#define ASSERT_ARGS_Parrot_str_length __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_Parrot_str_new __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_str_new_constant __attribute__unused__ int _ASSERT_ARGS_CHECK = (\

Modified: trunk/src/ops/string.ops
==============================================================================
--- trunk/src/ops/string.ops	Thu May  6 20:53:51 2010	(r46370)
+++ trunk/src/ops/string.ops	Thu May  6 21:23:24 2010	(r46371)
@@ -184,19 +184,11 @@
 =cut
 
 inline op length(out INT, in STR) :base_mem {
-    $1 = $2 ? Parrot_str_byte_length(interp, $2) : 0;
+    $1 = Parrot_str_length(interp, $2);
 }
 
 inline op bytelength(out INT, in STR) :base_mem {
-    UINTVAL n;
-    const STRING * const s = $2;
-    if (STRING_IS_NULL(s))
-        n = 0;
-    else {
-        n = s->bufused;
-        PARROT_ASSERT(n == ENCODING_BYTES(interp, $2));
-    }
-    $1 = n;
+    $1 = Parrot_str_byte_length(interp, $2);
 }
 
 

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Thu May  6 20:53:51 2010	(r46370)
+++ trunk/src/string/api.c	Thu May  6 21:23:24 2010	(r46371)
@@ -427,7 +427,7 @@
     /* XXX should this be a CHARSET method? */
 
     /* If B isn't real, we just bail */
-    const UINTVAL b_len = b ? Parrot_str_byte_length(interp, b) : 0;
+    const UINTVAL b_len = b ? Parrot_str_length(interp, b) : 0;
     if (!b_len)
         return STRING_IS_NULL(a) ? STRINGNULL : Parrot_str_copy(interp, a);
 
@@ -797,7 +797,7 @@
 {
     ASSERT_ARGS(Parrot_str_byte_length)
 
-    return STRING_IS_NULL(s) ? 0 : s->strlen;
+    return STRING_IS_NULL(s) ? 0 : s->bufused;
 }
 
 
@@ -852,7 +852,7 @@
     if (start < 0)
         return -1;
 
-    len = Parrot_str_byte_length(interp, s);
+    len = Parrot_str_length(interp, s);
 
     if (!len)
         return -1;
@@ -860,7 +860,7 @@
     if (start >= (INTVAL)len)
         return -1;
 
-    if (!Parrot_str_byte_length(interp, s2))
+    if (!Parrot_str_length(interp, s2))
         return -1;
     else {
         DECL_CONST_CAST;
@@ -896,7 +896,7 @@
         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ORD_OUT_OF_STRING,
             "Cannot get character of NULL string");
 
-    len = Parrot_str_byte_length(interp, s);
+    len = Parrot_str_length(interp, s);
     if (len == 0)
         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ORD_OUT_OF_STRING,
             "Cannot get character of empty string");
@@ -959,7 +959,7 @@
 
 =item C<INTVAL Parrot_str_length(PARROT_INTERP, const STRING *s)>
 
-Calculates and returns the number of characters in the specified Parrot string.
+Returns the number of characters in the specified Parrot string.
 
 =cut
 
@@ -968,11 +968,11 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 INTVAL
-Parrot_str_length(SHIM_INTERP, ARGIN(const STRING *s))
+Parrot_str_length(SHIM_INTERP, ARGIN_NULLOK(const STRING *s))
 {
     ASSERT_ARGS(Parrot_str_length)
 
-    return s->strlen;
+    return STRING_IS_NULL(s) ? 0 : s->strlen;
 }
 
 
@@ -1068,7 +1068,7 @@
     ASSERT_STRING_SANITY(src);
 
     /* Allow regexes to return $' easily for "aaa" =~ /aaa/ */
-    if (offset == (INTVAL)Parrot_str_byte_length(interp, src) || length < 1)
+    if (offset == (INTVAL)Parrot_str_length(interp, src) || length < 1)
         return Parrot_str_new_noinit(interp, enum_stringrep_one, 0);
 
     if (offset < 0)
@@ -3096,12 +3096,12 @@
 
     res  = Parrot_pmc_new(interp,
             Parrot_get_ctx_HLL_type(interp, enum_class_ResizableStringArray));
-    slen = Parrot_str_byte_length(interp, str);
+    slen = Parrot_str_length(interp, str);
 
     if (!slen)
         return res;
 
-    dlen = Parrot_str_byte_length(interp, delim);
+    dlen = Parrot_str_length(interp, delim);
 
     if (dlen == 0) {
         int i;
@@ -3129,7 +3129,7 @@
         STRING * const tstr = Parrot_str_substr(interp, str, ps, pl);
 
         VTABLE_push_string(interp, res, tstr);
-        ps = pe + Parrot_str_byte_length(interp, delim);
+        ps = pe + Parrot_str_length(interp, delim);
 
         if (ps > slen)
             break;


More information about the parrot-commits mailing list