[svn:parrot] r42563 - in trunk: include/parrot src/string
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Tue Nov 17 21:14:01 UTC 2009
Author: chromatic
Date: Tue Nov 17 21:14:01 2009
New Revision: 42563
URL: https://trac.parrot.org/parrot/changeset/42563
Log:
[string] Added STRINGNULL. Now we can use it appropriately instead of assuming
that a NULL STRING represents STRINGNULL.
Modified:
trunk/include/parrot/interpreter.h
trunk/include/parrot/string_funcs.h
trunk/src/string/api.c
Modified: trunk/include/parrot/interpreter.h
==============================================================================
--- trunk/include/parrot/interpreter.h Tue Nov 17 20:59:30 2009 (r42562)
+++ trunk/include/parrot/interpreter.h Tue Nov 17 21:14:01 2009 (r42563)
@@ -341,7 +341,7 @@
#endif
#if PARROT_CATCH_NULL
-PARROT_DATA PMC * PMCNULL; /* Holds single Null PMC */
+PARROT_DATA PMC *PMCNULL; /* Holds single Null PMC */
#else
# define PMCNULL ((PMC *)NULL)
#endif /* PARROT_CATCH_NULL */
@@ -353,7 +353,9 @@
# define PMC_IS_NULL(pmc) (pmc) == NULL
#endif
-#define STRING_IS_NULL(s) ((s) == NULL)
+PARROT_DATA STRING *STRINGNULL; /* a single Null STRING */
+
+#define STRING_IS_NULL(s) ((s) == STRINGNULL || (s) == NULL)
#define STRING_IS_EMPTY(s) !(int)(s)->strlen
/* &gen_from_def(sysinfo.pasm) prefix(SYSINFO_) */
@@ -592,6 +594,9 @@
#ifndef PMC_IS_NULL
# define PMC_IS_NULL(pmc) PMC_is_null(NULL, (pmc))
#endif
+#ifndef STRING_IS_NULL
+# define STRING_IS_NULL(s) ((s) == NULL || STRING_is_null(NULL, (s))
+#endif
#endif /* PARROT_INTERPRETER_H_GUARD */
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h Tue Nov 17 20:59:30 2009 (r42562)
+++ trunk/include/parrot/string_funcs.h Tue Nov 17 21:14:01 2009 (r42563)
@@ -481,6 +481,9 @@
__attribute__nonnull__(2);
PARROT_EXPORT
+INTVAL STRING_is_null(SHIM_INTERP, ARGIN_NULLOK(const STRING *s));
+
+PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * string_make(PARROT_INTERP,
@@ -692,6 +695,7 @@
#define ASSERT_ARGS_string_increment __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(s))
+#define ASSERT_ARGS_STRING_is_null __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_string_make __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_string_make_from_charset __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c Tue Nov 17 20:59:30 2009 (r42562)
+++ trunk/src/string/api.c Tue Nov 17 21:14:01 2009 (r42563)
@@ -29,6 +29,9 @@
#include "private_cstring.h"
#include "api.str"
+/* for parrot/interpreter.h */
+STRING *STRINGNULL;
+
#define nonnull_encoding_name(s) (s) ? (s)->encoding->name : "null string"
#define saneify_string(s) \
PARROT_ASSERT((s)->encoding); \
@@ -70,6 +73,24 @@
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
+/*
+
+=item C<INTVAL STRING_is_null(PARROT_INTERP, const STRING *s)>
+
+Tests if the given STRING is STRINGNULL.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+INTVAL
+STRING_is_null(SHIM_INTERP, ARGIN_NULLOK(const STRING *s))
+{
+ ASSERT_ARGS(STRING_is_null)
+ return !s || s == STRINGNULL;
+}
+
/*
@@ -275,6 +296,11 @@
interp->hash_seed = Parrot_uint_rand(0);
}
+ /* initialize STRINGNULL, but not in the constant table */
+ STRINGNULL = Parrot_str_new_init(interp, NULL, 0,
+ PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
+ PObj_constant_FLAG);
+
/* initialize the constant string table */
if (interp->parent_interpreter) {
interp->const_cstring_table =
More information about the parrot-commits
mailing list