aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-02-27 16:30:32 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2023-03-03 14:19:46 +0100
commit166b149d5b473f277c63e64ced03c40df44ac3c9 (patch)
treeaf1b66f0a4b0b13ad128d0cef106aef5bfbfc704
parentfbaf5bde55d42869ed6d9e9fc072110ac9976c66 (diff)
downloadrneovim-166b149d5b473f277c63e64ced03c40df44ac3c9.tar.gz
rneovim-166b149d5b473f277c63e64ced03c40df44ac3c9.tar.bz2
rneovim-166b149d5b473f277c63e64ced03c40df44ac3c9.zip
refactor(build): remove unused stdlib function and include checks
In addition: merge some checks for the same feature into one test_compile. This reduces the total number of test compiles which speeds up the cmake configure stage.
-rw-r--r--cmake.config/CMakeLists.txt32
-rw-r--r--cmake.config/config.h.in13
-rwxr-xr-xsrc/nvim/CMakeLists.txt10
-rw-r--r--src/nvim/charset.c2
-rw-r--r--src/nvim/fileio.c10
-rw-r--r--src/nvim/os/os_defs.h5
-rw-r--r--src/nvim/os/shell.c4
-rw-r--r--src/nvim/os/users.c10
8 files changed, 38 insertions, 48 deletions
diff --git a/cmake.config/CMakeLists.txt b/cmake.config/CMakeLists.txt
index 1a06eccf68..7e8c7ecd16 100644
--- a/cmake.config/CMakeLists.txt
+++ b/cmake.config/CMakeLists.txt
@@ -28,9 +28,7 @@ int main(void)
check_type_size("int" SIZEOF_INT LANGUAGE C)
check_type_size("long" SIZEOF_LONG LANGUAGE C)
check_type_size("intmax_t" SIZEOF_INTMAX_T LANGUAGE C)
-check_type_size("int32_t" SIZEOF_INT32_T LANGUAGE C)
check_type_size("size_t" SIZEOF_SIZE_T LANGUAGE C)
-check_type_size("long long" SIZEOF_LONG_LONG LANGUAGE C)
check_type_size("void *" SIZEOF_VOID_PTR LANGUAGE C)
check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
@@ -38,7 +36,6 @@ check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
# Headers
check_include_files(langinfo.h HAVE_LANGINFO_H)
check_include_files(locale.h HAVE_LOCALE_H)
-check_include_files(pwd.h HAVE_PWD_H)
check_include_files(strings.h HAVE_STRINGS_H)
check_include_files(sys/utsname.h HAVE_SYS_UTSNAME_H)
check_include_files(termios.h HAVE_TERMIOS_H)
@@ -47,15 +44,8 @@ check_include_files(sys/sdt.h HAVE_SYS_SDT_H)
# Functions
check_function_exists(fseeko HAVE_FSEEKO)
-check_function_exists(getpwent HAVE_GETPWENT)
-check_function_exists(getpwnam HAVE_GETPWNAM)
-check_function_exists(getpwuid HAVE_GETPWUID)
check_function_exists(readv HAVE_READV)
-check_function_exists(opendir HAVE_OPENDIR)
check_function_exists(readlink HAVE_READLINK)
-check_function_exists(setpgid HAVE_SETPGID)
-check_function_exists(setsid HAVE_SETSID)
-check_function_exists(sigaction HAVE_SIGACTION)
check_function_exists(strnlen HAVE_STRNLEN)
check_function_exists(strcasecmp HAVE_STRCASECMP)
check_function_exists(strncasecmp HAVE_STRNCASECMP)
@@ -64,22 +54,28 @@ check_function_exists(strptime HAVE_STRPTIME)
check_c_source_compiles("
#include <sys/types.h>
#include <dirent.h>
+#include <sys/file.h>
int main(void)
{
DIR *dir = opendir(\"dirname\");
dirfd(dir);
+ flock(10, LOCK_SH);
return 0;
}
-" HAVE_DIRFD)
+" HAVE_DIRFD_AND_FLOCK)
+
check_c_source_compiles("
-#include <sys/file.h>
+#include <pwd.h>
int main(void)
{
- flock(10, LOCK_SH);
+ getpwent();
+ getpwuid(0);
+ getpwnam(\"root\");
return 0;
}
-" HAVE_FLOCK)
+" HAVE_PWD_FUNCS)
+
if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
check_c_source_compiles("
@@ -101,11 +97,13 @@ if(HAVE_LANGINFO_H)
endif()
check_include_files("endian.h" HAVE_ENDIAN_H)
-check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
set(ENDIAN_INCLUDE_FILE "endian.h")
-if(HAVE_SYS_ENDIAN_H AND NOT HAVE_ENDIAN_H)
- set(ENDIAN_INCLUDE_FILE "sys/endian.h")
+if(NOT HAVE_ENDIAN_H)
+ check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
+ if (HAVE_SYS_ENDIAN_H)
+ set(ENDIAN_INCLUDE_FILE "sys/endian.h")
+ endif()
endif()
set(SI "#include <stdint.h>\n")
diff --git a/cmake.config/config.h.in b/cmake.config/config.h.in
index 4669e42c0f..a1b46f8cb5 100644
--- a/cmake.config/config.h.in
+++ b/cmake.config/config.h.in
@@ -3,9 +3,7 @@
#cmakedefine SIZEOF_INT @SIZEOF_INT@
#cmakedefine SIZEOF_INTMAX_T @SIZEOF_INTMAX_T@
-#cmakedefine SIZEOF_INT32_T @SIZEOF_INT32_T@
#cmakedefine SIZEOF_LONG @SIZEOF_LONG@
-#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@
#cmakedefine SIZEOF_SIZE_T @SIZEOF_SIZE_T@
#if @SIZEOF_VOID_PTR@ == 8
@@ -19,18 +17,12 @@
#cmakedefine HAVE__NSGETENVIRON
#cmakedefine HAVE_FD_CLOEXEC
#cmakedefine HAVE_FSEEKO
-#cmakedefine HAVE_GETPWENT
-#cmakedefine HAVE_GETPWNAM
-#cmakedefine HAVE_GETPWUID
#cmakedefine HAVE_LANGINFO_H
#cmakedefine HAVE_LOCALE_H
#cmakedefine HAVE_NL_LANGINFO_CODESET
#cmakedefine HAVE_NL_MSG_CAT_CNTR
-#cmakedefine HAVE_PWD_H
+#cmakedefine HAVE_PWD_FUNCS
#cmakedefine HAVE_READLINK
-#cmakedefine HAVE_SETPGID
-#cmakedefine HAVE_SETSID
-#cmakedefine HAVE_SIGACTION
#cmakedefine HAVE_STRNLEN
#cmakedefine HAVE_STRCASECMP
#cmakedefine HAVE_STRINGS_H
@@ -51,8 +43,7 @@
# undef HAVE_SYS_UIO_H
# endif
#endif
-#cmakedefine HAVE_DIRFD
-#cmakedefine HAVE_FLOCK
+#cmakedefine HAVE_DIRFD_AND_FLOCK
#cmakedefine HAVE_FORKPTY
#ifndef UNIT_TESTING
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 8c23b501f9..504dde5a9c 100755
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -240,13 +240,15 @@ endif()
if(UNIX)
# -fstack-protector breaks non Unix builds even in Mingw-w64
check_c_compiler_flag(-fstack-protector-strong HAS_FSTACK_PROTECTOR_STRONG_FLAG)
- check_c_compiler_flag(-fstack-protector HAS_FSTACK_PROTECTOR_FLAG)
if(HAS_FSTACK_PROTECTOR_STRONG_FLAG)
target_compile_options(main_lib INTERFACE -fstack-protector-strong)
target_link_libraries(main_lib INTERFACE -fstack-protector-strong)
- elseif(HAS_FSTACK_PROTECTOR_FLAG)
- target_compile_options(main_lib INTERFACE -fstack-protector --param ssp-buffer-size=4)
- target_link_libraries(main_lib INTERFACE -fstack-protector --param ssp-buffer-size=4)
+ else()
+ check_c_compiler_flag(-fstack-protector HAS_FSTACK_PROTECTOR_FLAG)
+ if(HAS_FSTACK_PROTECTOR_FLAG)
+ target_compile_options(main_lib INTERFACE -fstack-protector --param ssp-buffer-size=4)
+ target_link_libraries(main_lib INTERFACE -fstack-protector --param ssp-buffer-size=4)
+ endif()
endif()
endif()
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 1cfb5350f3..bf18d110c0 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -1446,7 +1446,7 @@ long getdigits_long(char **pp, bool strict, long def)
int32_t getdigits_int32(char **pp, bool strict, long def)
{
intmax_t number = getdigits(pp, strict, def);
-#if SIZEOF_INTMAX_T > SIZEOF_INT32_T
+#if SIZEOF_INTMAX_T > 4
if (strict) {
assert(number >= INT32_MIN && number <= INT32_MAX);
} else if (!(number >= INT32_MIN && number <= INT32_MAX)) {
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 755b8e0834..c93df43cff 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -68,7 +68,7 @@
# include "nvim/charset.h"
#endif
-#if defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
+#ifdef HAVE_DIRFD_AND_FLOCK
# include <dirent.h>
# include <sys/file.h>
#endif
@@ -5146,7 +5146,7 @@ void forward_slash(char *fname)
/// Path to Nvim's own temp dir. Ends in a slash.
static char *vim_tempdir = NULL;
-#if defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
+#ifdef HAVE_DIRFD_AND_FLOCK
DIR *vim_tempdir_dp = NULL; ///< File descriptor of temp dir
#endif
@@ -5316,7 +5316,7 @@ int delete_recursive(const char *name)
return result;
}
-#if defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
+#ifdef HAVE_DIRFD_AND_FLOCK
/// Open temporary directory and take file lock to prevent
/// to be auto-cleaned.
static void vim_opentempdir(void)
@@ -5353,7 +5353,7 @@ void vim_deltempdir(void)
return;
}
-#if defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
+#ifdef HAVE_DIRFD_AND_FLOCK
vim_closetempdir();
#endif
// remove the trailing path separator
@@ -5391,7 +5391,7 @@ static bool vim_settempdir(char *tempdir)
vim_FullName(tempdir, buf, MAXPATHL, false);
add_pathsep(buf);
vim_tempdir = xstrdup(buf);
-#if defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
+#ifdef HAVE_DIRFD_AND_FLOCK
vim_opentempdir();
#endif
xfree(buf);
diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h
index f86c0d3483..9e201f1dfa 100644
--- a/src/nvim/os/os_defs.h
+++ b/src/nvim/os/os_defs.h
@@ -36,10 +36,9 @@
// Command-processing buffer. Use large buffers for all platforms.
#define CMDBUFFSIZE 1024
-// Note: Some systems need both string.h and strings.h (Savage). However,
-// some systems can't handle both, only use string.h in that case.
+// Note: Some systems need both string.h and strings.h (Savage).
#include <string.h>
-#if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H)
+#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index f1e2c5440f..f7d1154169 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -399,8 +399,8 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in
fclose(fd);
return FAIL;
}
-#if SIZEOF_LONG_LONG > SIZEOF_SIZE_T
- assert(templen <= (long long)SIZE_MAX); // NOLINT(runtime/int)
+#if 8 > SIZEOF_SIZE_T
+ assert(templen <= SIZE_MAX); // NOLINT(runtime/int)
#endif
len = (size_t)templen;
fseek(fd, 0L, SEEK_SET);
diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c
index ef2986246b..411ba91fa7 100644
--- a/src/nvim/os/users.c
+++ b/src/nvim/os/users.c
@@ -15,7 +15,7 @@
#include "nvim/os/os.h"
#include "nvim/types.h"
#include "nvim/vim.h"
-#ifdef HAVE_PWD_H
+#ifdef HAVE_PWD_FUNCS
# include <pwd.h>
#endif
#ifdef MSWIN
@@ -50,7 +50,7 @@ int os_get_usernames(garray_T *users)
}
ga_init(users, sizeof(char *), 20);
-#if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H)
+#ifdef HAVE_PWD_FUNCS
{
struct passwd *pw;
@@ -81,7 +81,7 @@ int os_get_usernames(garray_T *users)
}
}
#endif
-#if defined(HAVE_GETPWNAM)
+#ifdef HAVE_PWD_FUNCS
{
const char *user_env = os_getenv("USER");
@@ -141,7 +141,7 @@ int os_get_username(char *s, size_t len)
/// @return OK if a username was found, else FAIL.
int os_get_uname(uv_uid_t uid, char *s, size_t len)
{
-#if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID)
+#ifdef HAVE_PWD_FUNCS
struct passwd *pw;
if ((pw = getpwuid(uid)) != NULL // NOLINT(runtime/threadsafe_fn)
@@ -159,7 +159,7 @@ int os_get_uname(uv_uid_t uid, char *s, size_t len)
/// Caller must free() the returned string.
char *os_get_userdir(const char *name)
{
-#if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
+#ifdef HAVE_PWD_FUNCS
if (name == NULL || *name == NUL) {
return NULL;
}