From 29df67221cb300451c4b1506343ea188481e518b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 29 Sep 2023 11:33:49 +0300 Subject: [PATCH 1/3] Update to Freeciv server freeciv/freeciv@14b7a645a7 Signed-off-by: Marko Lindqvist --- freeciv/apply_patches.sh | 8 - ...-correctly-if-senate-blocks-war-comp.patch | 30 --- ...ua-Fix-Unit-is_on_possible_city_tile.patch | 240 ------------------ freeciv/version.txt | 2 +- 4 files changed, 1 insertion(+), 279 deletions(-) delete mode 100644 freeciv/patches/backports/0022-AI-Set-countdown-correctly-if-senate-blocks-war-comp.patch delete mode 100644 freeciv/patches/backports/0022-Lua-Fix-Unit-is_on_possible_city_tile.patch diff --git a/freeciv/apply_patches.sh b/freeciv/apply_patches.sh index 1b0c0fa0f..c83ad2e10 100755 --- a/freeciv/apply_patches.sh +++ b/freeciv/apply_patches.sh @@ -5,12 +5,6 @@ # osdn #????? is ticket in freeciv.org tracker: # https://osdn.net/projects/freeciv/ticket/????? # -# 0022-AI-Set-countdown-correctly-if-senate-blocks-war-comp.patch -# AI assert failure fix -# osdn #47786 -# 0022-Lua-Fix-Unit-is_on_possible_city_tile.patch -# Fix finding cities from huts -# osdn #48582 # 0014-build_flatpak.sh-Support-build-outside-srcdir.patch # Form baseline for 0030-Flatpak-Build-with-meson.patch # osdn #48625 @@ -51,8 +45,6 @@ declare -a GIT_PATCHLIST=( ) declare -a PATCHLIST=( - "backports/0022-AI-Set-countdown-correctly-if-senate-blocks-war-comp" - "backports/0022-Lua-Fix-Unit-is_on_possible_city_tile" "backports/0014-build_flatpak.sh-Support-build-outside-srcdir" "backports/0030-Flatpak-Build-with-meson" "backports/0013-Meson-Replace-boolean-ruledit-option-with-tools-arra" diff --git a/freeciv/patches/backports/0022-AI-Set-countdown-correctly-if-senate-blocks-war-comp.patch b/freeciv/patches/backports/0022-AI-Set-countdown-correctly-if-senate-blocks-war-comp.patch deleted file mode 100644 index 56d1c8f26..000000000 --- a/freeciv/patches/backports/0022-AI-Set-countdown-correctly-if-senate-blocks-war-comp.patch +++ /dev/null @@ -1,30 +0,0 @@ -From d6ef2c980eb6b179064e6b2abfb1be6ddf18d529 Mon Sep 17 00:00:00 2001 -From: Marko Lindqvist -Date: Sun, 3 Sep 2023 08:37:00 +0300 -Subject: [PATCH 22/22] AI: Set countdown correctly if senate blocks war - completely - -Reported by alain_bkr - -See osdn #47786 - -Signed-off-by: Marko Lindqvist ---- - ai/default/daidiplomacy.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/ai/default/daidiplomacy.c b/ai/default/daidiplomacy.c -index d4803db406..db311b0c5f 100644 ---- a/ai/default/daidiplomacy.c -+++ b/ai/default/daidiplomacy.c -@@ -1383,6 +1383,7 @@ static void dai_go_to_war(struct ai_type *ait, struct player *pplayer, - } else { - /* There would be Senate even during revolution. Better not to revolt for nothing */ - pplayer->government = real_gov; -+ adip->countdown = -1; /* War declaration aborted */ - - DIPLO_LOG(ait, LOG_DEBUG, pplayer, target, - "Not revolting, as there would be Senate regardless."); --- -2.40.1 - diff --git a/freeciv/patches/backports/0022-Lua-Fix-Unit-is_on_possible_city_tile.patch b/freeciv/patches/backports/0022-Lua-Fix-Unit-is_on_possible_city_tile.patch deleted file mode 100644 index dc20f5205..000000000 --- a/freeciv/patches/backports/0022-Lua-Fix-Unit-is_on_possible_city_tile.patch +++ /dev/null @@ -1,240 +0,0 @@ -From 83efb2f0a7b8e7192baf111a539eac66a1c89957 Mon Sep 17 00:00:00 2001 -From: Marko Lindqvist -Date: Mon, 4 Sep 2023 12:19:18 +0300 -Subject: [PATCH 22/22] Lua: Fix Unit:is_on_possible_city_tile() - -See osdn #48582 - -Signed-off-by: Marko Lindqvist ---- - ai/default/daisettler.c | 5 +++-- - client/gui-gtk-3.22/editprop.c | 2 +- - client/gui-gtk-4.0/editprop.c | 2 +- - client/mapview_common.c | 10 +++++----- - client/tilespec.c | 2 +- - common/city.c | 26 ++++++++++++++++++++++++-- - common/city.h | 11 ++++++----- - common/scriptcore/api_game_methods.c | 6 +++++- - server/citytools.c | 2 +- - 9 files changed, 47 insertions(+), 19 deletions(-) - -diff --git a/ai/default/daisettler.c b/ai/default/daisettler.c -index fcfa772345..efa6546fdf 100644 ---- a/ai/default/daisettler.c -+++ b/ai/default/daisettler.c -@@ -707,7 +707,7 @@ struct cityresult *city_desirability(struct ai_type *ait, struct player *pplayer - fc_assert_ret_val(punit, NULL); - fc_assert_ret_val(pplayer, NULL); - -- if (!city_can_be_built_here(ptile, punit) -+ if (!city_can_be_built_here(ptile, punit, FALSE) - || (has_handicap(pplayer, H_MAP) - && !map_is_known(ptile, pplayer))) { - return NULL; -@@ -1037,10 +1037,11 @@ BUILD_CITY: - - /* Check that the mission is still possible. If the tile has become - * unavailable, call it off. */ -- if (!city_can_be_built_here(ptile, punit)) { -+ if (!city_can_be_built_here(ptile, punit, FALSE)) { - dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL); - set_unit_activity(punit, ACTIVITY_IDLE); - send_unit_info(NULL, punit); -+ - return; /* Avoid recursion at all cost */ - } else { - /* Go there */ -diff --git a/client/gui-gtk-3.22/editprop.c b/client/gui-gtk-3.22/editprop.c -index 75fd39639f..234a0dc695 100644 ---- a/client/gui-gtk-3.22/editprop.c -+++ b/client/gui-gtk-3.22/editprop.c -@@ -5826,7 +5826,7 @@ static void property_page_create_objects(struct property_page *pp, - if (pplayer && hint_tiles) { - tile_list_iterate(hint_tiles, atile) { - if (!is_enemy_unit_tile(atile, pplayer) -- && city_can_be_built_here(atile, NULL)) { -+ && city_can_be_built_here(atile, NULL, FALSE)) { - ptile = atile; - break; - } -diff --git a/client/gui-gtk-4.0/editprop.c b/client/gui-gtk-4.0/editprop.c -index 0ea24f350d..542ef91f57 100644 ---- a/client/gui-gtk-4.0/editprop.c -+++ b/client/gui-gtk-4.0/editprop.c -@@ -5849,7 +5849,7 @@ static void property_page_create_objects(struct property_page *pp, - if (pplayer && hint_tiles) { - tile_list_iterate(hint_tiles, atile) { - if (!is_enemy_unit_tile(atile, pplayer) -- && city_can_be_built_here(atile, NULL)) { -+ && city_can_be_built_here(atile, NULL, FALSE)) { - ptile = atile; - break; - } -diff --git a/client/mapview_common.c b/client/mapview_common.c -index f89772ec21..b84b563f80 100644 ---- a/client/mapview_common.c -+++ b/client/mapview_common.c -@@ -2873,21 +2873,21 @@ struct city *find_city_or_settler_near_tile(const struct tile *ptile, - if ((NULL == client.conn.playing - || unit_owner(psettler) == client.conn.playing) - && unit_can_do_action(psettler, ACTION_FOUND_CITY) -- && city_can_be_built_here(unit_tile(psettler), psettler)) { -- if (!closest_settler) { -+ && city_can_be_built_here(unit_tile(psettler), psettler, FALSE)) { -+ if (closest_settler == NULL) { - closest_settler = psettler; - } -- if (!best_settler && psettler->client.colored) { -+ if (best_settler == NULL && psettler->client.colored) { - best_settler = psettler; - } - } - } unit_list_iterate_end; - } city_tile_iterate_end; - -- if (best_settler) { -+ if (best_settler != NULL) { - /* Rule e */ - *punit = best_settler; -- } else if (closest_settler) { -+ } else if (closest_settler != NULL) { - /* Rule f */ - *punit = closest_settler; - } -diff --git a/client/tilespec.c b/client/tilespec.c -index 81a01dcc5e..6b8f79d461 100644 ---- a/client/tilespec.c -+++ b/client/tilespec.c -@@ -5521,7 +5521,7 @@ bool unit_drawn_with_city_outline(const struct unit *punit, bool check_focus) - && unit_is_cityfounder(punit) - && !unit_has_orders(punit) - && (client_tile_get_known(unit_tile(punit)) != TILE_UNKNOWN -- && city_can_be_built_here(unit_tile(punit), punit)) -+ && city_can_be_built_here(unit_tile(punit), punit, FALSE)) - && (!check_focus || unit_is_in_focus(punit)); - } - -diff --git a/common/city.c b/common/city.c -index 428a5bda9f..b850fea97f 100644 ---- a/common/city.c -+++ b/common/city.c -@@ -1463,8 +1463,11 @@ bool citymindist_prevents_city_on_tile(const struct tile *ptile) - blue (e.g., through editing). - **************************************************************************/ - bool city_can_be_built_here(const struct tile *ptile, -- const struct unit *punit) -+ const struct unit *punit, -+ bool hut_test) - { -+ struct civ_map *nmap = &(wld.map); -+ - if (!city_can_be_built_tile_only(ptile)) { - return FALSE; - } -@@ -1474,6 +1477,25 @@ bool city_can_be_built_here(const struct tile *ptile, - return TRUE; - } - -+ if (hut_test) { -+ struct player *towner; -+ -+ /* Huts can be found only from native tiles, owned by the unit owner. -+ * Unlike actual city building, this behavior is not affected -+ * by the ruleset. */ -+ if (!can_unit_exist_at_tile(nmap, punit, ptile)) { -+ return FALSE; -+ } -+ -+ towner = tile_owner(ptile); -+ -+ if (towner == NULL || towner == unit_owner(punit)) { -+ return TRUE; -+ } -+ -+ return FALSE; -+ } -+ - action_by_result_iterate(paction, ACTRES_FOUND_CITY) { - if (!utype_can_do_action(unit_type_get(punit), action_id(paction))) { - /* This action can't be done by this unit type at all. */ -@@ -1481,7 +1503,7 @@ bool city_can_be_built_here(const struct tile *ptile, - } - - /* Non native tile detection */ -- if (!can_unit_exist_at_tile(&(wld.map), punit, ptile) -+ if (!can_unit_exist_at_tile(nmap, punit, ptile) - /* The ruleset may allow founding cities on non native terrain. */ - && !utype_can_do_act_when_ustate(unit_type_get(punit), paction->id, - USP_LIVABLE_TILE, FALSE)) { -diff --git a/common/city.h b/common/city.h -index 0485dfb4bd..9c508c800e 100644 ---- a/common/city.h -+++ b/common/city.h -@@ -683,11 +683,11 @@ void generate_city_map_indices(void); - void free_city_map_index(void); - void city_production_caravan_shields_init(void); - --/* output on spot */ -+/* Output on spot */ - int city_tile_output(const struct city *pcity, const struct tile *ptile, -- bool is_celebrating, Output_type_id otype); -+ bool is_celebrating, Output_type_id otype); - int city_tile_output_now(const struct city *pcity, const struct tile *ptile, -- Output_type_id otype); -+ Output_type_id otype); - - bool base_city_can_work_tile(const struct player *restriction, - const struct city *pcity, -@@ -697,10 +697,11 @@ bool city_can_work_tile(const struct city *pcity, const struct tile *ptile); - bool citymindist_prevents_city_on_tile(const struct tile *ptile); - - bool city_can_be_built_here(const struct tile *ptile, -- const struct unit *punit); -+ const struct unit *punit, -+ bool hut_test); - bool city_can_be_built_tile_only(const struct tile *ptile); - --/* list functions */ -+/* List functions */ - struct city *city_list_find_number(struct city_list *This, int id); - struct city *city_list_find_name(struct city_list *This, const char *name); - -diff --git a/common/scriptcore/api_game_methods.c b/common/scriptcore/api_game_methods.c -index 942ae2a599..183b43d3d9 100644 ---- a/common/scriptcore/api_game_methods.c -+++ b/common/scriptcore/api_game_methods.c -@@ -1312,13 +1312,17 @@ int api_methods_tile_sq_distance(lua_State *L, Tile *ptile1, Tile *ptile2) - - /**********************************************************************//** - Can punit found a city on its tile? -+ -+ FIXME: Unlike name suggests, this is currently used for finding -+ cities from huts and the like, and is not suitable for checking -+ if specified unit could act to build a city. - **************************************************************************/ - bool api_methods_unit_city_can_be_built_here(lua_State *L, Unit *punit) - { - LUASCRIPT_CHECK_STATE(L, FALSE); - LUASCRIPT_CHECK_SELF(L, punit, FALSE); - -- return city_can_be_built_here(unit_tile(punit), punit); -+ return city_can_be_built_here(unit_tile(punit), punit, TRUE); - } - - /**********************************************************************//** -diff --git a/server/citytools.c b/server/citytools.c -index 4ccdd8fced..0bfe43cb8a 100644 ---- a/server/citytools.c -+++ b/server/citytools.c -@@ -1673,7 +1673,7 @@ bool create_city_for_player(struct player *pplayer, struct tile *ptile, - const char *name) - { - if (is_enemy_unit_tile(ptile, pplayer) -- || !city_can_be_built_here(ptile, nullptr)) { -+ || !city_can_be_built_here(ptile, nullptr, FALSE)) { - return FALSE; - } - --- -2.40.1 - diff --git a/freeciv/version.txt b/freeciv/version.txt index 8c6dd34b4..749e7a98b 100644 --- a/freeciv/version.txt +++ b/freeciv/version.txt @@ -1,7 +1,7 @@ # The Git SHA hash for the commit to checkout from # https://github.com/freeciv/freeciv -FCREV=0f17de73dcaac86739cbcc107aecc3271d64a893 +FCREV=14b7a645a74155d4f3dd300221c5b4f0ffca8fe8 ORIGCAPSTR="+Freeciv.Devel-\${MAIN_VERSION}-2023.Sep.02" From 17c4cdf4d463d301b38265373d6bcf8f3f054235 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 29 Sep 2023 21:27:42 +0300 Subject: [PATCH 2/3] Server: Backport 0047-Meson-Turn-audio-option-to-a-combo.patch Signed-off-by: Marko Lindqvist --- freeciv/apply_patches.sh | 4 + ...7-Meson-Turn-audio-option-to-a-combo.patch | 81 +++++++++++++++++++ freeciv/prepare_freeciv.sh | 2 +- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 freeciv/patches/backports/0047-Meson-Turn-audio-option-to-a-combo.patch diff --git a/freeciv/apply_patches.sh b/freeciv/apply_patches.sh index c83ad2e10..57a6148de 100755 --- a/freeciv/apply_patches.sh +++ b/freeciv/apply_patches.sh @@ -23,6 +23,9 @@ # 0036-tile_move_cost_ptrs-Make-cardinal_move-signed.patch # Unit movemenet handling fix # osdn #48737 +# 0047-Meson-Turn-audio-option-to-a-combo.patch +# Rework disabling audio +# osdn #48757 # Not in the upstream Freeciv server # ---------------------------------- @@ -51,6 +54,7 @@ declare -a PATCHLIST=( "backports/0031-Lua-Always-pass-lua_Integer-to-API_TYPE_INT" "backports/0042-Meson-Make-manual-generator-build-optional" "backports/0036-tile_move_cost_ptrs-Make-cardinal_move-signed" + "backports/0047-Meson-Turn-audio-option-to-a-combo" "meson_webperimental" "metachange" "text_fixes" diff --git a/freeciv/patches/backports/0047-Meson-Turn-audio-option-to-a-combo.patch b/freeciv/patches/backports/0047-Meson-Turn-audio-option-to-a-combo.patch new file mode 100644 index 000000000..003b2bb71 --- /dev/null +++ b/freeciv/patches/backports/0047-Meson-Turn-audio-option-to-a-combo.patch @@ -0,0 +1,81 @@ +From 258d802b11fe6998f1b09581c1923c87499ccd02 Mon Sep 17 00:00:00 2001 +From: Marko Lindqvist +Date: Fri, 29 Sep 2023 20:50:33 +0300 +Subject: [PATCH 47/47] Meson: Turn 'audio' option to a combo + +See osdn #48757 + +Signed-off-by: Marko Lindqvist +--- + doc/INSTALL.meson | 4 ++-- + meson.build | 6 +++--- + meson_options.txt | 7 ++++--- + 3 files changed, 9 insertions(+), 8 deletions(-) + +diff --git a/doc/INSTALL.meson b/doc/INSTALL.meson +index 88f8c7af4c..98636a6e01 100644 +--- a/doc/INSTALL.meson ++++ b/doc/INSTALL.meson +@@ -147,8 +147,8 @@ readline ('try'/'true'/'false') + Whether to enable readline functionality on server. + The default is 'try' to enable it if suitable readline found. + +-audio (boolean): +- Build sound support to the clients. Defaults to true. ++audio ('none'/'sdl2'): ++ What kind of sound support should be built to the clients. Defaults to sdl2. + + tools (array): + Extra tools to build: +diff --git a/meson.build b/meson.build +index ce7ba03070..45663542c9 100644 +--- a/meson.build ++++ b/meson.build +@@ -770,7 +770,7 @@ if c_compiler.compiles('''int main(void) { __builtin_unreachable(); return 0; }' + pub_conf_data.set('FREECIV_HAVE_UNREACHABLE', 1) + endif + +-if get_option('audio') or get_option('clients').contains('sdl2') ++if get_option('audio') == 'sdl2' or get_option('clients').contains('sdl2') + if host_system == 'windows' + sdl2main_dep = [c_compiler.find_library('mingw32', dirs: cross_lib_path), + c_compiler.find_library('SDL2main', dirs: cross_lib_path), +@@ -781,7 +781,7 @@ if get_option('audio') or get_option('clients').contains('sdl2') + '-s', 'USE_SDL=2' + ] + +- if get_option('audio') ++ if get_option('audio') == 'sdl2' + emscripten_sdl2_args += [ '-s', 'USE_SDL_MIXER=2' ] + endif + +@@ -840,7 +840,7 @@ else + qt_opts = 'cpp_std=c++17' + endif + +-if get_option('audio') ++if get_option('audio') != 'none' + priv_conf_data.set('AUDIO_SDL', 1) + + if emscripten +diff --git a/meson_options.txt b/meson_options.txt +index f5bb14e456..ac65a3f727 100644 +--- a/meson_options.txt ++++ b/meson_options.txt +@@ -46,9 +46,10 @@ option('readline', + description: 'Enable readline functionality') + + option('audio', +- type: 'boolean', +- value: true, +- description: 'Build in sound support') ++ type: 'combo', ++ choices: ['none', 'sdl2'], ++ value: 'sdl2', ++ description: 'Sound support type to build') + + option('tools', + type: 'array', +-- +2.40.1 + diff --git a/freeciv/prepare_freeciv.sh b/freeciv/prepare_freeciv.sh index cf33e7bb5..d69b441f8 100755 --- a/freeciv/prepare_freeciv.sh +++ b/freeciv/prepare_freeciv.sh @@ -35,7 +35,7 @@ mkdir -p build ( cd build meson setup ../freeciv -Dserver='freeciv-web' \ -Dclients=[] -Dfcmp=cli -Djson-protocol=true -Dnls=false \ - -Daudio=false -Dtools=manual \ + -Daudio=none -Dtools=manual \ -Dproject-definition=../freeciv-web.fcproj \ -Ddefault_library=static -Dprefix=${HOME}/freeciv \ -Doptimization=3 $EXTRA_MESON_PARAMS From 04057e78fe8bb4c28d90e2cb4518f08f441a70ba Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 2 Oct 2023 00:15:04 +0300 Subject: [PATCH 3/3] Server: Backport new bitvector utility functions Signed-off-by: Marko Lindqvist --- freeciv/apply_patches.sh | 12 +++ ...-Add-new-bitvector-utility-functions.patch | 76 +++++++++++++++++++ ...47-Add-bv_match_dbv-utility-function.patch | 57 ++++++++++++++ .../0057-Fix-bitvector-copy-functions.patch | 48 ++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 freeciv/patches/backports/0008-Add-new-bitvector-utility-functions.patch create mode 100644 freeciv/patches/backports/0047-Add-bv_match_dbv-utility-function.patch create mode 100644 freeciv/patches/backports/0057-Fix-bitvector-copy-functions.patch diff --git a/freeciv/apply_patches.sh b/freeciv/apply_patches.sh index 57a6148de..1c92cdc73 100755 --- a/freeciv/apply_patches.sh +++ b/freeciv/apply_patches.sh @@ -26,6 +26,15 @@ # 0047-Meson-Turn-audio-option-to-a-combo.patch # Rework disabling audio # osdn #48757 +# 0008-Add-new-bitvector-utility-functions.patch +# New bitvector utility functions +# osdn #48731 +# 0047-Add-bv_match_dbv-utility-function.patch +# New bitvector utility function +# osdn #48771 +# 0057-Fix-bitvector-copy-functions.patch +# Fix to bitvector utility functions +# osdn #48772 # Not in the upstream Freeciv server # ---------------------------------- @@ -55,6 +64,9 @@ declare -a PATCHLIST=( "backports/0042-Meson-Make-manual-generator-build-optional" "backports/0036-tile_move_cost_ptrs-Make-cardinal_move-signed" "backports/0047-Meson-Turn-audio-option-to-a-combo" + "backports/0008-Add-new-bitvector-utility-functions" + "backports/0047-Add-bv_match_dbv-utility-function" + "backports/0057-Fix-bitvector-copy-functions" "meson_webperimental" "metachange" "text_fixes" diff --git a/freeciv/patches/backports/0008-Add-new-bitvector-utility-functions.patch b/freeciv/patches/backports/0008-Add-new-bitvector-utility-functions.patch new file mode 100644 index 000000000..51ae7df5e --- /dev/null +++ b/freeciv/patches/backports/0008-Add-new-bitvector-utility-functions.patch @@ -0,0 +1,76 @@ +From ef337f93a4c8d4147da296703ef466252a449137 Mon Sep 17 00:00:00 2001 +From: Marko Lindqvist +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 +--- + 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 + diff --git a/freeciv/patches/backports/0047-Add-bv_match_dbv-utility-function.patch b/freeciv/patches/backports/0047-Add-bv_match_dbv-utility-function.patch new file mode 100644 index 000000000..dd75ccfd2 --- /dev/null +++ b/freeciv/patches/backports/0047-Add-bv_match_dbv-utility-function.patch @@ -0,0 +1,57 @@ +From e0f53590a33f02bc3c082382c02dabdfb0861f60 Mon Sep 17 00:00:00 2001 +From: Marko Lindqvist +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 +--- + 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 + diff --git a/freeciv/patches/backports/0057-Fix-bitvector-copy-functions.patch b/freeciv/patches/backports/0057-Fix-bitvector-copy-functions.patch new file mode 100644 index 000000000..6d8d56997 --- /dev/null +++ b/freeciv/patches/backports/0057-Fix-bitvector-copy-functions.patch @@ -0,0 +1,48 @@ +From 7184a785f82ecd5aac8fe0830355e71d4614501b Mon Sep 17 00:00:00 2001 +From: Marko Lindqvist +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 +--- + 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 +