2 Commits ba99b81a78 ... 83a56a9f18

Author SHA1 Message Date
  Pentium44 83a56a9f18 Call this V0.7.0 2 years ago
  Pentium44 3bcdb74759 Call this V0.7.0 2 years ago
5 changed files with 30 additions and 23 deletions
  1. 1 1
      Makefile
  2. 6 0
      docs/README.txt
  3. 1 0
      src/inc/x3mem.h
  4. 17 18
      src/lz78/lz78.c
  5. 5 4
      src/lz78/wrapper.c

+ 1 - 1
Makefile

@@ -2,7 +2,7 @@
 # (C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
 # Some changes and tweaks from Menchers
 
-VERSION       = \"0.6.0\"
+VERSION       = \"0.7.0\"
 VERSION_EXTRA = \"$(EXTRA)\"
 
 PREFIX ?= /usr

+ 6 - 0
docs/README.txt

@@ -151,6 +151,12 @@ Changelog
 
 Changes between version bumps in SlideScript. Hoping to have a lightweight top-down scripting language
 by V1.0.0 release! From there it will be molding and preserving the art.
+* V0.7.0
+   * Ditched old LZ77 example code, and went with a more polished LZ78 ()
+   * Converted dynamic memory management layer into LZ78 engine and tar code.
+   * Compress & Decompress are both fully functioning.
+   * Tidies, and polishing (pushing more for that full lenguage)
+
 * V0.6.0
    * Multiple dynamic memory bug fixes, SlideScript is 99% dynamic on memory use
    * Included if, and ifn functions for comp, isfile, isdir, etc return values.

+ 1 - 0
src/inc/x3mem.h

@@ -261,6 +261,7 @@ typedef struct qlist QLIST;     /* typedef the list header      */
 /* a QLIST pointer and as the QLIST entry itself.               */
 
 UX3_EXT QLIST QM_GEN [ONE];     /* general-purpose QLIST        */
+UX3_EXT QLIST QM_LZ  [ONE];
 
 /* ------------------------------------------------------------ */
 

+ 17 - 18
src/lz78/lz78.c

@@ -24,6 +24,10 @@
 #include <stdio.h>
 
 #include "lz78.h"
+#include "../inc/x3mem.h"
+
+UX3_EXT QLIST QM_LZ [ONE];     // Dynamic-memory QLIST
+
 
 /* Code used to represent an EOF */
 #define DICT_CODE_EOF    256
@@ -168,14 +172,13 @@ uint8_t bitlen(uint32_t i) {
 }
 
 ht_dictionary* ht_dictionary_new(uint32_t d_size) {
-    ht_dictionary* dict = malloc(sizeof(ht_dictionary));
+    ht_dictionary* dict = qmalloc(QM_LZ, sizeof(ht_dictionary));
     if (dict == NULL)
         return NULL;
 
     d_size = DICT_LIMIT(d_size);
-    dict->root = calloc(1, sizeof(ht_entry) * d_size);
+    dict->root = qcalloc(QM_LZ, 1, sizeof(ht_entry) * d_size);
     if (dict->root == NULL) {
-        free(dict);
         return NULL;
     } else {
         dict->d_size = d_size;
@@ -243,22 +246,19 @@ void ht_dictionary_reset(ht_dictionary* d) {
 void ht_dictionary_destroy(ht_dictionary* d) {
     if (d != NULL)
     {
-        //free(d);
-        printf("I SHOULD BE FREEING MEMORY RIGHT NOW!\n");
-        // This is obviously going to be fixed in due course.
+        //qfree(d);
     }
 }
 
 dictionary* dictionary_new(uint32_t d_size) {
     uint16_t i;
-    dictionary* dict = malloc(sizeof(dictionary) + d_size);
+    dictionary* dict = qmalloc(QM_LZ, sizeof(dictionary) + d_size);
     if (dict == NULL)
         return NULL;
 
     d_size = DICT_LIMIT(d_size);
-    dict->root = malloc(sizeof(entry) * d_size);
+    dict->root = qmalloc(QM_LZ, sizeof(entry) * d_size);
     if (dict->root == NULL) {
-        free(dict);
         return NULL;
     }
 
@@ -310,8 +310,7 @@ void dictionary_reset(dictionary* d) {
 
 void dictionary_destroy(dictionary* d) {
     if (d != NULL) {
-        free(d->root);
-        free(d);
+        //qfree(d);
     }
 }
 
@@ -441,7 +440,7 @@ lz78_instance* lz78_new(uint8_t cmode, uint32_t dsize) {
     lz78_d* d;
 
     int max_dim = (sizeof(lz78_c) > sizeof(lz78_d)) ? sizeof(lz78_c) : sizeof(lz78_d);
-    i = malloc(sizeof(lz78_instance) + max_dim);
+    i = qmalloc(QM_LZ, (sizeof(lz78_instance) + max_dim));
     if (i == NULL)
         return NULL;
     i->mode = cmode;
@@ -454,13 +453,13 @@ lz78_instance* lz78_new(uint8_t cmode, uint32_t dsize) {
             c->completed = 0;
             c->main = ht_dictionary_new(c->d_size);
             if (c->main == NULL) {
-                free(i);
+                //qfree(i);
                 return NULL;
             }
             c->secondary = ht_dictionary_new(c->d_size);
             if (c->secondary == NULL) {
                 ht_dictionary_destroy(c->main);
-                free(i);
+                //qfree(i);
                 return NULL;
             }
             c->bitbuf = DICT_CODE_START;
@@ -473,7 +472,7 @@ lz78_instance* lz78_new(uint8_t cmode, uint32_t dsize) {
             d->completed = 0;
             d->main = dictionary_new(DICT_SIZE_MIN);
             if (d->main == NULL) {
-                free(i);
+                //qfree(i);
                 return NULL;
             }
             return i;
@@ -630,13 +629,13 @@ void lz78_destroy(lz78_instance *lz78) {
 
             case LZ78_MODE_DECOMPRESS:
                 d = (lz78_d*)&lz78->state;
-                if (d != NULL) {
-                    //dictionary_destroy(d->main);
+                if (d != NULL && d->main != NULL) {
+                    dictionary_destroy(d->main);
                     ht_dictionary_destroy(d->secondary);
                 }
                 break;
         }
 
-        free(lz78);
+        qflush(QM_LZ);
     }
 }

+ 5 - 4
src/lz78/wrapper.c

@@ -22,6 +22,7 @@
 #include <string.h>
 
 #include "wrapper.h"
+#include "../inc/x3mem.h"
 
 /* Structure representing the type of algorithm */
 struct __algorithm {
@@ -161,7 +162,7 @@ void wrapper_perror() {
 }
 
 wrapper* wrapper_new(uint8_t w_mode, uint8_t w_type, char* argv) {
-    wrapper* w = malloc(sizeof(wrapper));
+    wrapper* w = qmalloc(QM_LZ, sizeof(wrapper));
     if (w == NULL)
         return NULL;
 
@@ -174,14 +175,14 @@ wrapper* wrapper_new(uint8_t w_mode, uint8_t w_type, char* argv) {
             break;
 
         default:
-            free(w);
+            qfree(w);
             return NULL;
     }
 
     if (w->data)
         return w;
     else {
-        free(w);
+        qfree(w);
         return NULL;
     }
 }
@@ -198,7 +199,7 @@ void wrapper_destroy(wrapper* w) {
         default:
             return;
     }
-    free(w);
+    qflush(QM_LZ);
 }
 
 uint8_t wrapper_compress(wrapper* w, char* input, char* output) {