Revision: 3142 http://geany.svn.sourceforge.net/geany/?rev=3142&view=rev Author: eht16 Date: 2008-10-22 15:36:16 +0000 (Wed, 22 Oct 2008)
Log Message: ----------- Add get_path_max() to get a sane value if PATH_MAX is not defined. Change code where PATH_MAX was used unnecessarily. Use GSlice API when building against GLib >= 2.10 (patch by Colomban Wendling, thanks).
Modified Paths: -------------- trunk/ChangeLog trunk/tagmanager/general.h trunk/tagmanager/tm_file_entry.c trunk/tagmanager/tm_project.c trunk/tagmanager/tm_symbol.c trunk/tagmanager/tm_tag.c trunk/tagmanager/tm_work_object.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-10-22 15:35:51 UTC (rev 3141) +++ trunk/ChangeLog 2008-10-22 15:36:16 UTC (rev 3142) @@ -3,6 +3,13 @@ * src/highlighting.c, data/filetypes.css: Change style for 'identifier3' to bold to be in sync with the other identifier styles. + * tagmanager/general.h, tagmanager/tm_file_entry.c, + tagmanager/tm_project.c, tagmanager/tm_symbol.c, tagmanager/tm_tag.c, + tagmanager/tm_work_object.c: + Add get_path_max() to get a sane value if PATH_MAX is not defined. + Change code where PATH_MAX was used unnecessarily. + Use GSlice API when building against GLib >= 2.10 + (patch by Colomban Wendling, thanks).
2008-10-20 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
Modified: trunk/tagmanager/general.h =================================================================== --- trunk/tagmanager/general.h 2008-10-22 15:35:51 UTC (rev 3141) +++ trunk/tagmanager/general.h 2008-10-22 15:36:16 UTC (rev 3142) @@ -39,7 +39,6 @@ #endif
- /* MS-DOS doesn't allow manipulation of standard error, so we send it to * stdout instead. */
Modified: trunk/tagmanager/tm_file_entry.c =================================================================== --- trunk/tagmanager/tm_file_entry.c 2008-10-22 15:35:51 UTC (rev 3141) +++ trunk/tagmanager/tm_file_entry.c 2008-10-22 15:36:16 UTC (rev 3142) @@ -27,6 +27,15 @@ #include "tm_work_object.h" #include "tm_file_entry.h"
+ +#if GLIB_CHECK_VERSION (2, 10, 0) +/* Use GSlices if present */ + +#define FILE_NEW(T) ((T) = g_slice_new0(TMFileEntry)) +#define FILE_FREE(T) g_slice_free(TMFileEntry, (T)) + +#else /* GLib < 2.10 */ + static GMemChunk *file_mem_chunk = NULL;
#define FILE_NEW(T) {\ @@ -37,6 +46,9 @@
#define FILE_FREE(T) g_mem_chunk_free(file_mem_chunk, (T))
+#endif /* GLib version check */ + + void tm_file_entry_print(TMFileEntry *entry, gpointer __unused__ user_data , guint level) { @@ -120,7 +132,7 @@ DIR *dir; struct dirent *dir_entry; TMFileEntry *new_entry; - char file_name[PATH_MAX]; + char *file_name; struct stat s; char *entries = NULL;
@@ -163,7 +175,7 @@ tm_file_entry_free(entry); return NULL; } - g_snprintf(file_name, PATH_MAX, "%s/CVS/Entries", entry->path); + file_name = g_strdup_printf("%s/CVS/Entries", entry->path); if (0 == g_stat(file_name, &s)) { if (S_ISREG(s.st_mode)) @@ -188,6 +200,7 @@ } } } + g_free(file_name); if (NULL != (dir = opendir(entry->path))) { while (NULL != (dir_entry = readdir(dir))) @@ -195,11 +208,11 @@ if ((0 == strcmp(dir_entry->d_name, ".")) || (0 == strcmp(dir_entry->d_name, ".."))) continue; - g_snprintf(file_name, PATH_MAX, "%s/%s", entry->path - , dir_entry->d_name); + file_name = g_strdup_printf("%s/%s", entry->path, dir_entry->d_name); new_entry = tm_file_entry_new(file_name, entry, recurse , file_match, file_unmatch, dir_match, dir_unmatch , ignore_hidden_files, ignore_hidden_dirs); + g_free(file_name); if (new_entry) { if (entries)
Modified: trunk/tagmanager/tm_project.c =================================================================== --- trunk/tagmanager/tm_project.c 2008-10-22 15:35:51 UTC (rev 3141) +++ trunk/tagmanager/tm_project.c 2008-10-22 15:36:16 UTC (rev 3142) @@ -61,7 +61,7 @@ , const char **sources, const char **ignore, gboolean force) { struct stat s; - char path[PATH_MAX]; + char *path;
g_return_val_if_fail((project && dir), FALSE); #ifdef TM_DEBUG @@ -88,7 +88,7 @@ else project->ignore = s_ignore; project->file_list = NULL; - g_snprintf(path, PATH_MAX, "%s/%s", project->dir, TM_FILE_NAME); + path = g_strdup_printf("%s/%s", project->dir, TM_FILE_NAME); if ((0 != g_stat(path, &s)) || (0 == s.st_size)) force = TRUE; if (FALSE == tm_work_object_init(&(project->work_object), @@ -96,14 +96,18 @@ { g_warning("Unable to init project file %s", path); g_free(project->dir); + g_free(path); + g_free(path); return FALSE; } if (! tm_workspace_add_object(TM_WORK_OBJECT(project))) { g_warning("Unable to init project file %s", path); g_free(project->dir); + g_free(path); return FALSE; } + g_free(path); tm_project_open(project, force); if (!project->file_list || (0 == project->file_list->len)) tm_project_autoscan(project);
Modified: trunk/tagmanager/tm_symbol.c =================================================================== --- trunk/tagmanager/tm_symbol.c 2008-10-22 15:35:51 UTC (rev 3141) +++ trunk/tagmanager/tm_symbol.c 2008-10-22 15:36:16 UTC (rev 3142) @@ -12,6 +12,15 @@ #include <string.h> #include "tm_symbol.h"
+ +#if GLIB_CHECK_VERSION (2, 10, 0) +/* Use GSlices if present */ + +#define SYM_NEW(T) ((T) = g_slice_new0(TMSymbol)) +#define SYM_FREE(T) g_slice_free(TMSymbol, (T)) + +#else /* GLib < 2.10 */ + static GMemChunk *sym_mem_chunk = NULL;
#define SYM_NEW(T) {\ @@ -22,6 +31,9 @@
#define SYM_FREE(T) g_mem_chunk_free(sym_mem_chunk, (T))
+#endif /* GLib version check */ + + void tm_symbol_print(TMSymbol *sym, guint level) { guint i;
Modified: trunk/tagmanager/tm_tag.c =================================================================== --- trunk/tagmanager/tm_tag.c 2008-10-22 15:35:51 UTC (rev 3141) +++ trunk/tagmanager/tm_tag.c 2008-10-22 15:36:16 UTC (rev 3142) @@ -17,6 +17,15 @@ #define LIBCTAGS_DEFINED #include "tm_tag.h"
+ +#if GLIB_CHECK_VERSION (2, 10, 0) +/* Use GSlices if present */ + +#define TAG_NEW(T) ((T) = g_slice_new0(TMTag)) +#define TAG_FREE(T) g_slice_free(TMTag, (T)) + +#else /* GLib < 2.10 */ + static GMemChunk *s_tag_mem_chunk = NULL;
#define TAG_NEW(T) {\ @@ -27,6 +36,9 @@
#define TAG_FREE(T) g_mem_chunk_free(s_tag_mem_chunk, (T))
+#endif /* GLib version check */ + + /* Note: To preserve binary compatibility, it is very important that you only *append* to this list ! */ enum
Modified: trunk/tagmanager/tm_work_object.c =================================================================== --- trunk/tagmanager/tm_work_object.c 2008-10-22 15:35:51 UTC (rev 3141) +++ trunk/tagmanager/tm_work_object.c 2008-10-22 15:36:16 UTC (rev 3142) @@ -26,18 +26,33 @@
static GPtrArray *s_work_object_subclasses = NULL;
+ +static int get_path_max(const char *path) +{ +#ifdef PATH_MAX + return PATH_MAX; +#else + int path_max = pathconf(path, _PC_PATH_MAX); + if (path_max <= 0) + path_max = 4096; + return path_max; +#endif +} + + #ifdef G_OS_WIN32 /* realpath implementation for Windows found at http://bugzilla.gnome.org/show_bug.cgi?id=342926 * this one is better than e.g. liberty's lrealpath because this one uses Win32 API and works * with special chars within the filename */ -static char *realpath (const char *pathname, char resolved_path[PATH_MAX]) +static char *realpath (const char *pathname, char *resolved_path) { int size;
if (resolved_path != NULL) { - size = GetFullPathNameA (pathname, PATH_MAX, resolved_path, NULL); - if (size > PATH_MAX) + int path_max = get_path_max(pathname); + size = GetFullPathNameA (pathname, path_max, resolved_path, NULL); + if (size > path_max) return NULL; else return resolved_path; @@ -56,10 +71,11 @@ { if (file_name) { - gchar path[PATH_MAX+1]; - memset(path, '\0', PATH_MAX+1); + gsize len = get_path_max(file_name) + 1; + gchar *path = g_malloc0(len); + realpath(file_name, path); - return g_strdup(path); + return path; } else return NULL;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.