qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs buffer.c dired.c display.c display.h ext...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs buffer.c dired.c display.c display.h ext...
Date: Thu, 23 Jan 2014 12:56:24 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/01/23 12:56:24

Modified files:
        .              : buffer.c dired.c display.c display.h extras.c 
                         fbfrender.c fbfrender.h haiku.cpp html.c 
                         html2png.c kmap.c Makefile orgmode.c qe.c qe.h 
                         shell.c tty.c unix.c util.c variables.c video.c 
                         win32.c x11.c 
        libqhtml       : css.c css.h cssparse.c Makefile xmlparse.c 

Log message:
        improve consistency in new/delete methodology
        
        * use qe_mallocz for all structures
        * prevent spurious uses of malloc/free/realloc
        * pass pointers to pointers to all deletion functions
        * use consistent patterns for list deletions
        * add more dependencies in Makefiles

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.64&r2=1.65
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/qemacs/display.c?cvsroot=qemacs&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/qemacs/display.h?cvsroot=qemacs&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/qemacs/extras.c?cvsroot=qemacs&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/qemacs/fbfrender.c?cvsroot=qemacs&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/qemacs/fbfrender.h?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/haiku.cpp?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/html.c?cvsroot=qemacs&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/qemacs/html2png.c?cvsroot=qemacs&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/qemacs/kmap.c?cvsroot=qemacs&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/qemacs/Makefile?cvsroot=qemacs&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/qemacs/orgmode.c?cvsroot=qemacs&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.132&r2=1.133
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.128&r2=1.129
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.80&r2=1.81
http://cvs.savannah.gnu.org/viewcvs/qemacs/tty.c?cvsroot=qemacs&r1=1.55&r2=1.56
http://cvs.savannah.gnu.org/viewcvs/qemacs/unix.c?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.59&r2=1.60
http://cvs.savannah.gnu.org/viewcvs/qemacs/variables.c?cvsroot=qemacs&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/qemacs/video.c?cvsroot=qemacs&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/qemacs/win32.c?cvsroot=qemacs&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/qemacs/x11.c?cvsroot=qemacs&r1=1.30&r2=1.31
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/css.c?cvsroot=qemacs&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/css.h?cvsroot=qemacs&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/cssparse.c?cvsroot=qemacs&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/Makefile?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/xmlparse.c?cvsroot=qemacs&r1=1.24&r2=1.25

Patches:
Index: buffer.c
===================================================================
RCS file: /sources/qemacs/qemacs/buffer.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -b -r1.64 -r1.65
--- buffer.c    21 Jan 2014 00:01:20 -0000      1.64
+++ buffer.c    23 Jan 2014 12:56:22 -0000      1.65
@@ -1,7 +1,7 @@
 /*
  * Buffer handling for QEmacs
  *
- * Copyright (c) 2000 Fabrice Bellard.
+ * Copyright (c) 2000-2002 Fabrice Bellard.
  * Copyright (c) 2002-2014 Charlie Gordon.
  *
  * This library is free software; you can redistribute it and/or
@@ -435,14 +435,11 @@
 /* flush the log */
 void log_reset(EditBuffer *b)
 {
-    if (b->log_buffer) {
-        eb_free(b->log_buffer);
-        b->log_buffer = NULL;
+    eb_free(&b->log_buffer);
         b->log_new_index = 0;
         b->log_current = 0;
         b->nb_logs = 0;
-    }
-    b->modified = 0;
+    b->modified = 0;    /* ??? */
 }
 
 /* rename a buffer and add characters so that the name is unique */
@@ -548,26 +545,23 @@
     //memset(b, 0, offsetof(EditBuffer, remanent_area));
 }
 
-void eb_free(EditBuffer *b)
+void eb_free(EditBuffer **bp)
 {
+    if (*bp) {
+        EditBuffer *b = *bp;
     QEmacsState *qs = &qe_state;
     EditBuffer **pb;
-    EditBufferCallbackList *l, *l1;
-
-    if (b == NULL)
-        return;
 
     /* call user defined close */
     if (b->close)
         b->close(b);
 
     /* free each callback */
-    for (l = b->first_callback; l != NULL;) {
-        l1 = l->next;
-        qe_free(&l);
-        l = l1;
+        while (b->first_callback) {
+            EditBufferCallbackList *cb = b->first_callback;
+            b->first_callback = cb->next;
+            qe_free(&cb);
     }
-    b->first_callback = NULL;
 
     eb_clear(b);
 
@@ -585,7 +579,8 @@
 
     eb_free_style_buffer(b);
 
-    qe_free(&b);
+        qe_free(bp);
+    }
 }
 
 EditBuffer *eb_find(const char *name)
@@ -702,11 +697,12 @@
 /************************************************************/
 /* callbacks */
 
-int eb_add_callback(EditBuffer *b, EditBufferCallback cb, void *opaque, int 
arg)
+int eb_add_callback(EditBuffer *b, EditBufferCallback cb,
+                    void *opaque, int arg)
 {
     EditBufferCallbackList *l;
 
-    l = qe_malloc(EditBufferCallbackList);
+    l = qe_mallocz(EditBufferCallbackList);
     if (!l)
         return -1;
     l->callback = cb;
@@ -775,10 +771,7 @@
 
 void eb_free_style_buffer(EditBuffer *b)
 {
-    if (b->b_styles) {
-        eb_free(b->b_styles);
-        b->b_styles = NULL;
-    }
+    eb_free(&b->b_styles);
     b->style_shift = b->style_bytes = 0;
     eb_free_callback(b, eb_style_callback, NULL);
 }
@@ -1488,7 +1481,7 @@
     /* cannot load a buffer if already I/Os or readonly */
     if (b->flags & (BF_LOADING | BF_SAVING | BF_READONLY))
         return -1;
-    s = qe_malloc(BufferIOState);
+    s = qe_mallocz(BufferIOState);
     if (!s)
         return -1;
     b->io_state = s;
@@ -1804,7 +1797,7 @@
         va_start(ap, fmt);
         size = len + 1;
 #ifdef CONFIG_WIN32
-        buf = malloc(size);
+        buf = qe_malloc_bytes(size);
 #else
         buf = alloca(size);
 #endif
@@ -1818,7 +1811,7 @@
     eb_insert_utf8_buf(b, b->total_size, buf, len);
 #ifdef CONFIG_WIN32
     if (buf != buf0)
-        free(buf);
+        qe_free(&buf);
 #endif
     return len;
 }
@@ -1906,7 +1899,7 @@
 
         if (b != dest) {
             size = eb_insert_buffer(dest, dest_offset, b, 0, b->total_size);
-            eb_free(b);
+            eb_free(&b);
         }
         return size;
     }

Index: dired.c
===================================================================
RCS file: /sources/qemacs/qemacs/dired.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- dired.c     13 Jan 2014 11:00:43 -0000      1.34
+++ dired.c     23 Jan 2014 12:56:22 -0000      1.35
@@ -366,7 +366,7 @@
             item->opaque = dip;
         }
     }
-    find_file_close(ffst);
+    find_file_close(&ffst);
     
     dired_sort_list(s);
 

Index: display.c
===================================================================
RCS file: /sources/qemacs/qemacs/display.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- display.c   8 Apr 2008 06:55:44 -0000       1.14
+++ display.c   23 Jan 2014 12:56:22 -0000      1.15
@@ -58,7 +58,7 @@
 }
 
 static void dummy_dpy_close_font(__unused__ QEditScreen *s,
-                                 __unused__ QEFont *font)
+                                 __unused__ QEFont **fontp)
 {
 }
 
