Skip to content

Commit

Permalink
add Parrot_gc_new_string_header
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/branches/pmc_freeze_cleanup@43236 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
tewk committed Dec 24, 2009
1 parent 5fa8fcd commit b19d9a2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
9 changes: 9 additions & 0 deletions include/parrot/string_funcs.h
Expand Up @@ -274,6 +274,15 @@ STRING * Parrot_str_new(PARROT_INTERP,
const UINTVAL len)
__attribute__nonnull__(1);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_str_new_from_buffer(PARROT_INTERP,
ARGIN_NULLOK(const Buffer * buffer),
const UINTVAL len)
__attribute__nonnull__(1);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
Expand Down
12 changes: 1 addition & 11 deletions src/pmc_freeze.c
Expand Up @@ -1129,17 +1129,7 @@ Parrot_freeze(PARROT_INTERP, ARGIN(PMC *pmc))
STRING *result;

visit_info_init(interp, &info, VISIT_FREEZE_NORMAL, STRINGNULL, pmc);

result = Parrot_gc_new_string_header(interp, 0);
Buffer_bufstart(result) = Buffer_bufstart(info.buffer);
Buffer_buflen(result) = Buffer_buflen(info.buffer);
result->bufused = OUTPUT_LENGTH(&info);
result->strstart = Buffer_bufstart(result);
result->strlen = result->bufused;
result->encoding = Parrot_fixed_8_encoding_ptr;
result->charset = Parrot_binary_charset_ptr;

return result;
return Parrot_str_new_from_buffer(interp, info.buffer, OUTPUT_LENGTH(&info));
}


Expand Down
33 changes: 33 additions & 0 deletions src/string/api.c
Expand Up @@ -650,6 +650,39 @@ Parrot_str_new(PARROT_INTERP, ARGIN_NULLOK(const char * const buffer), const UIN
point? */
}


/*
=item C<STRING * Parrot_str_new_from_buffer(PARROT_INTERP, const Buffer *buffer)>
Make a Parrot string from a Buffer
=cut
*/

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
STRING *
Parrot_str_new_from_buffer(PARROT_INTERP, ARGIN(const Buffer *buffer), const UINTVAL len)
{
ASSERT_ARGS(Parrot_str_new)
STRING *result;

result = Parrot_gc_new_string_header(interp, 0);
Buffer_bufstart(result) = Buffer_bufstart(buffer);
Buffer_buflen(result) = Buffer_buflen(buffer);
result->strstart = Buffer_bufstart(result);
result->bufused = len;
result->strlen = len;
result->encoding = Parrot_fixed_8_encoding_ptr;
result->charset = Parrot_binary_charset_ptr;

return result;
}

/*
=item C<const char* string_primary_encoding_for_representation(PARROT_INTERP,
Expand Down

0 comments on commit b19d9a2

Please sign in to comment.