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 %s decimal usz
%f f64 %f f64
%p pointer %p pointer
%c char %c unicode character (u32)
%S char* C-string consisting of ASCII %S char* C-string consisting of ASCII
%U char* of UTF-8 data %U char* of UTF-8 data
%R a B object of a number or string (string is printed without quotes or escaping) %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; break;
} }
case 'c': { case 'c': {
buf[0] = va_arg(a, int); buf[1] = 0; u32 p = va_arg(a, u32);
A8(buf); ACHR(p);
break; break;
} }
case '%': { case '%': {

View File

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