change %c in format strings to u32 unicode codepoint

This commit is contained in:
dzaima 2023-04-21 23:56:58 +03:00
parent 21ed8f77a7
commit 20b3867581
3 changed files with 6 additions and 6 deletions

View File

@ -325,7 +325,7 @@ A fancier message can be created with `thrF(message, …)` with printf-like (but
%s decimal usz
%f f64
%p pointer
%c char
%c unicode character (u32)
%S char* C-string consisting of ASCII
%U char* of UTF-8 data
%R a B object of a number or string (string is printed without quotes or escaping)

View File

@ -304,8 +304,8 @@ NOINLINE B do_fmt(B s, char* p, va_list a) {
break;
}
case 'c': {
buf[0] = va_arg(a, int); buf[1] = 0;
A8(buf);
u32 p = va_arg(a, u32);
ACHR(p);
break;
}
case '%': {

View File

@ -429,11 +429,11 @@ BQNFFIEnt ffi_parseTypeStr(u32** src, bool inPtr, bool top) { // parse actual ty
c++;
u8 t = *c++;
u32 n = readUInt(&c);
if (t=='i' | t=='c') if (n!=8 & n!=16 & n!=32) { badW: thrF("Bad width in :%c%i", t, n); }
if (t=='i' | t=='c') if (n!=8 & n!=16 & n!=32) { badW: thrF("Bad width in :%c%i", (u32)t, n); }
if (t=='u') if (n!=1 & n!=8 & n!=16 & n!=32) goto badW;
if (t=='f') if (n!=64) goto badW;
if (isC32(ro) && n > myWidth*8) thrF("FFI: Representation wider than the value for \"%S:%c%i\"", sty_names[o2cG(ro)], t, n);
if (isC32(ro) && n > myWidth*8) thrF("FFI: Representation wider than the value for \"%S:%c%i\"", sty_names[o2cG(ro)], (u32)t, n);
// TODO figure out what to do with i32:i32 etc
B roP = ro;
@ -588,7 +588,7 @@ void genObj(B o, B c, bool anyMut, void* ptr) {
if (isC32(o2)) { // scalar:any
u8 et = o2cG(o2);
u8 etw = sty_w[et]*8;
if (!isArr(c)) thrF("FFI: Expected array corresponding to \"%S:%c%i\"", sty_names[et], reT, 1<<reW);
if (!isArr(c)) thrF("FFI: Expected array corresponding to \"%S:%c%i\"", sty_names[et], (u32)reT, 1<<reW);
if (IA(c) != etw>>reW) thrM("FFI: Bad input array length");
B cG = toW(reT, reW, inc(c));
memcpy(ptr, tyany_ptr(cG), 8); // may over-read, ¯\_(ツ)_/¯