[svn:parrot] r49429 - in trunk: docs/pdds include/parrot src src/ops src/pmc src/string

nwellnhof at svn.parrot.org nwellnhof at svn.parrot.org
Sun Oct 3 01:25:10 UTC 2010


Author: nwellnhof
Date: Sun Oct  3 01:25:09 2010
New Revision: 49429
URL: https://trac.parrot.org/parrot/changeset/49429

Log:
[str] Prepare deprecation of string_* functions

Modified:
   trunk/docs/pdds/pdd28_strings.pod
   trunk/include/parrot/string_funcs.h
   trunk/src/extend.c
   trunk/src/library.c
   trunk/src/ops/core_ops.c
   trunk/src/ops/string.ops
   trunk/src/pmc/string.pmc
   trunk/src/spf_render.c
   trunk/src/string/api.c

Modified: trunk/docs/pdds/pdd28_strings.pod
==============================================================================
--- trunk/docs/pdds/pdd28_strings.pod	Sun Oct  3 00:56:09 2010	(r49428)
+++ trunk/docs/pdds/pdd28_strings.pod	Sun Oct  3 01:25:09 2010	(r49429)
@@ -403,6 +403,10 @@
 of the string). Combining characters are counted separately. Variable-width
 encodings will lookahead to capture full character values.
 
+=head4 Parrot_str_chr (was string_chr)
+
+Returns a single character string from a codepoint.
+
 =head4 Parrot_str_grapheme_indexed
 
 Returns the grapheme at the given index (the Nth grapheme from the string's
@@ -554,8 +558,7 @@
 
 =head4 string_chr
 
-This is handled just fine by C<Parrot_str_new>, we don't need a special
-version for a single character.
+Replaced by C<Parrot_str_chr>.
 
 =head4 make_writable
 

Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h	Sun Oct  3 00:56:09 2010	(r49428)
+++ trunk/include/parrot/string_funcs.h	Sun Oct  3 01:25:09 2010	(r49429)
@@ -87,6 +87,12 @@
         __attribute__nonnull__(2);
 
 PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+STRING * Parrot_str_chr(PARROT_INTERP, UINTVAL character)
+        __attribute__nonnull__(1);
+
+PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 INTVAL Parrot_str_compare(PARROT_INTERP,
     ARGIN_NULLOK(const STRING *s1),
@@ -408,13 +414,6 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
-STRING * string_increment(PARROT_INTERP, ARGIN(const STRING *s))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2);
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
 STRING * string_make(PARROT_INTERP,
     ARGIN_NULLOK(const char *buffer),
     UINTVAL len,
@@ -424,12 +423,6 @@
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
-PARROT_PURE_FUNCTION
-INTVAL string_max_bytes(SHIM_INTERP, ARGIN(const STRING *s), UINTVAL nchars)
-        __attribute__nonnull__(2);
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
 INTVAL string_ord(PARROT_INTERP, ARGIN(const STRING *s), INTVAL idx)
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
@@ -508,6 +501,8 @@
 #define ASSERT_ARGS_Parrot_str_chopn __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(s))
+#define ASSERT_ARGS_Parrot_str_chr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_str_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_str_compose __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -616,13 +611,8 @@
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_string_chr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_string_increment __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(interp) \
-    , PARROT_ASSERT_ARG(s))
 #define ASSERT_ARGS_string_make __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
-#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(s))

Modified: trunk/src/extend.c
==============================================================================
--- trunk/src/extend.c	Sun Oct  3 00:56:09 2010	(r49428)
+++ trunk/src/extend.c	Sun Oct  3 01:25:09 2010	(r49429)
@@ -511,8 +511,21 @@
 {
     ASSERT_ARGS(Parrot_new_string)
     Parrot_String retval;
+    const STR_VTABLE *encoding;
+
     PARROT_CALLIN_START(interp);
-    retval = string_make(interp, buffer, length, encoding_name, flags);
+
+    if (encoding_name) {
+        encoding = Parrot_find_encoding(interp, encoding_name);
+        if (!encoding)
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
+                "Can't make '%s' encoding strings", encoding_name);
+    }
+    else
+        encoding = Parrot_default_encoding_ptr;
+
+    retval = Parrot_str_new_init(interp, buffer, length, encoding, flags);
+
     PARROT_CALLIN_END(interp);
     return retval;
 }

