Re: [PATCH] libiberty: stop using PTR macro.

2022-05-10 Thread Martin Liška
On 5/10/22 16:20, Alan Modra wrote:
> On Tue, May 10, 2022 at 10:56:22AM +0200, Martin Liška wrote:
> 
>> diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
> 
>> @@ -457,15 +457,15 @@ htab_empty (htab_t htab)
>>else if (htab->free_with_arg_f != NULL)
>>  (*htab->free_with_arg_f) (htab->alloc_arg, htab->entries);
>>if (htab->alloc_with_arg_f != NULL)
>> -htab->entries = (PTR *) (*htab->alloc_with_arg_f) (htab->alloc_arg, 
>> nsize,
>> -   sizeof (PTR *));
>> +htab->entries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, 
>> nsize,
>> +   sizeof (void **));
> 
> Here, and below, the code should really be using "sizeof (void *)".
> You may as well fix that nit while you're at it.  Also, indentation
> looks wrong.
> 
>>else
>> -htab->entries = (PTR *) (*htab->alloc_f) (nsize, sizeof (PTR *));
>> +htab->entries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
>>   htab->size = nsize;
>>   htab->size_prime_index = nindex;
>>  }
>>else
>> -memset (entries, 0, size * sizeof (PTR));
>> +memset (entries, 0, size * sizeof (void *));
>>htab->n_deleted = 0;
>>htab->n_elements = 0;
>>  }
> 
>> @@ -543,10 +543,10 @@ htab_expand (htab_t htab)
>>  }
>>  
>>if (htab->alloc_with_arg_f != NULL)
>> -nentries = (PTR *) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
>> -  sizeof (PTR *));
>> +nentries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
>> +  sizeof (void **));
>>else
>> -nentries = (PTR *) (*htab->alloc_f) (nsize, sizeof (PTR *));
>> +nentries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
>>if (nentries == NULL)
>>  return 0;
>>htab->entries = nentries;
> 
> Here too.
> 

Thanks for the comments, I'm going to push the following patch.

MartinFrom 5dac43b43c3999f94b451cd7925e24d8e7c38a7a Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Tue, 10 May 2022 17:31:24 +0200
Subject: [PATCH] libiberty: fix type in allocation

The allocation function alloc_f is called for nsize
items where each is of type void *.

libiberty/ChangeLog:

	* hashtab.c (htab_empty): Use void * type instead of void **.
	(htab_expand): Likewise.

Co-Authored-By: Alan Modra 
---
 libiberty/hashtab.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
index f7621cd47e5..470d3e66c32 100644
--- a/libiberty/hashtab.c
+++ b/libiberty/hashtab.c
@@ -458,9 +458,9 @@ htab_empty (htab_t htab)
 	(*htab->free_with_arg_f) (htab->alloc_arg, htab->entries);
   if (htab->alloc_with_arg_f != NULL)
 	htab->entries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
-		   sizeof (void **));
+			 sizeof (void *));
   else
-	htab->entries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
+	htab->entries = (void **) (*htab->alloc_f) (nsize, sizeof (void *));
  htab->size = nsize;
  htab->size_prime_index = nindex;
 }
@@ -544,9 +544,9 @@ htab_expand (htab_t htab)
 
   if (htab->alloc_with_arg_f != NULL)
 nentries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
-		  sizeof (void **));
+		sizeof (void *));
   else
-nentries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
+nentries = (void **) (*htab->alloc_f) (nsize, sizeof (void *));
   if (nentries == NULL)
 return 0;
   htab->entries = nentries;
-- 
2.36.0



Re: [PATCH] libiberty: stop using PTR macro.

2022-05-10 Thread Alan Modra via Gcc-patches
On Tue, May 10, 2022 at 10:56:22AM +0200, Martin Liška wrote:

> diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c

> @@ -457,15 +457,15 @@ htab_empty (htab_t htab)
>else if (htab->free_with_arg_f != NULL)
>   (*htab->free_with_arg_f) (htab->alloc_arg, htab->entries);
>if (htab->alloc_with_arg_f != NULL)
> - htab->entries = (PTR *) (*htab->alloc_with_arg_f) (htab->alloc_arg, 
> nsize,
> -sizeof (PTR *));
> + htab->entries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, 
> nsize,
> +sizeof (void **));

