-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server: Backport new bitvector utility functions
Signed-off-by: Marko Lindqvist <[email protected]>
- Loading branch information
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
freeciv/patches/backports/0008-Add-new-bitvector-utility-functions.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
From ef337f93a4c8d4147da296703ef466252a449137 Mon Sep 17 00:00:00 2001 | ||
From: Marko Lindqvist <[email protected]> | ||
Date: Tue, 26 Sep 2023 12:32:50 +0300 | ||
Subject: [PATCH 08/47] Add new bitvector utility functions | ||
|
||
- dbv_copy() | ||
- dbv_to_bv() | ||
- bv_to_dbv() | ||
|
||
See osdn #48731 | ||
|
||
Signed-off-by: Marko Lindqvist <[email protected]> | ||
--- | ||
utility/bitvector.c | 30 ++++++++++++++++++++++++++++++ | ||
utility/bitvector.h | 4 ++++ | ||
2 files changed, 34 insertions(+) | ||
|
||
diff --git a/utility/bitvector.c b/utility/bitvector.c | ||
index 2d1851b68b..65047bfda6 100644 | ||
--- a/utility/bitvector.c | ||
+++ b/utility/bitvector.c | ||
@@ -198,6 +198,36 @@ bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2) | ||
_BV_BYTES(pdbv2->bits)); | ||
} | ||
|
||
+/***********************************************************************//** | ||
+ Copy dynamic bit vector content from another. | ||
+***************************************************************************/ | ||
+void dbv_copy(struct dbv *dest, const struct dbv *src) | ||
+{ | ||
+ if (dest->bits != src->bits) { | ||
+ dbv_resize(dest, src->bits); | ||
+ } | ||
+ | ||
+ memcpy(&dest->vec, &src->vec, _BV_BYTES(src->bits)); | ||
+} | ||
+ | ||
+/***********************************************************************//** | ||
+ Copy dynamic bit vector content to static bitvector. Static vector | ||
+ is assumed to be at least same size as the dynamic one. | ||
+***************************************************************************/ | ||
+void dbv_to_bv(unsigned char *dest, const struct dbv *src) | ||
+{ | ||
+ memcpy(dest, &(src->vec), _BV_BYTES(src->bits)); | ||
+} | ||
+ | ||
+/***********************************************************************//** | ||
+ Copy static bit vector content to dynamic bitvector. Static vector | ||
+ is assumed to be at least same size as the dynamic one. | ||
+***************************************************************************/ | ||
+void bv_to_dbv(struct dbv *dest, const unsigned char *src) | ||
+{ | ||
+ memcpy(&(dest->vec), dest, _BV_BYTES(dest->bits)); | ||
+} | ||
+ | ||
/***********************************************************************//** | ||
Debug a dynamic bitvector. | ||
***************************************************************************/ | ||
diff --git a/utility/bitvector.h b/utility/bitvector.h | ||
index cccde12a83..9ce4230853 100644 | ||
--- a/utility/bitvector.h | ||
+++ b/utility/bitvector.h | ||
@@ -50,6 +50,10 @@ void dbv_clr(struct dbv *pdbv, int bit); | ||
void dbv_clr_all(struct dbv *pdbv); | ||
|
||
bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2); | ||
+void dbv_copy(struct dbv *dest, const struct dbv *src); | ||
+ | ||
+void dbv_to_bv(unsigned char *dest, const struct dbv *src); | ||
+void bv_to_dbv(struct dbv *dest, const unsigned char *src); | ||
|
||
void dbv_debug(struct dbv *pdbv); | ||
|
||
-- | ||
2.40.1 | ||
|
57 changes: 57 additions & 0 deletions
57
freeciv/patches/backports/0047-Add-bv_match_dbv-utility-function.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
From e0f53590a33f02bc3c082382c02dabdfb0861f60 Mon Sep 17 00:00:00 2001 | ||
From: Marko Lindqvist <[email protected]> | ||
Date: Sun, 1 Oct 2023 03:53:26 +0300 | ||
Subject: [PATCH 47/47] Add bv_match_dbv() utility function | ||
|
||
See osdn #48771 | ||
|
||
Signed-off-by: Marko Lindqvist <[email protected]> | ||
--- | ||
utility/bitvector.c | 18 ++++++++++++++++++ | ||
utility/bitvector.h | 1 + | ||
2 files changed, 19 insertions(+) | ||
|
||
diff --git a/utility/bitvector.c b/utility/bitvector.c | ||
index 65047bfda6..7debd38ede 100644 | ||
--- a/utility/bitvector.c | ||
+++ b/utility/bitvector.c | ||
@@ -198,6 +198,24 @@ bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2) | ||
_BV_BYTES(pdbv2->bits)); | ||
} | ||
|
||
+/***********************************************************************//** | ||
+ Is content of static bitvector same as that of dynamic one. | ||
+ Comparison size is taken from the dynamic one. | ||
+***************************************************************************/ | ||
+bool bv_match_dbv(const struct dbv *match, const unsigned char *src) | ||
+{ | ||
+ size_t bytes = _BV_BYTES(match->bits); | ||
+ int i; | ||
+ | ||
+ for (i = 0; i < bytes; i++) { | ||
+ if (match->vec[i] != src[i]) { | ||
+ return FALSE; | ||
+ } | ||
+ } | ||
+ | ||
+ return TRUE; | ||
+} | ||
+ | ||
/***********************************************************************//** | ||
Copy dynamic bit vector content from another. | ||
***************************************************************************/ | ||
diff --git a/utility/bitvector.h b/utility/bitvector.h | ||
index 9ce4230853..7c0879a4cf 100644 | ||
--- a/utility/bitvector.h | ||
+++ b/utility/bitvector.h | ||
@@ -50,6 +50,7 @@ void dbv_clr(struct dbv *pdbv, int bit); | ||
void dbv_clr_all(struct dbv *pdbv); | ||
|
||
bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2); | ||
+bool bv_match_dbv(const struct dbv *match, const unsigned char *src); | ||
void dbv_copy(struct dbv *dest, const struct dbv *src); | ||
|
||
void dbv_to_bv(unsigned char *dest, const struct dbv *src); | ||
-- | ||
2.40.1 | ||
|
48 changes: 48 additions & 0 deletions
48
freeciv/patches/backports/0057-Fix-bitvector-copy-functions.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
From 7184a785f82ecd5aac8fe0830355e71d4614501b Mon Sep 17 00:00:00 2001 | ||
From: Marko Lindqvist <[email protected]> | ||
Date: Sun, 1 Oct 2023 23:17:57 +0300 | ||
Subject: [PATCH 57/57] Fix bitvector copy functions | ||
|
||
So far unused functions were copying either from or to wrong address | ||
|
||
See osdn #48772 | ||
|
||
Signed-off-by: Marko Lindqvist <[email protected]> | ||
--- | ||
utility/bitvector.c | 6 +++--- | ||
1 file changed, 3 insertions(+), 3 deletions(-) | ||
|
||
diff --git a/utility/bitvector.c b/utility/bitvector.c | ||
index 7debd38ede..17a65411e6 100644 | ||
--- a/utility/bitvector.c | ||
+++ b/utility/bitvector.c | ||
@@ -225,7 +225,7 @@ void dbv_copy(struct dbv *dest, const struct dbv *src) | ||
dbv_resize(dest, src->bits); | ||
} | ||
|
||
- memcpy(&dest->vec, &src->vec, _BV_BYTES(src->bits)); | ||
+ memcpy(&dest->vec, src->vec, _BV_BYTES(src->bits)); | ||
} | ||
|
||
/***********************************************************************//** | ||
@@ -234,7 +234,7 @@ void dbv_copy(struct dbv *dest, const struct dbv *src) | ||
***************************************************************************/ | ||
void dbv_to_bv(unsigned char *dest, const struct dbv *src) | ||
{ | ||
- memcpy(dest, &(src->vec), _BV_BYTES(src->bits)); | ||
+ memcpy(dest, src->vec, _BV_BYTES(src->bits)); | ||
} | ||
|
||
/***********************************************************************//** | ||
@@ -243,7 +243,7 @@ void dbv_to_bv(unsigned char *dest, const struct dbv *src) | ||
***************************************************************************/ | ||
void bv_to_dbv(struct dbv *dest, const unsigned char *src) | ||
{ | ||
- memcpy(&(dest->vec), dest, _BV_BYTES(dest->bits)); | ||
+ memcpy(dest->vec, dest, _BV_BYTES(dest->bits)); | ||
} | ||
|
||
/***********************************************************************//** | ||
-- | ||
2.40.1 | ||
|