Modified: trunk/src/library.c
==============================================================================
--- trunk/src/library.c	Sun Oct  3 00:56:09 2010	(r49428)
+++ trunk/src/library.c	Sun Oct  3 01:25:09 2010	(r49429)
@@ -413,7 +413,7 @@
      *      the goal is just to have for sure an invisible 0 at end
      */
 
-    STRING * const nul = string_chr(interp, '\0');
+    STRING * const nul = Parrot_str_chr(interp, '\0');
 
     path = Parrot_str_concat(interp, path, nul);
     --path->bufused;
@@ -445,12 +445,11 @@
 path_guarantee_trailing_separator(PARROT_INTERP, ARGMOD(STRING *path))
 {
     ASSERT_ARGS(path_guarantee_trailing_separator)
-    STRING * const path_separator_string = string_chr(interp, path_separator);
 
     /* make sure the path has a trailing slash before appending the file */
-    if (STRING_ord(interp, path, -1)
-         != STRING_ord(interp, path_separator_string, 0))
-        path = Parrot_str_concat(interp, path , path_separator_string);
+    if (STRING_ord(interp, path, -1) != path_separator)
+        path = Parrot_str_concat(interp, path,
+                Parrot_str_chr(interp, path_separator));
 
     return path;
 }

Modified: trunk/src/ops/core_ops.c
==============================================================================
--- trunk/src/ops/core_ops.c	Sun Oct  3 00:56:09 2010	(r49428)
+++ trunk/src/ops/core_ops.c	Sun Oct  3 01:25:09 2010	(r49429)
@@ -22268,7 +22268,7 @@
 opcode_t *
 Parrot_chr_s_i(opcode_t *cur_opcode, PARROT_INTERP)  {
     const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
-    STRING * const s = string_chr(interp, (UINTVAL)IREG(2));
+    STRING * const s = Parrot_str_chr(interp, (UINTVAL)IREG(2));
     SREG(1) = s;
 
 return (opcode_t *)cur_opcode + 3;}
@@ -22276,7 +22276,7 @@
 opcode_t *
 Parrot_chr_s_ic(opcode_t *cur_opcode, PARROT_INTERP)  {
     const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
-    STRING * const s = string_chr(interp, (UINTVAL)ICONST(2));
+    STRING * const s = Parrot_str_chr(interp, (UINTVAL)ICONST(2));
     SREG(1) = s;
 
 return (opcode_t *)cur_opcode + 3;}

Modified: trunk/src/ops/string.ops
==============================================================================
--- trunk/src/ops/string.ops	Sun Oct  3 00:56:09 2010	(r49428)
+++ trunk/src/ops/string.ops	Sun Oct  3 01:25:09 2010	(r49429)
@@ -55,7 +55,7 @@
 =cut
 
 inline op chr(out STR, in INT) :base_core {
-    STRING * const s = string_chr(interp, (UINTVAL)$2);
+    STRING * const s = Parrot_str_chr(interp, (UINTVAL)$2);
     $1 = s;
 }
 

Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc	Sun Oct  3 00:56:09 2010	(r49428)
+++ trunk/src/pmc/string.pmc	Sun Oct  3 01:25:09 2010	(r49429)
@@ -478,7 +478,7 @@
 
     VTABLE void set_integer_keyed_int(INTVAL pos, INTVAL value) {
         STRING      *str_val;
-        STRING * const c = string_chr(INTERP, (UINTVAL) value);
+        STRING * const c = Parrot_str_chr(INTERP, (UINTVAL) value);
         GET_ATTR_str_val(INTERP, SELF, str_val);
         str_val = Parrot_str_replace(INTERP, str_val, pos, 1, c);
         SET_ATTR_str_val(INTERP, SELF, str_val);

Modified: trunk/src/spf_render.c
==============================================================================
--- trunk/src/spf_render.c	Sun Oct  3 00:56:09 2010	(r49428)
+++ trunk/src/spf_render.c	Sun Oct  3 01:25:09 2010	(r49429)
@@ -685,7 +685,7 @@
                             /* INTEGERS */
                           case 'c':
                             {
-                            STRING * const ts = string_chr(interp,
+                            STRING * const ts = Parrot_str_chr(interp,
                                  (UINTVAL)obj->getint(interp, info.type, obj));
                             targ = str_concat_w_flags(interp, targ, &info, ts, NULL);
                             }

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Sun Oct  3 00:56:09 2010	(r49428)
+++ trunk/src/string/api.c	Sun Oct  3 01:25:09 2010	(r49429)
@@ -44,6 +44,13 @@
 /* HEADERIZER BEGIN: static */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 
+PARROT_WARN_UNUSED_RESULT
+PARROT_PURE_FUNCTION
+static INTVAL string_max_bytes(SHIM_INTERP,
+    ARGIN(const STRING *s),
+    UINTVAL nchars)
+        __attribute__nonnull__(2);
+
 PARROT_INLINE
 PARROT_IGNORABLE_RESULT
 PARROT_CAN_RETURN_NULL
@@ -58,6 +65,8 @@
 static void throw_illegal_escape(PARROT_INTERP)
         __attribute__nonnull__(1);
 
+#define ASSERT_ARGS_string_max_bytes __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(s))
 #define ASSERT_ARGS_string_rep_compatible __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(a) \
     , PARROT_ASSERT_ARG(b))
@@ -676,7 +685,8 @@
 len, const STR_VTABLE *encoding, UINTVAL flags)>
 
 Given a buffer, its length, an encoding, a character set, and STRING flags,
