[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 01/01: Rename `array_size` to `array_length`.
From: |
G. Branden Robinson |
Subject: |
[groff] 01/01: Rename `array_size` to `array_length`. |
Date: |
Mon, 28 Aug 2023 16:27:32 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit e0cb0910cb14831cec1173cdcd4b6b362d35df7d
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Aug 28 15:06:20 2023 -0500
Rename `array_size` to `array_length`.
* src/include/lib.h (array_size): Rename to...
(array_length): ...this.
* src/preproc/eqn/box.cpp (set_param, reset_param, get_param)
(init_param_table, free_param_table): Migrate call sites.
Thanks to Alex Colomar for the discussion.
See <https://lists.gnu.org/archive/html/groff/2023-08/msg00140.html>.
Acked-by: Alejandro Colomar <alx@kernel.org>
---
ChangeLog | 10 ++++++++++
HACKING | 6 ++++++
src/include/lib.h | 2 +-
src/preproc/eqn/box.cpp | 12 ++++++------
4 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 40f395359..6e11965c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-08-28 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/include/lib.h (array_size): Rename to...
+ (array_length): ...this.
+
+ * src/preproc/eqn/box.cpp (set_param, reset_param, get_param)
+ (init_param_table, free_param_table): Migrate call sites.
+
+ Thanks to Alex Colomar for the discussion.
+
2023-08-28 G. Branden Robinson <g.branden.robinson@gmail.com>
* Makefile.am (EXTRA_DIST): Ship ancient groff ChangeLog files
diff --git a/HACKING b/HACKING
index 73c29fc70..c5acaf86a 100644
--- a/HACKING
+++ b/HACKING
@@ -22,6 +22,12 @@ Standard Template Library is little used. A modest effort
is underway
to update the code to more idiomatic C++98. Where a C++11 feature
promises to be advantageous, it may be annotated in a code comment.
+Portability notes:
+
+* `std::size` is not available in C++98. Use the `array_length`
+ template function in src/include/lib.h instead of `sizeof` and
+ dividing.
+
Automake
--------
diff --git a/src/include/lib.h b/src/include/lib.h
index 841f0ed99..c08ab5b4b 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -155,7 +155,7 @@ static const double PI = 3.14159265358979323846;
#ifdef __cplusplus
template <typename T, size_t N>
// constexpr // C++11
-size_t array_size(T(&)[N]) {
+size_t array_length(T(&)[N]) {
return N;
}
#endif
diff --git a/src/preproc/eqn/box.cpp b/src/preproc/eqn/box.cpp
index 6a1313a9c..7e455ef69 100644
--- a/src/preproc/eqn/box.cpp
+++ b/src/preproc/eqn/box.cpp
@@ -135,7 +135,7 @@ struct param *param_table = 0 /* nullptr */;
void set_param(const char *name, int value)
{
- for (size_t i = 0; i <= array_size(default_param_table); i++)
+ for (size_t i = 0; i <= array_length(default_param_table); i++)
if (strcmp(param_table[i].name, name) == 0) {
*(param_table[i].ptr) = value;
return;
@@ -145,7 +145,7 @@ void set_param(const char *name, int value)
void reset_param(const char *name)
{
- for (size_t i = 0; i < array_size(default_param_table); i++)
+ for (size_t i = 0; i < array_length(default_param_table); i++)
if (strcmp(param_table[i].name, name) == 0) {
*param_table[i].ptr = *(default_param_table[i].ptr);
return;
@@ -156,7 +156,7 @@ void reset_param(const char *name)
int get_param(const char *name)
{
- for (size_t i = 0; i < array_size(default_param_table); i++)
+ for (size_t i = 0; i < array_length(default_param_table); i++)
if (strcmp(param_table[i].name, name) == 0)
return *(param_table[i].ptr);
assert(0 == "attempted to access parameter not in table");
@@ -165,8 +165,8 @@ int get_param(const char *name)
void init_param_table()
{
- param_table = new param[array_size(default_param_table)];
- for (size_t i = 0; i < array_size(default_param_table); i++) {
+ param_table = new param[array_length(default_param_table)];
+ for (size_t i = 0; i < array_length(default_param_table); i++) {
param_table[i].name = default_param_table[i].name;
param_table[i].ptr = new int(*(default_param_table[i].ptr));
}
@@ -175,7 +175,7 @@ void init_param_table()
void free_param_table()
{
if (param_table != 0 /* nullptr */) {
- for (size_t i = 0; i < array_size(default_param_table); i++)
+ for (size_t i = 0; i < array_length(default_param_table); i++)
delete param_table[i].ptr;
delete[] param_table;
param_table = 0 /* nullptr */;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 01/01: Rename `array_size` to `array_length`.,
G. Branden Robinson <=
- Prev by Date:
[groff] 18/27: ChangeLog.{old,111,112,113,114}: Split off.
- Next by Date:
[groff] 01/14: [libdriver, grohtml]: Revise diagnostics.
- Previous by thread:
[groff] 18/27: ChangeLog.{old,111,112,113,114}: Split off.
- Next by thread:
[groff] 01/14: [libdriver, grohtml]: Revise diagnostics.
- Index(es):