Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: remove environ arguments, remove sysenviron #3111

Merged
merged 1 commit into from
Dec 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "stats.h" // for ClearError
#include "streams.h"
#include "stringobj.h"
#include "sysenv.h"
#include "sysfiles.h"
#include "sysmem.h"
#include "sysopt.h"
Expand Down Expand Up @@ -151,8 +152,6 @@ void ViewObjHandler ( Obj obj )
UInt QUITTINGGVar;


static char **sysenviron;

/*
TL: Obj ShellContext = 0;
TL: Obj BaseShellContext = 0;
Expand Down Expand Up @@ -433,7 +432,7 @@ Obj FuncSHELL (Obj self, Obj args)
return res;
}

int realmain( int argc, char * argv[], char * environ[] )
int realmain( int argc, char * argv[] )
{
UInt type; /* result of compile */
Obj func; /* function (compiler) */
Expand All @@ -442,7 +441,7 @@ int realmain( int argc, char * argv[], char * environ[] )
SetupGAPLocation(argc, argv);

/* initialize everything and read init.g which runs the GAP session */
InitializeGap( &argc, argv, environ );
InitializeGap( &argc, argv );
if (!STATE(UserHasQUIT)) { /* maybe the user QUIT from the initial
read of init.g somehow*/
/* maybe compile in which case init.g got skipped */
Expand All @@ -468,17 +467,17 @@ int realmain( int argc, char * argv[], char * environ[] )
}

#if !defined(COMPILECYGWINDLL)
int main ( int argc, char * argv[], char * environ[] )
int main ( int argc, char * argv[] )
{
#if defined(HAVE_BACKTRACE) && defined(PRINT_BACKTRACE)
InstallBacktraceHandlers();
#endif

#ifdef HPCGAP
RunThreadedMain(realmain, argc, argv, environ);
RunThreadedMain(realmain, argc, argv);
return 0;
#else
return realmain(argc, argv, environ);
return realmain(argc, argv);
#endif
}