@@ -277,8 +277,7 @@
         goto fail;
     }
     if (font_cache[min_index]) {
-        close_font(s, font_cache[min_index]);
-        font_cache[min_index] = NULL;
+        close_font(s, &font_cache[min_index]);
     }
     fc = open_font(s, style, size);
     if (!fc) {
@@ -313,7 +312,7 @@
 
     if (!s->dpy.dpy_bmp_alloc)
         return NULL;
-    b = qe_malloc(QEBitmap);
+    b = qe_mallocz(QEBitmap);
     if (!b)
         return NULL;
     b->width = width;

Index: display.h
===================================================================
RCS file: /sources/qemacs/qemacs/display.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- display.h   15 Jan 2014 19:44:25 -0000      1.13
+++ display.h   23 Jan 2014 12:56:22 -0000      1.14
@@ -105,7 +105,7 @@
     void (*dpy_fill_rectangle)(QEditScreen *s,
                                int x, int y, int w, int h, QEColor color);
     QEFont *(*dpy_open_font)(QEditScreen *s, int style, int size);
-    void (*dpy_close_font)(QEditScreen *s, QEFont *font);
+    void (*dpy_close_font)(QEditScreen *s, QEFont **fontp);
     void (*dpy_text_metrics)(QEditScreen *s, QEFont *font,
                              QECharMetrics *metrics,
                              const unsigned int *str, int len);
@@ -171,10 +171,10 @@
     return s->dpy.dpy_open_font(s, style, size);
 }
 
-static inline void close_font(QEditScreen *s, QEFont *font)
+static inline void close_font(QEditScreen *s, QEFont **fontp)
 {
-    if (!font->system_font)
-        s->dpy.dpy_close_font(s, font);
+    if (*fontp && !(*fontp)->system_font)
+        s->dpy.dpy_close_font(s, fontp);
 }
 
 static inline void text_metrics(QEditScreen *s, QEFont *font,

Index: extras.c
===================================================================
RCS file: /sources/qemacs/qemacs/extras.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- extras.c    19 Jan 2014 17:25:02 -0000      1.16
+++ extras.c    23 Jan 2014 12:56:22 -0000      1.17
@@ -412,7 +412,7 @@
         /* XXX: This will create 2 undo records */
         eb_delete(b, offset0, size0 + size1 + size2);
         eb_insert_buffer_convert(b, offset0, b1, 0, size0 + size1 + size2);
-        eb_free(b1);
+        eb_free(&b1);
     }
     s->offset = end_offset;
 }
@@ -592,7 +592,7 @@
         }
     } else {
         if (show)
-            eb_free(b);
+            eb_free(&b);
         put_status(s, "No apropos matches for `%s'", str);
     }
 }

Index: fbfrender.c
===================================================================
RCS file: /sources/qemacs/qemacs/fbfrender.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- fbfrender.c 17 Dec 2013 23:42:52 -0000      1.12
+++ fbfrender.c 23 Jan 2014 12:56:22 -0000      1.13
@@ -237,7 +237,7 @@
     UniFontData *fonts[MAX_MATCHES];
     int nb_fonts, i;
 
-    font = qe_malloc(QEFont);
+    font = qe_mallocz(QEFont);
     if (!font)
         return NULL;
 
@@ -276,9 +276,9 @@
     return font;
 }
 
-void fbf_close_font(__unused__ QEditScreen *s, QEFont *font)
+void fbf_close_font(__unused__ QEditScreen *s, QEFont **fontp)
 {
-    qe_free(&font);
+    qe_free(fontp);
 }
 
 static void *my_malloc(__unused__ void *opaque, int size)
@@ -485,17 +485,15 @@
 
 void fbf_render_cleanup(void)
 {
-    UniFontData *uf, *uf1;
-
-    for (uf = first_font; uf != NULL; uf = uf1) {
-        uf1 = uf->next_font;
+    while (first_font) {
+        UniFontData *uf = first_font;
+        first_font = uf->next_font;
         /* close font data structures */
         fbf_free_font(uf);
         /* close font file */
         qe_free(&uf->infile);
         qe_free(&uf);
     }
-    first_font = NULL;
 }
 
 #endif

Index: fbfrender.h
===================================================================
RCS file: /sources/qemacs/qemacs/fbfrender.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- fbfrender.h 17 Dec 2013 23:42:52 -0000      1.6
+++ fbfrender.h 23 Jan 2014 12:56:22 -0000      1.7
@@ -43,7 +43,7 @@
                       const unsigned int *str, int len);
 GlyphCache *decode_cached_glyph(QEditScreen *s, QEFont *font, int code);
 QEFont *fbf_open_font(QEditScreen *s, int style, int size);
-void fbf_close_font(QEditScreen *s, QEFont *font);
+void fbf_close_font(QEditScreen *s, QEFont **fontp);
 
 int fbf_render_init(const char *font_path);
 void fbf_render_cleanup(void);

Index: haiku.cpp
===================================================================
RCS file: /sources/qemacs/qemacs/haiku.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- haiku.cpp   9 Jan 2014 12:25:12 -0000       1.5
+++ haiku.cpp   23 Jan 2014 12:56:22 -0000      1.6
@@ -260,7 +260,7 @@
 
     init_application();
 
-    ctx = (WindowState *)malloc(sizeof(WindowState));
+    ctx = qe_mallocz(WindowState);
     if (ctx == NULL)
         return -1;
     s->priv_data = ctx;
@@ -329,7 +329,7 @@
     WindowState *ctx = (WindowState *)s->priv_data;
     ctx->w->Lock();
     ctx->w->Quit();
-    free(s->priv_data);
+    qe_free(&s->priv_data);
     uninit_application();
 }
 
@@ -664,7 +664,7 @@
     //fprintf(stderr, "%s()\n", __FUNCTION__);
     QEFont *font;
 
-    font = (QEFont *)malloc(sizeof(QEFont));
+    font = qe_mallocz(QEFont);
     if (!font)
         return NULL;
 
@@ -679,11 +679,13 @@
     return font;
 }
 
-static void haiku_close_font(QEditScreen *s, QEFont *font)
+static void haiku_close_font(QEditScreen *s, QEFont **fontp)
 {
-    BFont *f = (BFont *)font->priv_data;
+    if (*fontp) {
+        BFont *f = (BFont *)(*fontp)->priv_data;
     delete f;
-    free(font);
+        qe_free(fontp);
+    }
 }
 
 static void haiku_text_metrics(QEditScreen *s, QEFont *font, 

Index: html.c
===================================================================
RCS file: /sources/qemacs/qemacs/html.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- html.c      21 Jan 2014 00:01:21 -0000      1.27
+++ html.c      23 Jan 2014 12:56:22 -0000      1.28
@@ -165,13 +165,8 @@
         }
 
         /* delete previous document */
-        css_delete_box(hs->top_box);
-        hs->top_box = NULL;
-
-        if (hs->css_ctx) {
-            css_delete_document(hs->css_ctx);
-            hs->css_ctx = NULL;
-        }
+        css_delete_box(&hs->top_box);
+        css_delete_document(&hs->css_ctx);
 
         /* find error message buffer */
         b = eb_find(HTML_ERROR_BUFFER);
