diff -Naur pkg-config-0.21-orig/findme.c pkg-config-0.21/findme.c --- pkg-config-0.21-orig/findme.c Wed Aug 16 10:05:30 2006 +++ pkg-config-0.21/findme.c Fri Nov 24 00:24:26 2006 @@ -22,13 +22,7 @@ #include "config.h" #endif -#ifdef HAVE_ALLOCA_H -# include -#else -# ifdef _AIX -# pragma alloca -# endif -#endif +#include "pkg-glib.h" #include #include @@ -57,16 +51,17 @@ /* If there is a / in the argv[0], it has to be an absolute path */ if (strchr(argv0, '/')) - return strdup(argv0); + return g_strdup(argv0); if (!path) return NULL; start = pathbuf = alloca(strlen(path) + 1); - buf = malloc(strlen(path) + strlen(argv0) + 2); + buf = g_malloc(strlen(path) + strlen(argv0) + 2); strcpy(pathbuf, path); chptr = NULL; do { + // Note: should this be G_SEARCHPATH_SEPARATOR_S instead of ':'? if ((chptr = strchr(start, ':'))) *chptr = '\0'; sprintf(buf, "%s/%s", start, argv0); @@ -80,7 +75,7 @@ start = NULL; } while (start && *start); - free(buf); + g_free(buf); return NULL; } diff -Naur pkg-config-0.21-orig/main.c pkg-config-0.21/main.c --- pkg-config-0.21-orig/main.c Wed Aug 16 10:54:56 2006 +++ pkg-config-0.21/main.c Thu Nov 23 23:46:30 2006 @@ -169,6 +169,118 @@ return FALSE; } +#if 0 +/* for debug purposes only */ +static const char bad_cafe[8] = { 'B', 'a', 'd', 'c', 'a', 'f', 'f', 'e' }; +static size_t +pkg_test(void *ptr, const char *func) +{ + int i, j; + char *p; + size_t sz; + + if(ptr == 0) + return fprintf(stderr, "ERROR! %s NULL POINTER\n", func), 0; + + p = (char*)ptr; + if(memcmp(p - 16, bad_cafe, 8) != 0) + return fprintf(stderr, "ERROR! %s BAD POINTER [invalid at -16] (%p)\n", func, ptr), 0; + + if(memcmp(p - 8, bad_cafe, 4) != 0) + return fprintf(stderr, "ERROR! %s BAD POINTER [invalid at -8] (%p)\n", func, ptr), 0; + + sz = *(size_t*)(p-4); + if(sz == 0 || sz > 0x10000) /* assume 64Kb max. */ + return fprintf(stderr, "ERROR! %s BAD POINTER [invalid size: %d] (%p)\n", func, sz, ptr), 0; + + if(memcmp(p + sz, bad_cafe, 8) != 0) { + fprintf(stderr, "ERROR! %s BAD POINTER [invalid at +sz=%d] (%p)\n", func, sz, ptr); + for(i = -16; i < (int) (sz + 32); i++) { + if((i & 15) == 0) { + fprintf(stderr, "%08X- ", p + i); + } + fprintf(stderr, "%02X ", (unsigned char)p[i]); + if((i & 15) == 15) { + char buf[2]; + buf[1] = '\0'; + for(j = -15; j < 1; j++) { + if(p[i + j] < ' ' || p[i + j] > 0x7E) buf[0] = '.'; + else buf[0] = p[j + i]; + fprintf(stderr, "%s", buf); + } + fprintf(stderr, "\n"); + } + } + if((i & 15) != 0) fprintf(stderr, "\n"); + return 0; + } + + if(memcmp(p + sz + 8, bad_cafe, 8) != 0) + return fprintf(stderr, "ERROR! %s BAD POINTER [invalid at +sz+8] (%p)\n", func, ptr), 0; + + return sz; +} +static void * +pkg_malloc(size_t sz) +{ + char *p = malloc(sz + 64); + memcpy(p, bad_cafe, 8); + memcpy(p + 8, bad_cafe, 4); + p += 16; + *(size_t*)(p-4) = sz; + memcpy(p + sz, bad_cafe, 8); + memcpy(p + sz + 8, bad_cafe, 8); + memcpy(p + sz + 16, bad_cafe, 8); + memcpy(p + sz + 24, bad_cafe, 8); + fprintf(stderr, "MALLOC[%d] %p \n", sz, p); + return p; +} +static void +pkg_free(void *ptr) +{ + char *p; + size_t sz; + + // this is a valid case here + if(ptr == 0) return; + + sz = pkg_test(ptr, "FREEING"); + if(sz == 0) return; + + fprintf(stderr, "FREE[%d] %p\n", sz, ptr); + p = (char*)ptr; + memset(p-16,0xee,sz+64); + free(p-16); +} +static void * +pkg_realloc(void *ptr, size_t new_size) +{ + char *p; + size_t sz; + + if(new_size == 0) return fprintf(stderr,"REALLOC->"), pkg_free(ptr), (void*)0; + if(ptr == 0) return fprintf(stderr,"REALLOC->"), pkg_malloc(new_size); + + sz = pkg_test(ptr, "REALLOCATING"); + if(sz == 0) return 0; + + p = (char*) ptr; + p = realloc(p - 16, new_size + 64); + memcpy(p, bad_cafe, 8); + memcpy(p + 8, bad_cafe, 4); + p += 16; + *(size_t*)(p-4) = new_size; + memcpy(p + new_size, bad_cafe, 8); + memcpy(p + new_size + 8, bad_cafe, 8); + memcpy(p + new_size + 16, bad_cafe, 8); + memcpy(p + new_size + 24, bad_cafe, 8); + + fprintf(stderr, "REALLOC[%d -> %d] %p -> %p\n", sz, new_size, ptr, p); + + return p; +} +#endif + int main (int argc, char **argv) { @@ -197,13 +309,9 @@ GSList *packages = NULL; char *search_path; char *pcbuilddir; - const char *pkglibdir; - char **search_dirs; - char **iter; gboolean need_newline; const char *pkgname; - Package *pkg; poptContext opt_context; @@ -270,6 +378,17 @@ { NULL, 0, 0, NULL, 0 } }; +#if 0 + { + GMemVTable vtable; + memset(&vtable, 0, sizeof(vtable)); + vtable.malloc = pkg_malloc; + vtable.realloc = pkg_realloc; + vtable.free = pkg_free; + g_mem_set_vtable(&vtable); + } +#endif + /* This is here so that we get debug spew from the start, * during arg parsing */ @@ -292,7 +411,7 @@ } else { - add_search_dirs(PKG_CONFIG_PC_PATH, G_SEARCHPATH_SEPARATOR_S); + add_search_dirs("/mingw/lib/pkgconfig:/mingw/share/pkgconfig", G_SEARCHPATH_SEPARATOR_S); } #ifdef G_OS_WIN32 diff -Naur pkg-config-0.21-orig/parse.c pkg-config-0.21/parse.c --- pkg-config-0.21-orig/parse.c Wed Aug 16 11:45:46 2006 +++ pkg-config-0.21/parse.c Thu Nov 23 23:56:10 2006 @@ -614,8 +614,6 @@ static void parse_conflicts (Package *pkg, const char *str, const char *path) { - GSList *parsed; - GSList *iter; char *trimmed; if (pkg->conflicts) @@ -1111,6 +1111,7 @@ return pkg; } +/* unused static char * backticks (const char *command) { @@ -1124,7 +1125,7 @@ if (f == NULL) return NULL; - len = fread (buf, 1, 4090, f); + len = fread (buf, 1, sizeof(buf) - 1, f); if (ferror (f)) { @@ -1138,7 +1139,9 @@ return g_strdup (buf); } +*/ +/* unused static gboolean try_command (const char *command) { @@ -1161,6 +1164,8 @@ return WIFEXITED(status) && (WEXITSTATUS(status) == 0); #endif } +*/ + Package * get_compat_package (const char *name) diff -Naur pkg-config-0.21-orig/partial-glib.h pkg-config-0.21/partial-glib.h --- pkg-config-0.21-orig/partial-glib.h Wed Aug 16 10:05:30 2006 +++ pkg-config-0.21/partial-glib.h Wed Dec 31 16:00:00 1969 @@ -1,6 +0,0 @@ -#ifndef PKG_CONFIG_PARTIAL_GLIB_H -#define PKG_CONFIG_PARTIAL_GLIB_H - -#include "glib-1.2.8/glib.h" - -#endif diff -Naur pkg-config-0.21-orig/pkg-glib.h pkg-config-0.21/pkg-glib.h --- pkg-config-0.21-orig/pkg-glib.h Wed Dec 31 16:00:00 1969 +++ pkg-config-0.21/pkg-glib.h Thu Nov 23 19:18:10 2006 @@ -0,0 +1,48 @@ +/* +Copyright (c) 1998 Red Hat Software + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. +*/ + +#ifndef PKG_CONFIG_GLIB_H +#define PKG_CONFIG_GLIB_H + +#ifdef USE_INSTALLED_GLIB +#include +#else +#include "glib-1.2.8/glib.h" +#endif + +#if 0 +// this is part of glib.h somewhere (except _AIX test?) +#ifdef HAVE_ALLOCA_H +# include +#else +# ifdef _AIX +# pragma alloca +# else +# include +# endif +#endif +#endif + +#endif // #ifndef PKG_CONFIG_GLIB_H diff -Naur pkg-config-0.21-orig/pkg.c pkg-config-0.21/pkg.c --- pkg-config-0.21-orig/pkg.c Wed Aug 16 12:01:04 2006 +++ pkg-config-0.21/pkg.c Thu Nov 23 19:20:18 2006 @@ -25,13 +25,6 @@ #include "pkg.h" #include "parse.h" -#ifdef HAVE_ALLOCA_H -# include -#else -# ifdef _AIX -# pragma alloca -# endif -#endif #include #include @@ -159,8 +152,9 @@ /* Turn backslashes into slashes or * poptParseArgvString() will eat them when ${prefix} * has been expanded in parse_libs(). + * WARNING: we're modifying the 'const' input string */ - p = dirname; + p = (char*)dirname; while (*p) { if (*p == '\\') @@ -188,7 +182,7 @@ if (ends_in_dotpc (dent->d_name)) { - char *pkgname = malloc (len - 2); + char *pkgname = g_malloc (len - 2); debug_spew ("File '%s' appears to be a .pc file\n", dent->d_name); @@ -263,6 +257,7 @@ } } +/* unused static gboolean file_readable (const char *path) { @@ -276,6 +271,7 @@ else return FALSE; } +*/ static Package * @@ -577,6 +573,7 @@ debug_spew ("\n"); } +/* unused static void spew_string_list (const char *name, GSList *list) @@ -593,6 +590,7 @@ } debug_spew ("\n"); } +*/ static GSList* packages_sort_by_path_position (GSList *list) @@ -705,6 +703,7 @@ g_slist_free (expanded); } +/* unused static gint compare_req_version_names (gconstpointer a, gconstpointer b) { @@ -713,7 +712,9 @@ return strcmp (ver_a->name, ver_b->name); } +*/ +/* unused static gint compare_package_keys (gconstpointer a, gconstpointer b) { @@ -722,6 +723,7 @@ return strcmp (pkg_a->key, pkg_b->key); } +*/ static GSList * add_env_variable_to_list (GSList *list, const gchar *env) @@ -750,7 +752,7 @@ GSList *conflicts_iter; GSList *system_dir_iter = NULL; int count; - gchar *c_include_path; + const gchar *c_include_path; /* Be sure we have the required fields */ @@ -1009,7 +1011,6 @@ get_multi_merged (GSList *pkgs, GetListFunc func, gboolean in_path_order, gboolean include_private) { - GSList *tmp; GSList *dups_list = NULL; GSList *list; char *retval; @@ -1031,7 +1036,6 @@ get_multi_merged_from_back (GSList *pkgs, GetListFunc func, gboolean in_path_order, gboolean include_private) { - GSList *tmp; GSList *dups_list = NULL; GSList *list; char *retval; diff -Naur pkg-config-0.21-orig/pkg.h pkg-config-0.21/pkg.h --- pkg-config-0.21-orig/pkg.h Wed Aug 16 10:05:30 2006 +++ pkg-config-0.21/pkg.h Thu Nov 23 18:53:10 2006 @@ -20,11 +20,7 @@ #ifndef PKG_CONFIG_PKG_H #define PKG_CONFIG_PKG_H -#ifdef USE_INSTALLED_GLIB -#include -#else -#include "partial-glib.h" -#endif +#include "pkg-glib.h" typedef enum { diff -Naur pkg-config-0.21-orig/popt.c pkg-config-0.21/popt.c --- pkg-config-0.21-orig/popt.c Wed Aug 16 10:55:08 2006 +++ pkg-config-0.21/popt.c Fri Nov 24 00:41:34 2006 @@ -21,13 +21,7 @@ #include "config.h" #endif -#ifdef HAVE_ALLOCA_H -# include -#else -# ifdef _AIX -# pragma alloca -# endif -#endif +#include "pkg-glib.h" #include #include @@ -45,8 +39,8 @@ #include "poptint.h" void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) { - if (con->execPath) free(con->execPath); - con->execPath = strdup(path); + if (con->execPath) g_free(con->execPath); + con->execPath = g_strdup(path); con->execAbsolute = allowAbsolute; } @@ -71,7 +65,7 @@ poptContext poptGetContext(char * name, int argc, char ** argv, const struct poptOption * options, int flags) { - poptContext con = malloc(sizeof(*con)); + poptContext con = g_malloc(sizeof(*con)); memset(con, 0, sizeof(*con)); @@ -82,9 +76,9 @@ if (!(flags & POPT_CONTEXT_KEEP_FIRST)) con->os->next = 1; /* skip argv[0] */ - con->leftovers = malloc(sizeof(char *) * (argc + 1)); + con->leftovers = g_malloc(sizeof(char *) * (argc + 1)); con->options = options; - con->finalArgv = malloc(sizeof(*con->finalArgv) * (argc * 2)); + con->finalArgv = g_malloc(sizeof(*con->finalArgv) * (argc * 2)); con->finalArgvAlloced = argc * 2; con->flags = flags; con->execAbsolute = 1; @@ -93,7 +87,7 @@ con->flags |= POPT_CONTEXT_POSIXMEHARDER; if (name) - con->appName = strcpy(malloc(strlen(name) + 1), name); + con->appName = g_strdup(name); invokeCallbacks(con, con->options, 0); @@ -141,12 +135,12 @@ time 'round */ if ((con->finalArgvCount + 1) >= (con->finalArgvAlloced)) { con->finalArgvAlloced += 10; - con->finalArgv = realloc(con->finalArgv, + con->finalArgv = g_realloc(con->finalArgv, sizeof(*con->finalArgv) * con->finalArgvAlloced); } i = con->finalArgvCount++; - con->finalArgv[i] = malloc((longName ? strlen(longName) : 0) + 3); + con->finalArgv[i] = g_malloc((longName ? strlen(longName) : 0) + 3); if (longName) sprintf(con->finalArgv[i], "--%s", longName); else @@ -202,7 +196,7 @@ int pos = 0; char * script = con->doExec->script; - argv = malloc(sizeof(*argv) * + argv = g_malloc(sizeof(*argv) * (6 + con->numLeftovers + con->finalArgvCount)); if (!con->execAbsolute && strchr(script, '/')) return; @@ -439,20 +433,20 @@ if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) { con->finalArgvAlloced += 10; - con->finalArgv = realloc(con->finalArgv, + con->finalArgv = g_realloc(con->finalArgv, sizeof(*con->finalArgv) * con->finalArgvAlloced); } i = con->finalArgvCount++; con->finalArgv[i] = - malloc((opt->longName ? strlen(opt->longName) : 0) + 3); + g_malloc((opt->longName ? strlen(opt->longName) : 0) + 3); if (opt->longName) sprintf(con->finalArgv[i], "--%s", opt->longName); else sprintf(con->finalArgv[i], "-%c", opt->shortName); if (opt->arg && (opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) - con->finalArgv[con->finalArgvCount++] = strdup(con->os->nextArg); + con->finalArgv[con->finalArgvCount++] = g_strdup(con->os->nextArg); } return opt->val; @@ -487,42 +481,37 @@ int i; for (i = 0; i < con->numAliases; i++) { - if (con->aliases[i].longName) free(con->aliases[i].longName); - free(con->aliases[i].argv); + if (con->aliases[i].longName) g_free(con->aliases[i].longName); + g_free(con->aliases[i].argv); } for (i = 0; i < con->numExecs; i++) { - if (con->execs[i].longName) free(con->execs[i].longName); - free(con->execs[i].script); + if (con->execs[i].longName) g_free(con->execs[i].longName); + g_free(con->execs[i].script); } for (i = 0; i < con->finalArgvCount; i++) - free(con->finalArgv[i]); + g_free(con->finalArgv[i]); - free(con->leftovers); - free(con->finalArgv); - if (con->appName) free(con->appName); - if (con->aliases) free(con->aliases); - if (con->otherHelp) free(con->otherHelp); - free(con); + g_free(con->leftovers); + g_free(con->finalArgv); + if (con->appName) g_free(con->appName); + if (con->aliases) g_free(con->aliases); + if (con->otherHelp) g_free(con->otherHelp); + g_free(con); } int poptAddAlias(poptContext con, struct poptAlias newAlias, int flags) { int aliasNum = con->numAliases++; struct poptAlias * alias; - /* SunOS won't realloc(NULL, ...) */ - if (!con->aliases) - con->aliases = malloc(sizeof(newAlias) * con->numAliases); - else - con->aliases = realloc(con->aliases, + con->aliases = g_realloc(con->aliases, sizeof(newAlias) * con->numAliases); alias = con->aliases + aliasNum; *alias = newAlias; if (alias->longName) - alias->longName = strcpy(malloc(strlen(alias->longName) + 1), - alias->longName); + alias->longName = g_strdup(alias->longName); else alias->longName = NULL; diff -Naur pkg-config-0.21-orig/popt.h pkg-config-0.21/popt.h --- pkg-config-0.21-orig/popt.h Wed Aug 16 10:05:30 2006 +++ pkg-config-0.21/popt.h Thu Nov 23 18:41:18 2006 @@ -77,7 +77,7 @@ char * longName; /* may be NULL */ char shortName; /* may be '\0' */ int argc; - char ** argv; /* must be free()able */ + char ** argv; /* must be g_free()able */ }; extern struct poptOption poptHelpOptions[]; @@ -118,7 +118,7 @@ /* like above, but reads /etc/popt and $HOME/.popt along with environment vars */ int poptReadDefaultConfig(poptContext con, int useEnv); -/* argv should be freed -- this allows ', ", and \ quoting, but ' is treated +/* argv should be g_free()'d -- this allows ', ", and \ quoting, but ' is treated the same as " and both may include \ quotes */ int poptParseArgvString(char * s, int * argcPtr, char *** argvPtr); const char * poptStrerror(const int error); diff -Naur pkg-config-0.21-orig/poptconfig.c pkg-config-0.21/poptconfig.c --- pkg-config-0.21-orig/poptconfig.c Wed Aug 16 10:05:30 2006 +++ pkg-config-0.21/poptconfig.c Fri Nov 24 00:03:30 2006 @@ -27,13 +27,7 @@ #include "config.h" #endif -#ifdef HAVE_ALLOCA_H -# include -#else -# ifdef _AIX -# pragma alloca -# endif -#endif +#include "pkg-glib.h" #include #include @@ -84,15 +78,15 @@ } #ifndef _WIN32 /* exec stuff too complex to be worthwhile to port */ else if (!strcmp(entryType, "exec")) { - con->execs = realloc(con->execs, + con->execs = g_realloc(con->execs, sizeof(*con->execs) * (con->numExecs + 1)); if (longName) - con->execs[con->numExecs].longName = strdup(longName); + con->execs[con->numExecs].longName = g_strdup(longName); else con->execs[con->numExecs].longName = NULL; con->execs[con->numExecs].shortName = shortName; - con->execs[con->numExecs].script = strdup(line); + con->execs[con->numExecs].script = g_strdup(line); con->numExecs++; } diff -Naur pkg-config-0.21-orig/popthelp.c pkg-config-0.21/popthelp.c --- pkg-config-0.21-orig/popthelp.c Wed Aug 16 10:05:30 2006 +++ pkg-config-0.21/popthelp.c Thu Nov 23 19:01:32 2006 @@ -27,13 +27,7 @@ #include "config.h" #endif -#ifdef HAVE_ALLOCA_H -# include -#else -# ifdef _AIX -# pragma alloca -# endif -#endif +#include "pkg-glib.h" #include #include @@ -297,6 +291,6 @@ } void poptSetOtherOptionHelp(poptContext con, const char * text) { - if (con->otherHelp) free(con->otherHelp); - con->otherHelp = strdup(text); + if (con->otherHelp) g_free(con->otherHelp); + con->otherHelp = g_strdup(text); } diff -Naur pkg-config-0.21-orig/poptparse.c pkg-config-0.21/poptparse.c --- pkg-config-0.21-orig/poptparse.c Wed Aug 16 10:05:30 2006 +++ pkg-config-0.21/poptparse.c Fri Nov 24 00:48:22 2006 @@ -27,13 +27,7 @@ #include "config.h" #endif -#ifdef HAVE_ALLOCA_H -# include -#else -# ifdef _AIX -# pragma alloca -# endif -#endif +#include "pkg-glib.h" #include #include @@ -47,7 +41,7 @@ char * src, * dst; char quote = '\0'; int argvAlloced = 5; - char ** argv = malloc(sizeof(*argv) * argvAlloced); + char ** argv = g_malloc(sizeof(*argv) * argvAlloced); char ** argv2; int argc = 0; int i; @@ -65,7 +59,7 @@ if (*src == '\\') { src++; if (!*src) { - free(argv); + g_free(argv); return POPT_ERROR_BADQUOTE; } if (*src != quote) *buf++ = '\\'; @@ -76,7 +70,7 @@ buf++, argc++; if (argc == argvAlloced) { argvAlloced += 5; - argv = realloc(argv, sizeof(*argv) * argvAlloced); + argv = g_realloc(argv, sizeof(*argv) * argvAlloced); } argv[argc] = buf; } @@ -88,7 +82,7 @@ case '\\': src++; if (!*src) { - free(argv); + g_free(argv); return POPT_ERROR_BADQUOTE; } /* fallthrough */ @@ -103,7 +97,7 @@ argc++, buf++; } - dst = malloc(argc * sizeof(*argv) + (buf - bufStart)); + dst = g_malloc(argc * sizeof(*argv) + (buf - bufStart)); argv2 = (void *) dst; dst += argc * sizeof(*argv); memcpy(argv2, argv, argc * sizeof(*argv)); @@ -113,7 +107,7 @@ argv2[i] = dst + (argv[i] - bufStart); } - free(argv); + g_free(argv); *argvPtr = argv2; *argcPtr = argc;