Expand Down Expand Up @@ -1374,17 +1373,17 @@ Obj FuncKERNEL_INFO(Obj self) {
AssPRec(res,r, tmp);

tmp = NEW_PREC(0);
for (i = 0; sysenviron[i]; i++) {
for (p = sysenviron[i]; *p != '='; p++)
for (i = 0; environ[i]; i++) {
for (p = environ[i]; *p != '='; p++)
;
lenstr2 = (UInt) (p-sysenviron[i]);
lenstr2 = (UInt) (p-environ[i]);
p++; /* Move pointer behind = character */
lenstr = strlen(p);
if (lenstr2 > lenstr)
str = NEW_STRING(lenstr2);
else
str = NEW_STRING(lenstr);
strncat(CSTR_STRING(str),sysenviron[i],lenstr2);
strncat(CSTR_STRING(str),environ[i],lenstr2);
r = RNamName(CONST_CSTR_STRING(str));
*(CSTR_STRING(str)) = 0;
strncat(CSTR_STRING(str),p, lenstr);
Expand Down Expand Up @@ -1724,8 +1723,7 @@ static Obj POST_RESTORE;

void InitializeGap (
int * pargc,
char * argv [],
char * environ [] )
char * argv [] )
{
/* initialize the basic system and gasman */
InitSystem( *pargc, argv );
Expand All @@ -1744,8 +1742,6 @@ void InitializeGap (
STATE(UserHasQuit) = 0;
STATE(JumpToCatchCallback) = 0;

sysenviron = environ;

// get info structures for the built in modules
ModulesSetup();

Expand Down
3 changes: 1 addition & 2 deletions src/gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ enum {
*/
extern void InitializeGap (
int * pargc,
char * argv [],
char * environ [] );
char * argv [] );


#endif // GAP_GAP_H
6 changes: 3 additions & 3 deletions src/gapw95.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
** SPDX-License-Identifier: GPL-2.0-or-later
*/

extern int realmain(int argc, char *argv[], char *environ[]);
extern int realmain(int argc, char *argv[]);

int main(int argc,char *argv[], char *environ[])
int main(int argc, char *argv[])
{
return realmain(argc,argv,environ);
return realmain(argc, argv);
}
19 changes: 8 additions & 11 deletions src/hpc/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,13 @@ void InitMainThread(void)
TLS(CountActive) = 1;
}

static NOINLINE void RunThreadedMain2(int (*mainFunction)(int, char **, char **),
static NOINLINE void RunThreadedMain2(int (*mainFunction)(int, char **),
int argc,
char ** argv,
char ** environ);
char ** argv);

void RunThreadedMain(int (*mainFunction)(int, char **, char **),
void RunThreadedMain(int (*mainFunction)(int, char **),
int argc,
char ** argv,
char ** environ)
char ** argv)
{
#ifndef HAVE_NATIVE_TLS
#ifdef STACK_GROWS_UP
Expand All @@ -240,13 +238,12 @@ void RunThreadedMain(int (*mainFunction)(int, char **, char **),
}
#endif
#endif
RunThreadedMain2(mainFunction, argc, argv, environ);
RunThreadedMain2(mainFunction, argc, argv);
}

static void RunThreadedMain2(int (*mainFunction)(int, char **, char **),
static void RunThreadedMain2(int (*mainFunction)(int, char **),
int argc,
char ** argv,
char ** environ)
char ** argv)
{
int i;
static pthread_mutex_t main_thread_mutex;
Expand Down Expand Up @@ -276,7 +273,7 @@ static void RunThreadedMain2(int (*mainFunction)(int, char **, char **),
InitSignals();
if (sySetjmp(TLS(threadExit)))
exit(0);
exit((*mainFunction)(argc, argv, environ));
exit((*mainFunction)(argc, argv));
}

void CreateMainRegion(void)
Expand Down
5 changes: 2 additions & 3 deletions src/hpc/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ void AddGCRoots(void);
void RemoveGCroots(void);

void RunThreadedMain(
int (*mainFunction)(int, char **, char **),
int (*mainFunction)(int, char **),
int argc,
char **argv,
char **environ );
char **argv );

void CreateMainRegion(void);
Obj RunThread(void (*start)(void *), void *arg);
Expand Down
3 changes: 1 addition & 2 deletions src/libgap-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
//
void GAP_Initialize(int argc,
char ** argv,
char ** env,
GAP_CallbackFunc markBagsCallback,
GAP_CallbackFunc errorCallback)
{
InitializeGap(&argc, argv, env);
InitializeGap(&argc, argv);
SetExtraMarkFuncBags(markBagsCallback);
STATE(JumpToCatchCallback) = errorCallback;

Expand Down
1 change: 0 additions & 1 deletion src/libgap-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ typedef void (*GAP_CallbackFunc)(void);
// TODO: document this function
extern void GAP_Initialize(int argc,
char ** argv,
char ** env,
GAP_CallbackFunc markBagsCallback,
GAP_CallbackFunc errorCallback);

Expand Down
30 changes: 30 additions & 0 deletions src/sysenv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/****************************************************************************
**
** This file is part of GAP, a system for computational discrete algebra.
**
** Copyright of GAP belongs to its developers, whose names are too numerous
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef GAP_SYSENV_H
#define GAP_SYSENV_H

#ifdef SYS_IS_CYGWIN32

// cygwin declares environ in unistd.h
#include <unistd.h>

#elif defined(__APPLE__)

#include <crt_externs.h>
#define environ (*_NSGetEnviron())

#elif !defined(environ)

extern char ** environ;

#endif

#endif // GAP_SYSENV_H
7 changes: 1 addition & 6 deletions src/sysfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "records.h"
#include "stats.h"
#include "stringobj.h"
#include "sysenv.h"
#include "sysopt.h"

#include "hpc/thread.h"
Expand Down Expand Up @@ -2988,12 +2989,6 @@ void SySetErrorNo ( void )
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif

#ifdef SYS_IS_CYGWIN32
// cygwin declares environ in unistd.h
#else
extern char ** environ;
#endif

void NullSignalHandler(int scratch) {}

#ifdef SYS_IS_CYGWIN32
Expand Down
2 changes: 1 addition & 1 deletion tst/testlibgap/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
int main(int argc, char ** argv)
{
printf("# Initializing GAP...\n");
GAP_Initialize(argc, argv, environ, 0L, 0L);
GAP_Initialize(argc, argv, 0, 0);
test_eval("1+2+3;");
test_eval("g:=FreeGroup(2);");
test_eval("a:=g.1;");
Expand Down
2 changes: 1 addition & 1 deletion tst/testlibgap/wscreate.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "common.h"
int main(int argc, char ** argv)
{
GAP_Initialize(argc, argv, environ, 0L, 0L);
GAP_Initialize(argc, argv, 0, 0);
test_eval("g:=FreeGroup(2);");
test_eval("a:=g.1;");
test_eval("b:=g.2;");
Expand Down
2 changes: 1 addition & 1 deletion tst/testlibgap/wsload.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main(int argc, char ** argv)
args[argc] = lpar;
args[argc+1] = wsname;
args[argc+2] = NULL;
GAP_Initialize(argc+2, args, environ, 0L, 0L);
GAP_Initialize(argc+2, args, 0, 0);
printf("# looking at saved stuff...\n");
test_eval("g;");
test_eval("a;");
Expand Down