Mail Archives: cygwin/1999/05/26/10:17:34
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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#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
- Raw text -