Author: paultcochrane
Date: Sun Oct 28 09:49:43 2007
New Revision: 22563

Modified:
   trunk/src/string.c

Log:
[core] Converted nonnull_encoding_name() from dodgy function into a more
elegant macro.  This also helps problems the function had with allocating
memory correctly.  Many thanks to leo++ for the solution!


Modified: trunk/src/string.c
==============================================================================
--- trunk/src/string.c  (original)
+++ trunk/src/string.c  Sun Oct 28 09:49:43 2007
@@ -44,7 +44,7 @@
 
 #define EXTRA_SIZE 256
 
-
+#define nonnull_encoding_name(s) (s) ? (s)->encoding->name : "null string"
 #define saneify_string(s) \
     PARROT_ASSERT(s->encoding); \
     PARROT_ASSERT(s->charset); \
@@ -61,7 +61,6 @@
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 
-static const char * nonnull_encoding_name(STRING *s);
 /* HEADERIZER END: static */
 
 
@@ -1439,32 +1438,6 @@
 
 /*
 
-=item C<nonnull_encoding_name(STRING *s)>
-
-Returns the string's encoding name if the string pointer is non-null, if the
-string pointer is null it simply returns the string "null string".  This
-function prevents problems whereby the string used in C<real_exception>
-to print the exception message could potentially be null.
-
-=cut
-
-*/
-
-static const char *
-nonnull_encoding_name(STRING *s)
-{
-    char *string;
-    string = mem_allocate_zeroed_typed(char);
-    if (!s)
-        strcpy(string, "null string");
-    else
-        strcpy(string, s->encoding->name);
-
-    return string;
-}
-
-/*
-
 =item C<string_bitwise_and>
 
 Performs a bitwise C<AND> on two Parrot string, performing type and

Reply via email to