cleanup warnings in gcc, fixed some hw module cleanup routines
authorJustin Wind <justin.wind@gmail.com>
Thu, 17 May 2012 22:22:49 +0000 (15:22 -0700)
committerJustin Wind <justin.wind@gmail.com>
Thu, 17 May 2012 22:22:49 +0000 (15:22 -0700)
Makefile
hw_keyboard.c
hw_lem1802.c
hw_spc2000.c

index 0593b49d6028abf71f612d4c2cb2c388140dd3f3..4dcde613241b5595f8829ebf4fe6f0e34138e8c8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,10 @@
 ifeq "$(origin CC)" "default"
 CC = clang
 endif
+ifeq ($(CC),gcc)
+CPPFLAGS += -DWANT_VARIADIC_VOIDP_CAST
+endif
+
 
 PROGRAMS = as-dcpu16 vm-dcpu16
 SOURCES = common.c dcpu16.c as-dcpu16.c vm-dcpu16.c \
index d5c90b3faf4b2af6f5a1519894c02107d8b7ea8d..90c30b3809590f9882a91da23f67a0af17d476c8 100644 (file)
 
 #define BUF_SZ 32
 
+#ifdef WANT_VARIADIC_VOIDP_CAST
+#define VOIDP(__x__) ((void *)(__x__))
+#else
+#define VOIDP(__x__) (__x__)
+#endif
+
 static dcpu16_hw_signal_t keyboard_reset_;
 static dcpu16_hw_signal_t keyboard_cycle_;
 static dcpu16_hw_signal_t keyboard_hwi_;
