more tabling fixes

use malloc when AllocCodeSpace fails
use snprintf when available.


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1458 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc
2005-11-16 01:55:03 +00:00
parent e021bef90d
commit 4c0865ca37
9 changed files with 158 additions and 13 deletions

View File

@@ -5,7 +5,7 @@
Copyright: R. Rocha and NCC - University of Porto, Portugal
File: opt.init.c
version: $Id: opt.init.c,v 1.13 2005-11-04 01:17:17 vsc Exp $
version: $Id: opt.init.c,v 1.14 2005-11-16 01:55:03 vsc Exp $
**********************************************************************/
@@ -57,6 +57,36 @@ ma_h_inner_struct *Yap_ma_h_top;
#if YAP_MEMORY_ALLOC_SCHEME
char *
Yap_get_yap_space(int sz)
{
char *ptr = Yap_AllocCodeSpace(sz+sizeof(CELL));
if (ptr) {
*ptr = 'y';
return ptr+sizeof(CELL);
}
ptr = (char *)malloc(sz+sizeof(CELL));
if (ptr) {
*ptr = 'm';
return ptr+sizeof(CELL);
}
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "Yap_AllocCodeSpace error (ALLOC_STRUCT), when allocating %d B", sz);
return NULL;
}
void
Yap_free_yap_space(char *ptr)
{
ptr -= sizeof(CELL);
if (ptr[0] == 'y') {
Yap_FreeCodeSpace(ptr);
} else {
free((void *)ptr);
}
}
#endif
/* -------------------------- **
** Global functions **
** -------------------------- */
@@ -265,3 +295,4 @@ void init_workers(void) {
}
#endif /* YAPOR */
#endif /* YAPOR || TABLING */