From 4aa4f75058b758ca6f7dbf692fd40e4c082205aa Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Thu, 14 Mar 2024 09:57:40 +0100 Subject: [PATCH 1/3] fix aliased string `move` --- src/stdlib_string_type.fypp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/stdlib_string_type.fypp b/src/stdlib_string_type.fypp index 6ca4e1363..88c698800 100644 --- a/src/stdlib_string_type.fypp +++ b/src/stdlib_string_type.fypp @@ -17,6 +17,7 @@ module stdlib_string_type & to_title_ => to_title, to_sentence_ => to_sentence, reverse_ => reverse use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool use stdlib_optval, only: optval + use iso_c_binding, only: c_loc,c_associated implicit none private @@ -679,10 +680,12 @@ contains !> Moves the allocated character scalar from 'from' to 'to' !> No output elemental subroutine move_string_string(from, to) - type(string_type), intent(inout) :: from - type(string_type), intent(inout) :: to - character(:), allocatable :: tmp + type(string_type), intent(inout), target :: from + type(string_type), intent(inout), target :: to + character(:), allocatable :: tmp + if (c_associated(c_loc(from),c_loc(to))) return + call move_alloc(from%raw, tmp) call move_alloc(tmp, to%raw) From 299230599b634ae0951992db3143b2b7abe1cc43 Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Thu, 14 Mar 2024 10:20:44 +0100 Subject: [PATCH 2/3] temporary is now unnecessary --- src/stdlib_string_type.fypp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/stdlib_string_type.fypp b/src/stdlib_string_type.fypp index 88c698800..fa77c8f33 100644 --- a/src/stdlib_string_type.fypp +++ b/src/stdlib_string_type.fypp @@ -682,12 +682,9 @@ contains elemental subroutine move_string_string(from, to) type(string_type), intent(inout), target :: from type(string_type), intent(inout), target :: to - character(:), allocatable :: tmp if (c_associated(c_loc(from),c_loc(to))) return - - call move_alloc(from%raw, tmp) - call move_alloc(tmp, to%raw) + call move_alloc(from%raw, to%raw) end subroutine move_string_string From 9703a803f6be41d7b4ec19d02e5ad88922dd8d63 Mon Sep 17 00:00:00 2001 From: Federico Perini Date: Thu, 14 Mar 2024 14:44:15 +0100 Subject: [PATCH 3/3] do not use `iso_c_binding` --- src/stdlib_string_type.fypp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/stdlib_string_type.fypp b/src/stdlib_string_type.fypp index fa77c8f33..4ee87ddf2 100644 --- a/src/stdlib_string_type.fypp +++ b/src/stdlib_string_type.fypp @@ -17,7 +17,6 @@ module stdlib_string_type & to_title_ => to_title, to_sentence_ => to_sentence, reverse_ => reverse use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool use stdlib_optval, only: optval - use iso_c_binding, only: c_loc,c_associated implicit none private @@ -682,8 +681,10 @@ contains elemental subroutine move_string_string(from, to) type(string_type), intent(inout), target :: from type(string_type), intent(inout), target :: to + type(string_type), pointer :: fromp - if (c_associated(c_loc(from),c_loc(to))) return + fromp => from + if (associated(fromp,to)) return call move_alloc(from%raw, to%raw) end subroutine move_string_string