Permalink
Browse files

Big cleanup of signed/unsigned mess.

Turns out that using anything but char * for things that are C level
and string-ish goes against enough C culture to be a real pain. So
standardize on that. Clears up almost all the remaining warnings in
clang, and the overall number of casts has probably decreased some
along the way.
  • Loading branch information...
jnthn committed Jan 17, 2015
1 parent 527af71 commit 686058bc41702c8fb92e8c931de9abbdc471d5c7
@@ -221,8 +221,9 @@ static size_t varintsize(int64_t value) {
return 9;
}
static size_t write_varint9(MVMuint8 *buffer, size_t offset, int64_t value) {
static size_t write_varint9(char *c_buffer, size_t offset, int64_t value) {
// do we hvae to compare < or <= ?

This comment has been minimized.

@vendethiel

vendethiel Jan 17, 2015

Contributor

typo "hvae"

This comment has been minimized.

@coke

coke Jan 17, 2015

Contributor

This was fixed in ab041da

MVMuint8 *buffer = (MVMuint8 *)c_buffer;
size_t position;
size_t needed_bytes = varintsize(value);
for (position = 0; position < needed_bytes && position != 8; position++) {
@@ -1199,7 +1200,8 @@ static MVMnum64 read_double(const char *buffer, size_t offset) {
/* Reads an int64 from up to 128bits of storage.
* Returns how far to advance the offset. */
static size_t read_varint9(const MVMuint8 *buffer, size_t offset, int64_t *value) {
static size_t read_varint9(const char *c_buffer, size_t offset, int64_t *value) {
MVMuint8 *buffer = (MVMuint8 *)c_buffer;
size_t inner_offset = 0;
size_t shift_amount = 0;
int64_t negation_mask = 0;
@@ -1546,7 +1548,7 @@ static void check_and_dissect_input(MVMThreadContext *tc,
}
else {
/* Try to get it from the current compilation unit. */
data = (*tc->interp_cu)->body.serialized;
data = (char *)(*tc->interp_cu)->body.serialized;
if (!data)
fail_deserialize(tc, reader,
"Failed to find deserialization data in compilation unit");
View
@@ -285,7 +285,7 @@ static MVMString ** deserialize_strings(MVMThreadContext *tc, MVMCompUnit *cu, R
/* Ensure we can read in the string of this size, and decode
* it if so. */
ensure_can_read(tc, cu, rs, pos, ss);
MVM_ASSIGN_REF(tc, &(cu->common.header), strings[i], MVM_string_utf8_decode(tc, tc->instance->VMString, pos, ss));
MVM_ASSIGN_REF(tc, &(cu->common.header), strings[i], MVM_string_utf8_decode(tc, tc->instance->VMString, (char *)pos, ss));
pos += ss;
/* Add alignment. */
View
@@ -289,7 +289,7 @@ char * MVM_exception_backtrace_line(MVMThreadContext *tc, MVMFrame *cur_frame, M
MVMuint32 line_number = annot ? annot->line_number : 1;
MVMuint16 string_heap_index = annot ? annot->filename_string_heap_index : 0;
MVMuint8 *tmp1 = annot && string_heap_index < cur_frame->static_info->body.cu->body.num_strings
char *tmp1 = annot && string_heap_index < cur_frame->static_info->body.cu->body.num_strings
? MVM_string_utf8_encode(tc,
cur_frame->static_info->body.cu->body.strings[string_heap_index], NULL)
: NULL;
@@ -301,10 +301,10 @@ char * MVM_exception_backtrace_line(MVMThreadContext *tc, MVMFrame *cur_frame, M
snprintf(o, 1024, " %s %s:%u (%s:%s:%u)",
not_top ? "from" : " at",
tmp1 ? tmp1 : (MVMuint8 *)"<unknown>",
tmp1 ? tmp1 : "<unknown>",
line_number,
filename ? (char *) MVM_string_utf8_encode(tc, filename, NULL) : "<ephemeral file>",
name ? (char *) MVM_string_utf8_encode(tc, name, NULL) : "<anonymous frame>",
filename ? MVM_string_utf8_encode(tc, filename, NULL) : "<ephemeral file>",
name ? MVM_string_utf8_encode(tc, name, NULL) : "<anonymous frame>",
instr
);
@@ -406,7 +406,7 @@ MVMObject * MVM_exception_backtrace_strings(MVMThreadContext *tc, MVMObject *ex_
MVMuint32 count = 0;
while (cur_frame != NULL) {
char *line = MVM_exception_backtrace_line(tc, cur_frame, count++);
MVMString *line_str = MVM_string_utf8_decode(tc, tc->instance->VMString, (MVMuint8 *)line, strlen(line));
MVMString *line_str = MVM_string_utf8_decode(tc, tc->instance->VMString, line, strlen(line));
MVMObject *line_obj = MVM_repr_box_str(tc, tc->instance->boot_types.BOOTStr, line_str);
MVM_repr_push_o(tc, arr, line_obj);
cur_frame = cur_frame->caller;
@@ -703,7 +703,7 @@ void MVM_exception_throw_adhoc_va(MVMThreadContext *tc, const char *messageForma
MVMROOT(tc, ex, {
char *c_message = MVM_malloc(1024);
int bytes = vsnprintf(c_message, 1024, messageFormat, args);
MVMString *message = MVM_string_utf8_decode(tc, tc->instance->VMString, (MVMuint8 *)c_message, bytes);
MVMString *message = MVM_string_utf8_decode(tc, tc->instance->VMString, c_message, bytes);
MVM_free(c_message);
MVM_ASSIGN_REF(tc, &(ex->common.header), ex->body.message, message);
if (tc->cur_frame) {
View
@@ -1859,7 +1859,7 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
OP(coerce_sI): {
MVMString *s = GET_REG(cur_op, 2).s;
MVMObject *type = GET_REG(cur_op, 4).o;
MVMuint8 *buf = MVM_string_ascii_encode(tc, s, NULL);
char *buf = MVM_string_ascii_encode(tc, s, NULL);
MVMObject *a = MVM_repr_alloc_init(tc, type);
MVM_bigint_from_str(tc, a, buf);
MVM_free(buf);
View
@@ -56,7 +56,7 @@ static void on_read(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) {
}
else {
MVMArray *res_buf = (MVMArray *)MVM_repr_alloc_init(tc, ri->buf_type);
res_buf->body.slots.i8 = buf->base;
res_buf->body.slots.i8 = (MVMint8 *)buf->base;
res_buf->body.start = 0;
res_buf->body.ssize = nread;
res_buf->body.elems = nread;
@@ -308,7 +308,7 @@ static void write_setup(MVMThreadContext *tc, uv_loop_t *loop, MVMObject *async_
}
else {
MVMArray *buffer = (MVMArray *)wi->buf_data;
output = buffer->body.slots.i8 + buffer->body.start;
output = (char *)(buffer->body.slots.i8 + buffer->body.start);
output_size = (int)buffer->body.elems;
}
View
@@ -165,7 +165,7 @@ MVMint64 MVM_io_write_string(MVMThreadContext *tc, MVMObject *oshandle, MVMStrin
void MVM_io_write_bytes(MVMThreadContext *tc, MVMObject *oshandle, MVMObject *buffer) {
MVMOSHandle *handle = verify_is_handle(tc, oshandle, "write bytes");
MVMuint8 *output;
char *output;
MVMint64 output_size;
MVMint64 bytes_written;
@@ -176,7 +176,7 @@ void MVM_io_write_bytes(MVMThreadContext *tc, MVMObject *oshandle, MVMObject *bu
&& ((MVMArrayREPRData *)STABLE(buffer)->REPR_data)->slot_type != MVM_ARRAY_I8)
MVM_exception_throw_adhoc(tc, "write_fhb requires a native array of uint8 or int8");
output = ((MVMArray *)buffer)->body.slots.i8 + ((MVMArray *)buffer)->body.start;
output = (char *)(((MVMArray *)buffer)->body.slots.i8 + ((MVMArray *)buffer)->body.start);
output_size = ((MVMArray *)buffer)->body.elems;
if (handle->body.ops->sync_writable) {
View
@@ -438,7 +438,7 @@ static void write_setup(MVMThreadContext *tc, uv_loop_t *loop, MVMObject *async_
}
else {
MVMArray *buffer = (MVMArray *)wi->buf_data;
output = buffer->body.slots.i8 + buffer->body.start;
output = (char *)(buffer->body.slots.i8 + buffer->body.start);
output_size = (int)buffer->body.elems;
}
@@ -707,7 +707,7 @@ static void async_read(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf,
MVMObject *buf_type = MVM_repr_at_key_o(tc, si->callbacks,
tc->instance->str_consts.buf_type);
MVMArray *res_buf = (MVMArray *)MVM_repr_alloc_init(tc, buf_type);
res_buf->body.slots.i8 = buf->base;
res_buf->body.slots.i8 = (MVMint8 *)buf->base;
res_buf->body.start = 0;
res_buf->body.ssize = nread;
res_buf->body.elems = nread;
View
@@ -201,8 +201,9 @@ static MVMint64 eof(MVMThreadContext *tc, MVMOSHandle *h) {
/* Writes the specified string to the file handle, maybe with a newline. */
static MVMint64 write_str(MVMThreadContext *tc, MVMOSHandle *h, MVMString *str, MVMint64 newline) {
MVMIOFileData *data = (MVMIOFileData *)h->body.data;
MVMint64 output_size, bytes_written;
MVMuint8 *output = MVM_string_encode(tc, str, 0, -1, &output_size, data->encoding);
MVMuint64 output_size;
MVMint64 bytes_written;
char *output = MVM_string_encode(tc, str, 0, -1, &output_size, data->encoding);
uv_buf_t write_buf = uv_buf_init(output, output_size);
uv_fs_t req;
View
@@ -177,15 +177,15 @@ static void write_cb(uv_write_t* req, int status) {
}
MVMint64 MVM_io_syncstream_write_str(MVMThreadContext *tc, MVMOSHandle *h, MVMString *str, MVMint64 newline) {
MVMIOSyncStreamData *data = (MVMIOSyncStreamData *)h->body.data;
MVMuint8 *output;
MVMint64 output_size;
char *output;
MVMuint64 output_size;
uv_write_t *req;
uv_buf_t write_buf;
int r;
output = MVM_string_encode(tc, str, 0, -1, &output_size, data->encoding);
if (newline) {
output = (MVMuint8 *)MVM_realloc(output, ++output_size);
output = (char *)MVM_realloc(output, ++output_size);
output[output_size - 1] = '\n';
}
req = MVM_malloc(sizeof(uv_write_t));
View
@@ -13,9 +13,9 @@ void MVM_jit_log(MVMThreadContext *tc, const char * fmt, ...) {
static char * jitcode_name(MVMThreadContext *tc, MVMJitCode *code) {
MVMuint64 cuuid_len;
MVMuint64 name_len;
MVMuint8 *cuuid = MVM_string_ascii_encode(tc, code->sf->body.cuuid,
char *cuuid = MVM_string_ascii_encode(tc, code->sf->body.cuuid,
&cuuid_len);
MVMuint8 *name = MVM_string_ascii_encode(tc, code->sf->body.name,
char *name = MVM_string_ascii_encode(tc, code->sf->body.name,
&name_len);
MVMuint64 dirname_len = strlen(tc->instance->jit_bytecode_dir);
// 4 chars for prefix, 3 chars for the separators, 4 for the postfix, 1 for the 0
View
@@ -1307,7 +1307,7 @@ static char * form_string_heap(VM, WriterState *ws, unsigned int *string_heap_si
/* Add each string to the heap. */
for (i = 0; i < num_strings; i++) {
MVMuint64 bytelen;
MVMuint8 *utf8 = MVM_string_utf8_encode(tc, ATPOS_S(vm, ws->strings, i), &bytelen);
char *utf8 = MVM_string_utf8_encode(tc, ATPOS_S(vm, ws->strings, i), &bytelen);
/* Ensure we have space. */
unsigned short align = bytelen & 3 ? 4 - (bytelen & 3) : 0;
View
@@ -716,11 +716,11 @@ void MVM_bigint_expmod(MVMThreadContext *tc, MVMObject *result, MVMObject *a, MV
clear_temp_bigints(tmp, 3);
}
void MVM_bigint_from_str(MVMThreadContext *tc, MVMObject *a, MVMuint8 *buf) {
void MVM_bigint_from_str(MVMThreadContext *tc, MVMObject *a, char *buf) {
MVMP6bigintBody *body = get_bigint_body(tc, a);
mp_int *i = MVM_malloc(sizeof(mp_int));
mp_init(i);
mp_read_radix(i, (const char *)buf, 10);
mp_read_radix(i, buf, 10);
if (can_be_smallint(i)) {
body->u.smallint.flag = MVM_BIGINT_32_FLAG;
body->u.smallint.value = SIGN(i) ? -DIGIT(i, 0) : DIGIT(i, 0);
View
@@ -27,7 +27,7 @@ void MVM_bigint_expmod(MVMThreadContext *tc, MVMObject *result, MVMObject *a, MV
MVMint64 MVM_bigint_cmp(MVMThreadContext *tc, MVMObject *a, MVMObject *b);
void MVM_bigint_from_str(MVMThreadContext *tc, MVMObject *a, MVMuint8 *buf);
void MVM_bigint_from_str(MVMThreadContext *tc, MVMObject *a, char *buf);
MVMString * MVM_bigint_to_str(MVMThreadContext *tc, MVMObject *a, int base);
MVMnum64 MVM_bigint_to_num(MVMThreadContext *tc, MVMObject *a);
void MVM_bigint_from_num(MVMThreadContext *tc, MVMObject *a, MVMnum64 n);
View
@@ -31,7 +31,7 @@ static void appendf(DumpStr *ds, const char *fmt, ...) {
/* Turns a MoarVM string into a C string and appends it. */
static void append_str(MVMThreadContext *tc, DumpStr *ds, MVMString *s) {
MVMuint8 *cs = MVM_string_utf8_encode_C_string(tc, s);
char *cs = MVM_string_utf8_encode_C_string(tc, s);
append(ds, cs);
MVM_free(cs);
}
@@ -218,9 +218,8 @@ static void dump_callsite(MVMThreadContext *tc, DumpStr *ds, MVMSpeshGraph *g) {
MVMuint16 i;
appendf(ds, "Callsite %p (%d args, %d pos)\n", g->cs, g->cs->arg_count, g->cs->num_pos);
for (i = 0; i < (g->cs->arg_count - g->cs->num_pos) / 2; i++) {
MVMuint8 *argname_utf8;
if (g->cs->arg_names[i]) {
argname_utf8 = MVM_string_utf8_encode(tc, g->cs->arg_names[i], NULL);
char * argname_utf8 = MVM_string_utf8_encode(tc, g->cs->arg_names[i], NULL);
appendf(ds, " - %s\n", argname_utf8);
MVM_free(argname_utf8);
}
@@ -234,7 +233,7 @@ static void dump_fileinfo(MVMThreadContext *tc, DumpStr *ds, MVMSpeshGraph *g) {
MVMint32 str_idx = ann ? ann->filename_string_heap_index : 0;
MVMint32 line_nr = ann ? ann->line_number : 1;
MVMString *filename = cu->body.filename;
MVMuint8 *filename_utf8 = "<unknown>";
char *filename_utf8 = "<unknown>";
if (ann && str_idx < cu->body.num_strings) {
filename = cu->body.strings[str_idx];
}
View
@@ -2,7 +2,7 @@
/* Decodes the specified number of bytes of ASCII into an NFG string, creating
* a result of the specified type. The type must have the MVMString REPR. */
MVMString * MVM_string_ascii_decode(MVMThreadContext *tc, MVMObject *result_type, const MVMint8 *ascii, size_t bytes) {
MVMString * MVM_string_ascii_decode(MVMThreadContext *tc, MVMObject *result_type, const char *ascii, size_t bytes) {
MVMString *result = (MVMString *)REPR(result_type)->allocate(tc, STABLE(result_type));
size_t i;
@@ -94,7 +94,7 @@ void MVM_string_ascii_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds,
/* Encodes the specified substring to ASCII. Anything outside of ASCII range
* will become a ?. The result string is NULL terminated, but the specified
* size is the non-null part. */
MVMuint8 * MVM_string_ascii_encode_substr(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size, MVMint64 start, MVMint64 length) {
char * MVM_string_ascii_encode_substr(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size, MVMint64 start, MVMint64 length) {
/* ASCII is a single byte encoding, so each grapheme will just become
* a single byte. */
MVMuint32 startu = (MVMuint32)start;
@@ -133,17 +133,17 @@ MVMuint8 * MVM_string_ascii_encode_substr(MVMThreadContext *tc, MVMString *str,
if (output_size)
*output_size = lengthu;
return result;
return (char *)result;
}
/* Encodes the specified string to ASCII. */
MVMuint8 * MVM_string_ascii_encode(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size) {
char * MVM_string_ascii_encode(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size) {
return MVM_string_ascii_encode_substr(tc, str, output_size, 0,
MVM_string_graphs(tc, str));
}
/* Encodes the specified string to ASCII not returning length. */
MVMuint8 * MVM_string_ascii_encode_any(MVMThreadContext *tc, MVMString *str) {
char * MVM_string_ascii_encode_any(MVMThreadContext *tc, MVMString *str) {
MVMuint64 output_size;
return MVM_string_ascii_encode(tc, str, &output_size);
}
View
@@ -1,6 +1,6 @@
MVM_PUBLIC MVMString * MVM_string_ascii_decode(MVMThreadContext *tc, MVMObject *result_type, const MVMint8 *ascii, size_t bytes);
MVM_PUBLIC MVMString * MVM_string_ascii_decode(MVMThreadContext *tc, MVMObject *result_type, const char *ascii, size_t bytes);
MVM_PUBLIC MVMString * MVM_string_ascii_decode_nt(MVMThreadContext *tc, MVMObject *result_type, const char *ascii);
MVM_PUBLIC void MVM_string_ascii_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds, MVMint32 *stopper_chars, MVMint32 *stopper_sep);
MVM_PUBLIC MVMuint8 * MVM_string_ascii_encode_substr(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size, MVMint64 start, MVMint64 length);
MVM_PUBLIC MVMuint8 * MVM_string_ascii_encode(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size);
MVMuint8 * MVM_string_ascii_encode_any(MVMThreadContext *tc, MVMString *str);
MVM_PUBLIC char * MVM_string_ascii_encode_substr(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size, MVMint64 start, MVMint64 length);
MVM_PUBLIC char * MVM_string_ascii_encode(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size);
char * MVM_string_ascii_encode_any(MVMThreadContext *tc, MVMString *str);
View
@@ -4,7 +4,8 @@
* creating a result of the specified type. The type must have the MVMString
* REPR. */
MVMString * MVM_string_latin1_decode(MVMThreadContext *tc, MVMObject *result_type,
MVMuint8 *latin1, size_t bytes) {
char *latin1_c, size_t bytes) {
MVMuint8 *latin1 = (MVMuint8 *)latin1_c;
MVMString *result = (MVMString *)REPR(result_type)->allocate(tc, STABLE(result_type));
size_t i;
@@ -47,7 +48,7 @@ void MVM_string_latin1_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds,
while (cur_bytes) {
/* Process this buffer. */
MVMint32 pos = cur_bytes == ds->bytes_head ? ds->bytes_head_pos : 0;
unsigned char *bytes = cur_bytes->bytes;
unsigned char *bytes = (unsigned char *)cur_bytes->bytes;
while (pos < cur_bytes->length) {
MVMCodepoint codepoint = bytes[pos++];
if (count == bufsize) {
@@ -80,7 +81,7 @@ void MVM_string_latin1_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds,
/* Encodes the specified substring to latin-1. Anything outside of latin-1 range
* will become a ?. The result string is NULL terminated, but the specified
* size is the non-null part. */
MVMuint8 * MVM_string_latin1_encode_substr(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size, MVMint64 start, MVMint64 length) {
char * MVM_string_latin1_encode_substr(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size, MVMint64 start, MVMint64 length) {
/* Latin-1 is a single byte encoding, so each grapheme will just become
* a single byte. */
MVMuint32 startu = (MVMuint32)start;
@@ -117,5 +118,5 @@ MVMuint8 * MVM_string_latin1_encode_substr(MVMThreadContext *tc, MVMString *str,
}
if (output_size)
*output_size = lengthu;
return result;
return (char *)result;
}
View
@@ -1,3 +1,3 @@
MVMString * MVM_string_latin1_decode(MVMThreadContext *tc, MVMObject *result_type, MVMuint8 *latin1, size_t bytes);
MVMString * MVM_string_latin1_decode(MVMThreadContext *tc, MVMObject *result_type, char *latin1, size_t bytes);
MVM_PUBLIC void MVM_string_latin1_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds, MVMint32 *stopper_chars, MVMint32 *stopper_sep);
MVMuint8 * MVM_string_latin1_encode_substr(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size, MVMint64 start, MVMint64 length);
char * MVM_string_latin1_encode_substr(MVMThreadContext *tc, MVMString *str, MVMuint64 *output_size, MVMint64 start, MVMint64 length);
Oops, something went wrong.

0 comments on commit 686058b

Please sign in to comment.