@@ -820,11 +815,9 @@
     eb_free_callback(s->b, html_callback, s);
 
     s->busy = 0;
-    if (hs->top_box)
-        css_delete_box(hs->top_box);
-    if (hs->css_ctx)
-        css_delete_document(hs->css_ctx);
-    css_free_style_sheet(hs->default_style_sheet);
+    css_delete_box(&hs->top_box);
+    css_delete_document(&hs->css_ctx);
+    css_free_style_sheet(&hs->default_style_sheet);
 }
 
 /* search for HTML tag */

Index: html2png.c
===================================================================
RCS file: /sources/qemacs/qemacs/html2png.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- html2png.c  17 Dec 2013 16:06:36 -0000      1.13
+++ html2png.c  23 Jan 2014 12:56:22 -0000      1.14
@@ -156,7 +156,7 @@
 {
     CFBContext *cfb;
 
-    cfb = qe_malloc(CFBContext);
+    cfb = qe_mallocz(CFBContext);
     if (!cfb)
         return -1;
 
@@ -372,7 +372,7 @@
 
     css_close(f);
 
-    top_box = xml_end(xml);
+    top_box = xml_end(&xml);
 
     /* CSS computation */
     css_compute(s, top_box);
@@ -394,16 +394,14 @@
 
     css_display(s, top_box, &rect, 0, 0);
 
-    css_delete_box(top_box);
-    css_delete_document(s);
+    css_delete_box(&top_box);
+    css_delete_document(&s);
     return 0;
  fail:
     if (f)
         css_close(f);
-    if (top_box)
-        css_delete_box(top_box);
-    if (s)
-        css_delete_document(s);
+    css_delete_box(&top_box);
+    css_delete_document(&s);
     return -1;
 }
 

Index: kmap.c
===================================================================
RCS file: /sources/qemacs/qemacs/kmap.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- kmap.c      5 Apr 2008 23:04:57 -0000       1.2
+++ kmap.c      23 Jan 2014 12:56:22 -0000      1.3
@@ -213,7 +213,7 @@
         if (offset == 0)
             break;
         /* Should add validation tests */
-        m = qe_malloc(InputMethod);
+        m = qe_mallocz(InputMethod);
         if (m) {
             m->data = file_ptr + offset;
             m->input_match = kmap_input;

Index: Makefile
===================================================================
RCS file: /sources/qemacs/qemacs/Makefile,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- Makefile    7 Jan 2014 18:26:07 -0000       1.58
+++ Makefile    23 Jan 2014 12:56:23 -0000      1.59
@@ -1,7 +1,7 @@
 # QEmacs, tiny but powerful multimode editor
 #
 # Copyright (c) 2000-2002 Fabrice Bellard.
-# Copyright (c) 2000-2013 Charlie Gordon.
+# Copyright (c) 2000-2014 Charlie Gordon.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,9 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-include config.mak
+DEPTH=.
+
+include $(DEPTH)/config.mak
 
 ifeq ($(CC),gcc)
   CFLAGS   += -Wall -g -O2 -funsigned-char
@@ -27,7 +29,7 @@
 endif
 
 #include local compiler configuration file
--include cflags.mk
+-include $(DEPTH)/cflags.mk
 
 ifdef TARGET_GPROF
   CFLAGS   += -p
@@ -125,19 +127,19 @@
 ifdef CONFIG_X11
   OBJS+= x11.o
   ifdef CONFIG_XRENDER
-    LIBS+=-lXrender
+    LIBS+= -lXrender
   endif
   ifdef CONFIG_XV
-    LIBS+=-lXv
+    LIBS+= -lXv
   endif
   LIBS+= -L/usr/X11R6/lib -lXext -lX11
 endif
 
 ifdef CONFIG_HTML
-  CFLAGS+=-I./libqhtml
-  DEP_LIBS+=libqhtml/libqhtml.a
-  LIBS+=-L./libqhtml -lqhtml
-  OBJS+=html.o docbook.o
+  CFLAGS+= -I./libqhtml
+  DEP_LIBS+= libqhtml/libqhtml.a
+  LIBS+= -L./libqhtml -lqhtml
+  OBJS+= html.o docbook.o
   ifndef CONFIG_WIN32
     TARGETLIBS+= libqhtml
     TARGETS+= html2png$(EXE)
@@ -162,9 +164,12 @@
 TSRCS:= $(TOBJS:.o=.c)
 TSRCS:= $(TSRCS:tqe.c=qe.c)
 
-OBJS_DIR:=.objs
-OBJS:=$(addprefix $(OBJS_DIR)/, $(OBJS))
-TOBJS:=$(addprefix $(OBJS_DIR)/, $(TOBJS))
+DEPENDS:= qe.h config.h cutils.h display.h qestyles.h config.mak
+DEPENDS:= $(addprefix $(DEPTH)/, $(DEPENDS))
+
+OBJS_DIR:= $(DEPTH)/.objs
+OBJS:= $(addprefix $(OBJS_DIR)/, $(OBJS))
+TOBJS:= $(addprefix $(OBJS_DIR)/, $(TOBJS))
 
 $(shell mkdir -p $(OBJS_DIR))
 
@@ -201,7 +206,7 @@
        echo `size address@hidden `wc -c address@hidden tqe $(OPTIONS) \
                | cut -d ' ' -f 7-10,13,15-40 >> STATS
 
-$(OBJS_DIR)/tqe.o: qe.c qe.h qestyles.h qeconfig.h config.h config.mak Makefile
+$(OBJS_DIR)/tqe.o: qe.c qeconfig.h $(DEPENDS) Makefile
        $(CC) $(DEFINES) -DCONFIG_TINY $(CFLAGS) -o $@ -c $<
 
 ffplay$(EXE): qe$(EXE) Makefile
@@ -228,13 +233,13 @@
 $(OBJS_DIR)/qe.o: qe.c qe.h qfribidi.h qeconfig.h
 $(OBJS_DIR)/qfribidi.o: qfribidi.c qfribidi.h
 
-$(OBJS_DIR)/%.o: %.c qe.h qestyles.h config.h config.mak Makefile
+$(OBJS_DIR)/%.o: %.c $(DEPENDS) Makefile
        $(CC) $(DEFINES) $(CFLAGS) -o $@ -c $<
 
-$(OBJS_DIR)/haiku.o: haiku.cpp qe.h qestyles.h config.h config.mak Makefile
+$(OBJS_DIR)/haiku.o: haiku.cpp $(DEPENDS) Makefile
        g++ $(DEFINES) $(CFLAGS) -Wno-multichar -o $@ -c $<
 
-%.s: %.c qe.h qestyles.h config.h config.mak Makefile
+%.s: %.c $(DEPENDS) Makefile
        $(CC) $(DEFINES) $(CFLAGS) -o $@ -S $<
 
 #

Index: orgmode.c
===================================================================
RCS file: /sources/qemacs/qemacs/orgmode.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- orgmode.c   20 Jan 2014 18:04:01 -0000      1.9
+++ orgmode.c   23 Jan 2014 12:56:23 -0000      1.10
@@ -631,7 +631,7 @@
     if (offset2 > offset)
         offset2 -= size;
     eb_insert_buffer_convert(s->b, offset2, b1, 0, b1->total_size);
-    eb_free(b1);
+    eb_free(&b1);
     s->offset = offset2;
 }
 

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -b -r1.132 -r1.133
--- qe.c        21 Jan 2014 00:01:21 -0000      1.132
+++ qe.c        23 Jan 2014 12:56:23 -0000      1.133
@@ -1445,12 +1445,9 @@
     if (qs->yank_buffers[qs->yank_current]) {
         if (++qs->yank_current == NB_YANK_BUFFERS)
             qs->yank_current = 0;
-        b = qs->yank_buffers[qs->yank_current];
-        if (b) {
             /* problem if buffer is displayed in window, should instead
              * just clear the buffer */
-            eb_free(b);
-        }
+        eb_free(&qs->yank_buffers[qs->yank_current]);
     }
     snprintf(bufname, sizeof(bufname), "*kill-%d*", qs->yank_current + 1);
     b = eb_new(bufname, base->flags & BF_STYLES);