-creates and returns a new string.  Don't call this directly.
+creates and returns a new string. If buffer is NULL and len >= 0, allocates
+len bytes.
 
 =cut
 
@@ -846,7 +856,7 @@
 
 /*
 
-=item C<STRING * string_chr(PARROT_INTERP, UINTVAL character)>
+=item C<STRING * Parrot_str_chr(PARROT_INTERP, UINTVAL character)>
 
 Returns a single-character Parrot string.
 
@@ -858,9 +868,9 @@
 PARROT_CANNOT_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
 STRING *
-string_chr(PARROT_INTERP, UINTVAL character)
+Parrot_str_chr(PARROT_INTERP, UINTVAL character)
 {
-    ASSERT_ARGS(string_chr)
+    ASSERT_ARGS(Parrot_str_chr)
 
     if (character > 0xff)
         return Parrot_utf8_encoding_ptr->chr(interp, character);
@@ -873,6 +883,29 @@
 
 /*
 
+=item C<STRING * string_chr(PARROT_INTERP, UINTVAL character)>
+
+Returns a single-character Parrot string.
+
+Deprecated, use Parrot_str_chr instead.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+STRING *
+string_chr(PARROT_INTERP, UINTVAL character)
+{
+    ASSERT_ARGS(string_chr)
+    return Parrot_str_chr(interp, character);
+}
+
+
+/*
+
 =back
 
 =head2 Vtable Dispatch Functions
@@ -901,7 +934,8 @@
 
 /*
 
-=item C<INTVAL string_max_bytes(PARROT_INTERP, const STRING *s, UINTVAL nchars)>
+=item C<static INTVAL string_max_bytes(PARROT_INTERP, const STRING *s, UINTVAL
+nchars)>
 
 Returns the number of bytes required to safely contain the specified number
 of characters in the specified Parrot string's representation.
@@ -910,10 +944,9 @@
 
 */
 
-PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
-INTVAL
+static INTVAL
 string_max_bytes(SHIM_INTERP, ARGIN(const STRING *s), UINTVAL nchars)
 {
     ASSERT_ARGS(string_max_bytes)
@@ -2782,43 +2815,6 @@
 
 /*
 
-=item C<STRING * string_increment(PARROT_INTERP, const STRING *s)>
-
-Increments the string in the Perl 5 fashion, where incrementing aa gives you bb
-and so on.  Currently single char only.
-
-=cut
-
-*/
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-STRING *
-string_increment(PARROT_INTERP, ARGIN(const STRING *s))
-{
-    ASSERT_ARGS(string_increment)
-    UINTVAL o;
-
-    if (Parrot_str_length(interp, s) != 1)
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
-            "increment only for length = 1 done");
-
-    o = (UINTVAL)STRING_ord(interp, s, 0);
-
-    if ((o >= 'A' && o < 'Z') || (o >= 'a' && o < 'z')) {
-        ++o;
-        /* TODO increment in place */
-        return string_chr(interp, o);
-    }
-
-    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
-        "increment out of range - unimplemented");
-}
-
-
-/*
-
 =item C<const char * Parrot_str_cstring(PARROT_INTERP, const STRING *str)>
 
 Returns a C string from a Parrot string.  Both sides are treated


More information about the parrot-commits mailing list