allow memory recovery

This commit is contained in:
Vitor Santos Costa 2014-05-28 01:54:28 +01:00
parent 800ddd23a6
commit e7e9dab151

View File

@ -1137,7 +1137,7 @@ static Int
p_set_random_state ( USES_REGS1 )
{
register Term t0 = Deref (ARG1);
char *old, * new = (char *) malloc(256);
char *old, * new;
if (IsVarTerm (t0)) {
return FALSE;
@ -1149,6 +1149,23 @@ p_set_random_state ( USES_REGS1 )
old = setstate( new );
return Yap_unify(ARG2, MkIntegerTerm((Int)old));
}
static Int
p_release_random_state ( USES_REGS1 )
{
register Term t0 = Deref (ARG1);
char *old;
if (IsVarTerm (t0)) {
return FALSE;
}
if (IsIntegerTerm (t0))
old = (char *) IntegerOfTerm (t0);
else
return FALSE;
free( old );
return TRUE;
}
#endif
static Int
@ -3054,6 +3071,7 @@ Yap_InitSysPreds(void)
#if HAVE_RANDOM
Yap_InitCPred ("init_random_state", 3, p_init_random_state, SafePredFlag);
Yap_InitCPred ("set_random_state", 2, p_set_random_state, SafePredFlag);
Yap_InitCPred ("release_random_state", 1, p_release_random_state, SafePredFlag);
#endif
Yap_InitCPred ("sh", 0, p_sh, SafePredFlag|SyncPredFlag);
Yap_InitCPred ("$shell", 1, p_shell, SafePredFlag|SyncPredFlag|UserCPredFlag);