diff mbox series

[2/4] compat/regex: silence `make sparse` warning

Message ID 25f595f56f7f895ab31bf7269aabad9142c0590c.1587648870.git.congdanhqx@gmail.com (mailing list archive)
State New, archived
Headers show
Series fix make sparse warning | expand

Commit Message

Đoàn Trần Công Danh April 23, 2020, 1:47 p.m. UTC
* alloca: somewhere later in the code, we indirectly include alloca.h
which will define alloca again, include it prior to define alloca in
order to not define it against.

* Copy all attributes from the header to source file, and move the
  attributes prior to function name. cgcc is very picky on the position
  of attribute.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
 compat/regex/regex.c          | 1 +
 compat/regex/regex_internal.c | 2 +-
 compat/regex/regex_internal.h | 5 ++---
 3 files changed, 4 insertions(+), 4 deletions(-)

Comments

Ramsay Jones April 24, 2020, 12:51 a.m. UTC | #1
On 23/04/2020 14:47, Đoàn Trần Công Danh wrote:
> * alloca: somewhere later in the code, we indirectly include alloca.h
> which will define alloca again, include it prior to define alloca in
> order to not define it against.
> 
> * Copy all attributes from the header to source file, and move the
>   attributes prior to function name. cgcc is very picky on the position
>   of attribute.

This patch is no longer needed (iff you use a bleeding edge version of
sparse), since this was fixed in commit 172f6a98 ("let function definition inherit prototype attributes", 2019-11-19).

  $ git describe 172f6a98
  v0.6.1-37-g172f6a98
  $ 

Ah, so this fix is not in any released version of sparse (v0.6.1 is the
current release - I always build/run the tip of the 'master' branch from
the sparse git repo).

I starred at this warning for years (on cygwin, I don't build with NO_REGEX
on Linux), but I didn't send a patch for it because it was a sparse fault.

ATB,
Ramsay Jones

> 
> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
> ---
>  compat/regex/regex.c          | 1 +
>  compat/regex/regex_internal.c | 2 +-
>  compat/regex/regex_internal.h | 5 ++---
>  3 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/compat/regex/regex.c b/compat/regex/regex.c
> index f3e03a9eab..4bef75a716 100644
> --- a/compat/regex/regex.c
> +++ b/compat/regex/regex.c
> @@ -62,6 +62,7 @@
>  #include <stdint.h>
>  
>  #ifdef GAWK
> +#include <alloca.h>
>  #undef alloca
>  #define alloca alloca_is_bad_you_should_never_use_it
>  #endif
> diff --git a/compat/regex/regex_internal.c b/compat/regex/regex_internal.c
> index ec51cf3446..58504f795b 100644
> --- a/compat/regex/regex_internal.c
> +++ b/compat/regex/regex_internal.c
> @@ -921,7 +921,7 @@ re_string_destruct (re_string_t *pstr)
>  /* Return the context at IDX in INPUT.  */
>  
>  static unsigned int
> -internal_function
> +internal_function __attribute ((pure))
>  re_string_context_at (const re_string_t *input, int idx, int eflags)
>  {
>    int c;
> diff --git a/compat/regex/regex_internal.h b/compat/regex/regex_internal.h
> index 3ee8aae59d..c61a1e4971 100644
> --- a/compat/regex/regex_internal.h
> +++ b/compat/regex/regex_internal.h
> @@ -430,9 +430,8 @@ static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
>  # endif /* RE_ENABLE_I18N */
>  static void build_upper_buffer (re_string_t *pstr) internal_function;
>  static void re_string_translate_buffer (re_string_t *pstr) internal_function;
> -static unsigned int re_string_context_at (const re_string_t *input, int idx,
> -					  int eflags)
> -     internal_function __attribute ((pure));
> +static internal_function __attribute ((pure))
> +unsigned int re_string_context_at (const re_string_t *input, int idx, int eflags);
>  #endif
>  #define re_string_peek_byte(pstr, offset) \
>    ((pstr)->mbs[(pstr)->cur_idx + offset])
>
Đoàn Trần Công Danh April 24, 2020, 1:04 a.m. UTC | #2
On 2020-04-24 01:51:40+0100, Ramsay Jones <ramsay@ramsayjones.plus.com> wrote:
> 
> 
> On 23/04/2020 14:47, Đoàn Trần Công Danh wrote:
> > * alloca: somewhere later in the code, we indirectly include alloca.h
> > which will define alloca again, include it prior to define alloca in
> > order to not define it against.
> > 
> > * Copy all attributes from the header to source file, and move the
> >   attributes prior to function name. cgcc is very picky on the position
> >   of attribute.
> 
> This patch is no longer needed (iff you use a bleeding edge version of
> sparse), since this was fixed in commit 172f6a98 ("let function definition inherit prototype attributes", 2019-11-19).
> 
>   $ git describe 172f6a98
>   v0.6.1-37-g172f6a98
>   $ 
> 
> Ah, so this fix is not in any released version of sparse (v0.6.1 is the
> current release - I always build/run the tip of the 'master' branch from
> the sparse git repo).

Correct, when I saw your bleeding edge, I check my sparse version. It
says 0.6.1

> I starred at this warning for years (on cygwin, I don't build with NO_REGEX
> on Linux), but I didn't send a patch for it because it was a sparse fault.

It's sparse' fault, of course, I talked about its pickiness in the
commit message after all.

But, we still need the alloca part of this patch.
diff mbox series

Patch

diff --git a/compat/regex/regex.c b/compat/regex/regex.c
index f3e03a9eab..4bef75a716 100644
--- a/compat/regex/regex.c
+++ b/compat/regex/regex.c
@@ -62,6 +62,7 @@ 
 #include <stdint.h>
 
 #ifdef GAWK
+#include <alloca.h>
 #undef alloca
 #define alloca alloca_is_bad_you_should_never_use_it
 #endif
diff --git a/compat/regex/regex_internal.c b/compat/regex/regex_internal.c
index ec51cf3446..58504f795b 100644
--- a/compat/regex/regex_internal.c
+++ b/compat/regex/regex_internal.c
@@ -921,7 +921,7 @@  re_string_destruct (re_string_t *pstr)
 /* Return the context at IDX in INPUT.  */
 
 static unsigned int
-internal_function
+internal_function __attribute ((pure))
 re_string_context_at (const re_string_t *input, int idx, int eflags)
 {
   int c;
diff --git a/compat/regex/regex_internal.h b/compat/regex/regex_internal.h
index 3ee8aae59d..c61a1e4971 100644
--- a/compat/regex/regex_internal.h
+++ b/compat/regex/regex_internal.h
@@ -430,9 +430,8 @@  static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
 # endif /* RE_ENABLE_I18N */
 static void build_upper_buffer (re_string_t *pstr) internal_function;
 static void re_string_translate_buffer (re_string_t *pstr) internal_function;
-static unsigned int re_string_context_at (const re_string_t *input, int idx,
-					  int eflags)
-     internal_function __attribute ((pure));
+static internal_function __attribute ((pure))
+unsigned int re_string_context_at (const re_string_t *input, int idx, int eflags);
 #endif
 #define re_string_peek_byte(pstr, offset) \
   ((pstr)->mbs[(pstr)->cur_idx + offset])