Skip to content

Commit c97065d

Browse files
committed
Fix busted build on Parrot/Windows.
1 parent fe8cb95 commit c97065d

File tree

1 file changed

+23
-2
lines changed
  • src/vm/parrot/6model/reprs

1 file changed

+23
-2
lines changed

src/vm/parrot/6model/reprs/CStr.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ static REPROps *this_repr;
1111
static wrap_object_t wrap_object_func;
1212
static create_stable_t create_stable_func;
1313

14+
/* This is what Parrot_str_new_from_cstring does but that isn't exported. */
15+
static STRING *
16+
new_from_cstring(PARROT_INTERP, const char *buffer, STRING *encodingname)
17+
{
18+
STRING *result = STRINGNULL;
19+
if (buffer) {
20+
const STR_VTABLE *encoding = STRING_IS_NULL(encodingname) ?
21+
Parrot_platform_encoding_ptr :
22+
Parrot_find_encoding_by_string(interp, encodingname);
23+
if (encoding == NULL)
24+
Parrot_ex_throw_from_c_args(interp, NULL,
25+
EXCEPTION_INVALID_ENCODING,
26+
"Invalid encoding");
27+
else {
28+
int size = strlen(buffer);
29+
result = Parrot_str_new_init(interp, buffer, size, encoding, 0);
30+
}
31+
}
32+
return result;
33+
}
34+
1435
static void set_str(PARROT_INTERP, STable *st, void *data, STRING *value) {
1536
CStrBody *body = (CStrBody *) data;
1637
PMC *old_ctx, *cappy, *meth, *enc_pmc;
@@ -46,7 +67,7 @@ static void set_str(PARROT_INTERP, STable *st, void *data, STRING *value) {
4667
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
4768
"Unknown encoding passed to CStr representation");
4869

49-
body->cstr = Parrot_str_to_encoded_cstring(interp, value, encoding);
70+
body->cstr = new_from_cstring(interp, value, encoding);
5071
}
5172

5273
static STRING *get_str(PARROT_INTERP, STable *st, void *data) {
@@ -74,7 +95,7 @@ static STRING *get_str(PARROT_INTERP, STable *st, void *data) {
7495
enc_pmc = decontainerize(interp, VTABLE_get_pmc_keyed_int(interp, cappy, 0));
7596
enc = REPR(enc_pmc)->box_funcs->get_str(interp, STABLE(enc_pmc), OBJECT_BODY(enc_pmc));
7697

77-
return Parrot_str_new_from_cstring(interp, body->cstr, enc);
98+
return new_from_cstring(interp, body->cstr, enc);
7899
}
79100

80101
/* Creates a new type object of this representation, and associates it with

0 commit comments

Comments
 (0)