[PATCH 2/4] score: Return a status in _Objects_Set_name()

Gedare Bloom gedare at rtems.org
Wed Nov 25 17:26:55 UTC 2020


Should rtems_object_set_name() propagate the memory error condition also?

On Tue, Nov 24, 2020 at 5:52 AM Sebastian Huber <
sebastian.huber at embedded-brains.de> wrote:

> ---
>  cpukit/include/rtems/score/objectimpl.h | 14 ++++++++------
>  cpukit/score/src/objectsetname.c        |  6 +++---
>  testsuites/psxtests/psxobj01/init.c     |  6 +++---
>  3 files changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/cpukit/include/rtems/score/objectimpl.h
> b/cpukit/include/rtems/score/objectimpl.h
> index 32387594f2..a963396d65 100644
> --- a/cpukit/include/rtems/score/objectimpl.h
> +++ b/cpukit/include/rtems/score/objectimpl.h
> @@ -25,6 +25,7 @@
>  #include <rtems/score/apimutex.h>
>  #include <rtems/score/assert.h>
>  #include <rtems/score/isrlock.h>
> +#include <rtems/score/status.h>
>  #include <rtems/score/sysstate.h>
>  #include <rtems/score/threaddispatch.h>
>
> @@ -463,14 +464,15 @@ size_t _Objects_Name_to_string(
>   * or up to the first four characters of the string based upon
>   * whether this object class uses strings for names.
>   *
> - * @param information points to the object information structure
> - * @param[out] the_object is the object to operate upon
> - * @param name is a pointer to the name to use
> + * @param information points to the object information.
> + * @param[out] the_object is the object to operate upon.
> + * @param name is a pointer to the name to use.
>   *
> - * @retval true The operation succeeded.
> - * @retval false The operation failed.
> + * @retval STATUS_SUCCESSFUL The operation succeeded.
> + *
> + * @retval STATUS_NO_MEMORY There was no memory available to duplicate
> the name.
>   */
> -bool _Objects_Set_name(
> +Status_Control _Objects_Set_name(
>    const Objects_Information *information,
>    Objects_Control           *the_object,
>    const char                *name
> diff --git a/cpukit/score/src/objectsetname.c
> b/cpukit/score/src/objectsetname.c
> index 0808ab87af..4d85332711 100644
> --- a/cpukit/score/src/objectsetname.c
> +++ b/cpukit/score/src/objectsetname.c
> @@ -24,7 +24,7 @@
>
>  #include <string.h>
>
> -bool _Objects_Set_name(
> +Status_Control _Objects_Set_name(
>    const Objects_Information *information,
>    Objects_Control           *the_object,
>    const char                *name
> @@ -37,7 +37,7 @@ bool _Objects_Set_name(
>      length = strnlen( name, information->name_length );
>      dup = _Workspace_String_duplicate( name, length );
>      if ( dup == NULL ) {
> -      return false;
> +      return STATUS_NO_MEMORY;
>      }
>
>      the_object->name.name_p = dup;
> @@ -59,5 +59,5 @@ bool _Objects_Set_name(
>        _Objects_Build_name( c[ 0 ], c[ 1 ], c[ 2 ], c[ 3 ] );
>    }
>
> -  return true;
> +  return STATUS_SUCCESSFUL;
>  }
> diff --git a/testsuites/psxtests/psxobj01/init.c
> b/testsuites/psxtests/psxobj01/init.c
> index ba1e327ea5..fef749b3e9 100644
> --- a/testsuites/psxtests/psxobj01/init.c
> +++ b/testsuites/psxtests/psxobj01/init.c
> @@ -37,7 +37,7 @@ static rtems_task Init(
>    Objects_Control           *the_object;
>    char                       name[64];
>    size_t                     name_len;
> -  bool                       bc;
> +  Status_Control             status;
>
>    TEST_BEGIN();
>
> @@ -70,12 +70,12 @@ static rtems_task Init(
>    puts( "INIT - _Objects_Set_name fails - out of memory" );
>    rtems_workspace_greedy_allocate( NULL, 0 );
>
> -  bc = _Objects_Set_name(
> +  status = _Objects_Set_name(
>      &Test_Information,
>      &_Thread_Get_executing()->Object,
>      name
>    );
> -  rtems_test_assert( bc == false );
> +  rtems_test_assert( status == STATUS_NO_MEMORY );
>
>    TEST_END();
>    rtems_test_exit(0);
> --
> 2.26.2
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20201125/929b87f5/attachment.html>


More information about the devel mailing list