@@ -1854,8 +1851,7 @@
 
     /* replace current buffer with conversion */
     /* quick hack to transfer styles from tmp buffer to b */
-    eb_free(b->b_styles);
-    b->b_styles = NULL;
+    eb_free(&b->b_styles);
     eb_delete(b, 0, b->total_size);
     eb_set_charset(b, charset);
     eb_insert_buffer(b, 0, b1, 0, b1->total_size);
@@ -1871,7 +1867,7 @@
         }
     }
 
-    eb_free(b1);
+    eb_free(&b1);
 
     put_status(s, "Buffer charset is now %s, %d bytes",
                s->b->charset->name, b->total_size);
@@ -3756,7 +3752,7 @@
 
 static void arg_edit_cb(void *opaque, char *str);
 static void parse_args(ExecCmdState *es);
-static void free_cmd(ExecCmdState *es);
+static void free_cmd(ExecCmdState **esp);
 
 void exec_command(EditState *s, CmdDef *d, int argval, int key)
 {
@@ -3772,7 +3768,7 @@
         }
     }
 
-    es = qe_malloc(ExecCmdState);
+    es = qe_mallocz(ExecCmdState);
     if (!es)
         return;
 
@@ -3917,11 +3913,13 @@
 
     qs->last_cmd_func = qs->this_cmd_func;
  fail:
-    free_cmd(es);
+    free_cmd(&es);
 }
 
-static void free_cmd(ExecCmdState *es)
+static void free_cmd(ExecCmdState **esp)
 {
+    if (*esp) {
+        ExecCmdState *es = *esp;
     int i;
 
     /* free allocated parameters */
@@ -3932,7 +3930,8 @@
             break;
         }
     }
-    qe_free(&es);
+        qe_free(esp);
+    }
 }
 
 /* when the argument has been typed by the user, this callback is
@@ -3947,7 +3946,7 @@
         /* command aborted */
     fail:
         qe_free(&str);
-        free_cmd(es);
+        free_cmd(&es);
         return;
     }
     index = es->nb_args - 1;
@@ -4574,8 +4573,7 @@
              *   CG: Should free previous such data ?
              */
             if (b1->flags & BF_TRANSIENT) {
-                eb_free(b1);
-                b1 = NULL;
+                eb_free(&b1);
             } else {
                 b1->saved_data = s->mode->mode_save_data(s);
             }
@@ -4786,7 +4784,7 @@
         add_string(&cp->cs, filename);
     }
 
-    find_file_close(ffst);
+    find_file_close(&ffst);
 }
 
 void buffer_completion(CompleteState *cp)
@@ -4806,7 +4804,7 @@
     QEmacsState *qs = &qe_state;
     CompletionEntry **lp, *p;
 
-    p = qe_malloc(CompletionEntry);
+    p = qe_mallocz(CompletionEntry);
     if (!p)
         return;
 
@@ -5459,7 +5457,7 @@
     }
 
     /* now we can safely delete buffer */
-    eb_free(b);
+    eb_free(&b);
 
     do_refresh(qs->first_window);
 }
@@ -5806,7 +5804,7 @@
         return;
     }
 
-    is = qe_malloc(QuitState);
+    is = qe_mallocz(QuitState);
     if (!is)
         return;
 
@@ -6222,7 +6220,7 @@
 {
     ISearchState *is;
 
-    is = qe_malloc(ISearchState);
+    is = qe_mallocz(ISearchState);
     if (!is)
         return;
     is->s = s;
@@ -7156,7 +7154,7 @@
 {
     ModeSavedData *saved_data;
 
-    saved_data = qe_malloc(ModeSavedData);
+    saved_data = qe_mallocz(ModeSavedData);
     if (!saved_data)
         return NULL;
     saved_data->mode = s->mode;
@@ -7204,7 +7202,7 @@
         return -1;
     ret = find_file_next(ffst, path, path_size);
 
-    find_file_close(ffst);
+    find_file_close(&ffst);
 
     return ret;
 }
@@ -7508,7 +7506,7 @@
     while (find_file_next(ffst, filename, sizeof(filename)) == 0) {
         parse_config_file(e, filename);
     }
-    find_file_close(ffst);
+    find_file_close(&ffst);
     if (file)
         do_refresh(e);
 }
@@ -7846,7 +7844,7 @@
         /* all is OK: we can init the module now */
         (*init_func)();
     }
-    find_file_close(ffst);
+    find_file_close(&ffst);
 
   done:
     qs->ec = ec;

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -b -r1.128 -r1.129
--- qe.h        21 Jan 2014 00:01:21 -0000      1.128
+++ qe.h        23 Jan 2014 12:56:23 -0000      1.129
@@ -106,10 +106,20 @@
 #define qe_malloc_hack(t, n)    ((t *)qe_malloc_bytes(sizeof(t) + (n)))
 #define qe_mallocz_hack(t, n)   ((t *)qe_mallocz_bytes(sizeof(t) + (n)))
 #ifdef CONFIG_HAS_TYPEOF
-#define qe_free(pp)      do { typeof(**(pp)) **__ = (pp); free(*__); *__ = 
NULL; } while (0)
+#define qe_free(pp)    do { typeof(**(pp)) **__ = (pp); (free)(*__); *__ = 
NULL; } while (0)
 #else
 #define qe_free(pp)      \
-    do if (sizeof(**(pp)) >= 0) { void *_ = (pp); free(*(void **)_); *(void 
**)_ = NULL; } while (0)
+    do if (sizeof(**(pp)) >= 0) { void *_ = (pp); (free)(*(void **)_); *(void 
**)_ = NULL; } while (0)
+#endif
+
+#ifndef free
+#define free(p)       do_not_use_free!!(p)
+#endif
+#ifndef malloc
+#define malloc(s)     do_not_use_malloc!!(s)
+#endif
+#ifndef realloc
+#define realloc(p,s)  do_not_use_realloc!!(p,s)
 #endif
 
 /************************/
@@ -129,12 +139,9 @@
 #define INT_MIN  (-0x7fffffff-1)
 #endif
 #define NO_ARG  INT_MIN
-/* Size for a filename buffer */
-#define MAX_FILENAME_SIZE    1024
-/* Size for a buffer name buffer */
-#define MAX_BUFFERNAME_SIZE  256
-/* Size for a command name buffer */
-#define MAX_CMDNAME_SIZE     32
+#define MAX_FILENAME_SIZE    1024       /* Size for a filename buffer */
+#define MAX_BUFFERNAME_SIZE  256        /* Size for a buffer name buffer */
+#define MAX_CMDNAME_SIZE     32         /* Size for a command name buffer */
 
 extern const char str_version[];
 extern const char str_credits[];
@@ -152,7 +159,7 @@
 
 typedef struct QETimer QETimer;
 QETimer *qe_add_timer(int delay, void *opaque, void (*cb)(void *opaque));
-void qe_kill_timer(QETimer *ti);
+void qe_kill_timer(QETimer **tip);
 
 /* main loop for Unix programs using liburlio */
 void url_main_loop(void (*init)(void *opaque), void *opaque);
@@ -203,7 +210,7 @@
 
 FindFileState *find_file_open(const char *path, const char *pattern);
 int find_file_next(FindFileState *s, char *filename, int filename_size_max);
-void find_file_close(FindFileState *s);
+void find_file_close(FindFileState **sp);
 int is_directory(const char *path);
 void canonicalize_path(char *buf, int buf_size, const char *path);
 void canonicalize_absolute_path(char *buf, int buf_size, const char *path1);
@@ -847,7 +854,7 @@
 EditBuffer *eb_new(const char *name, int flags);
 EditBuffer *eb_scratch(const char *name, int flags);
 void eb_clear(EditBuffer *b);
-void eb_free(EditBuffer *b);
+void eb_free(EditBuffer **ep);
 EditBuffer *eb_find(const char *name);
 EditBuffer *eb_find_new(const char *name, int flags);
 EditBuffer *eb_find_file(const char *filename);

Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -b -r1.80 -r1.81
--- shell.c     21 Jan 2014 00:01:21 -0000      1.80
+++ shell.c     23 Jan 2014 12:56:23 -0000      1.81
@@ -1333,7 +1333,7 @@
     if (s->pty_fd >= 0) {
         set_read_handler(s->pty_fd, NULL, NULL);
     }