@@ -83,10 +89,17 @@ void keyboard_rfbevent_(rfbBool down, rfbKeySym key, rfbClientPtr cl) {
 
     keysym_rfbtodcpu(key, &dcpu_key);
 
-    fprintf(stderr, "%s: down:%u key:0x%04x dcpu_key:0x%04x\n", __func__,
-            down, key, dcpu_key);
+    fprintf(stderr, "%s: down:%u key:0x%04x dcpu_key:0x%04x\n",
+            __func__,
+            down,
+            key,
+            dcpu_key);
 
-    fprintf(stderr, "%s: hw:%p name:%s vm:%p\n", __func__, hw, hw->name_, hw->vm);
+    fprintf(stderr, "%s: hw:%p name:%s vm:%p\n",
+            __func__,
+            VOIDP(hw),
+            hw->name_,
+            VOIDP(hw->vm));
 
     keyboard->keys_pressed[dcpu_key] = (down ? 1 : 0);
     if (down) {
@@ -192,13 +205,16 @@ struct dcpu16_hw *keyboard_new(struct dcpu16 *vm) {
 
 void keyboard_del(struct dcpu16_hw **hw) {
     if (hw) {
-        free(((struct keyboard_ *)((*hw)->data))->buf);
-        ((struct keyboard_ *)((*hw)->data))->buf = NULL;
-
-        free((*hw)->data);
-        (*hw)->data = NULL;
-
-        free(*hw);
-        *hw = NULL;
+        if (*hw) {
+            if ((*hw)->data) {
+                free(((struct keyboard_ *)((*hw)->data))->buf);
+                ((struct keyboard_ *)((*hw)->data))->buf = NULL;
+
+                free((*hw)->data);
+                (*hw)->data = NULL;
+            }
+            free(*hw);
+            *hw = NULL;
+        }
     }
 }
index e7e618393fc4e313607a24b7f9022a012656b1ae..31a69b8be3e8f6ffc5fccf0c5b8ce3ba6f1d9bc6 100644 (file)
 #define TRACE(...) do {} while (0)
 #endif /* DEBUG */
 
+#ifdef WANT_VARIADIC_VOIDP_CAST
+#define VOIDP(__x__) ((void *)(__x__))
+#define VOIDFP(__x__) ((void *)(size_t)(__x__))
+#else
+#define VOIDP(__x__) (__x__)
+#define VOIDFP(__x__) (__x__)
+#endif
+
 static dcpu16_hw_signal_t lem1802_reset_;
 static dcpu16_hw_signal_t lem1802_cycle_;
 static dcpu16_hw_signal_t lem1802_hwi_;
@@ -252,8 +260,8 @@ void lem1802_pixbuf_refresh_full_(struct lem1802_ *display, DCPU16_WORD *mem) {
                            mem,
                            display->video_base,
                            display->video_base + tile,
-                           display->palette_base ? mem + display->palette_base : palette_default_,
-                           display->font_base ? mem + display->font_base : (unsigned short *)chargen_4x8_glyphs,
+                           display->palette_base ? mem + display->palette_base : (DCPU16_WORD *)palette_default_,
+                           display->font_base ? mem + display->font_base : (DCPU16_WORD *)chargen_4x8_glyphs,
                            display->blink_state);
     }
 }
@@ -339,8 +347,8 @@ rfbScreenInfoPtr lem1802_rfb_new(int argc, char *argv[]) {
     s->httpDir = "../classes";
 #endif
 
-    TRACE("%s>> s:%p", __func__, s);
-    TRACE("%s>> s->kbdAddEvent:%p s->frameBuffer:%p", __func__, s->kbdAddEvent, s->frameBuffer);
+    TRACE("%s>> s:%p", __func__, VOIDP(s));
+    TRACE("%s>> s->kbdAddEvent:%p s->frameBuffer:%p", __func__, VOIDFP(s->kbdAddEvent), s->frameBuffer);
 
     return s;
 }
@@ -352,7 +360,7 @@ void lem1802_vnc_associate(struct dcpu16_hw *hw, rfbScreenInfoPtr s) {
     s->desktopName = "NYA ELEKTRISKA LEM1802";
     s->frameBuffer = (char *)display->pixbuf;
 
-    TRACE("%s>> s:%p\n", __func__, s);
+    TRACE("%s>> s:%p\n", __func__, VOIDP(s));
 }
 
 /* notify rfb server that pixels may have changed */
@@ -435,7 +443,7 @@ void lem1802_cycle_(struct dcpu16 *vm, void *data) {
             TRACE("%s>> copy_to_ram words:%zu src:%p dst_addr:0x%04x",
                   __func__,
                   display->cycle_state_copy_words_,
-                  display->cycle_state_copy_src_ptr_,
+                  VOIDP(display->cycle_state_copy_src_ptr_),
                   display->cycle_state_copy_dst_addr_);
             vm->ram[display->cycle_state_copy_dst_addr_] = *display->cycle_state_copy_src_ptr_;
             display->cycle_state_copy_dst_addr_++;
@@ -566,7 +574,7 @@ struct dcpu16_hw *lem1802_new(struct dcpu16 *vm) {
 
     memcpy(hw, &hw_, sizeof *hw);
 
-    hw->data = calloc(1, sizeof(struct dcpu16_hw));
+    hw->data = calloc(1, sizeof(struct lem1802_));
     if (hw->data == NULL) {
         vm->warn_cb_("%s():%s", "calloc", strerror(errno));
         free(hw);
@@ -601,7 +609,7 @@ void lem1802_del(struct dcpu16_hw **hw) {
                 (*hw)->data = NULL;
             }
             free(*hw);
+            *hw = NULL;
         }
-        *hw = NULL;
     }
 }
index 2fa0c7b3ff8702734681adec556ad7316aed099b..49ba35042c5ace4360c7eca649617c52b5cecb20 100644 (file)
@@ -78,3 +78,39 @@ void spc2000_hwi_(struct dcpu16 *vm, void *data) {
             break;
     }
 }
+
+struct dcpu16_hw *spc2000_new(struct dcpu16 *vm) {
+    struct dcpu16_hw *hw;
+
+    hw = calloc(1, sizeof *hw);
+    if (hw == NULL) {
+        vm->warn_cb_("%s():%s", "calloc", strerror(errno));
+        return NULL;
+    }
+
+    memcpy(hw, &hw_, sizeof *hw);
+
+    hw->data = calloc(1, sizeof(struct spc2000_));
+    if (hw->data == NULL) {
+        vm->warn_cb_("%s():%s", "calloc", strerror(errno));
+        free(hw);
+        return NULL;
+    }
+
+    hw->vm = vm;
+
+    return hw;
+}
+
+void spc2000_del(struct dcpu16_hw **hw) {
+    if (hw) {
+        if (*hw) {
+            if ((*hw)->data) {
+                free((*hw)->data);
+                (*hw)->data = NULL;
+            }
+            free(*hw);
+            *hw = NULL;
+        }
+    }
+}