[svn:parrot] r42308 - in trunk: include/parrot src/string t/op
NotFound at svn.parrot.org
NotFound at svn.parrot.org
Fri Nov 6 15:24:43 UTC 2009
Author: NotFound
Date: Fri Nov 6 15:24:42 2009
New Revision: 42308
URL: https://trac.parrot.org/parrot/changeset/42308
Log:
make downcase and titlecase throw on null like upcase already doed, add tests for passing null to upcase, downcase and titlecase
Modified:
trunk/include/parrot/string_funcs.h
trunk/src/string/api.c
trunk/t/op/string.t
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h Fri Nov 6 13:19:51 2009 (r42307)
+++ trunk/include/parrot/string_funcs.h Fri Nov 6 15:24:42 2009 (r42308)
@@ -145,14 +145,12 @@
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_MALLOC
-STRING * Parrot_str_downcase(PARROT_INTERP, ARGIN(const STRING *s))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
+STRING * Parrot_str_downcase(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
+ __attribute__nonnull__(1);
PARROT_EXPORT
-void Parrot_str_downcase_inplace(PARROT_INTERP, ARGMOD(STRING *s))
+void Parrot_str_downcase_inplace(PARROT_INTERP, ARGMOD_NULLOK(STRING *s))
__attribute__nonnull__(1)
- __attribute__nonnull__(2)
FUNC_MODIFIES(*s);
PARROT_EXPORT
@@ -394,14 +392,12 @@
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_MALLOC
-STRING * Parrot_str_titlecase(PARROT_INTERP, ARGIN(const STRING *s))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
+STRING * Parrot_str_titlecase(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
+ __attribute__nonnull__(1);
PARROT_EXPORT
-void Parrot_str_titlecase_inplace(PARROT_INTERP, ARGMOD(STRING *s))
+void Parrot_str_titlecase_inplace(PARROT_INTERP, ARGMOD_NULLOK(STRING *s))
__attribute__nonnull__(1)
- __attribute__nonnull__(2)
FUNC_MODIFIES(*s);
PARROT_EXPORT
@@ -581,11 +577,9 @@
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_str_downcase __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
+ PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_downcase_inplace __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
+ PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_equal __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_escape __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -664,11 +658,9 @@
#define ASSERT_ARGS_Parrot_str_substr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_titlecase __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
+ PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_titlecase_inplace __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
+ PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_to_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_to_hashval __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c Fri Nov 6 13:19:51 2009 (r42307)
+++ trunk/src/string/api.c Fri Nov 6 15:24:42 2009 (r42308)
@@ -2942,13 +2942,19 @@
PARROT_CANNOT_RETURN_NULL
PARROT_MALLOC
STRING *
-Parrot_str_downcase(PARROT_INTERP, ARGIN(const STRING *s))
+Parrot_str_downcase(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
{
ASSERT_ARGS(Parrot_str_downcase)
- DECL_CONST_CAST;
- STRING * const dest = Parrot_str_copy(interp, PARROT_const_cast(STRING *, s));
- Parrot_str_downcase_inplace(interp, dest);
- return dest;
+ if (STRING_IS_NULL(s)) {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
+ "Can't downcase NULL string");
+ }
+ else {
+ DECL_CONST_CAST;
+ STRING * const dest = Parrot_str_copy(interp, PARROT_const_cast(STRING *, s));
+ Parrot_str_downcase_inplace(interp, dest);
+ return dest;
+ }
}
@@ -2964,17 +2970,23 @@
PARROT_EXPORT
void
-Parrot_str_downcase_inplace(PARROT_INTERP, ARGMOD(STRING *s))
+Parrot_str_downcase_inplace(PARROT_INTERP, ARGMOD_NULLOK(STRING *s))
{
ASSERT_ARGS(Parrot_str_downcase_inplace)
- /*
- * TODO get rid of all the inplace variants. We have for utf8:
- * * 1 Parrot_str_copy from the non-incase variant
- * * conversion to utf16, with doubling the buffer
- * * possibly one more reallocation in downcase
- */
- Parrot_str_write_COW(interp, s);
- CHARSET_DOWNCASE(interp, s);
+ if (STRING_IS_NULL(s)) {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
+ "Can't downcase NULL string");
+ }
+ else {
+ /*
+ * TODO get rid of all the inplace variants. We have for utf8:
+ * * 1 Parrot_str_copy from the non-incase variant
+ * * conversion to utf16, with doubling the buffer
+ * * possibly one more reallocation in downcase
+ */
+ Parrot_str_write_COW(interp, s);
+ CHARSET_DOWNCASE(interp, s);
+ }
}
@@ -2993,13 +3005,19 @@
PARROT_CANNOT_RETURN_NULL
PARROT_MALLOC
STRING *
-Parrot_str_titlecase(PARROT_INTERP, ARGIN(const STRING *s))
+Parrot_str_titlecase(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
{
ASSERT_ARGS(Parrot_str_titlecase)
- DECL_CONST_CAST;
- STRING * const dest = Parrot_str_copy(interp, PARROT_const_cast(STRING *, s));
- Parrot_str_titlecase_inplace(interp, dest);
- return dest;
+ if (STRING_IS_NULL(s)) {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
+ "Can't titlecase NULL string");
+ }
+ else {
+ DECL_CONST_CAST;
+ STRING * const dest = Parrot_str_copy(interp, PARROT_const_cast(STRING *, s));
+ Parrot_str_titlecase_inplace(interp, dest);
+ return dest;
+ }
}
@@ -3015,11 +3033,17 @@
PARROT_EXPORT
void
-Parrot_str_titlecase_inplace(PARROT_INTERP, ARGMOD(STRING *s))
+Parrot_str_titlecase_inplace(PARROT_INTERP, ARGMOD_NULLOK(STRING *s))
{
ASSERT_ARGS(Parrot_str_titlecase_inplace)
- Parrot_str_write_COW(interp, s);
- CHARSET_TITLECASE(interp, s);
+ if (STRING_IS_NULL(s)) {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
+ "Can't titlecase NULL string");
+ }
+ else {
+ Parrot_str_write_COW(interp, s);
+ CHARSET_TITLECASE(interp, s);
+ }
}
Modified: trunk/t/op/string.t
==============================================================================
--- trunk/t/op/string.t Fri Nov 6 13:19:51 2009 (r42307)
+++ trunk/t/op/string.t Fri Nov 6 15:24:42 2009 (r42308)
@@ -19,7 +19,7 @@
.sub main :main
.include 'test_more.pir'
- plan(405)
+ plan(411)
set_s_s_sc()
test_clone()
@@ -1899,25 +1899,103 @@
is( $S1, "ABCD012YZ", 'upcase' )
upcase $S0
- is( $S0, "ABCD012YZ", 'upcase' )
+ is( $S0, "ABCD012YZ", 'upcase inplace' )
+
+ push_eh catch1
+ null $S9
+ null $S0
+ upcase $S1, $S0
+ pop_eh
+ goto null1
+catch1:
+ .get_results($P9)
+ $S9 = $P9['message']
+ pop_eh
+null1:
+ is ($S9, "Can't upcase NULL string", 'upcase null')
+
+ push_eh catch2
+ null $S9
+ null $S0
+ upcase $S0
+ pop_eh
+ goto null2
+catch2:
+ .get_results($P9)
+ $S9 = $P9['message']
+ pop_eh
+null2:
+ is ($S9, "Can't upcase NULL string", 'upcase inplace null')
.end
.sub test_downcase
set $S0, "ABcd012YZ"
downcase $S1, $S0
- is( $S1, "abcd012yz", 'test_downcase' )
+ is( $S1, "abcd012yz", 'downcase' )
downcase $S0
- is( $S0, "abcd012yz", 'test_downcase' )
+ is( $S0, "abcd012yz", 'downcase inplace' )
+
+ push_eh catch1
+ null $S9
+ null $S0
+ downcase $S1, $S0
+ pop_eh
+ goto null1
+catch1:
+ .get_results($P9)
+ $S9 = $P9['message']
+ pop_eh
+null1:
+ is ($S9, "Can't downcase NULL string", 'downcase null')
+
+ push_eh catch2
+ null $S9
+ null $S0
+ downcase $S0
+ pop_eh
+ goto null2
+catch2:
+ .get_results($P9)
+ $S9 = $P9['message']
+ pop_eh
+null2:
+ is ($S9, "Can't downcase NULL string", 'downcase inplace null')
.end
.sub test_titlecase
set $S0, "aBcd012YZ"
titlecase $S1, $S0
- is( $S1, "Abcd012yz", 'test_titlecase' )
+ is( $S1, "Abcd012yz", 'titlecase' )
titlecase $S0
- is( $S0, "Abcd012yz", 'test_titlecase' )
+ is( $S0, "Abcd012yz", 'titlecase inplace' )
+
+ push_eh catch1
+ null $S9
+ null $S0
+ titlecase $S1, $S0
+ pop_eh
+ goto null1
+catch1:
+ .get_results($P9)
+ $S9 = $P9['message']
+ pop_eh
+null1:
+ is ($S9, "Can't titlecase NULL string", 'titlecase null')
+
+ push_eh catch2
+ null $S9
+ null $S0
+ titlecase $S0
+ pop_eh
+ goto null2
+catch2:
+ .get_results($P9)
+ $S9 = $P9['message']
+ pop_eh
+null2:
+ is ($S9, "Can't titlecase NULL string", 'titlecase inplace null')
.end
.sub three_param_ord_one_character_string_register_i
More information about the parrot-commits
mailing list