MCPcopy Index your code
hub / github.com/RustPython/RustPython / dump_hexadecimal

Function dump_hexadecimal

crates/stdlib/src/faulthandler.rs:150–171  ·  view source on GitHub ↗
(fd: i32, value: u64, width: usize)

Source from the content-addressed store, hash-verified

148 // _Py_DumpHexadecimal (traceback.c)
149 #[cfg(any(unix, windows))]
150 fn dump_hexadecimal(fd: i32, value: u64, width: usize) {
151 const HEX_CHARS: &[u8; 16] = b"0123456789abcdef";
152 let mut buf = [0u8; 18]; // "0x" + 16 hex digits
153 buf[0] = b'0';
154 buf[1] = b'x';
155
156 for i in 0..width {
157 let digit = ((value >> (4 * (width - 1 - i))) & 0xf) as usize;
158 buf[2 + i] = HEX_CHARS[digit];
159 }
160
161 let _ = unsafe {
162 #[cfg(windows)]
163 {
164 libc::write(fd, buf.as_ptr() as *const libc::c_void, (2 + width) as u32)
165 }
166 #[cfg(not(windows))]
167 {
168 libc::write(fd, buf.as_ptr() as *const libc::c_void, 2 + width)
169 }
170 };
171 }
172
173 // _Py_DumpDecimal (traceback.c)
174 #[cfg(any(unix, windows))]

Callers 2

write_thread_idFunction · 0.85
faulthandler_exc_handlerFunction · 0.85

Calls 2

writeFunction · 0.50
as_ptrMethod · 0.45

Tested by

no test coverage detected