[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 08/08: Use a better type for symbol hashes.
From: |
G. Branden Robinson |
Subject: |
[groff] 08/08: Use a better type for symbol hashes. |
Date: |
Mon, 6 Mar 2023 16:22:22 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 5848bf3a3ee43a8be529d5d8bcef7a80c1ef3934
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Mar 6 12:50:15 2023 -0600
Use a better type for symbol hashes.
* bootstrap.conf: Add "stdint" module to ensure that the `uintptr_t`
type is available.
* src/include/symbol.h: Include <stdint.h> for `uintptr_t`.
(class symbol):
(symbol::hash): Change return type from `unsigned long`, which causes
build failures on 64-bit MinGW, to `uintptr_t`.
(symbol::hash): Use a C++ type cast, not a C-style one.
Thanks to Bruno Haible for reporting the build failure in the 64-bit
MinGW environment, and for suggesting a remedy.
Also update editor aid comments; drop old style Emacs file-local
variable setting.
Any day you get to use the foot-Howitzer reinterpret_cast is a good one.
Commits since 0221b657fe tested on:
Debian bullseye
Debian sid 2023-03-06 chroot
macOS 12
OpenBSD 7.2
Solaris 10
Solaris 11
---
ChangeLog | 15 +++++++++++++++
bootstrap.conf | 1 +
src/include/symbol.h | 17 ++++++++++++-----
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6d2b6a4b7..36c7200a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2023-03-06 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ Use a better type for symbol hashes.
+
+ * bootstrap.conf: Add "stdint" module to ensure that the
+ `uintptr_t` type is available.
+ * src/include/symbol.h: Include <stdint.h> for `uintptr_t`.
+ (class symbol):
+ (symbol::hash): Change return type from `unsigned long`, which
+ causes build failures on 64-bit MinGW, to `uintptr_t`.
+ (symbol::hash): Use a C++ type cast, not a C-style one.
+
+ Thanks to Bruno Haible for reporting the build failure in the
+ 64-bit MinGW environment, and for suggesting a remedy.
+
2023-03-06 G. Branden Robinson <g.branden.robinson@gmail.com>
[groff]: Revise a test to be more revealing.
diff --git a/bootstrap.conf b/bootstrap.conf
index 379a73ea3..48a27dcbc 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -43,6 +43,7 @@ gnulib_modules="
snprintf
vsnprintf
stdbool-c99
+ stdint
"
# Name of the Makefile.am
diff --git a/src/include/symbol.h b/src/include/symbol.h
index e8bf81946..047255d3b 100644
--- a/src/include/symbol.h
+++ b/src/include/symbol.h
@@ -1,5 +1,4 @@
-// -*- C++ -*-
-/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2023 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -17,6 +16,8 @@ for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#include <stdint.h> // uintptr_t
+
#define DONT_STORE 1
#define MUST_ALREADY_EXIST 2
@@ -30,7 +31,7 @@ class symbol {
public:
symbol(const char *p, int how = 0);
symbol();
- unsigned long hash() const;
+ uintptr_t hash() const;
int operator ==(symbol) const;
int operator !=(symbol) const;
const char *contents() const;
@@ -56,9 +57,9 @@ inline int symbol::operator!=(symbol p) const
return s != p.s;
}
-inline unsigned long symbol::hash() const
+inline uintptr_t symbol::hash() const
{
- return (unsigned long)s;
+ return reinterpret_cast<uintptr_t>(s);
}
inline const char *symbol::contents() const
@@ -79,3 +80,9 @@ inline int symbol::is_empty() const
symbol concat(symbol, symbol);
extern symbol default_symbol;
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 08/08: Use a better type for symbol hashes.,
G. Branden Robinson <=