mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Merge pull request #3704 from Feoramund/fix-fmt-p-verb
Fix `%p` pointers not printing leading `0x`
This commit is contained in:
+1
-1
@@ -1495,7 +1495,7 @@ fmt_pointer :: proc(fi: ^Info, p: rawptr, verb: rune) {
|
|||||||
u := u64(uintptr(p))
|
u := u64(uintptr(p))
|
||||||
switch verb {
|
switch verb {
|
||||||
case 'p', 'v', 'w':
|
case 'p', 'v', 'w':
|
||||||
if !fi.hash && verb == 'v' {
|
if !fi.hash {
|
||||||
io.write_string(fi.writer, "0x", &fi.n)
|
io.write_string(fi.writer, "0x", &fi.n)
|
||||||
}
|
}
|
||||||
_fmt_int(fi, u, 16, false, 8*size_of(rawptr), __DIGITS_UPPER)
|
_fmt_int(fi, u, 16, false, 8*size_of(rawptr), __DIGITS_UPPER)
|
||||||
|
|||||||
@@ -221,8 +221,45 @@ test_fmt_python_syntax :: proc(t: ^testing.T) {
|
|||||||
check(t, "%!(MISSING CLOSE BRACE)%!(EXTRA 1)", "{0", 1 )
|
check(t, "%!(MISSING CLOSE BRACE)%!(EXTRA 1)", "{0", 1 )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_pointers :: proc(t: ^testing.T) {
|
||||||
|
S :: struct { i: int }
|
||||||
|
a: rawptr
|
||||||
|
b: ^int
|
||||||
|
c: ^S
|
||||||
|
d: ^S = cast(^S)cast(uintptr)0xFFFF
|
||||||
|
|
||||||
|
check(t, "0x0", "%p", a)
|
||||||
|
check(t, "0x0", "%p", b)
|
||||||
|
check(t, "0x0", "%p", c)
|
||||||
|
check(t, "0xFFFF", "%p", d)
|
||||||
|
|
||||||
|
check(t, "0x0", "%#p", a)
|
||||||
|
check(t, "0x0", "%#p", b)
|
||||||
|
check(t, "0x0", "%#p", c)
|
||||||
|
check(t, "0xFFFF", "%#p", d)
|
||||||
|
|
||||||
|
check(t, "0x0", "%v", a)
|
||||||
|
check(t, "0x0", "%v", b)
|
||||||
|
check(t, "<nil>", "%v", c)
|
||||||
|
|
||||||
|
check(t, "0x0", "%#v", a)
|
||||||
|
check(t, "0x0", "%#v", b)
|
||||||
|
check(t, "<nil>", "%#v", c)
|
||||||
|
|
||||||
|
check(t, "0x0000", "%4p", a)
|
||||||
|
check(t, "0x0000", "%4p", b)
|
||||||
|
check(t, "0x0000", "%4p", c)
|
||||||
|
check(t, "0xFFFF", "%4p", d)
|
||||||
|
|
||||||
|
check(t, "0x0000", "%#4p", a)
|
||||||
|
check(t, "0x0000", "%#4p", b)
|
||||||
|
check(t, "0x0000", "%#4p", c)
|
||||||
|
check(t, "0xFFFF", "%#4p", d)
|
||||||
|
}
|
||||||
|
|
||||||
@(private)
|
@(private)
|
||||||
check :: proc(t: ^testing.T, exp: string, format: string, args: ..any) {
|
check :: proc(t: ^testing.T, exp: string, format: string, args: ..any, loc := #caller_location) {
|
||||||
got := fmt.tprintf(format, ..args)
|
got := fmt.tprintf(format, ..args)
|
||||||
testing.expectf(t, got == exp, "(%q, %v): %q != %q", format, args, got, exp)
|
testing.expectf(t, got == exp, "(%q, %v): %q != %q", format, args, got, exp, loc = loc)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user