Преглед на файлове

Properly clean up default data type.

Stefano Cossu преди 3 години
родител
ревизия
ff73f3f40d
променени са 3 файла, в които са добавени 19 реда и са изтрити 6 реда
  1. 14 3
      Makefile
  2. 3 2
      src/environment.c
  3. 2 1
      src/term.c

+ 14 - 3
Makefile

@@ -84,43 +84,53 @@ lib: $(DEPLIBS) $(LIBS) ## Compile main library (static and dynamic linking).
 
 debug: $(DEPLIBS) $(DBG_LIBS) ## Compile main library with debug symbols.
 
+
 # Static library.
 liblsuprdf.a: $(OBJ)
 	$(AR) rs $@ $^
 
+
 # Dynamic library.
 liblsuprdf.so: $(OBJ)
 	$(CC) -shared $(LDFLAGS) -o $@ $^
 
+
 # Static debug library.
 liblsuprdf_dbg.a: $(DBG_OBJ)
 	$(AR) rs $@ $^
 
+
 # Dynamic debug library.
 liblsuprdf_dbg.so: $(DBG_OBJ)
 	$(CC) -shared $(LDFLAGS) -o $@ $^
 
+
 # Debug objects.
 %_dbg.o: %.c
 	$(CC) $(CFLAGS) $(DBG_CFLAGS) $(LDFLAGS) -c $^ -o $@
 
+
 # Codecs.
 $(CODEC_OBJ): $(CODEC_SRC)
 
+
 # Parser C sources.
 %_parser.c: %_lexer.re %_grammar.c
 	$(LEXER) $< -o $@ -T --case-ranges
 
+
 # Parser generators.
 %_grammar.c: %_grammar.y
 	$(PARSER) $< -q -m -T$(CODEC_DIR)/lempar.c -d$(CODEC_DIR)
 
+
 # Ext libraries.
 
 .PHONY: libxxhash
 libxxhash:
 	$(MAKE) -C $(XXHASH_DIR)
-		
+
+
 .PHONY: liblmdb
 liblmdb:
 	$(MAKE) -C $(MDB_DIR)
@@ -156,6 +166,7 @@ uninstall:
 	rm -rf $(DESTDIR)$(includedir)
 	rm -f bin/test*
 
+
 # For testing, use debug symbols.
 bin/test: debug $(TEST_SRC)
 	$(CC) $(CFLAGS) $(DBG_CFLAGS) -Itest $(LDFLAGS) -llsuprdf_dbg \
@@ -173,6 +184,7 @@ gdb_test: bin/test ## Run a test suite within gdb.
 	@echo "Using libraries: "; ldd bin/test
 	exec gdb bin/test
 
+
 lint:
 	splint \
 		$(INCLUDE) -Itest \
@@ -188,7 +200,7 @@ memcheck:
 	--leak-check=full --show-leak-kinds=all --track-origins=yes \
 	--log-file=$(VALGRIND_DUMP) \
 	./bin/test
-	echo "Memcheck complete. Valgrind log is at $(VALGRIND_DUMP)"
+	@echo "Memcheck complete. Valgrind log is at $(VALGRIND_DUMP)"
 
 
 memtest: bin/test memcheck ## Run a test suite using Valgrind. Output to separate file.
@@ -223,7 +235,6 @@ pytest: ## Run a test suite for the Python package.
 	python3 test/cpython_test.py
 
 
-
 # Requires cinclude2dot (https://www.flourish.org/cinclude2dot) and Graphviz.
 depgraph: src/* include/* ## Build a visual dependency graph of the code.
 	cinclude2dot --merge=module --include=$(DEPS) \

+ 3 - 2
src/environment.c

@@ -76,8 +76,10 @@ LSUP_init (void)
         return LSUP_ERROR;
     }
 
-    // Default literal datatype key.
+    // Create and cache default literal datatype key.
     LSUP_default_datatype = LSUP_iriref_new (DEFAULT_DTYPE, NULL);
+    uint32_t dtype_hash = LSUP_term_hash (LSUP_default_datatype );
+    LSUP_tcache_add (dtype_hash, LSUP_default_datatype);
 
     // Default permanent store path.
     char *mdb_path = getenv ("LSUP_MDB_STORE_PATH");
@@ -147,7 +149,6 @@ LSUP_done (void)
         LSUP_term_free (entry->term);
         free (entry);
     }
-    LSUP_default_datatype = NULL;
 
     LSUP_env_is_init = false;
 }

+ 2 - 1
src/term.c

@@ -593,7 +593,8 @@ term_init (
         LSUP_Term *tmp = (LSUP_Term *) LSUP_tcache_get (dtype_hash);
         if (!tmp) LSUP_tcache_add (dtype_hash, term->datatype);
         else if (term->datatype != tmp) {
-            LSUP_term_free (term->datatype);
+            if (term->datatype != LSUP_default_datatype)
+                LSUP_term_free (term->datatype);
             term->datatype = tmp;
         }