small bugfixes and leaks, patch by João Silva
This commit is contained in:
		@@ -804,7 +804,7 @@ Yap_NewPredPropByFunctor(FunctorEntry *fe, Term cur_mod)
 | 
			
		||||
  PredEntry *p = (PredEntry *) Yap_AllocAtomSpace(sizeof(*p));
 | 
			
		||||
 | 
			
		||||
  if (p == NULL) {
 | 
			
		||||
    WRITE_UNLOCK(fe);
 | 
			
		||||
    WRITE_UNLOCK(fe->FRWLock);
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
  if (cur_mod == TermProlog)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								C/grow.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								C/grow.c
									
									
									
									
									
								
							@@ -1419,10 +1419,14 @@ Yap_locked_growheap(int fix_code, size_t in_size, void *cip)
 | 
			
		||||
  int res;
 | 
			
		||||
  int blob_overflow = (NOfBlobs > NOfBlobsMax);
 | 
			
		||||
 | 
			
		||||
#ifdef THREADS
 | 
			
		||||
  LOCK(GLOBAL_ThreadHandlesLock);
 | 
			
		||||
#endif
 | 
			
		||||
  // make sure that we cannot have more than a thread life
 | 
			
		||||
  if (Yap_NOfThreads() > 1) {
 | 
			
		||||
#ifdef THREADS
 | 
			
		||||
      UNLOCK(GLOBAL_ThreadHandlesLock);
 | 
			
		||||
#endif
 | 
			
		||||
      res = FALSE;
 | 
			
		||||
      if (NOfAtoms > 2*AtomHashTableSize || blob_overflow) {
 | 
			
		||||
	  Yap_undo_signal( YAP_CDOVF_SIGNAL );
 | 
			
		||||
@@ -1443,12 +1447,16 @@ Yap_locked_growheap(int fix_code, size_t in_size, void *cip)
 | 
			
		||||
      res  = growatomtable( PASS_REGS1 );
 | 
			
		||||
    } else {
 | 
			
		||||
      Yap_undo_signal( YAP_CDOVF_SIGNAL );
 | 
			
		||||
#ifdef THREADS
 | 
			
		||||
      UNLOCK(GLOBAL_ThreadHandlesLock);
 | 
			
		||||
#endif
 | 
			
		||||
      return TRUE;
 | 
			
		||||
    }
 | 
			
		||||
    LeaveGrowMode(GrowHeapMode);
 | 
			
		||||
    if (res) {
 | 
			
		||||
#ifdef THREADS
 | 
			
		||||
	UNLOCK(GLOBAL_ThreadHandlesLock);
 | 
			
		||||
#endif
 | 
			
		||||
      return res;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -1459,7 +1467,9 @@ Yap_locked_growheap(int fix_code, size_t in_size, void *cip)
 | 
			
		||||
  res=do_growheap(fix_code, in_size, (struct intermediates *)cip, NULL, NULL, NULL PASS_REGS);
 | 
			
		||||
#endif
 | 
			
		||||
  LeaveGrowMode(GrowHeapMode);
 | 
			
		||||
#ifdef THREADS
 | 
			
		||||
  UNLOCK(GLOBAL_ThreadHandlesLock);
 | 
			
		||||
#endif
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								C/qlyw.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								C/qlyw.c
									
									
									
									
									
								
							@@ -335,7 +335,7 @@ InitHash(void)
 | 
			
		||||
  LOCAL_ExportFunctorHashChain = (export_functor_hash_entry_t *)calloc(LOCAL_ExportFunctorHashTableSize, sizeof(export_functor_hash_entry_t ));
 | 
			
		||||
  LOCAL_ExportAtomHashTableNum = 0;
 | 
			
		||||
  LOCAL_ExportAtomHashTableSize = EXPORT_ATOM_TABLE_SIZE;
 | 
			
		||||
  LOCAL_ExportAtomHashChain = (export_atom_hash_entry_t *)calloc( LOCAL_ExportAtomHashTableSize,  sizeof(export_atom_hash_entry_t *));
 | 
			
		||||
  LOCAL_ExportAtomHashChain = (export_atom_hash_entry_t *)calloc( LOCAL_ExportAtomHashTableSize,  sizeof(export_atom_hash_entry_t));
 | 
			
		||||
  LOCAL_ExportPredEntryHashTableNum = 0;
 | 
			
		||||
  LOCAL_ExportPredEntryHashTableSize = EXPORT_PRED_ENTRY_TABLE_SIZE;
 | 
			
		||||
  LOCAL_ExportPredEntryHashChain = (export_pred_entry_hash_entry_t *)calloc(LOCAL_ExportPredEntryHashTableSize, sizeof(export_pred_entry_hash_entry_t));
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								C/save.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								C/save.c
									
									
									
									
									
								
							@@ -1307,9 +1307,9 @@ RestoreHashPreds( USES_REGS1 )
 | 
			
		||||
  UInt i;
 | 
			
		||||
  PredEntry **oldp = PredHash;
 | 
			
		||||
 | 
			
		||||
  np = (PredEntry **) Yap_AllocAtomSpace(sizeof(PredEntry **)*size);
 | 
			
		||||
  np = (PredEntry **) Yap_AllocAtomSpace(sizeof(PredEntry *)*size);
 | 
			
		||||
  if (!np) {
 | 
			
		||||
    if (!(np = (PredEntry **) malloc(sizeof(PredEntry **)*size))) {
 | 
			
		||||
    if (!(np = (PredEntry **) malloc(sizeof(PredEntry *)*size))) {
 | 
			
		||||
	Yap_Error(FATAL_ERROR,TermNil,"Could not allocate space for pred table");
 | 
			
		||||
	return;
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -1115,7 +1115,7 @@ static Int
 | 
			
		||||
p_init_random_state ( USES_REGS1 )
 | 
			
		||||
{
 | 
			
		||||
  register Term t0 = Deref (ARG1);
 | 
			
		||||
  char *old, * new = (char *) malloc(256);
 | 
			
		||||
  char *old, *new;
 | 
			
		||||
 | 
			
		||||
  if (IsVarTerm (t0)) {
 | 
			
		||||
    return(Yap_unify(ARG1,MkIntegerTerm((Int)current_seed)));
 | 
			
		||||
@@ -1128,6 +1128,8 @@ p_init_random_state ( USES_REGS1 )
 | 
			
		||||
    current_seed  = (unsigned int) FloatOfTerm (t0);
 | 
			
		||||
  else
 | 
			
		||||
    current_seed  = (unsigned int) LongIntOfTerm (t0);
 | 
			
		||||
  
 | 
			
		||||
  new = (char *) malloc(256);
 | 
			
		||||
  old = initstate(random(), new, 256);
 | 
			
		||||
  return Yap_unify(ARG2, MkIntegerTerm((Int)old)) &&
 | 
			
		||||
      Yap_unify(ARG3, MkIntegerTerm((Int)new));
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								C/text.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								C/text.c
									
									
									
									
									
								
							@@ -1358,7 +1358,7 @@ void *
 | 
			
		||||
Yap_Concat_Text( int n,  seq_tv_t inp[], seq_tv_t *out USES_REGS)
 | 
			
		||||
{
 | 
			
		||||
  encoding_t * encv;
 | 
			
		||||
   void **bufv;
 | 
			
		||||
  void **bufv;
 | 
			
		||||
  int minimal = FALSE;
 | 
			
		||||
  void *buf;
 | 
			
		||||
  size_t leng, *lengv;
 | 
			
		||||
@@ -1368,8 +1368,6 @@ Yap_Concat_Text( int n,  seq_tv_t inp[], seq_tv_t *out USES_REGS)
 | 
			
		||||
  HEAP_TERM_ERROR(bufv, void *);
 | 
			
		||||
  encv = (encoding_t *)malloc(n*sizeof(encoding_t));
 | 
			
		||||
  HEAP_ERROR(encv, encoding_t);
 | 
			
		||||
  lengv = (size_t *)malloc(n*sizeof(size_t));
 | 
			
		||||
  HEAP_ERROR(lengv, size_t);
 | 
			
		||||
  buf = NULL;
 | 
			
		||||
  for (i = 0 ; i < n ; i++) {
 | 
			
		||||
    void *nbuf = read_Text( buf, inp+i, encv+i, &minimal, &leng PASS_REGS );
 | 
			
		||||
@@ -1381,6 +1379,8 @@ Yap_Concat_Text( int n,  seq_tv_t inp[], seq_tv_t *out USES_REGS)
 | 
			
		||||
      buf = compute_end( nbuf, encv[i] );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  lengv = (size_t *)malloc(n*sizeof(size_t));
 | 
			
		||||
  HEAP_ERROR(lengv, size_t);
 | 
			
		||||
  buf = concat(n, out, bufv, encv, lengv PASS_REGS);
 | 
			
		||||
  return buf;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -690,7 +690,11 @@ static Int
 | 
			
		||||
p_thread_set_concurrency( USES_REGS1 )
 | 
			
		||||
{
 | 
			
		||||
  Term tnew = Deref(ARG2);
 | 
			
		||||
  int newc, cur;
 | 
			
		||||
  int newc;
 | 
			
		||||
#if HAVE_PTHREAD_GETCONCURRENCY
 | 
			
		||||
int cur;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  if (IsVarTerm(tnew)) {
 | 
			
		||||
    newc = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -337,7 +337,7 @@ char *YAPAtom::name(void) {
 | 
			
		||||
      sz = strlen(s)+1;
 | 
			
		||||
      char *os = new char[sz];
 | 
			
		||||
      memcpy(os, s, sz);
 | 
			
		||||
      delete s;
 | 
			
		||||
      delete[] s;
 | 
			
		||||
      return os;
 | 
			
		||||
  } else if (IsBlob(a)) {
 | 
			
		||||
      PL_blob_t *type = RepBlobProp(a->PropsOfAE)->blob_t;
 | 
			
		||||
@@ -365,7 +365,7 @@ char *YAPAtom::name(void) {
 | 
			
		||||
#endif
 | 
			
		||||
	  char *os = new char[sz];
 | 
			
		||||
	  memcpy(os, s, sz);
 | 
			
		||||
	  delete s;
 | 
			
		||||
	  delete[] s;
 | 
			
		||||
	  return os;
 | 
			
		||||
      }
 | 
			
		||||
  } else {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								H/Yap.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								H/Yap.h
									
									
									
									
									
								
							@@ -465,7 +465,7 @@ extern int Yap_output_msg;
 | 
			
		||||
#include <android/asset_manager_jni.h>
 | 
			
		||||
#include <android/log.h>
 | 
			
		||||
#else
 | 
			
		||||
inline void __android_log_print(int i, const char loc[], const char msg[], ...) {}
 | 
			
		||||
#define __android_log_print(i,loc,msg,...)
 | 
			
		||||
#define ANDROID_LOG_INFO 0
 | 
			
		||||
#define ANDROID_LOG_ERROR 0
 | 
			
		||||
#define ANDROID_LOG_DEBUG 0
 | 
			
		||||
 
 | 
			
		||||
@@ -142,10 +142,12 @@ RL_Tree* copy_rl(RL_Tree *tree) {
 | 
			
		||||
  buf_ptr=(RL_Node*)calloc(tree->size,NODE_SIZE);
 | 
			
		||||
  if( new==NULL ) {
 | 
			
		||||
    printf("new==NULL");
 | 
			
		||||
	free(buf_ptr);
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
  if( buf_ptr==NULL ) {
 | 
			
		||||
    printf("buf_ptr==NULL---%lu",tree->size);
 | 
			
		||||
	free(new);
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
  memcpy(new,tree,sizeof(RL_Tree));
 | 
			
		||||
 
 | 
			
		||||
@@ -481,7 +481,7 @@ file_property(void)
 | 
			
		||||
static int
 | 
			
		||||
p_mktemp(void)
 | 
			
		||||
{
 | 
			
		||||
#if HAVE_MKTEMP || defined(__MINGW32__) || _MSC_VER
 | 
			
		||||
#if HAVE_MKSTEMP || HAVE_MKTEMP || defined(__MINGW32__) || _MSC_VER
 | 
			
		||||
  char *s, tmp[BUF_SIZE];
 | 
			
		||||
  s = (char *)YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1));
 | 
			
		||||
#if HAVE_STRNCPY
 | 
			
		||||
@@ -495,6 +495,13 @@ p_mktemp(void)
 | 
			
		||||
    return(YAP_Unify(YAP_ARG3, YAP_MkIntTerm(errno)));
 | 
			
		||||
  }
 | 
			
		||||
  return(YAP_Unify(YAP_ARG2,YAP_MkAtomTerm(YAP_LookupAtom(s))));
 | 
			
		||||
#elif HAVE_MKSTEMP
 | 
			
		||||
  strcpy(tmp, "/tmp/TEST_tmpXXXXXXXX");
 | 
			
		||||
  if(mkstemp(tmp) == -1) {
 | 
			
		||||
    /* return an error number */
 | 
			
		||||
    return(YAP_Unify(YAP_ARG3, YAP_MkIntTerm(errno)));
 | 
			
		||||
  }
 | 
			
		||||
  return YAP_Unify(YAP_ARG2,YAP_MkAtomTerm(YAP_LookupAtom(tmp)));
 | 
			
		||||
#else
 | 
			
		||||
  if ((s = mktemp(tmp)) == NULL) {
 | 
			
		||||
    /* return an error number */
 | 
			
		||||
@@ -511,7 +518,13 @@ p_mktemp(void)
 | 
			
		||||
static int
 | 
			
		||||
p_tmpnam(void)
 | 
			
		||||
{
 | 
			
		||||
#if HAVE_MKTEMP
 | 
			
		||||
#if HAVE_MKSTEMP
 | 
			
		||||
  char s[22];
 | 
			
		||||
  strcpy(s, "/tmp/TEST_tmpXXXXXXXX");
 | 
			
		||||
  if(mkstemp(s) == -1)
 | 
			
		||||
    return FALSE;
 | 
			
		||||
  return YAP_Unify(YAP_ARG1,YAP_MkAtomTerm(YAP_LookupAtom(s)));
 | 
			
		||||
#elif HAVE_MKTEMP
 | 
			
		||||
  char *s;
 | 
			
		||||
  if (!(s = mktemp("/tmp/YAP_tmpXXXXXXXX")))
 | 
			
		||||
    return FALSE;
 | 
			
		||||
 
 | 
			
		||||
@@ -1428,6 +1428,7 @@ discardOutputRedirect(redir_context *ctx)
 | 
			
		||||
static
 | 
			
		||||
PRED_IMPL("with_output_to", 2, with_output_to, PL_FA_TRANSPARENT)
 | 
			
		||||
{ redir_context outctx;
 | 
			
		||||
  outctx.magic = 0;
 | 
			
		||||
 | 
			
		||||
  if ( setupOutputRedirect(A1, &outctx, TRUE) )
 | 
			
		||||
  { term_t ex = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -1332,7 +1332,7 @@ formatFloat(PL_locale *locale, int how, int arg, Number f, Buffer out)
 | 
			
		||||
      int written = 0;
 | 
			
		||||
      int fbits;
 | 
			
		||||
      int digits = 0;
 | 
			
		||||
      int padding = 0;
 | 
			
		||||
      int padding;
 | 
			
		||||
 | 
			
		||||
      switch(how)
 | 
			
		||||
      { case 'f':
 | 
			
		||||
@@ -1368,6 +1368,8 @@ formatFloat(PL_locale *locale, int how, int arg, Number f, Buffer out)
 | 
			
		||||
          if (digits <= arg)             /* leading '0's */
 | 
			
		||||
          { padding = (arg-digits+1);
 | 
			
		||||
            size += padding;
 | 
			
		||||
          } else
 | 
			
		||||
          { padding = 0;
 | 
			
		||||
          }
 | 
			
		||||
          size++;                        /* NULL terminator */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -791,7 +791,7 @@ PRED_IMPL("locale_destroy", 1, locale_destroy, 0)
 | 
			
		||||
static
 | 
			
		||||
PRED_IMPL("set_locale", 1, set_locale, 0)
 | 
			
		||||
{ PRED_LD
 | 
			
		||||
  PL_locale *l;
 | 
			
		||||
  PL_locale *l = NULL;
 | 
			
		||||
 | 
			
		||||
  if ( getLocaleEx(A1, &l) )
 | 
			
		||||
  { PL_locale *ol = LD->locale.current;
 | 
			
		||||
 
 | 
			
		||||
@@ -43,7 +43,7 @@
 | 
			
		||||
#include <android/asset_manager_jni.h>
 | 
			
		||||
#include <android/log.h>
 | 
			
		||||
#else
 | 
			
		||||
inline void __android_log_print(int i, const char loc[], const char msg[], ...) {}
 | 
			
		||||
#define __android_log_print(i,loc,msg,...)
 | 
			
		||||
#define ANDROID_LOG_INFO 0
 | 
			
		||||
#define ANDROID_LOG_ERROR 0
 | 
			
		||||
#define ANDROID_LOG_DEBUG 0
 | 
			
		||||
 
 | 
			
		||||
 Submodule packages/chr updated: 33b688ae73...608c12f48a
									
								
							@@ -1,3 +1,4 @@
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
void bp4p_init(int *argc, char **argv[]);
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,7 @@ int compute_daem_inside_scaling_log_exp(void);
 | 
			
		||||
int examine_inside_scaling_none(void);
 | 
			
		||||
int examine_inside_scaling_log_exp(void);
 | 
			
		||||
int compute_expectation_scaling_none(void);
 | 
			
		||||
int compute_inside_scaling_log_exp(void);
 | 
			
		||||
int compute_expectation_scaling_log_exp(void);
 | 
			
		||||
double compute_daem_log_prior(void);
 | 
			
		||||
double compute_likelihood_scaling_none(void);
 | 
			
		||||
 
 | 
			
		||||
@@ -24,11 +24,11 @@ python: $(SWIG_FILES) python/_yap.so python/yap.py
 | 
			
		||||
python/_yap.so: python/yap_wrap.o
 | 
			
		||||
	$(CXX) -shared $(LDSOFLAGS) -o python/_yap.so python/yap_wrap.o ../../yapi.o $(LIBS) @PYTHON_LIBS@ -L ../.. -lYap -lpthread
 | 
			
		||||
 | 
			
		||||
python/yap_wrap.c: $(srcdir)/yap.i
 | 
			
		||||
python/yap_wrap.cpp python/yap.py: $(srcdir)/yap.i
 | 
			
		||||
	mkdir -p python
 | 
			
		||||
	$(SWIG) -c++ -python  -outdir python -o $@ $(CXXFLAGS) -Wall $<
 | 
			
		||||
 | 
			
		||||
python/yap_wrap.o:  python/yap_wrap.c
 | 
			
		||||
python/yap_wrap.o:  python/yap_wrap.cpp
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) @PYTHON_INCLUDES@ $< -o $@
 | 
			
		||||
 | 
			
		||||
java: jni/libyap.@SO@ java/yap.java
 | 
			
		||||
@@ -37,7 +37,7 @@ java: jni/libyap.@SO@ java/yap.java
 | 
			
		||||
jni/libyap.@SO@: jni/yap_wrap.o
 | 
			
		||||
	$(CXX) -shared $(LDSOFLAGS) -o $@ ../../yapi.o  $< $(LIBS) @JPLLDFLAGS@ -L ../.. -lYap -lpthread
 | 
			
		||||
 | 
			
		||||
jni/yap_wrap.cpp: $(srcdir)/yap.i
 | 
			
		||||
jni/yap_wrap.cpp java/yap.java: $(srcdir)/yap.i
 | 
			
		||||
	$(SWIG) -c++ -java  -package pt.up.fc.dcc.yap -outdir java -o $@  $(CXXFLAGS) -Wall $<
 | 
			
		||||
 | 
			
		||||
jni/yap_wrap.o:  jni/yap_wrap.cpp
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user