* [PATCH 2/2] obstack.c: Fix some sparse warnings
@ 2011-09-11 19:26 Ramsay Jones
2011-09-11 21:56 ` Sverre Rabbelier
0 siblings, 1 reply; 3+ messages in thread
From: Ramsay Jones @ 2011-09-11 19:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: GIT Mailing-list
In particular, sparse issues the following warnings:
compat/obstack.c:176:17: warning: Using plain integer as NULL pointer
compat/obstack.c:224:17: warning: Using plain integer as NULL pointer
compat/obstack.c:324:16: warning: Using plain integer as NULL pointer
compat/obstack.c:329:16: warning: Using plain integer as NULL pointer
compat/obstack.c:347:16: warning: Using plain integer as NULL pointer
compat/obstack.c:362:19: warning: Using plain integer as NULL pointer
compat/obstack.c:379:29: warning: Using plain integer as NULL pointer
compat/obstack.c:399:1: error: symbol 'print_and_abort' redeclared with \
different type (originally declared at compat/obstack.c:95) \
- different modifiers
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
compat/obstack.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/compat/obstack.c b/compat/obstack.c
index a89ab5b..e276ccd 100644
--- a/compat/obstack.c
+++ b/compat/obstack.c
@@ -173,7 +173,7 @@ _obstack_begin (struct obstack *h,
alignment - 1);
h->chunk_limit = chunk->limit
= (char *) chunk + h->chunk_size;
- chunk->prev = 0;
+ chunk->prev = NULL;
/* The initial chunk now contains no empty object. */
h->maybe_empty_object = 0;
h->alloc_failed = 0;
@@ -221,7 +221,7 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment,
alignment - 1);
h->chunk_limit = chunk->limit
= (char *) chunk + h->chunk_size;
- chunk->prev = 0;
+ chunk->prev = NULL;
/* The initial chunk now contains no empty object. */
h->maybe_empty_object = 0;
h->alloc_failed = 0;
@@ -321,12 +321,12 @@ _obstack_allocated_p (struct obstack *h, void *obj)
/* We use >= rather than > since the object cannot be exactly at
the beginning of the chunk but might be an empty object exactly
at the end of an adjacent chunk. */
- while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
+ while (lp != NULL && ((void *) lp >= obj || (void *) (lp)->limit < obj))
{
plp = lp->prev;
lp = plp;
}
- return lp != 0;
+ return lp != NULL;
}
\f
/* Free objects in obstack H, including OBJ and everything allocate
@@ -344,7 +344,7 @@ obstack_free (struct obstack *h, void *obj)
/* We use >= because there cannot be an object at the beginning of a chunk.
But there can be an empty object at that address
at the end of another chunk. */
- while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
+ while (lp != NULL && ((void *) lp >= obj || (void *) (lp)->limit < obj))
{
plp = lp->prev;
CALL_FREEFUN (h, lp);
@@ -359,7 +359,7 @@ obstack_free (struct obstack *h, void *obj)
h->chunk_limit = lp->limit;
h->chunk = lp;
}
- else if (obj != 0)
+ else if (obj != NULL)
/* obj is not in any of the chunks! */
abort ();
}
@@ -376,7 +376,7 @@ _obstack_memory_used (struct obstack *h)
register struct _obstack_chunk* lp;
register int nbytes = 0;
- for (lp = h->chunk; lp != 0; lp = lp->prev)
+ for (lp = h->chunk; lp != NULL; lp = lp->prev)
{
nbytes += lp->limit - (char *) lp;
}
@@ -395,7 +395,6 @@ _obstack_memory_used (struct obstack *h)
# endif
static void
-__attribute__ ((noreturn))
print_and_abort (void)
{
/* Don't change any of these strings. Yes, it would be possible to add
--
1.7.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] obstack.c: Fix some sparse warnings
2011-09-11 19:26 [PATCH 2/2] obstack.c: Fix some sparse warnings Ramsay Jones
@ 2011-09-11 21:56 ` Sverre Rabbelier
2011-09-13 23:18 ` Ramsay Jones
0 siblings, 1 reply; 3+ messages in thread
From: Sverre Rabbelier @ 2011-09-11 21:56 UTC (permalink / raw)
To: Ramsay Jones; +Cc: Junio C Hamano, GIT Mailing-list
Heya,
On Sun, Sep 11, 2011 at 21:26, Ramsay Jones <ramsay@ramsay1.demon.co.uk> wrote:
> compat/obstack.c:399:1: error: symbol 'print_and_abort' redeclared with \
> different type (originally declared at compat/obstack.c:95) \
> - different modifiers
> @@ -395,7 +395,6 @@ _obstack_memory_used (struct obstack *h)
> # endif
>
> static void
> -__attribute__ ((noreturn))
> print_and_abort (void)
> {
> /* Don't change any of these strings. Yes, it would be possible to add
Wouldn't the better solution be to add noreturn to the declaration at
compat/obstack.c:95?
--
Cheers,
Sverre Rabbelier
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] obstack.c: Fix some sparse warnings
2011-09-11 21:56 ` Sverre Rabbelier
@ 2011-09-13 23:18 ` Ramsay Jones
0 siblings, 0 replies; 3+ messages in thread
From: Ramsay Jones @ 2011-09-13 23:18 UTC (permalink / raw)
To: Sverre Rabbelier; +Cc: Junio C Hamano, GIT Mailing-list
Sverre Rabbelier wrote:
> Heya,
>
> On Sun, Sep 11, 2011 at 21:26, Ramsay Jones <ramsay@ramsay1.demon.co.uk> wrote:
>> compat/obstack.c:399:1: error: symbol 'print_and_abort' redeclared with \
>> different type (originally declared at compat/obstack.c:95) \
>> - different modifiers
>
>> @@ -395,7 +395,6 @@ _obstack_memory_used (struct obstack *h)
>> # endif
>>
>> static void
>> -__attribute__ ((noreturn))
>> print_and_abort (void)
>> {
>> /* Don't change any of these strings. Yes, it would be possible to add
>
> Wouldn't the better solution be to add noreturn to the declaration at
> compat/obstack.c:95?
Hmm, well ... maybe; it is at least debatable. But I decided no! :-D
First, although I would not dismiss the possibility of some optimization
of the code of print_and_abort() (the *callee*), the main benefit of the
noreturn attribute should in fact be at the call sites (ie the *caller*).
So, yes, in general, the declaration of the function should have the
noreturn attribute applied, in addition to the definition, in order to
allow the compiler to apply some optimizations to the call sites.
[Note, also, that we should use the NORETURN and NORETURN_PTR macros.]
In this case, however, there are no (direct) call sites. This function
would only be called indirectly via the 'obstack_alloc_failed_handler'
function pointer. So, this would require the use of NORETURN_PTR on
that function pointer. In order to keep both the compiler(s) and sparse
happy, the required change would look like the diff given at the end
of this mail.
This would work fine, and I would happily change the patch to include
this if it is deemed the better approach. However, I looked at the
call sites in _obstack_begin[_1](), and _obstack_newchunck() and could
not see any great opportunity for optimizing the code ... so I decided
to go for the simpler patch ...
ATB,
Ramsay Jones
-- >8 --
diff --git a/compat/obstack.c b/compat/obstack.c
index a89ab5b..2029b8f 100644
--- a/compat/obstack.c
+++ b/compat/obstack.c
@@ -92,8 +92,8 @@ enum
abort gracefully or use longjump - but shouldn't return. This
variable by default points to the internal function
`print_and_abort'. */
-static void print_and_abort (void);
-void (*obstack_alloc_failed_handler) (void) = print_and_abort;
+static void NORETURN print_and_abort (void);
+NORETURN_PTR void (*obstack_alloc_failed_handler) (void) = print_and_abort;
# ifdef _LIBC
# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)
@@ -395,7 +395,7 @@ _obstack_memory_used (struct obstack *h)
# endif
static void
-__attribute__ ((noreturn))
+NORETURN
print_and_abort (void)
{
/* Don't change any of these strings. Yes, it would be possible to add
diff --git a/compat/obstack.h b/compat/obstack.h
index d178bd6..122f93f 100644
--- a/compat/obstack.h
+++ b/compat/obstack.h
@@ -194,7 +194,7 @@ void obstack_free (struct obstack *, void *);
more memory. This can be set to a user defined function which
should either abort gracefully or use longjump - but shouldn't
return. The default action is to print a message and abort. */
-extern void (*obstack_alloc_failed_handler) (void);
+extern NORETURN_PTR void (*obstack_alloc_failed_handler) (void);
\f
/* Pointer to beginning of object being allocated or to be allocated next.
Note that this might not be the final address of the object
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-09-13 23:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-11 19:26 [PATCH 2/2] obstack.c: Fix some sparse warnings Ramsay Jones
2011-09-11 21:56 ` Sverre Rabbelier
2011-09-13 23:18 ` Ramsay Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).