fix argv[0] discovery.
This commit is contained in:
parent
ec37045ca3
commit
798afc81c4
@ -333,6 +333,7 @@
|
|||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "clause.h"
|
#include "clause.h"
|
||||||
#include "yapio.h"
|
#include "yapio.h"
|
||||||
|
#include "Foreign.h"
|
||||||
#include "attvar.h"
|
#include "attvar.h"
|
||||||
#include "SWI-Stream.h"
|
#include "SWI-Stream.h"
|
||||||
#if HAVE_STDARG_H
|
#if HAVE_STDARG_H
|
||||||
@ -3261,8 +3262,14 @@ YAP_FastInit(char saved_state[])
|
|||||||
init_args.DelayedReleaseLoad = 3;
|
init_args.DelayedReleaseLoad = 3;
|
||||||
init_args.PrologShouldHandleInterrupts = FALSE;
|
init_args.PrologShouldHandleInterrupts = FALSE;
|
||||||
init_args.ExecutionMode = INTERPRETED;
|
init_args.ExecutionMode = INTERPRETED;
|
||||||
init_args.Argc = 0;
|
init_args.Argc = 1;
|
||||||
init_args.Argv = NULL;
|
{
|
||||||
|
size_t l1 = 2*sizeof(char *);
|
||||||
|
if (!(init_args.Argv = (char **)malloc(l1)))
|
||||||
|
return YAP_BOOT_ERROR;
|
||||||
|
init_args.Argv[0] = Yap_FindExecutable ();
|
||||||
|
init_args.Argv[1] = NULL;
|
||||||
|
}
|
||||||
init_args.ErrorNo = 0;
|
init_args.ErrorNo = 0;
|
||||||
init_args.ErrorCause = NULL;
|
init_args.ErrorCause = NULL;
|
||||||
init_args.QuietMode = FALSE;
|
init_args.QuietMode = FALSE;
|
||||||
|
@ -26,9 +26,10 @@
|
|||||||
* FindExecutable(argv[0]) should be called on yap initialization to
|
* FindExecutable(argv[0]) should be called on yap initialization to
|
||||||
* locate the executable of Yap
|
* locate the executable of Yap
|
||||||
*/
|
*/
|
||||||
void
|
char *
|
||||||
Yap_FindExecutable(char *name)
|
Yap_FindExecutable(void)
|
||||||
{
|
{
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ this code is no being maintained anymore
|
|||||||
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
||||||
* locate the executable of Yap
|
* locate the executable of Yap
|
||||||
*/
|
*/
|
||||||
void
|
char *
|
||||||
Yap_FindExecutable(char *name)
|
Yap_FindExecutable(void)
|
||||||
{
|
{
|
||||||
register char *cp, *cp2;
|
register char *cp, *cp2;
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
@ -94,7 +94,7 @@ Yap_FindExecutable(char *name)
|
|||||||
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
|
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
|
||||||
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
|
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
|
||||||
if (oktox(GLOBAL_Executable))
|
if (oktox(GLOBAL_Executable))
|
||||||
return;
|
return GLOBAL_Executable;
|
||||||
else
|
else
|
||||||
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(GLOBAL_Executable)),
|
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(GLOBAL_Executable)),
|
||||||
"cannot find file being executed");
|
"cannot find file being executed");
|
||||||
|
@ -50,8 +50,8 @@ this code is no being maintained anymore
|
|||||||
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
||||||
* locate the executable of Yap
|
* locate the executable of Yap
|
||||||
*/
|
*/
|
||||||
void
|
char *
|
||||||
Yap_FindExecutable(char *name)
|
Yap_FindExecutable(void)
|
||||||
{
|
{
|
||||||
register char *cp, *cp2;
|
register char *cp, *cp2;
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
@ -64,7 +64,7 @@ Yap_FindExecutable(char *name)
|
|||||||
if (oktox(GLOBAL_argv[0])) {
|
if (oktox(GLOBAL_argv[0])) {
|
||||||
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
|
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
|
||||||
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
|
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*cp == ':')
|
if (*cp == ':')
|
||||||
@ -84,16 +84,17 @@ Yap_FindExecutable(char *name)
|
|||||||
if (!oktox(LOCAL_FileNameBuf))
|
if (!oktox(LOCAL_FileNameBuf))
|
||||||
continue;
|
continue;
|
||||||
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
|
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
|
||||||
return;
|
return GLOBAL_Executable;
|
||||||
}
|
}
|
||||||
/* one last try for dual systems */
|
/* one last try for dual systems */
|
||||||
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
|
strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]);
|
||||||
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
|
Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE);
|
||||||
if (oktox(GLOBAL_Executable))
|
if (oktox(GLOBAL_Executable))
|
||||||
return;
|
return GLOBAL_Executable;
|
||||||
else
|
else
|
||||||
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(GLOBAL_Executable)),
|
Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(GLOBAL_Executable)),
|
||||||
"cannot find file being executed");
|
"cannot find file being executed");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
32
C/load_dl.c
32
C/load_dl.c
@ -24,6 +24,10 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef void (*prismf)(void);
|
typedef void (*prismf)(void);
|
||||||
|
|
||||||
@ -57,9 +61,29 @@ Yap_CallFunctionByName(const char *thing_string)
|
|||||||
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
||||||
* locate the executable of Yap
|
* locate the executable of Yap
|
||||||
*/
|
*/
|
||||||
void
|
char *
|
||||||
Yap_FindExecutable(char *name)
|
Yap_FindExecutable(void)
|
||||||
{
|
{
|
||||||
|
if (GLOBAL_argv && GLOBAL_argv[0])
|
||||||
|
return GLOBAL_argv[0];
|
||||||
|
#if HAVE_GETEXECNAME
|
||||||
|
return getxecname();
|
||||||
|
#elif __APPLE__
|
||||||
|
char path[1024];
|
||||||
|
uint32_t size = sizeof(path);
|
||||||
|
if (!_NSGetExecutablePath(path, &size)) {
|
||||||
|
size_t sz = strlen(path);
|
||||||
|
char *rc = malloc(sz+1);
|
||||||
|
strncpy(rc, path, sz);
|
||||||
|
return rc;
|
||||||
|
} else {
|
||||||
|
char *rc = malloc(size+1);
|
||||||
|
if (_NSGetExecutablePath(rc, &size) == 0)
|
||||||
|
return "yap";
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return "yap";
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
@ -200,7 +224,7 @@ Yap_ShutdownLoadForeign(void)
|
|||||||
if (dlclose(objs->handle) != 0)
|
if (dlclose(objs->handle) != 0)
|
||||||
return; /* ERROR */
|
return; /* ERROR */
|
||||||
objs = objs->next;
|
objs = objs->next;
|
||||||
Yap_FreeCodeSpace(old);
|
Yap_FreeCodeSpace((ADDR)old);
|
||||||
}
|
}
|
||||||
libs = f_code->libs;
|
libs = f_code->libs;
|
||||||
while (libs != NULL) {
|
while (libs != NULL) {
|
||||||
@ -208,7 +232,7 @@ Yap_ShutdownLoadForeign(void)
|
|||||||
if (dlclose(libs->handle) != 0)
|
if (dlclose(libs->handle) != 0)
|
||||||
return; /* ERROR */
|
return; /* ERROR */
|
||||||
libs = libs->next;
|
libs = libs->next;
|
||||||
Yap_FreeCodeSpace(old);
|
Yap_FreeCodeSpace((ADDR)old);
|
||||||
}
|
}
|
||||||
f_code = f_code->next;
|
f_code = f_code->next;
|
||||||
Yap_FreeCodeSpace((ADDR)of_code);
|
Yap_FreeCodeSpace((ADDR)of_code);
|
||||||
|
@ -26,15 +26,15 @@ this code is no being maintained anymore
|
|||||||
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
||||||
* locate the executable of Yap
|
* locate the executable of Yap
|
||||||
*/
|
*/
|
||||||
void
|
char *
|
||||||
Yap_FindExecutable(char *name)
|
Yap_FindExecutable(void)
|
||||||
{
|
{
|
||||||
/* use dld_find_executable */
|
/* use dld_find_executable */
|
||||||
char *res;
|
char *res;
|
||||||
if(name != NULL && (res=dld_find_executable(name))) {
|
if(name != NULL && (res=dld_find_executable(name))) {
|
||||||
strcpy(GLOBAL_Executable,res);
|
return GLOBAL_Executable;
|
||||||
} else {
|
} else {
|
||||||
strcpy(GLOBAL_Executable,"./yap");
|
return "yap";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
void
|
void
|
||||||
Yap_FindExecutable(char *name)
|
Yap_FindExecutable(char *name)
|
||||||
{
|
{
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
@ -65,6 +65,18 @@ mydlerror(void)
|
|||||||
void
|
void
|
||||||
Yap_FindExecutable(char *name)
|
Yap_FindExecutable(char *name)
|
||||||
{
|
{
|
||||||
|
char path[1024];
|
||||||
|
uint32_t size = sizeof(path);
|
||||||
|
if (_NSGetExecutablePath(path, &size) == 0) {
|
||||||
|
char *rc = malloc(size+1);
|
||||||
|
strncpy(rc, path, size);
|
||||||
|
return rc;
|
||||||
|
} else {
|
||||||
|
char *rc = malloc(size+1);
|
||||||
|
if (_NSGetExecutablePath(rc, &size) == 0)
|
||||||
|
return "yap";
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,10 +225,6 @@ p_open_shared_objects( USES_REGS1 ) {
|
|||||||
void
|
void
|
||||||
Yap_InitLoadForeign( void )
|
Yap_InitLoadForeign( void )
|
||||||
{
|
{
|
||||||
if (GLOBAL_argv == NULL)
|
|
||||||
Yap_FindExecutable("yap");
|
|
||||||
else
|
|
||||||
Yap_FindExecutable(GLOBAL_argv[0]);
|
|
||||||
Yap_InitCPred("$load_foreign_files", 3, p_load_foreign, SafePredFlag|SyncPredFlag);
|
Yap_InitCPred("$load_foreign_files", 3, p_load_foreign, SafePredFlag|SyncPredFlag);
|
||||||
Yap_InitCPred("$open_shared_objects", 0, p_open_shared_objects, SafePredFlag);
|
Yap_InitCPred("$open_shared_objects", 0, p_open_shared_objects, SafePredFlag);
|
||||||
Yap_InitCPred("$open_shared_object", 3, p_open_shared_object, SyncPredFlag);
|
Yap_InitCPred("$open_shared_object", 3, p_open_shared_object, SyncPredFlag);
|
||||||
|
@ -26,9 +26,10 @@
|
|||||||
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
||||||
* locate the executable of Yap
|
* locate the executable of Yap
|
||||||
*/
|
*/
|
||||||
void
|
char *
|
||||||
Yap_FindExecutable(char *name)
|
Yap_FindExecutable(void)
|
||||||
{
|
{
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* locate the executable of Yap
|
* locate the executable of Yap
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Yap_FindExecutable(char *name)
|
char * Yap_FindExecutable(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4007,8 +4007,11 @@ p_argv( USES_REGS1 )
|
|||||||
static Int
|
static Int
|
||||||
p_executable( USES_REGS1 )
|
p_executable( USES_REGS1 )
|
||||||
{
|
{
|
||||||
|
if (GLOBAL_argv && GLOBAL_argv[0])
|
||||||
Yap_TrueFileName (GLOBAL_argv[0], LOCAL_FileNameBuf, FALSE);
|
Yap_TrueFileName (GLOBAL_argv[0], LOCAL_FileNameBuf, FALSE);
|
||||||
|
else
|
||||||
|
strncpy(LOCAL_FileNameBuf,Yap_FindExecutable (), YAP_FILENAME_MAX) ;
|
||||||
|
|
||||||
return Yap_unify(MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),ARG1);
|
return Yap_unify(MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),ARG1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ typedef void (*YapInitProc)(void);
|
|||||||
#define STD_PROTO(F,A) F A
|
#define STD_PROTO(F,A) F A
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void STD_PROTO(Yap_FindExecutable,(char *));
|
char *STD_PROTO(Yap_FindExecutable,(void));
|
||||||
void *STD_PROTO(Yap_LoadForeignFile,(char *, int));
|
void *STD_PROTO(Yap_LoadForeignFile,(char *, int));
|
||||||
int STD_PROTO(Yap_CallForeignFile,(void *, char *));
|
int STD_PROTO(Yap_CallForeignFile,(void *, char *));
|
||||||
int STD_PROTO(Yap_CloseForeignFile,(void *));
|
int STD_PROTO(Yap_CloseForeignFile,(void *));
|
||||||
|
@ -186,6 +186,7 @@
|
|||||||
#undef HAVE_FTIME
|
#undef HAVE_FTIME
|
||||||
#undef HAVE_GETCWD
|
#undef HAVE_GETCWD
|
||||||
#undef HAVE_GETENV
|
#undef HAVE_GETENV
|
||||||
|
#undef HAVE_GETEXECNAME
|
||||||
#undef HAVE_GETHOSTBYNAME
|
#undef HAVE_GETHOSTBYNAME
|
||||||
#undef HAVE_GETHOSTENT
|
#undef HAVE_GETHOSTENT
|
||||||
#undef HAVE_GETHOSTID
|
#undef HAVE_GETHOSTID
|
||||||
|
11
configure
vendored
11
configure
vendored
@ -10250,6 +10250,17 @@ _ACEOF
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
for ac_func in getexecname
|
||||||
|
do :
|
||||||
|
ac_fn_c_check_func "$LINENO" "getexecname" "ac_cv_func_getexecname"
|
||||||
|
if test "x$ac_cv_func_getexecname" = xyes; then :
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define HAVE_GETEXECNAME 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
for ac_func in gethostbyname gethostent gethostid gethostname
|
for ac_func in gethostbyname gethostent gethostid gethostname
|
||||||
do :
|
do :
|
||||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
|
@ -2069,6 +2069,7 @@ AC_CHECK_FUNCS(alloca asinh atanh chdir clock clock_gettime)
|
|||||||
AC_CHECK_FUNCS(ctime dlopen dup2)
|
AC_CHECK_FUNCS(ctime dlopen dup2)
|
||||||
AC_CHECK_FUNCS(erf feclearexcept)
|
AC_CHECK_FUNCS(erf feclearexcept)
|
||||||
AC_CHECK_FUNCS(fesettrapenable fgetpos finite fpclass ftime getcwd getenv)
|
AC_CHECK_FUNCS(fesettrapenable fgetpos finite fpclass ftime getcwd getenv)
|
||||||
|
AC_CHECK_FUNCS(getexecname)
|
||||||
AC_CHECK_FUNCS(gethostbyname gethostent gethostid gethostname)
|
AC_CHECK_FUNCS(gethostbyname gethostent gethostid gethostname)
|
||||||
AC_CHECK_FUNCS(gethrtime getpagesize)
|
AC_CHECK_FUNCS(gethrtime getpagesize)
|
||||||
AC_CHECK_FUNCS(getpwnam getrlimit getrusage gettimeofday getwd)
|
AC_CHECK_FUNCS(getpwnam getrlimit getrusage gettimeofday getwd)
|
||||||
|
Reference in New Issue
Block a user