Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Message-ID: <779F20BCCE5AD31186A50008C75D997917167E@SILLDN_MAIL1> From: "Fifer, Eric" To: "'Steve Jorgensen'" , cygwin AT sourceware DOT cygnus DOT com Subject: RE: DLL's and environ again Date: Fri, 5 Nov 1999 16:22:05 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2448.0) Content-Type: text/plain; charset="iso-8859-1" Steve, I think I saw this before and I posted something to the list, but never got a response. My original message is below. The way I ended up working around this was to add a function to the dll that is initialized by the main exe, the function passes the address of environ from the exe to the dll. The dll then assigns it's local environ to the main exe's environ. Also a realloc can occur in setenv (in the main context) so after using setenv in the dll, you should assign the local environ to the main exe's environ again. See perl5_005.62's util.c for the working code. Hope this helps. Eric Fifer ---- Subject: Environ not shared between exe and dlls Date: Wed 5/26/99 3:17 PM This is a problem I found while fixing some problems with the latest dynamic build of perl. When I call setenv enough times to force a realloc of the global environ variable, the value of environ only changes in the exe and not in any of the dlls. Note that environ shows as defined in the exe *and* the dll: nm envbug.exe | grep environ 00402008 D _environ nm libenv.dll | grep environ 6dc02004 D _environ Should environ be in "struct _reent" or am I going about this in the wrong way? Thanks in advance. Eric Fifer ---------------------------------------- Just to be clear, here's an example ... output: exe: environ=a030008 environ[0]=!S:=S:\EFifer dll: environ=a030008 environ[0]=!S:=S:\EFifer exe: environ should be realloced exe: environ=a031330 environ[0]=!S:=S:\EFifer ^^^^^^^ environ realloced in exe dll: environ=a030008 environ[0]=`'^Fa`'^Fa ^^^^^^^ but not changed in dll, points to garbage dll: environ in dll reset dll: environ=a031330 environ[0]=!S:=S:\EFifer ^^^^^^^ after overriding environ everything is fine envbug.c: #include #include #include #define DLLIMPORT __declspec (dllimport) extern DLLIMPORT void dll_env_init(char ***penviron); extern DLLIMPORT void dll_env(); int main() { dll_env_init(&environ); printf("exe: environ=%x environ[0]=%s\n", environ, environ[0]); dll_env(); /* force the realloc of environ - see winsup/environ.cc */ setenv("foo1", "bar", 1); setenv("foo2", "bar", 1); setenv("foo3", "bar", 1); setenv("foo4", "bar", 1); setenv("foo5", "bar", 1); setenv("foo6", "bar", 1); setenv("foo7", "bar", 1); setenv("foo8", "bar", 1); printf("exe: environ should be realloced\n"); printf("exe: environ=%x environ[0]=%s\n", environ, environ[0]); dll_env(); return 0; } libenv.c: #include #include #include #define DLLIMPORT __declspec (dllexport) static char ***dll_env_environ; DLLIMPORT void dll_env_init(char ***penviron) { dll_env_environ = penviron; } DLLIMPORT void dll_env() { printf("dll: environ=%x environ[0]=%s\n", environ, environ[0]); if(environ != *dll_env_environ) { environ = *dll_env_environ; printf("dll: environ in dll reset\n"); printf("dll: environ=%x environ[0]=%s\n", environ, environ[0]); } } Makefile: CFLAGS = -g -Wall LDFLAGS = -g all: libenv.dll envbug envbug: envbug.o $(CC) $(LDFLAGS) -o envbug envbug.o -L. -lenv %.dll: %.o dllwrap --export-all --output-def $*.def \ --output-lib $*.a -o $@ $< -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com