error handling
This commit is contained in:
parent
bbd9049111
commit
350081a90d
72
C/arrays.c
72
C/arrays.c
@ -234,22 +234,23 @@ static Int CloseMmappedArray(StaticArrayEntry *pp, void *area USES_REGS) {
|
|||||||
}
|
}
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
#if !defined(USE_SYSTEM_MALLOC)
|
#if !defined(USE_SYSTEM_MALLOC)
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1,
|
Yap_FullError(SYSTEM_ERROR_INTERNAL, ARG1,
|
||||||
"close_mmapped_array (array chain incoherent)", strerror(errno));
|
"close_mmapped_array (array chain incoherent)",
|
||||||
|
strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (munmap(ptr->start, ptr->size) == -1) {
|
if (munmap(ptr->start, ptr->size) == -1) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1, "close_mmapped_array (munmap: %s)",
|
Yap_FullError(SYSTEM_ERROR_INTERNAL, ARG1,
|
||||||
strerror(errno));
|
"close_mmapped_array (munmap: %s)", strerror(errno));
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
optr->next = ptr->next;
|
optr->next = ptr->next;
|
||||||
pp->ValueOfVE.ints = NULL;
|
pp->ValueOfVE.ints = NULL;
|
||||||
pp->ArrayEArity = 0;
|
pp->ArrayEArity = 0;
|
||||||
if (close(ptr->fd) < 0) {
|
if (close(ptr->fd) < 0) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1, "close_mmapped_array (close: %s)",
|
Yap_FullError(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1,
|
||||||
strerror(errno));
|
"close_mmapped_array (close: %s)", strerror(errno));
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
Yap_FreeAtomSpace((char *)ptr);
|
Yap_FreeAtomSpace((char *)ptr);
|
||||||
@ -271,30 +272,31 @@ static void ResizeMmappedArray(StaticArrayEntry *pp, Int dim,
|
|||||||
and last we initialize again
|
and last we initialize again
|
||||||
*/
|
*/
|
||||||
if (munmap(ptr->start, ptr->size) == -1) {
|
if (munmap(ptr->start, ptr->size) == -1) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1, "resize_mmapped_array (munmap: %s)",
|
Yap_FullError(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1,
|
||||||
strerror(errno));
|
"resize_mmapped_array (munmap: %s)", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
total_size = (ptr->size / ptr->items) * dim;
|
total_size = (ptr->size / ptr->items) * dim;
|
||||||
if (ftruncate(ptr->fd, total_size) < 0) {
|
if (ftruncate(ptr->fd, total_size) < 0) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1,
|
Yap_FullError(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1,
|
||||||
"resize_mmapped_array (ftruncate: %s)", strerror(errno));
|
"resize_mmapped_array (ftruncate: %s)", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (lseek(ptr->fd, total_size - 1, SEEK_SET) < 0) {
|
if (lseek(ptr->fd, total_size - 1, SEEK_SET) < 0) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1, "resize_mmapped_array (lseek: %s)",
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1,
|
||||||
strerror(errno));
|
"resize_mmapped_array (lseek: %s)", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (write(ptr->fd, "", 1) < 0) {
|
if (write(ptr->fd, "", 1) < 0) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1, "resize_mmapped_array (write: %s)",
|
Yap_FullError(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1,
|
||||||
strerror(errno));
|
"resize_mmapped_array (write: %s)", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((ptr->start = (void *)mmap(0, (size_t)total_size, PROT_READ | PROT_WRITE,
|
if ((ptr->start = (void *)mmap(0, (size_t)total_size, PROT_READ | PROT_WRITE,
|
||||||
MAP_SHARED, ptr->fd, 0)) == (void *)-1) {
|
MAP_SHARED, ptr->fd, 0)) == (void *)-1) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, ARG1, "resize_mmapped_array (mmap: %s)",
|
Yap_FullError(SYSTEM_ERROR_OPERATING_SYSTEM, ARG1,
|
||||||
strerror(errno));
|
"resize_mmapped_array (mmap: %s)", ___LINE__, __FUNCTION__,
|
||||||
|
-__FILE__, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ptr->size = total_size;
|
ptr->size = total_size;
|
||||||
@ -309,25 +311,15 @@ static Term GetTermFromArray(DBTerm *ref USES_REGS) {
|
|||||||
Term TRef;
|
Term TRef;
|
||||||
|
|
||||||
while ((TRef = Yap_FetchTermFromDB(ref)) == 0L) {
|
while ((TRef = Yap_FetchTermFromDB(ref)) == 0L) {
|
||||||
if (LOCAL_Error_TYPE == RESOURCE_ERROR_ATTRIBUTED_VARIABLES) {
|
|
||||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
||||||
if (!Yap_growglobal(NULL)) {
|
|
||||||
Yap_Error(RESOURCE_ERROR_ATTRIBUTED_VARIABLES, TermNil,
|
|
||||||
LOCAL_ErrorMessage);
|
|
||||||
return TermNil;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
|
||||||
if (!Yap_gcl(LOCAL_Error_Size, 3, ENV, Yap_gcP())) {
|
if (!Yap_gcl(LOCAL_Error_Size, 3, ENV, Yap_gcP())) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
||||||
return TermNil;
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRef;
|
return TRef;
|
||||||
} else {
|
} else {
|
||||||
P = (yamop *)FAILCODE;
|
Yap_Error(DOMAIN_ERROR_NOT_ZERO, ARG1, "Null reference.");
|
||||||
return TermNil;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,8 +347,8 @@ static Term GetNBTerm(live_term *ar, Int indx USES_REGS) {
|
|||||||
livet = termt;
|
livet = termt;
|
||||||
} else {
|
} else {
|
||||||
DBTerm *ref = (DBTerm *)RepAppl(termt);
|
DBTerm *ref = (DBTerm *)RepAppl(termt);
|
||||||
if ((livet = GetTermFromArray(ref PASS_REGS)) == TermNil) {
|
if ((livet = GetTermFromArray(ref PASS_REGS)) == 0) {
|
||||||
return TermNil;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
YapBind(&(ar[indx].tlive), livet);
|
YapBind(&(ar[indx].tlive), livet);
|
||||||
@ -391,10 +383,13 @@ static Term AccessNamedArray(Atom a, Int indx USES_REGS) {
|
|||||||
if (ArrayIsDynamic(pp)) {
|
if (ArrayIsDynamic(pp)) {
|
||||||
Term out;
|
Term out;
|
||||||
READ_LOCK(pp->ArRWLock);
|
READ_LOCK(pp->ArRWLock);
|
||||||
if (IsVarTerm(pp->ValueOfVE) || pp->ArrayEArity <= indx || indx < 0) {
|
if (IsVarTerm(pp->ValueOfVE)) {
|
||||||
READ_UNLOCK(pp->ArRWLock);
|
READ_UNLOCK(pp->ArRWLock);
|
||||||
P = (yamop *)FAILCODE;
|
Yap_Error(INSTANTIATION_ERROR, ARG1, "unbound static array", indx);
|
||||||
return (MkAtomTerm(AtomFoundVar));
|
}
|
||||||
|
if (pp->ArrayEArity <= indx || indx < 0) {
|
||||||
|
READ_UNLOCK(pp->ArRWLock);
|
||||||
|
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW, ARG1, "bad index %ld", indx);
|
||||||
}
|
}
|
||||||
out = RepAppl(pp->ValueOfVE)[indx + 1];
|
out = RepAppl(pp->ValueOfVE)[indx + 1];
|
||||||
READ_UNLOCK(pp->ArRWLock);
|
READ_UNLOCK(pp->ArRWLock);
|
||||||
@ -404,11 +399,7 @@ static Term AccessNamedArray(Atom a, Int indx USES_REGS) {
|
|||||||
|
|
||||||
READ_LOCK(ptr->ArRWLock);
|
READ_LOCK(ptr->ArRWLock);
|
||||||
if (pp->ArrayEArity <= indx || indx < 0) {
|
if (pp->ArrayEArity <= indx || indx < 0) {
|
||||||
/* Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW, MkIntegerTerm(indx),
|
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW, ARG1, "bad index %ld", indx);
|
||||||
* "access_array");*/
|
|
||||||
READ_UNLOCK(ptr->ArRWLock);
|
|
||||||
P = (yamop *)FAILCODE;
|
|
||||||
return (MkAtomTerm(AtomFoundVar));
|
|
||||||
}
|
}
|
||||||
switch (ptr->ArrayType) {
|
switch (ptr->ArrayType) {
|
||||||
|
|
||||||
@ -489,9 +480,9 @@ static Term AccessNamedArray(Atom a, Int indx USES_REGS) {
|
|||||||
case array_of_nb_terms: {
|
case array_of_nb_terms: {
|
||||||
/* The object is now in use */
|
/* The object is now in use */
|
||||||
Term out = GetNBTerm(ptr->ValueOfVE.lterms, indx PASS_REGS);
|
Term out = GetNBTerm(ptr->ValueOfVE.lterms, indx PASS_REGS);
|
||||||
|
|
||||||
READ_UNLOCK(ptr->ArRWLock);
|
READ_UNLOCK(ptr->ArRWLock);
|
||||||
return out;
|
if (out == 0)
|
||||||
|
return TermNil;
|
||||||
}
|
}
|
||||||
case array_of_terms: {
|
case array_of_terms: {
|
||||||
/* The object is now in use */
|
/* The object is now in use */
|
||||||
@ -1655,7 +1646,6 @@ static Int array_references(USES_REGS1) {
|
|||||||
|
|
||||||
/** @pred update_array(+ _Name_, + _Index_, ? _Value_)
|
/** @pred update_array(+ _Name_, + _Index_, ? _Value_)
|
||||||
|
|
||||||
|
|
||||||
Attribute value _Value_ to _Name_[ _Index_]. Type
|
Attribute value _Value_ to _Name_[ _Index_]. Type
|
||||||
restrictions must be respected for static arrays. This operation is
|
restrictions must be respected for static arrays. This operation is
|
||||||
available for dynamic arrays if `MULTI_ASSIGNMENT_VARIABLES` is
|
available for dynamic arrays if `MULTI_ASSIGNMENT_VARIABLES` is
|
||||||
|
Reference in New Issue
Block a user