C++ compilability -- don't jump across variable initialization

C++ is picker than C about when you can "goto" across a variable being
defined.  The fix is to just minimize the variable's scope inside an
extra set of brackets.

Without this change, g++ has the following errors:

  transcode.c:590: error: jump to label 'resume_label3'
  transcode.c:514: error:   from here
  transcode.c:582: error:   crosses initialization of 'const unsigned char* p'
  transcode.c:2124: error: jump to label 'set_encs'
  transcode.c:2184: error:   from here
  transcode.c:2088: error:   skips initialization of 'const char* err'
  transcode.c:2089: error:   skips initialization of 'size_t error_len'
  transcode.c:2090: error:   skips initialization of 'mrb_value bytes'
  transcode.c:2091: error:   skips initialization of 'mrb_value dumped'
  transcode.c:2092: error:   skips initialization of 'size_t readagain_len'
  transcode.c:2093: error:   skips initialization of 'mrb_value bytes2'
This commit is contained in:
Mitchell Blank Jr
2012-05-20 00:06:49 -07:00
parent 8c752c73e2
commit 42c6b324db
+49 -44
View File
@@ -579,10 +579,12 @@ transcode_restartable0(mrb_state *mrb,
switch (mrb_fixnum(next_info) & 0x1F) {
case NOMAP:
{
const unsigned char *p = inchar_start;
writebuf_off = 0;
while (p < in_p) {
TRANSCODING_WRITEBUF(tc)[writebuf_off++] = (unsigned char)*p++;
{
const unsigned char *p = inchar_start;
writebuf_off = 0;
while (p < in_p) {
TRANSCODING_WRITEBUF(tc)[writebuf_off++] = (unsigned char)*p++;
}
}
writebuf_len = writebuf_off;
writebuf_off = 0;
@@ -2085,51 +2087,54 @@ make_econv_exception(mrb_state *mrb, mrb_econv_t *ec)
mrb_value mesg, exc;
if (ec->last_error.result == econv_invalid_byte_sequence ||
ec->last_error.result == econv_incomplete_input) {
const char *err = (const char *)ec->last_error.error_bytes_start;
size_t error_len = ec->last_error.error_bytes_len;
mrb_value bytes = mrb_str_new(mrb, err, error_len);
mrb_value dumped = mrb_str_dump(mrb, bytes);
size_t readagain_len = ec->last_error.readagain_len;
mrb_value bytes2 = mrb_nil_value();
mrb_value dumped2;
int idx;
if (ec->last_error.result == econv_incomplete_input) {
mesg = mrb_sprintf(mrb, "incomplete %s on %s",
//StringValueCStr(dumped),
mrb_string_value_cstr(mrb, &dumped),
ec->last_error.source_encoding);
{
const char *err = (const char *)ec->last_error.error_bytes_start;
size_t error_len = ec->last_error.error_bytes_len;
mrb_value bytes = mrb_str_new(mrb, err, error_len);
mrb_value dumped = mrb_str_dump(mrb, bytes);
size_t readagain_len = ec->last_error.readagain_len;
mrb_value bytes2 = mrb_nil_value();
mrb_value dumped2;
if (ec->last_error.result == econv_incomplete_input) {
mesg = mrb_sprintf(mrb, "incomplete %s on %s",
//StringValueCStr(dumped),
mrb_string_value_cstr(mrb, &dumped),
ec->last_error.source_encoding);
}
else if (readagain_len) {
bytes2 = mrb_str_new(mrb, err+error_len, readagain_len);
dumped2 = mrb_str_dump(mrb, bytes2);
mesg = mrb_sprintf(mrb, "%s followed by %s on %s",
//StringValueCStr(dumped),
mrb_string_value_cstr(mrb, &dumped),
//StringValueCStr(dumped2),
mrb_string_value_cstr(mrb, &dumped2),
ec->last_error.source_encoding);
}
else {
mesg = mrb_sprintf(mrb, "%s on %s",
//StringValueCStr(dumped),
mrb_string_value_cstr(mrb, &dumped),
ec->last_error.source_encoding);
}
exc = mrb_exc_new3(mrb, E_INVALIDBYTESEQUENCE_ERROR, mesg);
mrb_iv_set(mrb, exc, mrb_intern(mrb, "error_bytes"), bytes);
mrb_iv_set(mrb, exc, mrb_intern(mrb, "readagain_bytes"), bytes2);
mrb_iv_set(mrb, exc, mrb_intern(mrb, "incomplete_input"), ec->last_error.result == econv_incomplete_input ? mrb_true_value() : mrb_false_value());
}
else if (readagain_len) {
bytes2 = mrb_str_new(mrb, err+error_len, readagain_len);
dumped2 = mrb_str_dump(mrb, bytes2);
mesg = mrb_sprintf(mrb, "%s followed by %s on %s",
//StringValueCStr(dumped),
mrb_string_value_cstr(mrb, &dumped),
//StringValueCStr(dumped2),
mrb_string_value_cstr(mrb, &dumped2),
ec->last_error.source_encoding);
}
else {
mesg = mrb_sprintf(mrb, "%s on %s",
//StringValueCStr(dumped),
mrb_string_value_cstr(mrb, &dumped),
ec->last_error.source_encoding);
}
exc = mrb_exc_new3(mrb, E_INVALIDBYTESEQUENCE_ERROR, mesg);
mrb_iv_set(mrb, exc, mrb_intern(mrb, "error_bytes"), bytes);
mrb_iv_set(mrb, exc, mrb_intern(mrb, "readagain_bytes"), bytes2);
mrb_iv_set(mrb, exc, mrb_intern(mrb, "incomplete_input"), ec->last_error.result == econv_incomplete_input ? mrb_true_value() : mrb_false_value());
set_encs:
mrb_iv_set(mrb, exc, mrb_intern(mrb, "source_encoding_name"), mrb_str_new2(mrb, ec->last_error.source_encoding));
mrb_iv_set(mrb, exc, mrb_intern(mrb, "destination_encoding_name"), mrb_str_new2(mrb, ec->last_error.destination_encoding));
idx = mrb_enc_find_index(mrb, ec->last_error.source_encoding);
if (0 <= idx)
mrb_iv_set(mrb, exc, mrb_intern(mrb, "source_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx)));
idx = mrb_enc_find_index(mrb, ec->last_error.destination_encoding);
if (0 <= idx)
mrb_iv_set(mrb, exc, mrb_intern(mrb, "destination_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx)));
{
int idx = mrb_enc_find_index(mrb, ec->last_error.source_encoding);
if (0 <= idx)
mrb_iv_set(mrb, exc, mrb_intern(mrb, "source_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx)));
idx = mrb_enc_find_index(mrb, ec->last_error.destination_encoding);
if (0 <= idx)
mrb_iv_set(mrb, exc, mrb_intern(mrb, "destination_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx)));
}
return exc;
}
if (ec->last_error.result == econv_undefined_conversion) {