clean code a little bit.
This commit is contained in:
parent
8c3406adac
commit
04f3b32a9a
61
C/alloc.c
61
C/alloc.c
@ -893,37 +893,22 @@ InitWorkSpace(Int s)
|
|||||||
return (void *) a;
|
return (void *) a;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static MALLOC_T
|
||||||
ExtendWorkSpace(Int s, int fixed_allocation)
|
mmap_extension(Int s, MALLOC_T base, int fixed_allocation)
|
||||||
{
|
{
|
||||||
#ifdef YAPOR
|
|
||||||
Yap_Error(INTERNAL_ERROR, TermNil, "cannot extend stacks (ExtendWorkSpace)");
|
|
||||||
return(FALSE);
|
|
||||||
#else
|
|
||||||
MALLOC_T a;
|
MALLOC_T a;
|
||||||
prolog_exec_mode OldPrologMode = Yap_PrologMode;
|
|
||||||
MALLOC_T base = WorkSpaceTop;
|
|
||||||
#if !defined(_AIX) && !defined(__hpux) && !defined(__APPLE__)
|
#if !defined(_AIX) && !defined(__hpux) && !defined(__APPLE__)
|
||||||
int fd;
|
int fd;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fixed_allocation == MAP_FIXED)
|
|
||||||
base = WorkSpaceTop;
|
|
||||||
else
|
|
||||||
base = 0L;
|
|
||||||
|
|
||||||
#if defined(_AIX) || defined(__hpux)
|
#if defined(_AIX) || defined(__hpux)
|
||||||
Yap_PrologMode = ExtendStackMode;
|
|
||||||
a = mmap(base, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
|
a = mmap(base, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
Yap_PrologMode = ExtendStackMode;
|
|
||||||
|
|
||||||
a = mmap(base, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
|
a = mmap(base, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||||
MAP_PRIVATE | MAP_ANON | fixed_allocation, -1, 0);
|
MAP_PRIVATE | MAP_ANON | fixed_allocation, -1, 0);
|
||||||
#else
|
#else
|
||||||
Yap_PrologMode = ExtendStackMode;
|
|
||||||
fd = open("/dev/zero", O_RDWR);
|
fd = open("/dev/zero", O_RDWR);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
#if HAVE_MKSTEMP
|
#if HAVE_MKSTEMP
|
||||||
@ -939,8 +924,7 @@ ExtendWorkSpace(Int s, int fixed_allocation)
|
|||||||
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
||||||
"mkstemp could not create temporary file %s", file);
|
"mkstemp could not create temporary file %s", file);
|
||||||
#endif /* HAVE_STRERROR */
|
#endif /* HAVE_STRERROR */
|
||||||
Yap_PrologMode = OldPrologMode;
|
return (MALLOC_T)-1;
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#if HAVE_TMPNAM
|
#if HAVE_TMPNAM
|
||||||
@ -956,32 +940,28 @@ ExtendWorkSpace(Int s, int fixed_allocation)
|
|||||||
Yap_ErrorMessage = Yap_ErrorSay;
|
Yap_ErrorMessage = Yap_ErrorSay;
|
||||||
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
||||||
"mmap could not open %s", file);
|
"mmap could not open %s", file);
|
||||||
Yap_PrologMode = OldPrologMode;
|
return (MALLOC_T)-1;
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
if (lseek(fd, s, SEEK_SET) < 0) {
|
if (lseek(fd, s, SEEK_SET) < 0) {
|
||||||
Yap_ErrorMessage = Yap_ErrorSay;
|
Yap_ErrorMessage = Yap_ErrorSay;
|
||||||
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
||||||
"mmap could not lseek in mmapped file %s", file);
|
"mmap could not lseek in mmapped file %s", file);
|
||||||
Yap_PrologMode = OldPrologMode;
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return FALSE;
|
return (MALLOC_T)-1;
|
||||||
}
|
}
|
||||||
if (write(fd, "", 1) < 0) {
|
if (write(fd, "", 1) < 0) {
|
||||||
Yap_ErrorMessage = Yap_ErrorSay;
|
Yap_ErrorMessage = Yap_ErrorSay;
|
||||||
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
||||||
"mmap could not write in mmapped file %s", file);
|
"mmap could not write in mmapped file %s", file);
|
||||||
Yap_PrologMode = OldPrologMode;
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return FALSE;
|
return (MALLOC_T)-1;
|
||||||
}
|
}
|
||||||
if (unlink(file) < 0) {
|
if (unlink(file) < 0) {
|
||||||
Yap_ErrorMessage = Yap_ErrorSay;
|
Yap_ErrorMessage = Yap_ErrorSay;
|
||||||
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
||||||
"mmap could not unlink mmapped file %s", file);
|
"mmap could not unlink mmapped file %s", file);
|
||||||
Yap_PrologMode = OldPrologMode;
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return FALSE;
|
return (MALLOC_T)-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a = mmap(base, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
|
a = mmap(base, (size_t) s, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||||
@ -1000,10 +980,30 @@ ExtendWorkSpace(Int s, int fixed_allocation)
|
|||||||
snprintf3(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
snprintf3(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
||||||
"mmap could not close file ]\n");
|
"mmap could not close file ]\n");
|
||||||
#endif
|
#endif
|
||||||
Yap_PrologMode = OldPrologMode;
|
return (MALLOC_T)-1;
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ExtendWorkSpace(Int s, int fixed_allocation)
|
||||||
|
{
|
||||||
|
#ifdef YAPOR
|
||||||
|
Yap_Error(INTERNAL_ERROR, TermNil, "cannot extend stacks (ExtendWorkSpace)");
|
||||||
|
return(FALSE);
|
||||||
|
#else
|
||||||
|
MALLOC_T a;
|
||||||
|
prolog_exec_mode OldPrologMode = Yap_PrologMode;
|
||||||
|
MALLOC_T base = WorkSpaceTop;
|
||||||
|
|
||||||
|
if (fixed_allocation == MAP_FIXED)
|
||||||
|
base = WorkSpaceTop;
|
||||||
|
else
|
||||||
|
base = 0L;
|
||||||
|
Yap_PrologMode = ExtendStackMode;
|
||||||
|
a = mmap_extension(s, base, fixed_allocation);
|
||||||
|
Yap_PrologMode = OldPrologMode;
|
||||||
if (a == (MALLOC_T) - 1) {
|
if (a == (MALLOC_T) - 1) {
|
||||||
Yap_ErrorMessage = Yap_ErrorSay;
|
Yap_ErrorMessage = Yap_ErrorSay;
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
@ -1013,7 +1013,6 @@ ExtendWorkSpace(Int s, int fixed_allocation)
|
|||||||
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
snprintf4(Yap_ErrorMessage, MAX_ERROR_MSG_SIZE,
|
||||||
"could not allocate %d bytes", (int)s);
|
"could not allocate %d bytes", (int)s);
|
||||||
#endif
|
#endif
|
||||||
Yap_PrologMode = OldPrologMode;
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (fixed_allocation) {
|
if (fixed_allocation) {
|
||||||
|
Reference in New Issue
Block a user