Here, and below, the code should really be using "sizeof (void *)".
You may as well fix that nit while you're at it.  Also, indentation
looks wrong.

>else
> - htab->entries = (PTR *) (*htab->alloc_f) (nsize, sizeof (PTR *));
> + htab->entries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
>   htab->size = nsize;
>   htab->size_prime_index = nindex;
>  }
>else
> -memset (entries, 0, size * sizeof (PTR));
> +memset (entries, 0, size * sizeof (void *));
>htab->n_deleted = 0;
>htab->n_elements = 0;
>  }

> @@ -543,10 +543,10 @@ htab_expand (htab_t htab)
>  }
>  
>if (htab->alloc_with_arg_f != NULL)
> -nentries = (PTR *) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
> -   sizeof (PTR *));
> +nentries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
> +   sizeof (void **));
>else
> -nentries = (PTR *) (*htab->alloc_f) (nsize, sizeof (PTR *));
> +nentries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
>if (nentries == NULL)
>  return 0;
>htab->entries = nentries;

Here too.

-- 
Alan Modra
Australia Development Lab, IBM


Re: [PATCH] libiberty: stop using PTR macro.

2022-05-10 Thread Martin Liška
On 5/10/22 15:50, Eric Gallager wrote:
> Hi, please preserve existing style when possible when making this
> replacement; ISTR there are some tools (like for generating
> libiberty's documentation) that depend on the return type being on a
> separate line... If all of the relevant Makefile targets still work
> after this change, well, fine, but... well, just something to
> consider...

Hello.

Thanks for heads up. I make the replacement by a tool and wrongly forgot
to append a newline in some cases.

It's fixed in the installed version of the patch.

Martin


Re: [PATCH] libiberty: stop using PTR macro.

2022-05-10 Thread Eric Gallager via Gcc-patches
On Tue, May 10, 2022 at 5:37 AM Martin Liška  wrote:
>
> Hi.
>
> As noticed by Alan, we can stop using the non-ANSI C specific macro (PTR).
> Let's removed its usafe in libiberty.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
> include/ChangeLog:
>
> * hashtab.h (HTAB_EMPTY_ENTRY): Use void * instead PTR.
> (HTAB_DELETED_ENTRY): Likewise.
>
> libiberty/ChangeLog:
>
> * alloca.c (C_alloca): Use void * instead PTR.
> * calloc.c (malloc): Likewise.
> (bzero): Likewise.
> (calloc): Likewise.
> * hashtab.c (find_empty_slot_for_expand): Likewise.
> (eq_pointer): Likewise.
> (htab_create_alloc_ex): Likewise.
> (htab_create_typed_alloc): Likewise.
> (htab_set_functions_ex): Likewise.
> (htab_delete): Likewise.
> (htab_empty): Likewise.
> (htab_expand): Likewise.
> (htab_find_with_hash): Likewise.
> (htab_find): Likewise.
> (htab_find_slot_with_hash): Likewise.
> (htab_find_slot): Likewise.
> (htab_remove_elt): Likewise.
> (htab_remove_elt_with_hash): Likewise.
> (htab_clear_slot): Likewise.
> (htab_traverse_noresize): Likewise.
> (htab_traverse): Likewise.
> (htab_hash_string): Likewise.
> (iterative_hash): Likewise.
> (hash_pointer): Likewise.
> * memchr.c (memchr): Likewise.
> * memcmp.c (memcmp): Likewise.
> * memcpy.c (memcpy): Likewise.
> * memmove.c (memmove): Likewise.
> * mempcpy.c (memcpy): Likewise.
> (mempcpy): Likewise.
> * memset.c (memset): Likewise.
> * objalloc.c (malloc): Likewise.
> (free): Likewise.
> (objalloc_create): Likewise.
> (_objalloc_alloc): Likewise.
> (objalloc_free_block): Likewise.
> * random.c (PTR): Likewise.
> (void): Likewise.
> (initstate): Likewise.
> (setstate): Likewise.
> * regex.c: Likewise.
> * spaces.c (malloc): Likewise.
> (free): Likewise.
> * stpcpy.c (memcpy): Likewise.
> * strdup.c (malloc): Likewise.
> (memcpy): Likewise.
> * strerror.c (malloc): Likewise.
> (memset): Likewise.
> * strndup.c (malloc): Likewise.
> (memcpy): Likewise.
> * strsignal.c (malloc): Likewise.
> (memset): Likewise.
> * vasprintf.c (malloc): Likewise.
> * vprintf-support.c: Likewise.
> * xatexit.c (malloc): Likewise.
> * xmalloc.c (xmalloc): Likewise.
> (xcalloc): Likewise.
> (xrealloc): Likewise.
> * xmemdup.c (xmemdup): Likewise.
> ---
>  include/hashtab.h   |  4 +-
>  libiberty/alloca.c  |  7 ++-
>  libiberty/calloc.c  |  9 ++--
>  libiberty/hashtab.c | 92 ++---
>  libiberty/memchr.c  |  5 +-
>  libiberty/memcmp.c  |  2 +-
>  libiberty/memcpy.c  |  3 +-
>  libiberty/memmove.c |  3 +-
>  libiberty/mempcpy.c |  5 +-
>  libiberty/memset.c  |  3 +-
>  libiberty/objalloc.c| 23 +-
>  libiberty/random.c  | 14 +++---
>  libiberty/regex.c   |  8 ++--
>  libiberty/spaces.c  |  4 +-
>  libiberty/stpcpy.c  |  2 +-
>  libiberty/strdup.c  |  4 +-
>  libiberty/strerror.c|  4 +-
>  libiberty/strndup.c |  4 +-
>  libiberty/strsignal.c   |  4 +-
>  libiberty/vasprintf.c   |  2 +-
>  libiberty/vprintf-support.c |  2 +-
>  libiberty/xatexit.c |  2 +-
>  libiberty/xmalloc.c | 15 +++---
>  libiberty/xmemdup.c |  7 ++-
>  24 files changed, 106 insertions(+), 122 deletions(-)
>
> diff --git a/include/hashtab.h b/include/hashtab.h
> index 7117eee2afb..e74d2226e08 100644
> --- a/include/hashtab.h
> +++ b/include/hashtab.h
> @@ -79,12 +79,12 @@ typedef void (*htab_free_with_arg) (void *, void *);
>
>  /* This macro defines reserved value for empty table entry.  */
>
> -#define HTAB_EMPTY_ENTRY((PTR) 0)
> +#define HTAB_EMPTY_ENTRY((void *) 0)
>
>  /* This macro defines reserved value for table entry which contained
> a deleted element. */
>
> -#define HTAB_DELETED_ENTRY  ((PTR) 1)
> +#define HTAB_DELETED_ENTRY  ((void *) 1)
>
>  /* Hash tables are of the following type.  The structure
> (implementation) of this type is not needed for using the hash
> diff --git a/libiberty/alloca.c b/libiberty/alloca.c
> index 9b2e9cb12b6..46f920517e1 100644
> --- a/libiberty/alloca.c
> +++ b/libiberty/alloca.c
> @@ -158,8 +158,7 @@ static header *last_alloca_header = NULL;   /* -> last 
> alloca header.  */
>
>  /* @undocumented C_alloca */
>
> -PTR
> -C_alloca (size_t size)
> +void *C_alloca (size_t size)

Hi, please preserve existing style when possible when making this
replacement; ISTR there are some tools (like for generating
libiberty's 

Re: [PATCH] libiberty: stop using PTR macro.

2022-05-10 Thread Jeff Law via Gcc-patches




On 5/10/2022 2:56 AM, Martin Liška wrote:

Hi.

As noticed by Alan, we can stop using the non-ANSI C specific macro (PTR).
Let's removed its usafe in libiberty.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

include/ChangeLog:

* hashtab.h (HTAB_EMPTY_ENTRY): Use void * instead PTR.
(HTAB_DELETED_ENTRY): Likewise.

libiberty/ChangeLog:

* alloca.c (C_alloca): Use void * instead PTR.
* calloc.c (malloc): Likewise.
(bzero): Likewise.
(calloc): Likewise.
* hashtab.c (find_empty_slot_for_expand): Likewise.
(eq_pointer): Likewise.
(htab_create_alloc_ex): Likewise.
(htab_create_typed_alloc): Likewise.
(htab_set_functions_ex): Likewise.
(htab_delete): Likewise.
(htab_empty): Likewise.
(htab_expand): Likewise.
(htab_find_with_hash): Likewise.
(htab_find): Likewise.
(htab_find_slot_with_hash): Likewise.
(htab_find_slot): Likewise.
(htab_remove_elt): Likewise.
(htab_remove_elt_with_hash): Likewise.
(htab_clear_slot): Likewise.
(htab_traverse_noresize): Likewise.
(htab_traverse): Likewise.
(htab_hash_string): Likewise.
(iterative_hash): Likewise.
(hash_pointer): Likewise.
* memchr.c (memchr): Likewise.
* memcmp.c (memcmp): Likewise.
* memcpy.c (memcpy): Likewise.
* memmove.c (memmove): Likewise.
* mempcpy.c (memcpy): Likewise.
(mempcpy): Likewise.
* memset.c (memset): Likewise.
* objalloc.c (malloc): Likewise.
(free): Likewise.
(objalloc_create): Likewise.
(_objalloc_alloc): Likewise.
(objalloc_free_block): Likewise.
* random.c (PTR): Likewise.
(void): Likewise.
(initstate): Likewise.
(setstate): Likewise.
* regex.c: Likewise.
* spaces.c (malloc): Likewise.
(free): Likewise.
* stpcpy.c (memcpy): Likewise.
* strdup.c (malloc): Likewise.
(memcpy): Likewise.
* strerror.c (malloc): Likewise.
(memset): Likewise.
* strndup.c (malloc): Likewise.
(memcpy): Likewise.
* strsignal.c (malloc): Likewise.
(memset): Likewise.
* vasprintf.c (malloc): Likewise.
* vprintf-support.c: Likewise.
* xatexit.c (malloc): Likewise.
* xmalloc.c (xmalloc): Likewise.
(xcalloc): Likewise.
(xrealloc): Likewise.
* xmemdup.c (xmemdup): Likewise.

OK
jeff



[PATCH] libiberty: stop using PTR macro.

2022-05-10 Thread Martin Liška
Hi.

As noticed by Alan, we can stop using the non-ANSI C specific macro (PTR).
Let's removed its usafe in libiberty.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

include/ChangeLog:

* hashtab.h (HTAB_EMPTY_ENTRY): Use void * instead PTR.
(HTAB_DELETED_ENTRY): Likewise.

libiberty/ChangeLog:

* alloca.c (C_alloca): Use void * instead PTR.
* calloc.c (malloc): Likewise.
(bzero): Likewise.
(calloc): Likewise.
* hashtab.c (find_empty_slot_for_expand): Likewise.
(eq_pointer): Likewise.
(htab_create_alloc_ex): Likewise.
(htab_create_typed_alloc): Likewise.
(htab_set_functions_ex): Likewise.
(htab_delete): Likewise.
(htab_empty): Likewise.
(htab_expand): Likewise.
(htab_find_with_hash): Likewise.
(htab_find): Likewise.
(htab_find_slot_with_hash): Likewise.
(htab_find_slot): Likewise.
(htab_remove_elt): Likewise.
(htab_remove_elt_with_hash): Likewise.
(htab_clear_slot): Likewise.
(htab_traverse_noresize): Likewise.
(htab_traverse): Likewise.
(htab_hash_string): Likewise.
(iterative_hash): Likewise.
(hash_pointer): Likewise.
* memchr.c (memchr): Likewise.
* memcmp.c (memcmp): Likewise.
* memcpy.c (memcpy): Likewise.
* memmove.c (memmove): Likewise.
* mempcpy.c (memcpy): Likewise.
(mempcpy): Likewise.
* memset.c (memset): Likewise.
* objalloc.c (malloc): Likewise.
(free): Likewise.
(objalloc_create): Likewise.
(_objalloc_alloc): Likewise.
(objalloc_free_block): Likewise.
* random.c (PTR): Likewise.
(void): Likewise.
(initstate): Likewise.
(setstate): Likewise.
* regex.c: Likewise.
* spaces.c (malloc): Likewise.
(free): Likewise.
* stpcpy.c (memcpy): Likewise.
* strdup.c (malloc): Likewise.
(memcpy): Likewise.
* strerror.c (malloc): Likewise.
(memset): Likewise.
* strndup.c (malloc): Likewise.
(memcpy): Likewise.
* strsignal.c (malloc): Likewise.
(memset): Likewise.
* vasprintf.c (malloc): Likewise.
* vprintf-support.c: Likewise.
* xatexit.c (malloc): Likewise.
* xmalloc.c (xmalloc): Likewise.
(xcalloc): Likewise.
(xrealloc): Likewise.
* xmemdup.c (xmemdup): Likewise.
---
 include/hashtab.h   |  4 +-
 libiberty/alloca.c  |  7 ++-
 libiberty/calloc.c  |  9 ++--
 libiberty/hashtab.c | 92 ++---
 libiberty/memchr.c  |  5 +-
 libiberty/memcmp.c  |  2 +-
 libiberty/memcpy.c  |  3 +-
 libiberty/memmove.c |  3 +-
 libiberty/mempcpy.c |  5 +-
 libiberty/memset.c  |  3 +-
 libiberty/objalloc.c| 23 +-
 libiberty/random.c  | 14 +++---
 libiberty/regex.c   |  8 ++--
 libiberty/spaces.c  |  4 +-
 libiberty/stpcpy.c  |  2 +-
 libiberty/strdup.c  |  4 +-
 libiberty/strerror.c|  4 +-
 libiberty/strndup.c |  4 +-
 libiberty/strsignal.c   |  4 +-
 libiberty/vasprintf.c   |  2 +-
 libiberty/vprintf-support.c |  2 +-
 libiberty/xatexit.c |  2 +-
 libiberty/xmalloc.c | 15 +++---
 libiberty/xmemdup.c |  7 ++-
 24 files changed, 106 insertions(+), 122 deletions(-)

diff --git a/include/hashtab.h b/include/hashtab.h
index 7117eee2afb..e74d2226e08 100644
--- a/include/hashtab.h
+++ b/include/hashtab.h
@@ -79,12 +79,12 @@ typedef void (*htab_free_with_arg) (void *, void *);
 
 /* This macro defines reserved value for empty table entry.  */
 
-#define HTAB_EMPTY_ENTRY((PTR) 0)
+#define HTAB_EMPTY_ENTRY((void *) 0)
 
 /* This macro defines reserved value for table entry which contained
a deleted element. */
 
-#define HTAB_DELETED_ENTRY  ((PTR) 1)
+#define HTAB_DELETED_ENTRY  ((void *) 1)
 
 /* Hash tables are of the following type.  The structure
(implementation) of this type is not needed for using the hash
diff --git a/libiberty/alloca.c b/libiberty/alloca.c
index 9b2e9cb12b6..46f920517e1 100644
--- a/libiberty/alloca.c
+++ b/libiberty/alloca.c
@@ -158,8 +158,7 @@ static header *last_alloca_header = NULL;   /* -> last 
alloca header.  */
 
 /* @undocumented C_alloca */
 
-PTR
-C_alloca (size_t size)
+void *C_alloca (size_t size)
 {
   auto char probe; /* Probes stack depth: */
   register char *depth = ADDRESS_FUNCTION (probe);
@@ -181,7 +180,7 @@ C_alloca (size_t size)
{
  register header *np = hp->h.next;
 
- free ((PTR) hp);  /* Collect garbage.  */
+ free ((void *) hp);   /* Collect garbage.  */
 
  hp = np;  /* -> next header.  */
}
@@ -210,7 +209,7 @@ C_alloca (size_t size)
 
 /* User