[svn:parrot] r39214 - in trunk: include/parrot src src/packfile src/string
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Thu May 28 08:08:31 UTC 2009
Author: chromatic
Date: Thu May 28 08:08:29 2009
New Revision: 39214
URL: https://trac.parrot.org/parrot/changeset/39214
Log:
[STRING] Added string_make_from_charset() which makes a STRING given a charset
number, not a name. As PackFiles store STRING charsets by name (and we don't
have dyncharsets yet), thawing a STRING meant getting the charset's name by
number, then calling string_make() which uses the number to look up the
appropriate charset's name. Parrots are better than that.
Modified:
trunk/include/parrot/string_funcs.h
trunk/src/packfile.c
trunk/src/packfile/pf_items.c
trunk/src/string/api.c
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h Thu May 28 06:56:20 2009 (r39213)
+++ trunk/include/parrot/string_funcs.h Thu May 28 08:08:29 2009 (r39214)
@@ -497,6 +497,16 @@
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+STRING * string_make_from_charset(PARROT_INTERP,
+ ARGIN_NULLOK(const char *buffer),
+ UINTVAL len,
+ INTVAL charset_nr,
+ UINTVAL flags)
+ __attribute__nonnull__(1);
+
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
INTVAL string_max_bytes(SHIM_INTERP, ARGIN(const STRING *s), UINTVAL nchars)
__attribute__nonnull__(2);
@@ -710,6 +720,8 @@
|| PARROT_ASSERT_ARG(s)
#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 = \
+ 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 = \
Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c Thu May 28 06:56:20 2009 (r39213)
+++ trunk/src/packfile.c Thu May 28 08:08:29 2009 (r39214)
@@ -38,7 +38,8 @@
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-static void byte_code_destroy(SHIM_INTERP, ARGMOD(PackFile_Segment *self))
+static void byte_code_destroy(PARROT_INTERP, ARGMOD(PackFile_Segment *self))
+ __attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*self);
@@ -335,7 +336,8 @@
__attribute__nonnull__(3);
#define ASSERT_ARGS_byte_code_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(self)
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(self)
#define ASSERT_ARGS_byte_code_new __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_clone_constant __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
@@ -2518,7 +2520,7 @@
*/
static void
-byte_code_destroy(SHIM_INTERP, ARGMOD(PackFile_Segment *self))
+byte_code_destroy(PARROT_INTERP, ARGMOD(PackFile_Segment *self))
{
ASSERT_ARGS(byte_code_destroy)
PackFile_ByteCode * const byte_code = (PackFile_ByteCode *)self;
Modified: trunk/src/packfile/pf_items.c
==============================================================================
--- trunk/src/packfile/pf_items.c Thu May 28 06:56:20 2009 (r39213)
+++ trunk/src/packfile/pf_items.c Thu May 28 08:08:29 2009 (r39214)
@@ -1306,42 +1306,43 @@
PF_fetch_string(PARROT_INTERP, ARGIN_NULLOK(PackFile *pf), ARGIN(const opcode_t **cursor))
{
ASSERT_ARGS(PF_fetch_string)
- UINTVAL flags;
- opcode_t charset_nr;
- size_t size;
- STRING *s;
+ STRING *s;
+ UINTVAL flags = PF_fetch_opcode(pf, cursor);
const int wordsize = pf ? pf->header->wordsize : sizeof (opcode_t);
- const char *charset_name;
+ size_t size;
+ opcode_t charset_nr;
- flags = PF_fetch_opcode(pf, cursor);
/* don't let PBC mess our internals - only constant or not */
- flags &= (PObj_constant_FLAG | PObj_private7_FLAG);
- charset_nr = PF_fetch_opcode(pf, cursor);
+ flags &= (PObj_constant_FLAG | PObj_private7_FLAG);
+ charset_nr = PF_fetch_opcode(pf, cursor);
/* These may need to be separate */
- size = (size_t)PF_fetch_opcode(pf, cursor);
+ size = (size_t)PF_fetch_opcode(pf, cursor);
+
TRACE_PRINTF(("PF_fetch_string(): flags=0x%04x, ", flags));
TRACE_PRINTF(("charset_nr=%ld, ", charset_nr));
TRACE_PRINTF(("size=%ld.\n", size));
- charset_name = Parrot_charset_c_name(interp, charset_nr);
- s = string_make(interp, (const char *)*cursor, size, charset_name, flags);
+
+ s = string_make_from_charset(interp, (const char *)*cursor,
+ size, charset_nr, flags);
/* print only printable characters */
TRACE_PRINTF_VAL(("PF_fetch_string(): string is '%s' at 0x%x\n",
s->strstart, OFFS(pf, *cursor)));
-/* s = string_make(interp, *cursor, size,
- encoding_lookup_index(encoding),
- flags); */
TRACE_PRINTF_ALIGN(("-s ROUND_UP_B: cursor=0x%x, size=%d, wordsize=%d\n",
(const char *)*cursor + size, size, wordsize));
+
size = ROUND_UP_B(size, wordsize);
+
TRACE_PRINTF(("PF_fetch_string(): round size up to %ld.\n", size));
*((const unsigned char **) (cursor)) += size;
+
TRACE_PRINTF_ALIGN(("+s ROUND_UP_B: cursor=0x%x, size=%d\n", *cursor, size));
return s;
}
+
/*
=item C<opcode_t* PF_store_string(opcode_t *cursor, const STRING *s)>
Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c Thu May 28 06:56:20 2009 (r39213)
+++ trunk/src/string/api.c Thu May 28 08:08:29 2009 (r39214)
@@ -684,6 +684,7 @@
return s;
}
+
/*
=item C<STRING * string_make(PARROT_INTERP, const char *buffer, UINTVAL len,
@@ -737,6 +738,52 @@
}
+
+/*
+
+=item C<STRING * string_make_from_charset(PARROT_INTERP, const char *buffer,
+UINTVAL len, INTVAL charset_nr, UINTVAL flags)>
+
+Creates and returns a new Parrot string using C<len> bytes of string data read
+from C<buffer>.
+
+The value of C<charset_name> specifies the string's representation. It must be
+a valid charset identifier.
+
+ 'iso-8859-1'
+ 'ascii'
+ 'binary'
+ 'unicode'
+
+The encoding is implicitly guessed; C<unicode> implies the C<utf-8> encoding,
+and the other three assume C<fixed-8> encoding.
+
+The value of C<flags> is optionally one or more C<PObj_*> flags C<OR>-ed
+together.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+STRING *
+string_make_from_charset(PARROT_INTERP, ARGIN_NULLOK(const char *buffer),
+ UINTVAL len, INTVAL charset_nr, UINTVAL flags)
+{
+ ASSERT_ARGS(string_make_from_charset)
+ const CHARSET *charset = Parrot_get_charset(interp, charset_nr);
+
+ if (!charset)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
+ "Invalid charset number '%d' specified", charset_nr);
+
+ return Parrot_str_new_init(interp, buffer, len,
+ charset->preferred_encoding, charset, flags);
+}
+
+
/*
=item C<STRING * Parrot_str_new_init(PARROT_INTERP, const char *buffer, UINTVAL
More information about the parrot-commits
mailing list