From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 0788C3858D33; Thu, 28 Jul 2022 20:00:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0788C3858D33 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: rename __cygwin_environ and drop env redirection via cur_environ() X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: cea26c75705b3a56b3f211bb083b8e9afe319e1c X-Git-Newrev: 7f42498be6cd47e9d3d46ec82374d703e3275ddf Message-Id: <20220728200051.0788C3858D33@sourceware.org> Date: Thu, 28 Jul 2022 20:00:51 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jul 2022 20:00:51 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D7f42498be6c= d47e9d3d46ec82374d703e3275ddf commit 7f42498be6cd47e9d3d46ec82374d703e3275ddf Author: Corinna Vinschen Date: Thu Jul 28 22:00:40 2022 +0200 Cygwin: rename __cygwin_environ and drop env redirection via cur_enviro= n() =20 Back in early Cygwin development a function based access to the environment was exported, the internal environ in Cygwin was called __cygwin_environ and cur_environ() was used to access the environment indirectly . The history of that necessity is not documented, but kept in i686 for backward compatibility. =20 The x86_64 port eventually used __cygwin_environ directly and exported it as DATA under the usual name environ. =20 We don't need the i686 workaround anymore, so just rename __cygwin_environ to environ, drop the cur_environ() macro and simply export environ under its own name. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/common.din | 1 + winsup/cygwin/dcrt0.cc | 2 +- winsup/cygwin/environ.cc | 30 +++++++++++++++--------------- winsup/cygwin/environ.h | 2 -- winsup/cygwin/exec.cc | 8 ++++---- winsup/cygwin/external.cc | 2 +- winsup/cygwin/globals.cc | 4 +--- winsup/cygwin/pinfo.cc | 4 ++-- winsup/cygwin/spawn.cc | 8 ++++---- winsup/cygwin/syscalls.cc | 2 +- winsup/cygwin/x86_64.din | 3 --- 11 files changed, 30 insertions(+), 36 deletions(-) diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din index 751ab3754..afcb71725 100644 --- a/winsup/cygwin/common.din +++ b/winsup/cygwin/common.din @@ -18,6 +18,7 @@ _sys_errlist DATA _sys_nerr DATA _timezone DATA _tzname DATA +environ DATA error_message_count DATA error_one_per_line DATA error_print_progname DATA diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 97eefa19d..57694bcda 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -1002,7 +1002,7 @@ dll_crt0_1 (void *) sig_dispatch_pending (false); _my_tls.call_signal_handler (); _my_tls.incyg--; /* Not in Cygwin anymore */ - cygwin_exit (user_data->main (__argc, newargv, __cygwin_environ)); + cygwin_exit (user_data->main (__argc, newargv, environ)); } __asm__ (" \n\ .global _cygwin_exit_return \n\ diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index ca60bd8d4..0ac1acc41 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -422,7 +422,7 @@ getwinenv (const char *env, const char *in_posix, win_e= nv *temp) { win_env *we =3D conv_envvars + i; const char *val; - if (!cur_environ () || !(val =3D in_posix ?: getenv (we->name))) + if (!environ || !(val =3D in_posix ?: getenv (we->name))) debug_printf ("can't set native for %s since no environ yet", we->name); else if (!we->posix || strcmp (val, we->posix) !=3D 0) @@ -486,7 +486,7 @@ my_findenv (const char *name, int *offset) char **p; const char *c; =20 - if (cur_environ () =3D=3D NULL) + if (!environ) return NULL; =20 c =3D name; @@ -497,11 +497,11 @@ my_findenv (const char *name, int *offset) len++; } =20 - for (p =3D cur_environ (); *p; ++p) + for (p =3D environ; *p; ++p) if (!strncmp (*p, name, len)) if (*(c =3D *p + len) =3D=3D '=3D') { - *offset =3D p - cur_environ (); + *offset =3D p - environ; return (char *) (++c); } return NULL; @@ -602,7 +602,7 @@ _addenv (const char *name, const char *value, int overw= rite) } else { /* Create new slot. */ - int sz =3D envsize (cur_environ ()); + int sz =3D envsize (environ); =20 /* If sz =3D=3D 0, we need two new slots, one for the terminating NU= LL. */ int newsz =3D sz =3D=3D 0 ? 2 : sz + 1; @@ -611,11 +611,11 @@ _addenv (const char *name, const char *value, int ove= rwrite) offset =3D newsz - 2; =20 /* Allocate space for additional element. */ - if (cur_environ () =3D=3D lastenviron) - lastenviron =3D __cygwin_environ =3D (char **) realloc (lastenviron, + if (environ =3D=3D lastenviron) + lastenviron =3D environ =3D (char **) realloc (lastenviron, allocsz); else if ((lastenviron =3D (char **) realloc (lastenviron, allocsz)) = !=3D NULL) - __cygwin_environ =3D (char **) memcpy (lastenviron, __cygwin_environ, + environ =3D (char **) memcpy (lastenviron, environ, sz * sizeof (char *)); if (!lastenviron) { @@ -625,13 +625,13 @@ _addenv (const char *name, const char *value, int ove= rwrite) return -1; /* Oops. No more memory. */ } =20 - __cygwin_environ[offset + 1] =3D NULL; /* NULL terminate. */ + environ[offset + 1] =3D NULL; /* NULL terminate. */ } =20 char *envhere; if (!issetenv) /* Not setenv. Just overwrite existing. */ - envhere =3D cur_environ ()[offset] =3D (char *) (ENVMALLOC ? strdup (n= ame) : name); + envhere =3D environ[offset] =3D (char *) (ENVMALLOC ? strdup (name) : = name); else { /* setenv */ /* Look for an '=3D' in the name and ignore anything after that if f= ound. */ @@ -640,7 +640,7 @@ _addenv (const char *name, const char *value, int overw= rite) =20 int namelen =3D p - name; /* Length of name. */ /* Allocate enough space for name + '=3D' + value + '\0' */ - envhere =3D cur_environ ()[offset] =3D (char *) malloc (namelen + va= luelen + 2); + envhere =3D environ[offset] =3D (char *) malloc (namelen + valuelen = + 2); if (!envhere) return -1; /* Oops. No more memory. */ =20 @@ -718,7 +718,7 @@ unsetenv (const char *name) =20 while (my_findenv (name, &offset)) /* if set multiple times */ /* Move up the rest of the array */ - for (e =3D cur_environ () + offset; ; e++) + for (e =3D environ + offset; ; e++) if (!(*e =3D *(e + 1))) break; =20 @@ -735,12 +735,12 @@ clearenv (void) { __try { - if (cur_environ () =3D=3D lastenviron) + if (environ =3D=3D lastenviron) { free (lastenviron); lastenviron =3D NULL; } - __cygwin_environ =3D NULL; + environ =3D NULL; return 0; } __except (EFAULT) {} @@ -842,7 +842,7 @@ environ_init (char **envp, int envc) =20 out: findenv_func =3D (char * (*)(const char*, int*)) my_findenv; - __cygwin_environ =3D envp; + environ =3D envp; if (envp_passed_in) { p =3D getenv ("CYGWIN"); diff --git a/winsup/cygwin/environ.h b/winsup/cygwin/environ.h index 3980d6b5a..86e64a72f 100644 --- a/winsup/cygwin/environ.h +++ b/winsup/cygwin/environ.h @@ -33,8 +33,6 @@ struct win_env win_env *getwinenv (const char *name, const char *posix =3D NULL, win_env = * =3D NULL); char *getwinenveq (const char *name, size_t len, int); =20 -extern "C" char **__cygwin_environ; -#define cur_environ() __cygwin_environ char **build_env (const char * const *envp, PWCHAR &envblock, int &envc, bool need_envblock, HANDLE new_token); =20 diff --git a/winsup/cygwin/exec.cc b/winsup/cygwin/exec.cc index 6ed714d6a..2f4041329 100644 --- a/winsup/cygwin/exec.cc +++ b/winsup/cygwin/exec.cc @@ -32,7 +32,7 @@ execl (const char *path, const char *arg0, ...) argv[i] =3D va_arg (args, const char *); while (argv[i++] !=3D NULL); va_end (args); - return spawnve (_P_OVERLAY, path, (char * const *) argv, cur_environ ()= ); + return spawnve (_P_OVERLAY, path, (char * const *) argv, environ); } =20 extern "C" int @@ -71,13 +71,13 @@ execlp (const char *file, const char *arg0, ...) va_end (args); return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC, find_exec (file, buf, "PATH", FE_NNF) ?: "", - (char * const *) argv, cur_environ ()); + (char * const *) argv, environ); } =20 extern "C" int execv (const char *path, char * const *argv) { - return spawnve (_P_OVERLAY, path, argv, cur_environ ()); + return spawnve (_P_OVERLAY, path, argv, environ); } =20 extern "C" int @@ -94,7 +94,7 @@ execvp (const char *file, char * const *argv) =20 return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC, find_exec (file, buf, "PATH", FE_NNF) ?: "", - argv, cur_environ ()); + argv, environ); } =20 extern "C" int diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc index a9a5b6432..bc6a3139d 100644 --- a/winsup/cygwin/external.cc +++ b/winsup/cygwin/external.cc @@ -140,7 +140,7 @@ create_winenv (const char * const *env) { int unused_envc; PWCHAR envblock =3D NULL; - char **envp =3D build_env (env ?: cur_environ (), envblock, unused_envc,= false, + char **envp =3D build_env (env ?: environ, envblock, unused_envc, false, NULL); PWCHAR p =3D envblock; =20 diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc index 294a67fe8..e8147cb5c 100644 --- a/winsup/cygwin/globals.cc +++ b/winsup/cygwin/globals.cc @@ -155,9 +155,7 @@ const int __collate_load_error =3D 0; extern UNICODE_STRING _RDATA ro_u_mq_suffix =3D _ROU (L":mqueue"); #undef _ROU =20 - /* This is an exported copy of environ which can be used by DLLs - which use cygwin.dll. */ - char **__cygwin_environ; + char **environ; /* __progname used in getopt error message */ char *__progname; char *program_invocation_name; diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 832a3e6bc..2e336c1a3 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -769,7 +769,7 @@ commune_process (void *arg) { sigproc_printf ("processing PICOM_ENVIRON"); unsigned n =3D 0; - char **env =3D cur_environ (); + char **env =3D environ; if (env) for (char **e =3D env; *e; e++) n +=3D strlen (*e) + 1; @@ -1210,7 +1210,7 @@ _pinfo::environ (size_t& n) return cr.s; } else - env =3D cur_environ (); + env =3D ::environ; =20 if (env =3D=3D NULL) return NULL; diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 277f0d1b3..2f745e14a 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -1130,7 +1130,7 @@ spawnl (int mode, const char *path, const char *arg0,= ...) =20 va_end (args); =20 - return spawnve (mode, path, (char * const *) argv, cur_environ ()); + return spawnve (mode, path, (char * const *) argv, environ); } =20 extern "C" int @@ -1174,7 +1174,7 @@ spawnlp (int mode, const char *file, const char *arg0= , ...) va_end (args); =20 return spawnve (mode | _P_PATH_TYPE_EXEC, find_exec (file, buf), - (char * const *) argv, cur_environ ()); + (char * const *) argv, environ); } =20 extern "C" int @@ -1204,7 +1204,7 @@ spawnlpe (int mode, const char *file, const char *arg= 0, ...) extern "C" int spawnv (int mode, const char *path, const char * const *argv) { - return spawnve (mode, path, argv, cur_environ ()); + return spawnve (mode, path, argv, environ); } =20 extern "C" int @@ -1213,7 +1213,7 @@ spawnvp (int mode, const char *file, const char * con= st *argv) path_conv buf; return spawnve (mode | _P_PATH_TYPE_EXEC, find_exec (file, buf, "PATH", FE_NNF) ?: "", - argv, cur_environ ()); + argv, environ); } =20 extern "C" int diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index da8779743..6455f25ab 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -4372,7 +4372,7 @@ popen (const char *command, const char *in_type) fcntl (stdchild, F_SETFD, stdchild_state | FD_CLOEXEC); =20 /* Start a shell process to run the given command without forking. */ - pid_t pid =3D ch_spawn.worker ("/bin/sh", argv, cur_environ (), _P_N= OWAIT, + pid_t pid =3D ch_spawn.worker ("/bin/sh", argv, environ, _P_NOWAIT, __std[0], __std[1]); =20 /* Reinstate the close-on-exec state */ diff --git a/winsup/cygwin/x86_64.din b/winsup/cygwin/x86_64.din index e1896bf8a..b0b6f6b78 100644 --- a/winsup/cygwin/x86_64.din +++ b/winsup/cygwin/x86_64.din @@ -1,9 +1,6 @@ LIBRARY "cygwin1.dll" BASE=3D0x180040000 =20 EXPORTS -#Exported variables -environ =3D __cygwin_environ DATA - #Exported functions __wrap__Znam NOSIGFE # void *operator new[](std::size_t sz)= throw (std::bad_alloc) __wrap__ZnamRKSt9nothrow_t NOSIGFE # void *operator new[](std::size_t sz,= const std::nothrow_t &nt) throw()