Merge branch 'master' of ssh://git.code.sf.net/p/yap/yap-6.3

This commit is contained in:
Vitor Santos Costa 2014-01-06 18:28:45 +00:00
commit 411b7700e5
4 changed files with 59 additions and 64 deletions

View File

@ -330,7 +330,7 @@ AccessNamedArray(Atom a, Int indx USES_REGS)
StaticArrayEntry *ptr = (StaticArrayEntry *)pp; StaticArrayEntry *ptr = (StaticArrayEntry *)pp;
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), "access_array");*/ /* Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW, MkIntegerTerm(indx), "access_array");*/
READ_UNLOCK(ptr->ArRWLock); READ_UNLOCK(ptr->ArRWLock);
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
@ -566,6 +566,7 @@ CreateNamedArray(PropEntry * pp, Int dim, AtomEntry *ae USES_REGS)
p = (ArrayEntry *) Yap_AllocAtomSpace(sizeof(*p)); p = (ArrayEntry *) Yap_AllocAtomSpace(sizeof(*p));
p->KindOfPE = ArrayProperty; p->KindOfPE = ArrayProperty;
p->TypeOfAE = DYNAMIC_ARRAY;
AddPropToAtom(ae, (PropEntry *)p); AddPropToAtom(ae, (PropEntry *)p);
INIT_RWLOCK(p->ArRWLock); INIT_RWLOCK(p->ArRWLock);
#if THREADS #if THREADS
@ -578,9 +579,9 @@ CreateNamedArray(PropEntry * pp, Int dim, AtomEntry *ae USES_REGS)
} }
static void static void
AllocateStaticArraySpace(StaticArrayEntry *p, static_array_types atype, Int array_size USES_REGS) AllocateStaticArraySpace(StaticArrayEntry *p, static_array_types atype, void *old, size_t array_size USES_REGS)
{ {
Int asize = 0; size_t asize = 0;
switch (atype) { switch (atype) {
case array_of_doubles: case array_of_doubles:
asize = array_size*sizeof(Float); asize = array_size*sizeof(Float);
@ -606,7 +607,8 @@ AllocateStaticArraySpace(StaticArrayEntry *p, static_array_types atype, Int arra
asize = array_size*sizeof(DBRef); asize = array_size*sizeof(DBRef);
break; break;
} }
while ((p->ValueOfVE.floats = (Float *) Yap_AllocAtomSpace(asize) ) == NULL) { if (old == NULL) {
while ((p->ValueOfVE.floats = (Float *) Yap_AllocCodeSpace(asize) ) == NULL) {
YAPLeaveCriticalSection(); YAPLeaveCriticalSection();
if (!Yap_growheap(FALSE, asize, NULL)) { if (!Yap_growheap(FALSE, asize, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
@ -614,14 +616,24 @@ AllocateStaticArraySpace(StaticArrayEntry *p, static_array_types atype, Int arra
} }
YAPEnterCriticalSection(); YAPEnterCriticalSection();
} }
} else {
while ((p->ValueOfVE.floats = (Float *) Yap_ReallocCodeSpace(old, asize) ) == NULL) {
YAPLeaveCriticalSection();
if (!Yap_growheap(FALSE, asize, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return;
}
YAPEnterCriticalSection();
}
}
} }
/* ae and p are assumed to be locked, if they exist */ /* ae and p are assumed to be locked, if they exist */
static StaticArrayEntry * static StaticArrayEntry *
CreateStaticArray(AtomEntry *ae, Int dim, static_array_types type, CODEADDR start_addr, StaticArrayEntry *p USES_REGS) CreateStaticArray(AtomEntry *ae, size_t dim, static_array_types type, CODEADDR start_addr, StaticArrayEntry *p USES_REGS)
{ {
if (EndOfPAEntr(p)) { if (EndOfPAEntr(p)) {
while ((p = (StaticArrayEntry *) Yap_AllocAtomSpace(sizeof(*p))) == NULL) { while ((p = (StaticArrayEntry *) Yap_AllocCodeSpace(sizeof(*p))) == NULL) {
if (!Yap_growheap(FALSE, sizeof(*p), NULL)) { if (!Yap_growheap(FALSE, sizeof(*p), NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL; return NULL;
@ -634,12 +646,13 @@ CreateStaticArray(AtomEntry *ae, Int dim, static_array_types type, CODEADDR star
LOCAL_StaticArrays = p; LOCAL_StaticArrays = p;
} }
WRITE_LOCK(p->ArRWLock); WRITE_LOCK(p->ArRWLock);
p->ArrayEArity = -dim; p->ArrayEArity = dim;
p->ArrayType = type; p->ArrayType = type;
p->TypeOfAE = STATIC_ARRAY;
if (start_addr == NULL) { if (start_addr == NULL) {
Int i; Int i;
AllocateStaticArraySpace(p, type, dim PASS_REGS); AllocateStaticArraySpace(p, type, NULL, dim PASS_REGS);
if (p->ValueOfVE.ints == NULL) { if (p->ValueOfVE.ints == NULL) {
WRITE_UNLOCK(p->ArRWLock); WRITE_UNLOCK(p->ArRWLock);
return p; return p;
@ -683,6 +696,7 @@ CreateStaticArray(AtomEntry *ae, Int dim, static_array_types type, CODEADDR star
} }
} else { } else {
/* external array */ /* external array */
p->TypeOfAE |= MMAP_ARRAY;
p->ValueOfVE.chars = (char *)start_addr; p->ValueOfVE.chars = (char *)start_addr;
} }
WRITE_UNLOCK(p->ArRWLock); WRITE_UNLOCK(p->ArRWLock);
@ -690,86 +704,64 @@ CreateStaticArray(AtomEntry *ae, Int dim, static_array_types type, CODEADDR star
} }
static void static void
ResizeStaticArray(StaticArrayEntry *pp, Int dim USES_REGS) ResizeStaticArray(StaticArrayEntry *pp, size_t dim USES_REGS)
{ {
statarray_elements old_v = pp->ValueOfVE; statarray_elements old_v = pp->ValueOfVE;
static_array_types type = pp->ArrayType; static_array_types type = pp->ArrayType;
Int old_dim = - pp->ArrayEArity; size_t old_dim = pp->ArrayEArity;
Int mindim = (dim < old_dim ? dim : old_dim), i; size_t mindim = (dim < old_dim ? dim : old_dim), i;
/* change official size */ /* change official size */
if (pp->ArrayEArity >= 0){ if (pp->ArrayEArity == 0){
return; return;
} }
WRITE_LOCK(pp->ArRWLock); WRITE_LOCK(pp->ArRWLock);
pp->ArrayEArity = -dim; pp->ArrayEArity = dim;
#if HAVE_MMAP #if HAVE_MMAP
if (pp->ValueOfVE.chars < (char *)Yap_HeapBase || if (pp->TypeOfAE & MMAP_ARRAY) {
pp->ValueOfVE.chars > (char *)HeapTop) {
ResizeMmappedArray(pp, dim, (void *)(pp->ValueOfVE.chars) PASS_REGS); ResizeMmappedArray(pp, dim, (void *)(pp->ValueOfVE.chars) PASS_REGS);
WRITE_UNLOCK(pp->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
return; return;
} }
#endif #endif
AllocateStaticArraySpace(pp, type, dim PASS_REGS); AllocateStaticArraySpace(pp, type, old_v.chars, dim PASS_REGS);
switch(type) { switch(type) {
case array_of_ints: case array_of_ints:
for (i = 0; i <mindim; i++)
pp->ValueOfVE.ints[i] = old_v.ints[i];
for (i = mindim; i<dim; i++) for (i = mindim; i<dim; i++)
pp->ValueOfVE.ints[i] = 0; pp->ValueOfVE.ints[i] = 0;
break; break;
case array_of_chars: case array_of_chars:
for (i = 0; i <mindim; i++)
pp->ValueOfVE.chars[i] = old_v.chars[i];
for (i = mindim; i<dim; i++) for (i = mindim; i<dim; i++)
pp->ValueOfVE.chars[i] = '\0'; pp->ValueOfVE.chars[i] = '\0';
break; break;
case array_of_uchars: case array_of_uchars:
for (i = 0; i <mindim; i++)
pp->ValueOfVE.uchars[i] = old_v.uchars[i];
for (i = mindim; i<dim; i++) for (i = mindim; i<dim; i++)
pp->ValueOfVE.uchars[i] = '\0'; pp->ValueOfVE.uchars[i] = '\0';
break; break;
case array_of_doubles: case array_of_doubles:
for (i = 0; i <mindim; i++)
pp->ValueOfVE.floats[i] = old_v.floats[i];
for (i = mindim; i<dim; i++) for (i = mindim; i<dim; i++)
pp->ValueOfVE.floats[i] = 0.0; pp->ValueOfVE.floats[i] = 0.0;
break; break;
case array_of_ptrs: case array_of_ptrs:
for (i = 0; i <mindim; i++)
pp->ValueOfVE.ptrs[i] = old_v.ptrs[i];
for (i = mindim; i<dim; i++) for (i = mindim; i<dim; i++)
pp->ValueOfVE.ptrs[i] = NULL; pp->ValueOfVE.ptrs[i] = NULL;
break; break;
case array_of_atoms: case array_of_atoms:
for (i = 0; i <mindim; i++)
pp->ValueOfVE.atoms[i] = old_v.atoms[i];
for (i = mindim; i<dim; i++) for (i = mindim; i<dim; i++)
pp->ValueOfVE.atoms[i] = TermNil; pp->ValueOfVE.atoms[i] = TermNil;
break; break;
case array_of_dbrefs: case array_of_dbrefs:
for (i = 0; i <mindim; i++)
pp->ValueOfVE.dbrefs[i] = old_v.dbrefs[i];
for (i = mindim; i<dim; i++) for (i = mindim; i<dim; i++)
pp->ValueOfVE.dbrefs[i] = 0L; pp->ValueOfVE.dbrefs[i] = 0L;
break; break;
case array_of_terms: case array_of_terms:
for (i = 0; i <mindim; i++)
pp->ValueOfVE.terms[i] = old_v.terms[i];
for (i = mindim; i<dim; i++) for (i = mindim; i<dim; i++)
pp->ValueOfVE.terms[i] = NULL; pp->ValueOfVE.terms[i] = NULL;
break; break;
case array_of_nb_terms: case array_of_nb_terms:
for (i = 0; i <mindim; i++) { for (i = mindim; i <dim; i++) {
Term tlive = pp->ValueOfVE.lterms[i].tlive;
if (IsVarTerm(tlive) && IsUnboundVar(&(pp->ValueOfVE.lterms[i].tlive))) {
RESET_VARIABLE(&(pp->ValueOfVE.lterms[i].tlive)); RESET_VARIABLE(&(pp->ValueOfVE.lterms[i].tlive));
} else { pp->ValueOfVE.lterms[i].tstore = TermNil;
pp->ValueOfVE.lterms[i].tlive = tlive;
}
pp->ValueOfVE.lterms[i].tstore = old_v.lterms[i].tstore;
} }
break; break;
} }
@ -781,10 +773,10 @@ ClearStaticArray(StaticArrayEntry *pp)
{ {
statarray_elements old_v = pp->ValueOfVE; statarray_elements old_v = pp->ValueOfVE;
static_array_types type = pp->ArrayType; static_array_types type = pp->ArrayType;
Int dim = - pp->ArrayEArity, i; Int dim = pp->ArrayEArity, i;
/* change official size */ /* change official size */
if (pp->ArrayEArity >= 0){ if (pp->ArrayEArity == 0){
return; return;
} }
WRITE_LOCK(pp->ArRWLock); WRITE_LOCK(pp->ArRWLock);
@ -949,8 +941,7 @@ p_create_array( USES_REGS1 )
WRITE_UNLOCK(ae->ARWLock); WRITE_UNLOCK(ae->ARWLock);
if (!IsVarTerm(app->ValueOfVE) if (!IsVarTerm(app->ValueOfVE)
|| !IsUnboundVar(&app->ValueOfVE)) { || !IsUnboundVar(&app->ValueOfVE)) {
if (size == app->ArrayEArity || if (size == app->ArrayEArity)
size == -app->ArrayEArity)
return TRUE; return TRUE;
Yap_Error(PERMISSION_ERROR_CREATE_ARRAY,t,"create_array", Yap_Error(PERMISSION_ERROR_CREATE_ARRAY,t,"create_array",
ae->StrOfAE); ae->StrOfAE);
@ -1064,7 +1055,7 @@ p_create_static_array( USES_REGS1 )
return FALSE; return FALSE;
} }
} else { } else {
if (pp->ArrayEArity == -size && if (pp->ArrayEArity == size &&
pp->ArrayType == props) { pp->ArrayType == props) {
WRITE_UNLOCK(ae->ARWLock); WRITE_UNLOCK(ae->ARWLock);
return TRUE; return TRUE;
@ -1101,7 +1092,7 @@ p_static_array_properties( USES_REGS1 )
return (FALSE); return (FALSE);
} else { } else {
static_array_types tp = pp->ArrayType; static_array_types tp = pp->ArrayType;
Int dim = -pp->ArrayEArity; Int dim = pp->ArrayEArity;
READ_UNLOCK(ae->ARWLock); READ_UNLOCK(ae->ARWLock);
if (dim <= 0 || !Yap_unify(ARG2,MkIntegerTerm(dim))) if (dim <= 0 || !Yap_unify(ARG2,MkIntegerTerm(dim)))
@ -1169,7 +1160,7 @@ p_resize_static_array( USES_REGS1 )
Yap_Error(PERMISSION_ERROR_RESIZE_ARRAY,t,"resize a static array"); Yap_Error(PERMISSION_ERROR_RESIZE_ARRAY,t,"resize a static array");
return(FALSE); return(FALSE);
} else { } else {
Int osize = - pp->ArrayEArity; size_t osize = pp->ArrayEArity;
ResizeStaticArray(pp, size PASS_REGS); ResizeStaticArray(pp, size PASS_REGS);
return(Yap_unify(ARG2,MkIntegerTerm(osize))); return(Yap_unify(ARG2,MkIntegerTerm(osize)));
} }
@ -1237,11 +1228,9 @@ p_close_static_array( USES_REGS1 )
StaticArrayEntry *ptr = (StaticArrayEntry *)pp; StaticArrayEntry *ptr = (StaticArrayEntry *)pp;
if (ptr->ValueOfVE.ints != NULL) { if (ptr->ValueOfVE.ints != NULL) {
#if HAVE_MMAP #if HAVE_MMAP
if (ptr->ValueOfVE.chars < (char *)Yap_HeapBase ||
ptr->ValueOfVE.chars > (char *)HeapTop) {
Int val = CloseMmappedArray(ptr, (void *)ptr->ValueOfVE.chars PASS_REGS); Int val = CloseMmappedArray(ptr, (void *)ptr->ValueOfVE.chars PASS_REGS);
#if USE_SYSTEM_MALLOC #if USE_SYSTEM_MALLOC
if (val) if (val) {
#endif #endif
return(val); return(val);
} }
@ -1651,7 +1640,7 @@ p_assign_static( USES_REGS1 )
WRITE_LOCK(ptr->ArRWLock); WRITE_LOCK(ptr->ArRWLock);
READ_UNLOCK(ae->ARWLock); READ_UNLOCK(ae->ARWLock);
/* a static array */ /* a static array */
if (indx < 0 || indx >= - ptr->ArrayEArity) { if (indx < 0 || indx >= ptr->ArrayEArity) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static"); Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static");
return FALSE; return FALSE;
@ -1980,7 +1969,7 @@ p_assign_dynamic( USES_REGS1 )
WRITE_LOCK(ptr->ArRWLock); WRITE_LOCK(ptr->ArRWLock);
/* a static array */ /* a static array */
if (indx < 0 || indx >= - ptr->ArrayEArity) { if (indx < 0 || indx >= ptr->ArrayEArity) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static"); Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static");
return FALSE; return FALSE;
@ -2179,7 +2168,7 @@ p_add_to_array_element( USES_REGS1 )
WRITE_LOCK(ptr->ArRWLock); WRITE_LOCK(ptr->ArRWLock);
/* a static array */ /* a static array */
if (indx < 0 || indx >= - ptr->ArrayEArity) { if (indx < 0 || indx >= ptr->ArrayEArity) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"add_to_array_element"); Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"add_to_array_element");
return FALSE; return FALSE;
@ -2271,7 +2260,7 @@ p_static_array_to_term( USES_REGS1 )
return (FALSE); return (FALSE);
} else { } else {
static_array_types tp = pp->ArrayType; static_array_types tp = pp->ArrayType;
Int dim = -pp->ArrayEArity, indx; Int dim = pp->ArrayEArity, indx;
CELL *base; CELL *base;
while (H+1+dim > ASP-1024) { while (H+1+dim > ASP-1024) {

View File

@ -437,7 +437,7 @@ legalAtom(unsigned char *s) /* Is this a legal atom ? */
return (s[1] == '}' && !s[2]); return (s[1] == '}' && !s[2]);
} else if (Yap_chtype[ch] == SL) { } else if (Yap_chtype[ch] == SL) {
return (!s[1]); return (!s[1]);
} else if ((ch == ',' /* || ch == '.' */) && !s[1]) { } else if ((ch == ',' || ch == '.') && !s[1]) {
return FALSE; return FALSE;
} else { } else {
if (ch == '/') { if (ch == '/') {

View File

@ -1281,6 +1281,12 @@ IsTranslationProperty (int flags)
} }
typedef enum {
STATIC_ARRAY = 1,
DYNAMIC_ARRAY = 2,
MMAP_ARRAY = 4,
FIXED_ARRAY = 8
} array_type;
/* array property entry structure */ /* array property entry structure */
@ -1290,6 +1296,7 @@ typedef struct array_entry
Prop NextOfPE; /* used to chain properties */ Prop NextOfPE; /* used to chain properties */
PropFlags KindOfPE; /* kind of property */ PropFlags KindOfPE; /* kind of property */
Int ArrayEArity; /* Arity of Array (positive) */ Int ArrayEArity; /* Arity of Array (positive) */
array_type TypeOfAE;
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
rwlock_t ArRWLock; /* a read-write lock to protect the entry */ rwlock_t ArRWLock; /* a read-write lock to protect the entry */
#if THREADS #if THREADS
@ -1341,6 +1348,7 @@ typedef struct static_array_entry
Prop NextOfPE; /* used to chain properties */ Prop NextOfPE; /* used to chain properties */
PropFlags KindOfPE; /* kind of property */ PropFlags KindOfPE; /* kind of property */
Int ArrayEArity; /* Arity of Array (negative) */ Int ArrayEArity; /* Arity of Array (negative) */
array_type TypeOfAE;
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
rwlock_t ArRWLock; /* a read-write lock to protect the entry */ rwlock_t ArRWLock; /* a read-write lock to protect the entry */
#endif #endif
@ -1441,7 +1449,7 @@ INLINE_ONLY inline EXTERN int ArrayIsDynamic (ArrayEntry *);
INLINE_ONLY inline EXTERN int INLINE_ONLY inline EXTERN int
ArrayIsDynamic (ArrayEntry * are) ArrayIsDynamic (ArrayEntry * are)
{ {
return (int) (((are)->ArrayEArity > 0)); return (int) (((are)->TypeOfAE & DYNAMIC_ARRAY));
} }

View File

@ -26,5 +26,3 @@ typedef struct array_access_struct {
keep it as an integer! */ keep it as an integer! */
} array_access; } array_access;