public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Is __ptr_t needed?
@ 2021-09-28 10:38 Jonathan Wakely
  2021-09-28 11:22 ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2021-09-28 10:38 UTC (permalink / raw)
  To: GNU C Library

<bits/cdefs.h> says:

/* This is not a typedef so `const __ptr_t' does the right thing.  */
#define __ptr_t void *

But nothing in glibc headers ever use that macro. I see only three
uses in glibc sources, two of them are comments, and none actually use
const __ptr_t:

sysdeps/mach/hurd/i386/trampoline.c:  uc->uc_stack.ss_sp = (__ptr_t)
sc->sc_uesp;
sysdeps/powerpc/powerpc64/le/power10/memcpy.S:/* __ptr_t [r3] memcpy
(__ptr_t dst [r3], __ptr_t src [r4], size_t len [r5]);
sysdeps/powerpc/powerpc64/multiarch/memcpy-power8-cached.S:/* __ptr_t
[r3] memcpy (__ptr_t dst [r3], __ptr_t src [r4], size_t len [r5]);


Defining this as a macro means that libstdc++ can't use that name,
e.g. for something like:

namespace std { namespace__detail {
  template<typename _Tp>
    using __ptr_t = typename add_pointer<_Tp>::type;
}}

My attempts to squirrel it away in an internal namespace and using a
reserved name fail, because macros laugh at namespaces and crush them
beneath their clumsy feet.

This isn't the end of the world (I can pick another name, or use
#pragma push_macro/pop_macro) but could __ptr_t simply be removed, or
at least changed to a typedef? If any glibc sources do need to use it
for a non-modifiable pointer to void then '__ptr_t const' does the
right thing.

Defining a macro that is barely used seems unnecessary, even if it
does use a reserved name.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is __ptr_t needed?
  2021-09-28 10:38 Is __ptr_t needed? Jonathan Wakely
@ 2021-09-28 11:22 ` Andreas Schwab
  2021-09-28 11:31   ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2021-09-28 11:22 UTC (permalink / raw)
  To: Jonathan Wakely via Libc-alpha; +Cc: Jonathan Wakely

On Sep 28 2021, Jonathan Wakely via Libc-alpha wrote:

> <bits/cdefs.h> says:
>
> /* This is not a typedef so `const __ptr_t' does the right thing.  */
> #define __ptr_t void *
>
> But nothing in glibc headers ever use that macro.

See commit f17a42333f.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is __ptr_t needed?
  2021-09-28 11:22 ` Andreas Schwab
@ 2021-09-28 11:31   ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2021-09-28 11:31 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Jonathan Wakely via Libc-alpha

On Tue, 28 Sept 2021 at 12:29, Andreas Schwab wrote:
>
> On Sep 28 2021, Jonathan Wakely via Libc-alpha wrote:
>
> > <bits/cdefs.h> says:
> >
> > /* This is not a typedef so `const __ptr_t' does the right thing.  */
> > #define __ptr_t void *
> >
> > But nothing in glibc headers ever use that macro.
>
> See commit f17a42333f.

Yes, that's basically the answer I expected. Hyrum's Law strikes again.

Oh well, I can use _Ptr_t and it's one character shorter anyway.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-28 11:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 10:38 Is __ptr_t needed? Jonathan Wakely
2021-09-28 11:22 ` Andreas Schwab
2021-09-28 11:31   ` Jonathan Wakely

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).