summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc
diff options
context:
space:
mode:
authorTom Lane2014-01-23 22:18:23 +0000
committerTom Lane2014-01-23 22:18:33 +0000
commitac4ef637ad2ff2a24847f67d14027b8745f6741e (patch)
treecb49061503740d1bd9a0c916df55a29b4973fa64 /src/backend/storage/ipc
parentec8f692c3cd5760435712b7ec4afa8f014ed7b2e (diff)
Allow use of "z" flag in our printf calls, and use it where appropriate.
Since C99, it's been standard for printf and friends to accept a "z" size modifier, meaning "whatever size size_t has". Up to now we've generally dealt with printing size_t values by explicitly casting them to unsigned long and using the "l" modifier; but this is really the wrong thing on platforms where pointers are wider than longs (such as Win64). So let's start using "z" instead. To ensure we can do that on all platforms, teach src/port/snprintf.c to understand "z", and add a configure test to force use of that implementation when the platform's version doesn't handle "z". Having done that, modify a bunch of places that were using the unsigned-long hack to use "z" instead. This patch doesn't pretend to have gotten everyplace that could benefit, but it catches many of them. I made an effort in particular to ensure that all uses of the same error message text were updated together, so as not to increase the number of translatable strings. It's possible that this change will result in format-string warnings from pre-C99 compilers. We might have to reconsider if there are any popular compilers that will warn about this; but let's start by seeing what the buildfarm thinks. Andres Freund, with a little additional work by me
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r--src/backend/storage/ipc/dsm.c4
-rw-r--r--src/backend/storage/ipc/dsm_impl.c12
-rw-r--r--src/backend/storage/ipc/ipci.c3
-rw-r--r--src/backend/storage/ipc/shmem.c14
4 files changed, 15 insertions, 18 deletions
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c
index 4ee453e5ec4..327d6850971 100644
--- a/src/backend/storage/ipc/dsm.c
+++ b/src/backend/storage/ipc/dsm.c
@@ -201,8 +201,8 @@ dsm_postmaster_startup(void)
dsm_control = dsm_control_address;
on_shmem_exit(dsm_postmaster_shutdown, 0);
elog(DEBUG2,
- "created dynamic shared memory control segment %u (%lu bytes)",
- dsm_control_handle, (unsigned long) segsize);
+ "created dynamic shared memory control segment %u (%zu bytes)",
+ dsm_control_handle, segsize);
dsm_write_state_file(dsm_control_handle);
/* Initialize control segment. */
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index fc74990a2fa..a8d8a64afbd 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -329,8 +329,8 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
ereport(elevel,
(errcode_for_dynamic_shared_memory(),
- errmsg("could not resize shared memory segment %s to %lu bytes: %m",
- name, (unsigned long) request_size)));
+ errmsg("could not resize shared memory segment %s to %zu bytes: %m",
+ name, request_size)));
return false;
}
@@ -871,8 +871,8 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
ereport(elevel,
(errcode_for_dynamic_shared_memory(),
- errmsg("could not resize shared memory segment %s to %lu bytes: %m",
- name, (unsigned long) request_size)));
+ errmsg("could not resize shared memory segment %s to %zu bytes: %m",
+ name, request_size)));
return false;
}
else if (*mapped_size < request_size)
@@ -919,8 +919,8 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
ereport(elevel,
(errcode_for_dynamic_shared_memory(),
- errmsg("could not resize shared memory segment %s to %lu bytes: %m",
- name, (unsigned long) request_size)));
+ errmsg("could not resize shared memory segment %s to %zu bytes: %m",
+ name, request_size)));
return false;
}
}
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 3c04fc31bae..cc219237097 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -142,8 +142,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
/* might as well round it off to a multiple of a typical page size */
size = add_size(size, 8192 - (size % 8192));
- elog(DEBUG3, "invoking IpcMemoryCreate(size=%lu)",
- (unsigned long) size);
+ elog(DEBUG3, "invoking IpcMemoryCreate(size=%zu)", size);
/*
* Create the shmem segment
diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index 70b02ca8384..1d27a89bdd1 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -359,8 +359,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("not enough shared memory for data structure"
- " \"%s\" (%lu bytes requested)",
- name, (unsigned long) size)));
+ " \"%s\" (%zu bytes requested)",
+ name, size)));
shmemseghdr->index = structPtr;
*foundPtr = FALSE;
}
@@ -393,10 +393,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
LWLockRelease(ShmemIndexLock);
ereport(ERROR,
(errmsg("ShmemIndex entry size is wrong for data structure"
- " \"%s\": expected %lu, actual %lu",
- name,
- (unsigned long) size,
- (unsigned long) result->size)));
+ " \"%s\": expected %zu, actual %zu",
+ name, size, result->size)));
}
structPtr = result->location;
}
@@ -412,8 +410,8 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("not enough shared memory for data structure"
- " \"%s\" (%lu bytes requested)",
- name, (unsigned long) size)));
+ " \"%s\" (%zu bytes requested)",
+ name, size)));
}
result->size = size;
result->location = structPtr;