diff mbox series

[FFmpeg-devel,v2,07/13] avpriv_find_start_code(): constify pointer parameters

Message ID 20220203184450.5491-8-scott.the.elm@gmail.com
State New
Headers show
Series rewrite avpriv_find_start_code() for clarity | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Scott Theisen Feb. 3, 2022, 6:44 p.m. UTC
Have the compiler enforce not changing the addresses these parameters point to.

No functional change.
---
 libavcodec/internal.h | 6 +++---
 libavcodec/utils.c    | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

Comments

Andreas Rheinhardt Feb. 5, 2022, 5:49 a.m. UTC | #1
Scott Theisen:
> Have the compiler enforce not changing the addresses these parameters point to.
> 
> No functional change.
> ---
>  libavcodec/internal.h | 6 +++---
>  libavcodec/utils.c    | 4 ++--
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> index 94c41aef0b..dadd8d4a10 100644
> --- a/libavcodec/internal.h
> +++ b/libavcodec/internal.h
> @@ -313,7 +313,7 @@ static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) {
>   * @param[in] end   A pointer to the past-the-end memory address for the buffer
>   *                  given by @p p.  <b>@p p</b> must be ≤ <b>@p end</b>.
>   *
> - * @param[in,out] start_code A reference to a mutable @c uint32_t.<br>
> + * @param[in,out] start_code A constant pointer (reference) to a mutable @c uint32_t.<br>

There are no references in C.

>   *          As input: For no history preset to <b>@c ~0 </b>, otherwise preset to the last
>   *                    returned start code to enable detecting start codes across
>   *                    buffer boundaries.<br>
> @@ -325,8 +325,8 @@ static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) {
>   *         if no start code was found.
>   */
>  const uint8_t *avpriv_find_start_code(const uint8_t *p,
> -                                      const uint8_t *end,
> -                                      uint32_t *start_code);
> +                                      const uint8_t * const end,
> +                                      uint32_t * const start_code);
>  
>  int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec);
>  
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 80ccde023f..cf92d29f67 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -941,8 +941,8 @@ void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, in
>  #endif
>  
>  const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
> -                                      const uint8_t *end,
> -                                      uint32_t *av_restrict start_code)
> +                                      const uint8_t * const end,
> +                                      uint32_t * const av_restrict start_code)
>  {
>      av_assert0(p <= end);
>      if (p >= end)

Documenting restrictions on the callee that are irrelevant to the caller
in a public header seems weird.

- Andreas
Scott Theisen Feb. 5, 2022, 6:08 a.m. UTC | #2
On 2/5/22 00:49, Andreas Rheinhardt wrote:
>> - * @param[in,out] start_code A reference to a mutable @c uint32_t.<br>
>> + * @param[in,out] start_code A constant pointer (reference) to a mutable @c uint32_t.<br>
> There are no references in C.

A pointer is a type of reference.  However, I agree "A pointer to a 
mutable @c uint32_t.<br>" would be clearer.

> Documenting restrictions on the callee that are irrelevant to the caller
> in a public header seems weird.

Fair enough, the added consts shall be limited to libavcodec/utils.c.

-Scott
diff mbox series

Patch

diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 94c41aef0b..dadd8d4a10 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -313,7 +313,7 @@  static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) {
  * @param[in] end   A pointer to the past-the-end memory address for the buffer
  *                  given by @p p.  <b>@p p</b> must be ≤ <b>@p end</b>.
  *
- * @param[in,out] start_code A reference to a mutable @c uint32_t.<br>
+ * @param[in,out] start_code A constant pointer (reference) to a mutable @c uint32_t.<br>
  *          As input: For no history preset to <b>@c ~0 </b>, otherwise preset to the last
  *                    returned start code to enable detecting start codes across
  *                    buffer boundaries.<br>
@@ -325,8 +325,8 @@  static av_always_inline int avpriv_start_code_is_valid(uint32_t start_code) {
  *         if no start code was found.
  */
 const uint8_t *avpriv_find_start_code(const uint8_t *p,
-                                      const uint8_t *end,
-                                      uint32_t *start_code);
+                                      const uint8_t * const end,
+                                      uint32_t * const start_code);
 
 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec);
 
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 80ccde023f..cf92d29f67 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -941,8 +941,8 @@  void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, in
 #endif
 
 const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
-                                      const uint8_t *end,
-                                      uint32_t *av_restrict start_code)
+                                      const uint8_t * const end,
+                                      uint32_t * const av_restrict start_code)
 {
     av_assert0(p <= end);
     if (p >= end)