[svn:parrot] r46146 - in trunk: include/parrot src src/string t/op

petdance at svn.parrot.org petdance at svn.parrot.org
Thu Apr 29 16:42:58 UTC 2010


Author: petdance
Date: Thu Apr 29 16:42:58 2010
New Revision: 46146
URL: https://trac.parrot.org/parrot/changeset/46146

Log:
Disallow NULLs in string_ord, and fix const and ARGMOD on Parrot_sprintf_format

Modified:
   trunk/include/parrot/misc.h
   trunk/include/parrot/string_funcs.h
   trunk/src/spf_render.c
   trunk/src/string/api.c
   trunk/t/op/string.t

Modified: trunk/include/parrot/misc.h
==============================================================================
--- trunk/include/parrot/misc.h	Thu Apr 29 16:04:46 2010	(r46145)
+++ trunk/include/parrot/misc.h	Thu Apr 29 16:42:58 2010	(r46146)
@@ -306,11 +306,12 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 STRING * Parrot_sprintf_format(PARROT_INTERP,
-    ARGIN(STRING *pat),
-    ARGIN(SPRINTF_OBJ *obj))
+    ARGIN(const STRING *pat),
+    ARGMOD(SPRINTF_OBJ *obj))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2)
-        __attribute__nonnull__(3);
+        __attribute__nonnull__(3)
+        FUNC_MODIFIES(*obj);
 
 #define ASSERT_ARGS_Parrot_sprintf_format __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \

Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h	Thu Apr 29 16:04:46 2010	(r46145)
+++ trunk/include/parrot/string_funcs.h	Thu Apr 29 16:42:58 2010	(r46146)
@@ -431,8 +431,9 @@
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
-INTVAL string_ord(PARROT_INTERP, ARGIN_NULLOK(const STRING *s), INTVAL idx)
-        __attribute__nonnull__(1);
+INTVAL string_ord(PARROT_INTERP, ARGIN(const STRING *s), INTVAL idx)
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
 
 PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
@@ -604,7 +605,8 @@
 #define ASSERT_ARGS_string_max_bytes __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(s))
 #define ASSERT_ARGS_string_ord __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(interp))
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(s))
 #define ASSERT_ARGS_string_primary_encoding_for_representation \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))

Modified: trunk/src/spf_render.c
==============================================================================
--- trunk/src/spf_render.c	Thu Apr 29 16:04:46 2010	(r46145)
+++ trunk/src/spf_render.c	Thu Apr 29 16:42:58 2010	(r46146)
@@ -309,8 +309,8 @@
 
 /*
 
-=item C<STRING * Parrot_sprintf_format(PARROT_INTERP, STRING *pat, SPRINTF_OBJ
-*obj)>
+=item C<STRING * Parrot_sprintf_format(PARROT_INTERP, const STRING *pat,
+SPRINTF_OBJ *obj)>
 
 This is the engine that does all the formatting.
 
@@ -321,8 +321,7 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 STRING *
-Parrot_sprintf_format(PARROT_INTERP,
-        ARGIN(STRING *pat), ARGIN(SPRINTF_OBJ *obj))
+Parrot_sprintf_format(PARROT_INTERP, ARGIN(const STRING *pat), ARGMOD(SPRINTF_OBJ *obj))
 {
     ASSERT_ARGS(Parrot_sprintf_format)
     INTVAL i;

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Thu Apr 29 16:04:46 2010	(r46145)
+++ trunk/src/string/api.c	Thu Apr 29 16:42:58 2010	(r46146)
@@ -882,12 +882,17 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 INTVAL
-string_ord(PARROT_INTERP, ARGIN_NULLOK(const STRING *s), INTVAL idx)
+string_ord(PARROT_INTERP, ARGIN(const STRING *s), INTVAL idx)
 {
     ASSERT_ARGS(string_ord)
-    const UINTVAL len        = s ? Parrot_str_byte_length(interp, s) : 0;
+    UINTVAL len;
     UINTVAL       true_index = (UINTVAL)idx;
 
+    if (STRING_IS_NULL(s))
+        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);
     if (len == 0)
         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ORD_OUT_OF_STRING,
             "Cannot get character of empty string");

Modified: trunk/t/op/string.t
==============================================================================
--- trunk/t/op/string.t	Thu Apr 29 16:04:46 2010	(r46145)
+++ trunk/t/op/string.t	Thu Apr 29 16:42:58 2010	(r46146)
@@ -695,7 +695,7 @@
    ord $I0,$S0
    ok( 0, 'no exception: 2-param ord, empty string register' )
  handler:
-   .exception_is( 'Cannot get character of empty string' )
+   .exception_is( 'Cannot get character of NULL string' )
 .end
 
 .sub exception_three_param_ord_empty_string
@@ -711,7 +711,7 @@
    ord $I0,$S0,0
    ok( 0, 'no exception: 3-param ord, empty string register' )
  handler:
-   .exception_is( 'Cannot get character of empty string' )
+   .exception_is( 'Cannot get character of NULL string' )
 .end
 
 .sub two_param_ord_one_character_string


More information about the parrot-commits mailing list