From: Alan Modra <amodra@gmail.com>
To: Roland McGrath <roland@hack.frob.com>
Cc: libc-alpha@sourceware.org, bug-gnulib@gnu.org
Subject: Re: [PATCH 3/5] 64-bit obstack support, part 1
Date: Fri, 31 Oct 2014 00:38:00 -0000 [thread overview]
Message-ID: <20141031003833.GT4267@bubble.grove.modra.org> (raw)
In-Reply-To: <20141030195229.3304E2C3B15@topped-with-meat.com>
[-- Attachment #1: Type: text/plain, Size: 344 bytes --]
On Thu, Oct 30, 2014 at 12:52:29PM -0700, Roland McGrath wrote:
> It would be easier to review if you separated the very trivial changes from
> the others. The size_t change is clearly fine and can be approved quickly.
> The refactoring requires more attention.
Split as requested and attached.
--
Alan Modra
Australia Development Lab, IBM
[-- Attachment #2: 0001-64-bit-obstack-support-part-1a.patch --]
[-- Type: text/x-diff, Size: 5919 bytes --]
From fb249df2535a4fcd913589e27cd3c30a60cd5308 Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Fri, 31 Oct 2014 10:54:55 +1030
Subject: [PATCH 1/2] 64-bit obstack support, part 1a
a) Correct calls to alloc function, to use a size_t arg. "long" is
just wrong on targets like x86_64-mingw64 where "long" is 32 bits
and "size_t" 64 bits.
* lib/obstack.h (struct obstack <chunkfun>): Correct prototype to
use "size_t" rather than "long".
(_obstack_begin, _obstack_begin1): Likewise.
(obstack_init, obstack_begin, obstack_specify_allocation_with_arg,
obstack_chunkfun): Update alloc function casts.
* lib/obstack.c (CALL_CHUNKFUN): Update chunkfun cast.
(_obstack_begin, _obstack_begin_1): Update chunkfun type.
---
lib/obstack.c | 10 +++++-----
lib/obstack.h | 16 ++++++++--------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/lib/obstack.c b/lib/obstack.c
index 2d5dfbc..dfdb664 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -94,7 +94,7 @@ compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0);
# define CALL_CHUNKFUN(h, size) \
(((h)->use_extra_arg) \
? (*(h)->chunkfun)((h)->extra_arg, (size)) \
- : (*(struct _obstack_chunk *(*)(long))(h)->chunkfun)((size)))
+ : (*(struct _obstack_chunk *(*)(size_t))(h)->chunkfun)((size)))
# define CALL_FREEFUN(h, old_chunk) \
do { \
@@ -116,7 +116,7 @@ compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0);
int
_obstack_begin (struct obstack *h,
int size, int alignment,
- void *(*chunkfun) (long),
+ void *(*chunkfun) (size_t),
void (*freefun) (void *))
{
struct _obstack_chunk *chunk; /* points to new chunk */
@@ -140,7 +140,7 @@ _obstack_begin (struct obstack *h,
size = 4096 - extra;
}
- h->chunkfun = (struct _obstack_chunk * (*) (void *, long)) chunkfun;
+ h->chunkfun = (struct _obstack_chunk * (*) (void *, size_t)) chunkfun;
h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
h->chunk_size = size;
h->alignment_mask = alignment - 1;
@@ -161,7 +161,7 @@ _obstack_begin (struct obstack *h,
int
_obstack_begin_1 (struct obstack *h, int size, int alignment,
- void *(*chunkfun) (void *, long),
+ void *(*chunkfun) (void *, size_t),
void (*freefun) (void *, void *),
void *arg)
{
@@ -186,7 +186,7 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment,
size = 4096 - extra;
}
- h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
+ h->chunkfun = (struct _obstack_chunk * (*)(void *,size_t)) chunkfun;
h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
h->chunk_size = size;
h->alignment_mask = alignment - 1;
diff --git a/lib/obstack.h b/lib/obstack.h
index f3a7c77..ef647aa 100644
--- a/lib/obstack.h
+++ b/lib/obstack.h
@@ -156,7 +156,7 @@ struct obstack /* control current object in current chunk */
/* These prototypes vary based on 'use_extra_arg', and we use
casts to the prototypeless function type in all assignments,
but having prototypes here quiets -Wstrict-prototypes. */
- struct _obstack_chunk *(*chunkfun) (void *, long);
+ struct _obstack_chunk *(*chunkfun) (void *, size_t);
void (*freefun) (void *, struct _obstack_chunk *);
void *extra_arg; /* first arg for chunk alloc/dealloc funcs */
unsigned use_extra_arg : 1; /* chunk alloc/dealloc funcs take extra arg */
@@ -174,9 +174,9 @@ struct obstack /* control current object in current chunk */
extern void _obstack_newchunk (struct obstack *, int);
extern void _obstack_free (struct obstack *, void *);
extern int _obstack_begin (struct obstack *, int, int,
- void *(*)(long), void (*)(void *));
+ void *(*)(size_t), void (*)(void *));
extern int _obstack_begin_1 (struct obstack *, int, int,
- void *(*)(void *, long),
+ void *(*)(void *, size_t),
void (*)(void *, void *), void *);
extern int _obstack_memory_used (struct obstack *) __attribute_pure__;
@@ -211,26 +211,26 @@ extern int obstack_exit_failure;
/* To prevent prototype warnings provide complete argument list. */
#define obstack_init(h) \
_obstack_begin ((h), 0, 0, \
- (void *(*)(long))obstack_chunk_alloc, \
+ (void *(*)(size_t))obstack_chunk_alloc, \
(void (*)(void *))obstack_chunk_free)
#define obstack_begin(h, size) \
_obstack_begin ((h), (size), 0, \
- (void *(*)(long))obstack_chunk_alloc, \
+ (void *(*)(size_t))obstack_chunk_alloc, \
(void (*)(void *))obstack_chunk_free)
#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
_obstack_begin ((h), (size), (alignment), \
- (void *(*)(long))(chunkfun), \
+ (void *(*)(size_t))(chunkfun), \
(void (*)(void *))(freefun))
#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
_obstack_begin_1 ((h), (size), (alignment), \
- (void *(*)(void *, long))(chunkfun), \
+ (void *(*)(void *, size_t))(chunkfun), \
(void (*)(void *, void *))(freefun), (arg))
#define obstack_chunkfun(h, newchunkfun) \
- ((h)->chunkfun = (struct _obstack_chunk *(*)(void *, long))(newchunkfun))
+ ((h)->chunkfun = (struct _obstack_chunk *(*)(void *, size_t))(newchunkfun))
#define obstack_freefun(h, newfreefun) \
((h)->freefun = (void (*)(void *, struct _obstack_chunk *))(newfreefun))
[-- Attachment #3: 0002-64-bit-obstack-support-part-1b.patch --]
[-- Type: text/x-diff, Size: 4413 bytes --]
From cc881bf50b127aef86c8550bb2b12affbae8f5c5 Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Fri, 31 Oct 2014 11:01:49 +1030
Subject: [PATCH 2/2] 64-bit obstack support, part 1b
Consolidate _obstack_begin and _obstack_begin1 code.
* lib/obstack.c (chunkfun_type, freefun_type): New typdefs.
(_obstack_begin_worker): Split out from ..
(_obstack_begin, _obstack_begin_1): ..here.
---
lib/obstack.c | 73 +++++++++++++++++++++--------------------------------------
1 file changed, 26 insertions(+), 47 deletions(-)
diff --git a/lib/obstack.c b/lib/obstack.c
index dfdb664..d9beb9b 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -113,11 +113,13 @@ compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0);
Return nonzero if successful, calls obstack_alloc_failed_handler if
allocation fails. */
-int
-_obstack_begin (struct obstack *h,
- int size, int alignment,
- void *(*chunkfun) (size_t),
- void (*freefun) (void *))
+typedef struct _obstack_chunk * (*chunkfun_type) (void *, size_t);
+typedef void (*freefun_type) (void *, struct _obstack_chunk *);
+
+static int
+_obstack_begin_worker (struct obstack *h,
+ int size, int alignment,
+ chunkfun_type chunkfun, freefun_type freefun)
{
struct _obstack_chunk *chunk; /* points to new chunk */
@@ -140,11 +142,10 @@ _obstack_begin (struct obstack *h,
size = 4096 - extra;
}
- h->chunkfun = (struct _obstack_chunk * (*) (void *, size_t)) chunkfun;
- h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+ h->chunkfun = chunkfun;
+ h->freefun = freefun;
h->chunk_size = size;
h->alignment_mask = alignment - 1;
- h->use_extra_arg = 0;
chunk = h->chunk = CALL_CHUNKFUN (h, h->chunk_size);
if (!chunk)
@@ -160,51 +161,29 @@ _obstack_begin (struct obstack *h,
}
int
-_obstack_begin_1 (struct obstack *h, int size, int alignment,
+_obstack_begin (struct obstack *h,
+ int size, int alignment,
+ void *(*chunkfun) (size_t),
+ void (*freefun) (void *))
+{
+ h->use_extra_arg = 0;
+ return _obstack_begin_worker (h, size, alignment,
+ (chunkfun_type) chunkfun,
+ (freefun_type) freefun);
+}
+
+int
+_obstack_begin_1 (struct obstack *h,
+ int size, int alignment,
void *(*chunkfun) (void *, size_t),
void (*freefun) (void *, void *),
void *arg)
{
- struct _obstack_chunk *chunk; /* points to new chunk */
-
- if (alignment == 0)
- alignment = DEFAULT_ALIGNMENT;
- if (size == 0)
- /* Default size is what GNU malloc can fit in a 4096-byte block. */
- {
- /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
- Use the values for range checking, because if range checking is off,
- the extra bytes won't be missed terribly, but if range checking is on
- and we used a larger request, a whole extra 4096 bytes would be
- allocated.
-
- These number are irrelevant to the new GNU malloc. I suspect it is
- less sensitive to the size of the request. */
- int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
- + 4 + DEFAULT_ROUNDING - 1)
- & ~(DEFAULT_ROUNDING - 1));
- size = 4096 - extra;
- }
-
- h->chunkfun = (struct _obstack_chunk * (*)(void *,size_t)) chunkfun;
- h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
- h->chunk_size = size;
- h->alignment_mask = alignment - 1;
h->extra_arg = arg;
h->use_extra_arg = 1;
-
- chunk = h->chunk = CALL_CHUNKFUN (h, h->chunk_size);
- if (!chunk)
- (*obstack_alloc_failed_handler) ();
- h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
- alignment - 1);
- h->chunk_limit = chunk->limit
- = (char *) chunk + h->chunk_size;
- chunk->prev = 0;
- /* The initial chunk now contains no empty object. */
- h->maybe_empty_object = 0;
- h->alloc_failed = 0;
- return 1;
+ return _obstack_begin_worker (h, size, alignment,
+ (chunkfun_type) chunkfun,
+ (freefun_type) freefun);
}
/* Allocate a new current chunk for the obstack *H
next prev parent reply other threads:[~2014-10-31 0:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1414461460.git.amodra@gmail.com>
2014-10-29 3:32 ` [PATCH 2/5] obstack tidy part 2 Alan Modra
2014-10-30 19:51 ` Roland McGrath
2014-10-30 23:54 ` Alan Modra
2014-10-29 3:32 ` [PATCH 4/5] 64-bit obstack support, " Alan Modra
2014-10-29 3:32 ` [PATCH 3/5] 64-bit obstack support, part 1 Alan Modra
2014-10-30 19:52 ` Roland McGrath
2014-10-31 0:38 ` Alan Modra [this message]
2014-10-29 3:32 ` [PATCH 1/5] obstack tidy " Alan Modra
2014-10-30 19:43 ` Roland McGrath
2014-10-29 3:33 ` [PATCH 5/5] 64-bit obstack support, part 3 Alan Modra
2014-10-29 3:35 ` [PATCH] 64-bit obstack support Alan Modra
2014-10-29 18:34 ` Joseph S. Myers
2014-10-30 1:53 ` Alan Modra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141031003833.GT4267@bubble.grove.modra.org \
--to=amodra@gmail.com \
--cc=bug-gnulib@gnu.org \
--cc=libc-alpha@sourceware.org \
--cc=roland@hack.frob.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).