mirror of
https://github.com/python/cpython.git
synced 2026-06-07 02:11:41 +00:00
gh-149300: _remote_debugging: clean up magic and duplicate consts in the binary format helper (#149301)
This commit is contained in:
parent
9a268e3e33
commit
9dca1ff759
3 changed files with 47 additions and 29 deletions
|
|
@ -23,15 +23,11 @@
|
|||
* ============================================================================ */
|
||||
|
||||
/* File structure sizes */
|
||||
#define FILE_FOOTER_SIZE 32
|
||||
#define MIN_DECOMPRESS_BUFFER_SIZE (64 * 1024) /* Minimum decompression buffer */
|
||||
|
||||
/* Progress callback frequency */
|
||||
#define PROGRESS_CALLBACK_INTERVAL 1000
|
||||
|
||||
/* Maximum decompression size limit (1GB) */
|
||||
#define MAX_DECOMPRESS_SIZE (1ULL << 30)
|
||||
|
||||
/* ============================================================================
|
||||
* BINARY READER IMPLEMENTATION
|
||||
* ============================================================================ */
|
||||
|
|
@ -47,8 +43,8 @@ reader_parse_header(BinaryReader *reader, const uint8_t *data, size_t file_size)
|
|||
/* Use memcpy to avoid strict aliasing violations and unaligned access */
|
||||
uint32_t magic;
|
||||
uint32_t version;
|
||||
memcpy(&magic, &data[0], sizeof(magic));
|
||||
memcpy(&version, &data[4], sizeof(version));
|
||||
memcpy(&magic, &data[HDR_OFF_MAGIC], HDR_SIZE_MAGIC);
|
||||
memcpy(&version, &data[HDR_OFF_VERSION], HDR_SIZE_VERSION);
|
||||
|
||||
/* Detect endianness from magic number */
|
||||
if (magic == BINARY_FORMAT_MAGIC) {
|
||||
|
|
@ -119,8 +115,8 @@ reader_parse_footer(BinaryReader *reader, const uint8_t *data, size_t file_size)
|
|||
const uint8_t *footer = data + file_size - FILE_FOOTER_SIZE;
|
||||
/* Use memcpy to avoid strict aliasing violations */
|
||||
uint32_t strings_count, frames_count;
|
||||
memcpy(&strings_count, &footer[0], sizeof(strings_count));
|
||||
memcpy(&frames_count, &footer[4], sizeof(frames_count));
|
||||
memcpy(&strings_count, &footer[FTR_OFF_STRINGS], FTR_SIZE_STRINGS);
|
||||
memcpy(&frames_count, &footer[FTR_OFF_FRAMES], FTR_SIZE_FRAMES);
|
||||
|
||||
reader->strings_count = SWAP32_IF(reader->needs_swap, strings_count);
|
||||
reader->frames_count = SWAP32_IF(reader->needs_swap, frames_count);
|
||||
|
|
@ -984,11 +980,11 @@ binary_reader_replay(BinaryReader *reader, PyObject *collector, PyObject *progre
|
|||
/* Use memcpy to avoid strict aliasing violations, then byte-swap if needed */
|
||||
uint64_t thread_id_raw;
|
||||
uint32_t interpreter_id_raw;
|
||||
memcpy(&thread_id_raw, &reader->sample_data[offset], sizeof(thread_id_raw));
|
||||
offset += 8;
|
||||
memcpy(&thread_id_raw, &reader->sample_data[offset], SMP_SIZE_THREAD_ID);
|
||||
offset += SMP_SIZE_THREAD_ID;
|
||||
|
||||
memcpy(&interpreter_id_raw, &reader->sample_data[offset], sizeof(interpreter_id_raw));
|
||||
offset += 4;
|
||||
memcpy(&interpreter_id_raw, &reader->sample_data[offset], SMP_SIZE_INTERPRETER_ID);
|
||||
offset += SMP_SIZE_INTERPRETER_ID;
|
||||
|
||||
uint64_t thread_id = SWAP64_IF(reader->needs_swap, thread_id_raw);
|
||||
uint32_t interpreter_id = SWAP32_IF(reader->needs_swap, interpreter_id_raw);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue