Remove unnecessary includes of system headers in header files

Started by Peter Eisentrautabout 2 years ago5 messages
#1Peter Eisentraut
peter@eisentraut.org
3 attachment(s)

I noticed that some header files included system header files for no
apparent reason, so I did some digging and found out that in a few cases
the original reason has disappeared. So I propose the attached patches
to remove the unnecessary includes.

Attachments:

0001-Remove-unnecessary-includes-of-signal.h.patchtext/plain; charset=UTF-8; name=0001-Remove-unnecessary-includes-of-signal.h.patchDownload
From 535c69e62f1ed3db27ea6d39d304ebfcf0f12a29 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 1 Dec 2023 08:32:11 +0100
Subject: [PATCH 1/3] Remove unnecessary includes of <signal.h>

These were once needed for sig_atomic_t, but that no longer appears in
these headers, so the include is not needed.
---
 src/include/replication/walsender.h       | 2 --
 src/include/replication/worker_internal.h | 2 --
 2 files changed, 4 deletions(-)

diff --git a/src/include/replication/walsender.h b/src/include/replication/walsender.h
index 268f8e8d0f..60313980a9 100644
--- a/src/include/replication/walsender.h
+++ b/src/include/replication/walsender.h
@@ -12,8 +12,6 @@
 #ifndef _WALSENDER_H
 #define _WALSENDER_H
 
-#include <signal.h>
-
 /*
  * What to do with a snapshot in create replication slot command.
  */
diff --git a/src/include/replication/worker_internal.h b/src/include/replication/worker_internal.h
index 47854b5cd4..db73408937 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -12,8 +12,6 @@
 #ifndef WORKER_INTERNAL_H
 #define WORKER_INTERNAL_H
 
-#include <signal.h>
-
 #include "access/xlogdefs.h"
 #include "catalog/pg_subscription.h"
 #include "datatype/timestamp.h"
-- 
2.43.0

0002-Remove-unnecessary-include-of-sys-socket.h.patchtext/plain; charset=UTF-8; name=0002-Remove-unnecessary-include-of-sys-socket.h.patchDownload
From b738db5a571fce7cf6b20ab8760f31d6c69b0002 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 1 Dec 2023 08:32:11 +0100
Subject: [PATCH 2/3] Remove unnecessary include of <sys/socket.h>

This was put here as part of a mechanical replacement of the old
"getaddrinfo.h" with <netdb.h> plus <sys/socket.h> (commit
5579388d2d).  But here, we only need netdb.h (for NI_MAXHOST), not
sys/socket.h.
---
 src/include/replication/walreceiver.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h
index 04b439dc50..949e874f21 100644
--- a/src/include/replication/walreceiver.h
+++ b/src/include/replication/walreceiver.h
@@ -13,7 +13,6 @@
 #define _WALRECEIVER_H
 
 #include <netdb.h>
-#include <sys/socket.h>
 
 #include "access/xlog.h"
 #include "access/xlogdefs.h"
-- 
2.43.0

0003-Remove-unnecessary-include-of-math.h.patchtext/plain; charset=UTF-8; name=0003-Remove-unnecessary-include-of-math.h.patchDownload
From e805f390a1ebafeeed3cb0e38f4cebba80a85c41 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 1 Dec 2023 08:32:11 +0100
Subject: [PATCH 3/3] Remove unnecessary include of <math.h>

This was probably never necessary.  (The header used to use random(),
but that shouldn't require <math.h> either.  In any case, that's gone,
too.)
---
 src/include/optimizer/geqo_random.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/include/optimizer/geqo_random.h b/src/include/optimizer/geqo_random.h
index 08b0c08d85..e3e12e900d 100644
--- a/src/include/optimizer/geqo_random.h
+++ b/src/include/optimizer/geqo_random.h
@@ -24,8 +24,6 @@
 #ifndef GEQO_RANDOM_H
 #define GEQO_RANDOM_H
 
-#include <math.h>
-
 #include "optimizer/geqo.h"
 
 
-- 
2.43.0

#2Shubham.Khanna@fujitsu.com
Shubham.Khanna@fujitsu.com
In reply to: Peter Eisentraut (#1)
RE: Remove unnecessary includes of system headers in header files

Hi Peter,

I have reviewed the patches and also RUN the command, 'make check-world'. It is working fine. All test cases are passed successfully.

Thanks and Regards,
Shubham Khanna.

-----Original Message-----
From: Peter Eisentraut <peter@eisentraut.org>
Sent: Friday, December 1, 2023 1:24 PM
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Remove unnecessary includes of system headers in header files

I noticed that some header files included system header files for no apparent reason, so I did some digging and found out that in a few cases the original reason has disappeared. So I propose the attached patches to remove the unnecessary includes.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: Remove unnecessary includes of system headers in header files

Peter Eisentraut <peter@eisentraut.org> writes:

I noticed that some header files included system header files for no
apparent reason, so I did some digging and found out that in a few cases
the original reason has disappeared. So I propose the attached patches
to remove the unnecessary includes.

Seems generally reasonable. Have you checked that headerscheck and
cpluspluscheck are happy?

regards, tom lane

#4Peter Eisentraut
peter@eisentraut.org
In reply to: Tom Lane (#3)
Re: Remove unnecessary includes of system headers in header files

On 01.12.23 17:41, Tom Lane wrote:

Peter Eisentraut <peter@eisentraut.org> writes:

I noticed that some header files included system header files for no
apparent reason, so I did some digging and found out that in a few cases
the original reason has disappeared. So I propose the attached patches
to remove the unnecessary includes.

Seems generally reasonable. Have you checked that headerscheck and
cpluspluscheck are happy?

Yes, I ran it through Cirrus, which includes those checks.

#5Peter Eisentraut
peter@eisentraut.org
In reply to: Shubham.Khanna@fujitsu.com (#2)
Re: Remove unnecessary includes of system headers in header files

On 01.12.23 11:51, Shubham.Khanna@fujitsu.com wrote:

Hi Peter,

I have reviewed the patches and also RUN the command, 'make check-world'. It is working fine. All test cases are passed successfully.

committed

Show quoted text

Thanks and Regards,
Shubham Khanna.

-----Original Message-----
From: Peter Eisentraut <peter@eisentraut.org>
Sent: Friday, December 1, 2023 1:24 PM
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Remove unnecessary includes of system headers in header files

I noticed that some header files included system header files for no apparent reason, so I did some digging and found out that in a few cases the original reason has disappeared. So I propose the attached patches to remove the unnecessary includes.