From 5668cae79da67fee2eab6c5ce480fed521446680 Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Tue, 7 Apr 2026 21:21:57 +0200 Subject: [PATCH v20260407 4/4] Some check simplification/deduplication. --- src/backend/storage/ipc/shmem.c | 60 ++++++++++----------------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index 12de6344cac..540a51b50e5 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -704,49 +704,23 @@ AttachShmemIndexEntry(ShmemRequest *request, bool missing_ok) return false; } - /* Check that the sizes in the index match the request. */ - if (index_entry->size != request->options->size && - request->options->size != SHMEM_ATTACH_UNKNOWN_SIZE) - { - ereport(ERROR, - (errmsg("shared memory struct \"%s\" was created with" - " different size: existing %zu, requested %zu", - name, index_entry->size, request->options->size))); - } - - /* - * For resizable structures, also check that minimum_size and maximum_size - * match. For fixed-size structures, these are derived (set to size) in - * the index entry and not meaningful in the request. - */ - if (request->options->maximum_size != 0) - { - if (index_entry->minimum_size != request->options->minimum_size && - request->options->minimum_size != SHMEM_ATTACH_UNKNOWN_SIZE) - { - ereport(ERROR, - (errmsg("shared memory struct \"%s\" was created with" - " different minimum_size: existing %zu, requested %zu", - name, index_entry->minimum_size, - request->options->minimum_size))); - } - - if (index_entry->maximum_size != request->options->maximum_size && - request->options->maximum_size != SHMEM_ATTACH_UNKNOWN_SIZE) - { - ereport(ERROR, - (errmsg("shared memory struct \"%s\" was created with" - " different maximum_size: existing %zu, requested %zu", - name, index_entry->maximum_size, - request->options->maximum_size))); - } - } - else - { - if (index_entry->minimum_size != index_entry->maximum_size) - elog(ERROR, "shared memory struct \"%s\" was created as resizable, but requested as fixed-size", - name); - } +#define CHECK_SIZE(size) \ +do { \ + /* Check that the sizes in the index match the request. */ \ + if (request->options->size != SHMEM_ATTACH_UNKNOWN_SIZE && \ + index_entry->size != request->options->size) \ + { \ + ereport(ERROR, \ + (errmsg("shared memory struct \"%s\" was created with" \ + " different %s: existing %zu, requested %zu", \ + name, CppAsString(size), index_entry->size, \ + request->options->size))); \ + } \ +} while (false) + + CHECK_SIZE(size); + CHECK_SIZE(minimum_size); + CHECK_SIZE(maximum_size); /* * Re-establish the caller's pointer variable, or do other actions to -- 2.50.1 (Apple Git-155)