-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
translate-c: support goto #11992
Comments
Cannot reproduce on |
Ops! I am using the |
After removing the stage2 flag. I succeeded in proceeding, but a linking error occurred. I noticed that the function below was not completely translated just its declaration. Original: static void print_ident(struct rust_demangler *rdm,
struct rust_mangled_ident ident) {
if (rdm->errored || rdm->skipping_printing)
return;
if (!ident.punycode) {
print_str(rdm, ident.ascii, ident.ascii_len);
return;
}
size_t len = 0;
size_t cap = 4;
while (cap < ident.ascii_len) {
cap *= 2;
// Check for overflows.
CHECK_OR((cap * 4) / 4 == cap, return );
}
// Store the output codepoints as groups of 4 UTF-8 bytes.
uint8_t *out = (uint8_t *)malloc(cap * 4);
CHECK_OR(out, return );
// Populate initial output from ASCII fragment.
for (len = 0; len < ident.ascii_len; len++) {
uint8_t *p = out + 4 * len;
p[0] = 0;
p[1] = 0;
p[2] = 0;
p[3] = ident.ascii[len];
}
// Punycode parameters and initial state.
size_t base = 36;
size_t t_min = 1;
size_t t_max = 26;
size_t skew = 38;
size_t damp = 700;
size_t bias = 72;
size_t i = 0;
uint32_t c = 0x80;
size_t punycode_pos = 0;
while (punycode_pos < ident.punycode_len) {
// Read one delta value.
size_t delta = 0;
size_t w = 1;
size_t k = 0;
size_t t;
uint8_t d;
do {
k += base;
t = k < bias ? 0 : (k - bias);
if (t < t_min)
t = t_min;
if (t > t_max)
t = t_max;
CHECK_OR(punycode_pos < ident.punycode_len, goto cleanup);
d = ident.punycode[punycode_pos++];
if (IS_LOWER(d))
d = d - 'a';
else if (IS_DIGIT(d))
d = 26 + (d - '0');
else
ERROR_AND(goto cleanup);
delta += d * w;
w *= base - t;
} while (d >= t);
// Compute the new insert position and character.
len++;
i += delta;
c += i / len;
i %= len;
// Ensure enough space is available.
if (cap < len) {
cap *= 2;
// Check for overflows.
CHECK_OR((cap * 4) / 4 == cap, goto cleanup);
CHECK_OR(cap >= len, goto cleanup);
}
uint8_t *p = (uint8_t *)realloc(out, cap * 4);
CHECK_OR(p, goto cleanup);
out = p;
// Move the characters after the insert position.
p = out + i * 4;
memmove(p + 4, p, (len - i - 1) * 4);
// Insert the new character, as UTF-8 bytes.
p[0] = c >= 0x10000 ? 0xf0 | (c >> 18) : 0;
p[1] = c >= 0x800 ? (c < 0x10000 ? 0xe0 : 0x80) | ((c >> 12) & 0x3f) : 0;
p[2] = (c < 0x800 ? 0xc0 : 0x80) | ((c >> 6) & 0x3f);
p[3] = 0x80 | (c & 0x3f);
// If there are no more deltas, decoding is complete.
if (punycode_pos == ident.punycode_len)
break;
i++;
// Perform bias adaptation.
delta /= damp;
damp = 2;
delta += delta / len;
k = 0;
while (delta > ((base - t_min) * t_max) / 2) {
delta /= base - t_min;
k += base;
}
bias = k + ((base - t_min + 1) * delta) / (delta + skew);
}
// Remove all the 0 bytes to leave behind an UTF-8 string.
size_t j;
for (i = 0, j = 0; i < len * 4; i++)
if (out[i] != 0)
out[j++] = out[i];
print_str(rdm, (const char *)out, j);
cleanup:
free(out);
} output: pub extern fn print_ident(arg_rdm: [*c]struct_rust_demangler, arg_ident: struct_rust_mangled_ident) callconv(.C) void; |
|
translate-c
- Error on functor type
Zig Version
0.10.0-dev.2836+2360f8c49
Steps to Reproduce
During the code translation a type mismatch occurs.
Original C code:
Full code:
Zig translated
Full code:
Expected Behavior
No error
Actual Behavior
The text was updated successfully, but these errors were encountered: