MAD changes
- From: "Andrew V. Samoilov" <kai cmail ru>
- To: mdeans algonet se, proski gnu org
- Cc: mc-devel gnome org
- Subject: MAD changes
- Date: Fri, 2 Nov 2001 17:31:47 +0200
Hi, all!
I suggest this patch to incorporate into cvs. Glib support enabled
again now - sorry Pavel, but without it builtin editor fails on each
search. I write mad_get_current_dir to use instead of g_get_current_dir.
Also mad_tempname now has file and line parameters.
Fill free to fix my ChangeLog.
I will be offline until Monday.
Regards,
Andrew.
ChangeLog:
* mad.h: Enable glib support - builtin editor fails without it.
* mad.[ch] (mad_get_current_dir): New function to use instead
of g_get_current_dir.
(mad_tempnam): Add file and line parameters.
(mad_alloc0): Make file parameter const.
(mad_realloc): Likewise.
(mad_strdup): Likewise.
(mad_strndup): Likewise.
(mad_free): Likewise.
(mad_finalize): Likewise.
Index: mad.h
===================================================================
RCS file: /cvs/gnome/mc/src/mad.h,v
retrieving revision 1.14
diff -u -p -r1.14 mad.h
--- mad.h 2001/08/11 05:13:10 1.14
+++ mad.h 2001/11/02 14:47:32
@@ -30,7 +30,7 @@
# undef calloc
#endif
-#define tempnam(x,y) mad_tempnam (x, y)
+#define tempnam(x,y) mad_tempnam (x, y, __FILE__, __LINE__)
#define malloc(x) mad_alloc (x, __FILE__, __LINE__)
#define calloc(x, y) mad_alloc0 ((x) * (y), __FILE__, __LINE__)
@@ -50,7 +50,7 @@
* Define MAD_GLIB to debug allocations in glib as well.
* This code is not functional yet.
*/
-#undef MAD_GLIB
+#define MAD_GLIB
#ifdef MAD_GLIB
/* These definitions are grabbed from GLib.h */
@@ -70,22 +70,24 @@
#define g_strconcat mad_strconcat
#define g_strdup_printf mad_strdup_printf
#define g_strdup_vprintf mad_strdup_vprintf
+#define g_get_current_dir() mad_get_current_dir (__FILE__, __LINE__)
#endif /* MAD_GLIB */
void mad_init (void);
void mad_set_debug (const char *file);
void mad_check (const char *file, int line);
void *mad_alloc (int size, const char *file, int line);
-void *mad_alloc0 (int size, char *file, int line);
-void *mad_realloc (void *ptr, int newsize, char *file, int line);
-char *mad_strdup (const char *s, char *file, int line);
-char *mad_strndup (const char *s, int n, char *file, int line);
-void mad_free (void *ptr, char *file, int line);
-void mad_finalize (char *file, int line);
-char *mad_tempnam (char *s1, char *s2);
+void *mad_alloc0 (int size, const char *file, int line);
+void *mad_realloc (void *ptr, int newsize, const char *file, int line);
+char *mad_strdup (const char *s, const char *file, int line);
+char *mad_strndup (const char *s, int n, const char *file, int line);
+void mad_free (void *ptr, const char *file, int line);
+void mad_finalize (const char *file, int line);
+char *mad_tempnam (char *s1, char *s2, const char *file, int line);
char *mad_strconcat (const char *first, ...);
char *mad_strdup_printf (const char *format, ...);
char *mad_strdup_vprintf (const char *format, va_list args);
+char *mad_get_current_dir (const char *file, int line);
#else
Index: mad.c
===================================================================
RCS file: /cvs/gnome/mc/src/mad.c,v
retrieving revision 1.12
diff -u -p -r1.12 mad.c
--- mad.c 2001/08/06 15:32:34 1.12
+++ mad.c 2001/11/02 14:47:32
@@ -36,6 +36,7 @@
#undef g_strdup
#undef g_strndup
#undef g_free
+#undef g_get_current_dir
#include <stdlib.h>
#include <stdio.h>
@@ -180,7 +181,7 @@ void *mad_alloc (int size, const char *f
}
/* Reallocates a memory area. Used instead of realloc. */
-void *mad_realloc (void *ptr, int newsize, char *file, int line)
+void *mad_realloc (void *ptr, int newsize, const char *file, int line)
{
int i;
char *area;
@@ -211,16 +212,15 @@ void *mad_realloc (void *ptr, int newsiz
*(mem_areas [i].start_sig) = MAD_SIGNATURE;
*(mem_areas [i].end_sig) = MAD_SIGNATURE;
- if (strlen (file) >= MAD_MAX_FILE)
- file [MAD_MAX_FILE - 1] = 0;
- strcpy (mem_areas [i].file, file);
+ strncpy (mem_areas [i].file, file, MAD_MAX_FILE - 1);
+ mem_areas [i].file [MAD_MAX_FILE - 1] = 0;
mem_areas [i].line = line;
return mem_areas [i].data;
}
/* Allocates a memory area. Used instead of malloc and calloc. */
-void *mad_alloc0 (int size, char *file, int line)
+void *mad_alloc0 (int size, const char *file, int line)
{
char *t;
@@ -230,7 +230,7 @@ void *mad_alloc0 (int size, char *file,
}
/* Duplicates a character string. Used instead of strdup. */
-char *mad_strdup (const char *s, char *file, int line)
+char *mad_strdup (const char *s, const char *file, int line)
{
if (s) {
char *t;
@@ -244,7 +244,7 @@ char *mad_strdup (const char *s, char *f
/* Duplicates a character string. Used instead of strndup. */
/* Dup of GLib's gstrfuncs.c:g_strndup() */
-char *mad_strndup (const char *s, int n, char *file, int line)
+char *mad_strndup (const char *s, int n, const char *file, int line)
{
if(s) {
char *new_str = mad_alloc(n + 1, file, line);
@@ -257,7 +257,7 @@ char *mad_strndup (const char *s, int n,
}
/* Frees a memory area. Used instead of free. */
-void mad_free (void *ptr, char *file, int line)
+void mad_free (void *ptr, const char *file, int line)
{
int i;
@@ -300,18 +300,18 @@ void mad_free (void *ptr, char *file, in
Alloc_idx_hint = i;
}
-char *mad_tempnam (char *a, char *b)
+char *mad_tempnam (char *a, char *b, const char *file, int line)
{
char *t, *u;
t = tempnam(a,b); /* This malloc's internal buffer.. */
- u = mad_strdup(t, "(mad_tempnam)", 0);
+ u = mad_strdup(t, file, line);
free(t);
return u;
}
/* Outputs a list of unfreed memory areas,
to be called as a last thing before exiting */
-void mad_finalize (char *file, int line)
+void mad_finalize (const char *file, int line)
{
int i;
@@ -398,5 +398,14 @@ mad_strdup_printf (const char *format, .
va_end (args);
return buffer;
+}
+
+char*
+mad_get_current_dir (const char *file, int line)
+{
+ char *cwd = g_get_current_dir ();
+ char *ret = mad_strdup (cwd, file, line);
+ g_free (cwd);
+ return ret;
}
#endif /* HAVE_MAD */
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]