-    qe_free(&s);
+    qe_free(&b->priv_data);
 }
 
 EditBuffer *new_shell_buffer(EditBuffer *b0, const char *bufname,
@@ -1369,7 +1369,7 @@
     s = qe_mallocz(ShellState);
     if (!s) {
         if (!b0)
-            eb_free(b);
+            eb_free(&b);
         return NULL;
     }
     b->priv_data = s;
@@ -1392,7 +1392,7 @@
 
     if (run_process(cmd, &s->pty_fd, &s->pid, cols, rows, shell_flags) < 0) {
         if (!b0)
-            eb_free(b);
+            eb_free(&b);
         return NULL;
     }
 

Index: tty.c
===================================================================
RCS file: /sources/qemacs/qemacs/tty.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -b -r1.55 -r1.56
--- tty.c       15 Jan 2014 19:44:26 -0000      1.55
+++ tty.c       23 Jan 2014 12:56:23 -0000      1.56
@@ -936,7 +936,7 @@
 {
     QEFont *font;
 
-    font = qe_malloc(QEFont);
+    font = qe_mallocz(QEFont);
     if (!font)
         return NULL;
 
@@ -946,9 +946,9 @@
     return font;
 }
 
-static void tty_term_close_font(__unused__ QEditScreen *s, QEFont *font)
+static void tty_term_close_font(__unused__ QEditScreen *s, QEFont **fontp)
 {
-    qe_free(&font);
+    qe_free(fontp);
 }
 
 static inline int tty_term_glyph_width(__unused__ QEditScreen *s, unsigned int 
ucs)

Index: unix.c
===================================================================
RCS file: /sources/qemacs/qemacs/unix.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- unix.c      5 Apr 2008 23:04:57 -0000       1.7
+++ unix.c      23 Jan 2014 12:56:23 -0000      1.8
@@ -110,7 +110,7 @@
             }
         }
     } else {
-        p = qe_malloc(PidHandler);
+        p = qe_mallocz(PidHandler);
         if (!p)
             return -1;
         p->pid = pid;
@@ -129,7 +129,7 @@
     BottomHalfEntry *bh;
 
     /* Should not fail */
-    bh = qe_malloc(BottomHalfEntry);
+    bh = qe_mallocz(BottomHalfEntry);
     bh->cb = cb;
     bh->opaque = opaque;
     list_add(bh, &bottom_halves);
@@ -154,7 +154,7 @@
 {
     QETimer *ti;
 
-    ti = qe_malloc(QETimer);
+    ti = qe_mallocz(QETimer);
     if (!ti)
         return NULL;
     ti->timeout = get_clock_ms() + delay;
@@ -165,17 +165,21 @@
     return ti;
 }
 
-void qe_kill_timer(QETimer *ti)
+void qe_kill_timer(QETimer **tip)
 {
+    if (*tip) {
     QETimer **pt;
-    pt = &first_timer;
-    while (*pt != NULL) {
-        if (*pt == ti) {
-            *pt = ti->next;
-            qe_free(&ti);
-        } else {
-            pt = &(*pt)->next;
+
+        /* remove timer from list of active timers and free it */
+        for (pt = &first_timer; *pt != NULL; pt = &(*pt)->next) {
+            if (*pt == (*tip)) {
+                *pt = (*tip)->next;
+                qe_free(tip);
+                return;
+            }
         }
+        /* timer not found, was probably alread freed */
+        *tip = NULL;
     }
 }
 
@@ -315,4 +319,3 @@
 {
     url_exit_request = 1;
 }
-

Index: util.c
===================================================================
RCS file: /sources/qemacs/qemacs/util.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- util.c      20 Jan 2014 18:04:01 -0000      1.59
+++ util.c      23 Jan 2014 12:56:23 -0000      1.60
@@ -50,7 +50,7 @@
 {
     FindFileState *s;
 
-    s = qe_malloc(FindFileState);
+    s = qe_mallocz(FindFileState);
     if (!s)
         return NULL;
     pstrcpy(s->path, sizeof(s->path), path);
@@ -105,11 +105,15 @@
     }
 }
 
-void find_file_close(FindFileState *s)
+void find_file_close(FindFileState **sp)
 {
+    if (*sp) {
+        FindFileState *s = *sp;
+
     if (s->dir)
         closedir(s->dir);
-    qe_free(&s);
+        qe_free(sp);
+    }
 }
 
 #ifdef CONFIG_WIN32
@@ -1515,12 +1519,12 @@
 
 void *qe_malloc_bytes(size_t size)
 {
-    return malloc(size);
+    return (malloc)(size);
 }
 
 void *qe_mallocz_bytes(size_t size)
 {
-    void *p = malloc(size);
+    void *p = (malloc)(size);
     if (p)
         memset(p, 0, size);
     return p;
@@ -1528,7 +1532,7 @@
 
 void *qe_malloc_dup(const void *src, size_t size)
 {
-    void *p = malloc(size);
+    void *p = (malloc)(size);
     if (p)
         memcpy(p, src, size);
     return p;
@@ -1537,7 +1541,7 @@
 char *qe_strdup(const char *str)
 {
     size_t size = strlen(str) + 1;
-    char *p = malloc(size);
+    char *p = (malloc)(size);
 
     if (p)
         memcpy(p, str, size);
@@ -1546,7 +1550,7 @@
 
 void *qe_realloc(void *pp, size_t size)
 {
-    void *p = realloc(*(void **)pp, size);
+    void *p = (realloc)(*(void **)pp, size);
     if (p || !size)
         *(void **)pp = p;
     return p;

Index: variables.c
===================================================================
RCS file: /sources/qemacs/qemacs/variables.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- variables.c 21 Jan 2014 00:01:21 -0000      1.11
+++ variables.c 23 Jan 2014 12:56:23 -0000      1.12
@@ -205,7 +205,9 @@
  */
 extern u8 end[];
 #ifdef CONFIG_DARWIN
-u8 end[8];  /* FIXME: not really at the end, but beyond the bss, should remove 
this dependency */
+/* XXX: not really at the end, but should be beyond initialized data */
+/* XXX: should remove this hack */
+u8 end[8];
 #endif
 
 QVarType qe_set_variable(EditState *s, const char *name,

Index: video.c
===================================================================
RCS file: /sources/qemacs/qemacs/video.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- video.c     16 Jan 2014 14:00:28 -0000      1.16
+++ video.c     23 Jan 2014 12:56:23 -0000      1.17
@@ -843,9 +843,7 @@
         bmp_free(s->screen, &vp->bmp);
     }
 
-    if (is->video_timer) {
-        qe_kill_timer(is->video_timer);
-    }
+    qe_kill_timer(&is->video_timer);
 }
 
 char *get_stream_id(AVFormatContext *ic, AVStream *st, char *buf, int buf_size)

Index: win32.c
===================================================================
RCS file: /sources/qemacs/qemacs/win32.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- win32.c     17 Dec 2013 16:06:36 -0000      1.16
+++ win32.c     23 Jan 2014 12:56:23 -0000      1.17
@@ -202,7 +202,7 @@
 {
     QEEventQ *e;
 
-    e = qe_malloc(QEEventQ);
+    e = qe_mallocz(QEEventQ);
     if (!e)
         return;
     e->ev = *ev;
@@ -446,7 +446,7 @@
     QEFont *font;
     TEXTMETRIC tm;
 
-    font = qe_malloc(QEFont);
+    font = qe_mallocz(QEFont);
     if (!font)
         return NULL;
     GetTextMetrics(win_ctx.hdc, &tm);
@@ -456,9 +456,9 @@
     return font;
 }
 
-static void win_close_font(QEditScreen *s, QEFont *font)
+static void win_close_font(QEditScreen *s, QEFont **fontp)
 {
-    qe_free(&font);
+    qe_free(fontp);
 }
 
 static void win_text_metrics(QEditScreen *s, QEFont *font,

Index: x11.c
===================================================================
RCS file: /sources/qemacs/qemacs/x11.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- x11.c       13 Jan 2014 11:28:01 -0000      1.30
+++ x11.c       23 Jan 2014 12:56:23 -0000      1.31
@@ -45,7 +45,7 @@
 /* NOTE: XFT code is currently broken */
 
 static QEFont *term_open_font(QEditScreen *s, int style, int size);
-static void term_close_font(QEditScreen *s, QEFont *font);
+static void term_close_font(QEditScreen *s, QEFont **fontp);
 #ifdef CONFIG_XV
 static void xv_init(QEditScreen *s);
 #endif
@@ -224,7 +224,7 @@
     }
     font_ysize = font->ascent + font->descent;
     font_xsize = glyph_width(s, font, 'x');
-    term_close_font(s, font);
+    term_close_font(s, &font);
 
     if (w > 0 && h > 0) {
         xsize = w;
@@ -568,8 +568,11 @@
     return font;
 }
 
-static void term_close_font(QEditScreen *s, QEFont *font)
+static void term_close_font(QEditScreen *s, QEFont **fontp)
 {
+    QEFont *font = *fontp;
+
+    if (font) {
     XftFont *renderFont = font->priv_data;
 
     XftFontClose(display, renderFont);
@@ -577,7 +580,8 @@
      * close_font.
      */
     memset(font, 0, sizeof(*font));
-    qe_free(&font);
+        qe_free(fontp);
+    }
 }
 
 static int term_glyph_width(QEditScreen *s, QEFont *font, unsigned int cc)
@@ -665,7 +669,7 @@
     char **list;
     const char *p;
 
-    font = qe_malloc(QEFont);
+    font = qe_mallocz(QEFont);
     if (!font)
         return NULL;
 
@@ -772,8 +776,10 @@
     return NULL;
 }
 
-static void term_close_font(__unused__ QEditScreen *s, QEFont *font)
+static void term_close_font(__unused__ QEditScreen *s, QEFont **fontp)
 {
+    if (*fontp) {
+        QEFont *font = *fontp;
     XFontStruct *xfont = font->priv_data;
 
     XFreeFont(display, xfont);
@@ -781,7 +787,8 @@
      * close_font.
      */
     memset(font, 0, sizeof(*font));
-    qe_free(&font);
+        qe_free(fontp);
+    }
 }
 
 /* get a char struct associated to a char. Return NULL if no glyph
@@ -1471,7 +1478,7 @@
 {
     X11Bitmap *xb;
 
-    xb = qe_malloc(X11Bitmap);
+    xb = qe_mallocz(X11Bitmap);
     if (!xb)
         return -1;
     b->priv_data = xb;
@@ -1523,7 +1530,7 @@
             XShmSegmentInfo *shm_info;
 
             /* XXX: error testing */
-            shm_info = qe_malloc(XShmSegmentInfo);
+            shm_info = qe_mallocz(XShmSegmentInfo);
             ximage = XShmCreateImage(display, None, attr.depth, ZPixmap, NULL,
                                      shm_info, b->width, b->height);
             shm_info->shmid = shmget(IPC_PRIVATE,
@@ -1557,7 +1564,7 @@
             XvImage *xvimage;
             XShmSegmentInfo *shm_info;
 
-            shm_info = qe_malloc(XShmSegmentInfo);
+            shm_info = qe_mallocz(XShmSegmentInfo);
             xvimage = XvShmCreateImage(display, xv_port, xv_format, 0,
                                        b->width, b->height, shm_info);
             shm_info->shmid = shmget(IPC_PRIVATE,

Index: libqhtml/css.c
===================================================================
RCS file: /sources/qemacs/qemacs/libqhtml/css.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- libqhtml/css.c      24 Apr 2008 14:02:42 -0000      1.24
+++ libqhtml/css.c      23 Jan 2014 12:56:23 -0000      1.25
@@ -1,8 +1,8 @@
 /*
  * CSS core for qemacs.
  *
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- * Copyright (c) 2007-2008 Charlie Gordon.
+ * Copyright (c) 2000-2002 Fabrice Bellard.
+ * Copyright (c) 2007-2014 Charlie Gordon.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -324,25 +324,24 @@
         }
         p = p->hash_next;
     }
-    len = strlen(str);
-    p = qe_malloc_hack(CSSIdentEntry, len);
-    if (!p)
-        return CSS_ID_NIL;
-    p->id = table_ident_nb;
-    memcpy(p->str, str, len + 1);
-    p->hash_next = *pp;
-    *pp = p;
-
-    /* put ident in table */
+    /* allocate a new ident */
     if (table_ident_nb == table_ident_allocated) {
+        /* realloc ident table if needed */
         n = table_ident_allocated + CSS_IDENT_INCR;
         if (!qe_realloc(&table_ident, n * sizeof(CSSIdentEntry *))) {
-            qe_free(&p);
             return CSS_ID_NIL;
         }
         table_ident_allocated = n;
     }
+    len = strlen(str);
+    p = qe_malloc_hack(CSSIdentEntry, len);
+    if (!p)
+        return CSS_ID_NIL;
+    memcpy(p->str, str, len + 1);
+    p->id = table_ident_nb;
     table_ident[table_ident_nb++] = p;
+    p->hash_next = *pp;
+    *pp = p;
 
     return p->id;
 }
@@ -377,7 +376,7 @@
             p->value = value;
         }
     }
-    p = qe_malloc(CSSCounterValue);
+    p = qe_mallocz(CSSCounterValue);
     if (!p)
         return;
     p->counter_id = counter_id;
@@ -890,9 +889,9 @@
 }
 
 /* free one CSSState */
-static void free_props(CSSState *props)
+static void free_props(CSSState **propsp)
 {
-    qe_free(&props);
+    qe_free(propsp);
 }
 
 static int css_compute_block(CSSContext *s, CSSBox *box,
@@ -1080,7 +1079,7 @@
     }
     aprops = allocate_props(s, marker_props);
     if (!aprops) {
-        css_delete_box(box1);
+        css_delete_box(&box1);
         return NULL;
     }
     box1->props = aprops;
@@ -1739,7 +1738,7 @@
 #endif
     /* layout the interior */
     if (css_layout_block(s->ctx, &layout, box)) {
-        qe_free(&b);
+        //qe_free(&b);  // XXX: this is a BUG
         return -1;
     }
     /* add the float in the float list */
@@ -3241,7 +3240,7 @@
 {
     FloatBlock *b, **pb;
 
-    b = qe_malloc(FloatBlock);
+    b = qe_mallocz(FloatBlock);
     if (!b)
         return 0;
     b->box = box;
@@ -3256,14 +3255,12 @@
     return 0;
 }
 
-static void css_free_floats(FloatBlock *b)
+static void css_free_floats(FloatBlock **pp)
 {
-    FloatBlock *b1;
-
-    while (b != NULL) {
-        b1 = b->next;
+    while (*pp) {
+        FloatBlock *b = *pp;
+        *pp = b->next;
         qe_free(&b);
-        b = b1;
     }
 }
 
@@ -3576,7 +3573,7 @@
     layout_state.first_float = NULL;
     ret = css_layout_block_recurse(&layout_state, block_layout, block_box, 0, 
0);
 
-    css_free_floats(layout_state.first_float);
+    css_free_floats(&layout_state.first_float);
 
     return ret;
 }
@@ -4475,16 +4472,15 @@
 
 /* delete a box and all boxes after and inside */
 /* XXX: free generated content ! */
-void css_delete_box(CSSBox *box)
+void css_delete_box(CSSBox **bp)
 {
-    CSSBox *box1;
-    CSSAttribute *a1, *a;
-    CSSProperty *p1, *p;
+    while (*bp != NULL) {
+        CSSBox *box = *bp;
+        *bp = box->next;
 
-    while (box != NULL) {
         switch (box->content_type) {
         case CSS_CONTENT_TYPE_CHILDS:
-            css_delete_box(box->u.child.first);
+            css_delete_box(&box->u.child.first);
             break;
         case CSS_CONTENT_TYPE_STRING:
             /* split boxes never own their content */
@@ -4495,21 +4491,17 @@
             qe_free(&box->u.image.content_alt);
             break;
         }
-        box1 = box->next;
-        a = box->attrs;
-        while (a != NULL) {
-            a1 = a->next;
+        while (box->attrs) {
+            CSSAttribute *a = box->attrs;
+            box->attrs = a->next;
             qe_free(&a);
-            a = a1;
         }
-        p = box->properties;
-        while (p != NULL) {
-            p1 = p->next;
+        while (box->properties) {
+            CSSProperty *p = box->properties;
+            box->properties = p->next;
             qe_free(&p);
-            p = p1;
         }
         qe_free(&box);
-        box = box1;
     }
 }
 
@@ -4583,21 +4575,22 @@
     return s;
 }
 
-void css_delete_document(CSSContext *s)
+void css_delete_document(CSSContext **sp)
 {
+    if (*sp) {
+        CSSContext *s = *sp;
     int i;
-    CSSState *props, *props_next;
 
     for (i = 0; i < PROPS_HASH_SIZE; i++) {
-        for (props = s->hash_props[i]; props != NULL; props = props_next) {
-            props_next = props->hash_next;
-            free_props(props);
+            while (s->hash_props[i]) {
+                CSSState *props = s->hash_props[i];
+                s->hash_props[i] = props->hash_next;
+                free_props(&props);
         }
     }
-    if (s->style_sheet) {
-        css_free_style_sheet(s->style_sheet);
+        css_free_style_sheet(&s->style_sheet);
+        qe_free(sp);
     }
-    qe_free(&s);
 }
 
 /* must be called before using any css functions */

Index: libqhtml/css.h
===================================================================
RCS file: /sources/qemacs/qemacs/libqhtml/css.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- libqhtml/css.h      24 Apr 2008 14:02:42 -0000      1.10
+++ libqhtml/css.h      23 Jan 2014 12:56:24 -0000      1.11
@@ -1,8 +1,8 @@
 /*
  * CSS core for qemacs.
  *
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- * Copyright (c) 2007-2008 Charlie Gordon.
+ * Copyright (c) 2000-2002 Fabrice Bellard.
+ * Copyright (c) 2007-2014 Charlie Gordon.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -528,7 +528,7 @@
 CSSStyleSheet *css_new_style_sheet(void);
 void css_parse_style_sheet_str(CSSStyleSheet *s, const char *buffer, int 
flags);
 void css_parse_style_sheet(CSSStyleSheet *s, CSSParseState *b);
-void css_free_style_sheet(CSSStyleSheet *s);
+void css_free_style_sheet(CSSStyleSheet **sp);
 void css_dump_style_sheet(CSSStyleSheet *s);
 void css_merge_style_sheet(CSSStyleSheet *s, CSSStyleSheet *a);
 
@@ -599,7 +599,7 @@
 
 CSSContext *css_new_document(QEditScreen *screen,
                              EditBuffer *b);
-void css_delete_document(CSSContext *s);
+void css_delete_document(CSSContext **sp);
 
 int css_compute(CSSContext *s, CSSBox *box);
 int css_layout(CSSContext *s, CSSBox *box, int width,
@@ -625,7 +625,7 @@
 /* box tree handling */
 CSSBox *css_new_box(CSSIdent tag, CSSAttribute *attrs);
 CSSBox *css_add_box(CSSBox *parent_box, CSSBox *box);
-void css_delete_box(CSSBox *box);
+void css_delete_box(CSSBox **boxp);
 void css_set_text_buffer(CSSBox *box, EditBuffer *b,
                          int offset1, int offset2, int eol);
 void css_set_text_string(CSSBox *box, const char *string);
@@ -650,7 +650,7 @@
                     CSSAbortFunc *abort_func, void *abort_opaque,
                     const char *filename, QECharset *charset);
 int xml_parse(XMLState *s, char *buf, int buf_len);
-CSSBox *xml_end(XMLState *s);
+CSSBox *xml_end(XMLState **sp);
 
 CSSBox *xml_parse_buffer(EditBuffer *b, int offset_start, int offset_end,
                          CSSStyleSheet *style_sheet, int flags,

Index: libqhtml/cssparse.c
===================================================================
RCS file: /sources/qemacs/qemacs/libqhtml/cssparse.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- libqhtml/cssparse.c 23 Jan 2014 12:36:35 -0000      1.19
+++ libqhtml/cssparse.c 23 Jan 2014 12:56:24 -0000      1.20
@@ -1,7 +1,7 @@
 /*
  * CSS2 parser for qemacs.
  *
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
+ * Copyright (c) 2000-2002 Fabrice Bellard.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -638,39 +638,40 @@
 
 static void free_selector(CSSSimpleSelector *ss)
 {
-    CSSStyleSheetAttributeEntry *attr, *attr1;
-
-    for (attr = ss->attrs; attr != NULL; attr = attr1) {
-        attr1 = attr->next;
+    while (ss->attrs) {
+        CSSStyleSheetAttributeEntry *attr = ss->attrs;
+        ss->attrs = attr->next;
         qe_free(&attr);
     }
 }
 
 /* XXX: free idents too */
-void css_free_style_sheet(CSSStyleSheet *s)
+void css_free_style_sheet(CSSStyleSheet **sp)
 {
-    CSSStyleSheetEntry *e, *e1;
-    CSSProperty *p, *p1;
-    CSSSimpleSelector *ss, *ss1;
-
-    for (e = s->first_entry; e != NULL; e = e1) {
-        e1 = e->next;
+    if (*sp) {
+        CSSStyleSheet *s = *sp;
 
-        for (ss = e->sel.next; ss != NULL; ss = ss1) {
-            ss1 = ss->next;
+        while (s->first_entry) {
+            CSSStyleSheetEntry *e = s->first_entry;
+            s->first_entry = e->next;
+
+            while (e->sel.next) {
+                CSSSimpleSelector *ss = e->sel.next;
+                e->sel.next = ss->next;
             free_selector(ss);
             qe_free(&ss);
         }
         free_selector(&e->sel);
 
-        for (p = e->props; p != NULL; p = p1) {
-            p1 = p->next;
+            while (e->props) {
+                CSSProperty *p = e->props;
+                e->props = p->next;
             qe_free(&p);
         }
         qe_free(&e);
     }
-
-    qe_free(&s);
+        qe_free(sp);
+    }
 }
 
 static int bgetc1(CSSParseState *b)
@@ -845,7 +846,7 @@
         /* add selector operations */
         pss = &e1->sel.next;
         for (ss = e->sel.next; ss != NULL; ss = ss->next) {
-            ss1 = qe_malloc(CSSSimpleSelector);
+            ss1 = qe_mallocz(CSSSimpleSelector);
             dup_selector(ss1, ss);
             *pss = ss1;
             pss = &ss1->next;

Index: libqhtml/Makefile
===================================================================
RCS file: /sources/qemacs/qemacs/libqhtml/Makefile,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- libqhtml/Makefile   23 Nov 2013 10:54:33 -0000      1.6
+++ libqhtml/Makefile   23 Jan 2014 12:56:24 -0000      1.7
@@ -1,7 +1,7 @@
 # Libqhtml tiny HTML/CSS rendering library for QEmacs
 #
 # Copyright (c) 2000-2002 Fabrice Bellard.
-# Copyright (c) 2000-2008 Charlie Gordon.
+# Copyright (c) 2000-2014 Charlie Gordon.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -21,13 +21,19 @@
 
 include $(DEPTH)/config.mak
 
-CFLAGS:= -Wall -g $(CFLAGS) -funsigned-char
+ifeq ($(CC),gcc)
+  CFLAGS   += -Wall -g -O2 -funsigned-char
+  # do not warn about zero-length formats.
+  CFLAGS   += -Wno-format-zero-length
+  LDFLAGS  := -g
+endif
 
+#include local compiler configuration file
 -include $(DEPTH)/cflags.mk
 
 ifdef TARGET_GPROF
-  CFLAGS+= -p
-  LDFLAGS+= -p
+  CFLAGS  += -p
+  LDFLAGS += -p
 endif
 
 ifdef TARGET_ARCH_X86
@@ -41,32 +47,39 @@
 
 CFLAGS+=-I$(DEPTH)
 
-LIB=libqhtml.a
-OBJS=css.o xmlparse.o cssparse.o html_style.o docbook_style.o
+LIB= libqhtml.a
+OBJS= css.o xmlparse.o cssparse.o html_style.o docbook_style.o
+
+DEPENDS:= qe.h config.h cutils.h display.h qestyles.h config.mak
+DEPENDS:= $(addprefix $(DEPTH)/, $(DEPENDS))
+
+OBJS_DIR:= $(DEPTH)/.objs/libqhtml
+OBJS:= $(addprefix $(OBJS_DIR)/, $(OBJS))
 
-OBJS_DIR:=$(DEPTH)/.objs/libqhtml
-OBJS:=$(addprefix $(OBJS_DIR)/, $(OBJS))
 $(shell mkdir -p $(OBJS_DIR))
 
+#
+# Dependencies
+#
 all: $(LIB)
 
-$(LIB): $(OBJS)
+$(LIB): $(OBJS) Makefile
        rm -f $@
        $(AR) rc $@ $(OBJS)
 
-$(OBJS_DIR)/%.o: %.c Makefile
+$(OBJS_DIR)/%.o: %.c $(DEPENDS) Makefile
        $(CC) $(DEFINES) $(CFLAGS) -o $@ -c $<
 
 #
 # build default style sheet file
 #
-csstoqe$(EXE): csstoqe.c
+csstoqe$(EXE): csstoqe.c Makefile
        $(HOST_CC) $(CFLAGS) -o $@ $<
 
-html_style.c: html.css csstoqe$(EXE)
+html_style.c: html.css csstoqe$(EXE) Makefile
        ./csstoqe html_style < $< > $@
 
-docbook_style.c: docbook.css csstoqe$(EXE)
+docbook_style.c: docbook.css csstoqe$(EXE) Makefile
        ./csstoqe docbook_style < $< > $@
 
 clean:

Index: libqhtml/xmlparse.c
===================================================================
RCS file: /sources/qemacs/qemacs/libqhtml/xmlparse.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- libqhtml/xmlparse.c 2 May 2008 17:05:39 -0000       1.24
+++ libqhtml/xmlparse.c 23 Jan 2014 12:56:24 -0000      1.25
@@ -1,7 +1,7 @@
 /*
  * XML/HTML parser for qemacs.
  *
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
+ * Copyright (c) 2000-2002 Fabrice Bellard.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1277,10 +1277,14 @@
 }
 
 
-CSSBox *xml_end(XMLState *s)
+CSSBox *xml_end(XMLState **sp)
 {
+    XMLState *s = *sp;
     CSSBox *root_box;
 
+    if (!s)
+        return NULL;
+
     /* flush the lookahead buffer */
     if (s->lookahead_size > 0) {
         /* mark the end to stop parsing function */
@@ -1312,10 +1316,10 @@
     s = xml_begin(style_sheet, flags, abort_func, abort_opaque, b->name, NULL);
     ret = xml_parse_internal(s, NULL, offset_end - offset_start,
                              b, offset_start);
-    box = xml_end(s);
+    box = xml_end(&s);
     if (ret < 0) {
-        css_delete_box(box);
-        box = NULL;
+        css_delete_box(&box);
+        return NULL;
     }
     return box;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]