diff options
author | Karl Williamson <khw@cpan.org> | 2020-03-11 14:35:44 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2020-03-18 14:29:46 -0600 |
commit | 727613455d53416b197154b7b3cad20fe26372bb (patch) | |
tree | e9b2aa6843b2e571fb4dac849c71c35bf5b2845f /regen | |
parent | 5baa389e84c8348c7335cd8e58d1a2f6f917f7e4 (diff) | |
download | perl-727613455d53416b197154b7b3cad20fe26372bb.tar.gz |
reentr.c: revise handling of several wrapped fcns
Prior to this commit, the code in this function had generic variables,
like p0, and malloc'd them using void *, and then cast to what it
thought were the proper types. This was failing on solaris g++, because
of the stricter casting rules in C++.
This commit actually simplifies the code, by getting rid of the generic
stuff, and for each group of related functions, declares the appropriate
names for the variables, and mallocs them using the correct type as
expressed in the __DATA__ section of regen/reentr.pl. The casting is
eliminated, except for one case for gethostbyaddr(). Tony Cook pointed
out that the 2001 POSIX standard used a type name for this that may be
shorter than Size_t. This could be a potential issue, but not on the
platforms tested as of now.
And this fixes #17482, so works where the previous didn't.
Diffstat (limited to 'regen')
-rw-r--r-- | regen/reentr.pl | 110 |
1 files changed, 50 insertions, 60 deletions
diff --git a/regen/reentr.pl b/regen/reentr.pl index e672bb5233..d84e20adf2 100644 --- a/regen/reentr.pl +++ b/regen/reentr.pl @@ -885,21 +885,8 @@ Perl_reentrant_retry(const char *f, ...) } va_start(ap, f); - { #ifdef USE_REENTRANT_API -# if defined(USE_HOSTENT_BUFFER) || defined(USE_GRENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PWENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER) - void *p0; -# endif -# if defined(USE_SERVENT_BUFFER) - void *p1; -# endif -# if defined(USE_HOSTENT_BUFFER) - size_t asize; -# endif -# if defined(USE_HOSTENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER) - int anint; -# endif switch (key) { @@ -909,27 +896,32 @@ Perl_reentrant_retry(const char *f, ...) case KEY_gethostbyname: case KEY_endhostent: { + char * host_addr; + Size_t asize; + char * host_name; + int anint; # ifdef PERL_REENTRANT_MAXSIZE if (PL_reentrant_buffer->_hostent_size <= PERL_REENTRANT_MAXSIZE / 2) # endif - { + RenewDouble(PL_reentrant_buffer->_hostent_buffer, + &PL_reentrant_buffer->_hostent_size, char); switch (key) { - case KEY_gethostbyaddr: - p0 = va_arg(ap, void *); - asize = va_arg(ap, size_t); + case KEY_gethostbyaddr: + host_addr = va_arg(ap, char *); + asize = va_arg(ap, Size_t); anint = va_arg(ap, int); - retptr = gethostbyaddr((Netdb_host_t) p0, (Netdb_hlen_t) asize, anint); break; + /* socklen_t is what Posix 2001 says this should be */ + retptr = gethostbyaddr(host_addr, (socklen_t) asize, anint); break; case KEY_gethostbyname: - p0 = va_arg(ap, void *); - retptr = gethostbyname((Netdb_name_t) p0); break; + host_name = va_arg(ap, char *); + retptr = gethostbyname(host_name); break; case KEY_endhostent: retptr = gethostent(); break; default: SETERRNO(ERANGE, LIB_INVARG); break; - } } } break; @@ -941,19 +933,19 @@ Perl_reentrant_retry(const char *f, ...) case KEY_getgrgid: case KEY_getgrnam: { + char * name; + Gid_t gid; # ifdef PERL_REENTRANT_MAXSIZE if (PL_reentrant_buffer->_grent_size <= PERL_REENTRANT_MAXSIZE / 2) # endif - { - Gid_t gid; RenewDouble(PL_reentrant_buffer->_grent_buffer, &PL_reentrant_buffer->_grent_size, char); switch (key) { - case KEY_getgrnam: - p0 = va_arg(ap, void *); - retptr = getgrnam((char *)p0); break; + case KEY_getgrnam: + name = va_arg(ap, char *); + retptr = getgrnam(name); break; case KEY_getgrgid: # if Gid_t_size < INTSIZE gid = (Gid_t)va_arg(ap, int); @@ -966,7 +958,6 @@ Perl_reentrant_retry(const char *f, ...) default: SETERRNO(ERANGE, LIB_INVARG); break; - } } } break; @@ -978,30 +969,30 @@ Perl_reentrant_retry(const char *f, ...) case KEY_getnetbyname: case KEY_getnetent: { + char * name; + Netdb_net_t net; + int anint; # ifdef PERL_REENTRANT_MAXSIZE if (PL_reentrant_buffer->_netent_size <= PERL_REENTRANT_MAXSIZE / 2) # endif - { - Netdb_net_t net; RenewDouble(PL_reentrant_buffer->_netent_buffer, &PL_reentrant_buffer->_netent_size, char); switch (key) { - case KEY_getnetbyaddr: - net = va_arg(ap, Netdb_net_t); - anint = va_arg(ap, int); - retptr = getnetbyaddr(net, anint); break; - case KEY_getnetbyname: - p0 = va_arg(ap, void *); - retptr = getnetbyname((char *)p0); break; - case KEY_getnetent: - retptr = getnetent(); break; - default: - SETERRNO(ERANGE, LIB_INVARG); - break; - } - } + case KEY_getnetbyaddr: + net = va_arg(ap, Netdb_net_t); + anint = va_arg(ap, int); + retptr = getnetbyaddr(net, anint); break; + case KEY_getnetbyname: + name = va_arg(ap, char *); + retptr = getnetbyname(name); break; + case KEY_getnetent: + retptr = getnetent(); break; + default: + SETERRNO(ERANGE, LIB_INVARG); + break; + } } break; @@ -1012,20 +1003,20 @@ Perl_reentrant_retry(const char *f, ...) case KEY_getpwuid: case KEY_getpwent: { + Uid_t uid; + char * name; # ifdef PERL_REENTRANT_MAXSIZE if (PL_reentrant_buffer->_pwent_size <= PERL_REENTRANT_MAXSIZE / 2) # endif - { - Uid_t uid; RenewDouble(PL_reentrant_buffer->_pwent_buffer, &PL_reentrant_buffer->_pwent_size, char); switch (key) { case KEY_getpwnam: - p0 = va_arg(ap, void *); - retptr = getpwnam((char *)p0); break; + name = va_arg(ap, char *); + retptr = getpwnam(name); break; case KEY_getpwuid: # if Uid_t_size < INTSIZE @@ -1044,7 +1035,6 @@ Perl_reentrant_retry(const char *f, ...) SETERRNO(ERANGE, LIB_INVARG); break; } - } } break; @@ -1080,18 +1070,19 @@ Perl_reentrant_retry(const char *f, ...) case KEY_getprotobynumber: case KEY_getprotoent: { + char * name; + int anint; # ifdef PERL_REENTRANT_MAXSIZE if (PL_reentrant_buffer->_protoent_size <= PERL_REENTRANT_MAXSIZE / 2) # endif - { RenewDouble(PL_reentrant_buffer->_protoent_buffer, &PL_reentrant_buffer->_protoent_size, char); switch (key) { case KEY_getprotobyname: - p0 = va_arg(ap, void *); - retptr = getprotobyname((char *)p0); break; + name = va_arg(ap, char *); + retptr = getprotobyname(name); break; case KEY_getprotobynumber: anint = va_arg(ap, int); retptr = getprotobynumber(anint); break; @@ -1101,7 +1092,6 @@ Perl_reentrant_retry(const char *f, ...) SETERRNO(ERANGE, LIB_INVARG); break; } - } } break; @@ -1112,29 +1102,30 @@ Perl_reentrant_retry(const char *f, ...) case KEY_getservbyport: case KEY_getservent: { + char * name; + char * proto; + int anint; # ifdef PERL_REENTRANT_MAXSIZE if (PL_reentrant_buffer->_servent_size <= PERL_REENTRANT_MAXSIZE / 2) # endif - { RenewDouble(PL_reentrant_buffer->_servent_buffer, &PL_reentrant_buffer->_servent_size, char); switch (key) { case KEY_getservbyname: - p0 = va_arg(ap, void *); - p1 = va_arg(ap, void *); - retptr = getservbyname((char *)p0, (char *)p1); break; + name = va_arg(ap, char *); + proto = va_arg(ap, char *); + retptr = getservbyname(name, proto); break; case KEY_getservbyport: anint = va_arg(ap, int); - p0 = va_arg(ap, void *); - retptr = getservbyport(anint, (char *)p0); break; + name = va_arg(ap, char *); + retptr = getservbyport(anint, name); break; case KEY_getservent: retptr = getservent(); break; default: SETERRNO(ERANGE, LIB_INVARG); break; - } } } break; @@ -1152,7 +1143,6 @@ Perl_reentrant_retry(const char *f, ...) #endif - } va_end(ap); return retptr; } |