Package: ffindex / 0.9.9.9-2

basename.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Author: Laszlo Kajan <lkajan@rostlab.org>
Author: Elso Andras <elso.andras@gmail.com>
Subject: 40000000 bug and basename
 [Laszlo Kajan]
 The default value 40000000 for FFINDEX_MAX_INDEX_ENTRIES_DEFAULT is too high for a machine with 2G (or less) RAM.
 Bug fixed by introducing an environment variable FFINDEX_MAX_INDEX_ENTRIES to control the value.
 [Elso Andras]
 using basename for usage print, this helps help2man if a packager is using it
Forwarded: yes

--- a/src/ffindex_build.c
+++ b/src/ffindex_build.c
@@ -42,6 +42,8 @@ void usage(char *program_name)
                     "\t\t\tAnother append operations can be done without sorting.\n"
                     "\t-v\t\tprint version and other info then exit\n"
                     "\t-h\t\tdisplay this help message\n"
+                    "ENVIRONMENT\n"
+                    "\tFFINDEX_MAX_INDEX_ENTRIES - allocate memory for this number of entries\n"
                     "\nEXAMPLES:\n"
                     "\tCreate a new ffindex containing all files from the \"bar/\" directory containing\n"
                     "\tsay myfile1.txt, myfile2.txt and sort (-s) it so that e.g. ffindex_get can use it.\n"
@@ -55,7 +57,7 @@ void usage(char *program_name)
                     "\tdefault maximum entries %d.\n"
                     "\tThis can be changed in the sources.\n"
                     FFINDEX_COPYRIGHT,
-                    program_name, MAX_FILENAME_LIST_FILES, FFINDEX_MAX_ENTRY_NAME_LENTH, FFINDEX_MAX_INDEX_ENTRIES_DEFAULT);
+                    basename(program_name), MAX_FILENAME_LIST_FILES, FFINDEX_MAX_ENTRY_NAME_LENTH, FFINDEX_MAX_INDEX_ENTRIES_DEFAULT);
 }
 
 int main(int argn, char **argv)
--- a/src/ffindex_from_fasta.c
+++ b/src/ffindex_from_fasta.c
@@ -36,8 +36,10 @@ void usage(char *program_name)
                     "\t-i\tuse identifier as name (you probably want -s too)\n"
                     "\t-n\tuse incremental number as id (default)\n"
                     "\t-v\tprint version\n"
+                    "ENVIRONMENT\n"
+                    "\tFFINDEX_MAX_INDEX_ENTRIES - allocate memory for this number of entries\n"
                     FFINDEX_COPYRIGHT,
-                    program_name);
+                    basename(program_name));
 }
 
 int main(int argn, char **argv)
@@ -140,4 +142,4 @@ int main(int argn, char **argv)
   return err;
 }
 
-/* vim: ts=2 sw=2 et: */
+// vim: ts=2 sw=2 et:
--- a/src/ffindex.h
+++ b/src/ffindex.h
@@ -24,6 +24,8 @@
 #define FFINDEX_VERSION 0.999
 #define FFINDEX_COPYRIGHT "\nDesigned and implemented by Andreas Hauser <andy@splashground.de>.\n"
 
+// lkajan: the below makes a default allocation over 2G. malloc in ffindex.c:225 fails on a machine with 'only' 2G of RAM.
+// lkajan: let the default remain 80000000, and let the actual value be controlled by the env var FFINDEX_MAX_INDEX_ENTRIES wherever FFINDEX_MAX_INDEX_ENTRIES_DEFAULT is used.
 #define FFINDEX_MAX_INDEX_ENTRIES_DEFAULT 80000000
 #define FFINDEX_MAX_ENTRY_NAME_LENTH 63
 
@@ -76,6 +78,8 @@ int ffindex_index_close(ffindex_index_t*
 /* return *out_data_file, *out_index_file, out_offset. */
 int ffindex_index_open(char *data_filename, char *index_filename, char* mode, FILE **out_data_file, FILE **out_index_file, size_t *out_offset);
 
+inline size_t ffindex_max_index_entries(){ char *FMIE = getenv("FFINDEX_MAX_INDEX_ENTRIES"); if( FMIE ) { return atol( FMIE ); } else { return FFINDEX_MAX_INDEX_ENTRIES_DEFAULT; } }
+
 int ffindex_insert_memory(FILE *data_file, FILE *index_file, size_t *offset, char *from_start, size_t from_length, char *name);
 
 int ffindex_insert_file(FILE *data_file, FILE *index_file, size_t *offset, const char *path, char *name);
--- a/src/ffindex_get.c
+++ b/src/ffindex_get.c
@@ -29,8 +29,10 @@ void usage(char* program_name)
                     "\t-f FILE\t\tfile containing a list of file names, one per line\n"
                     "\t-h\t\tdisplay this help message\n"
                     "\t-n\t\tuse index of entry instead of entry name\n"
+                    "ENVIRONMENT\n"
+                    "\tFFINDEX_MAX_INDEX_ENTRIES - allocate memory for this number of entries\n"
                     FFINDEX_COPYRIGHT,
-                    program_name);
+                    basename(program_name));
 }
 
 int main(int argn, char **argv)
--- a/src/ffindex_modify.c
+++ b/src/ffindex_modify.c
@@ -41,7 +41,7 @@ void usage(char *program_name)
                     "\tTo clean up the data file after unlinking insert it to an new one:\n"
                     "\tffindex_build -as cleaned.ffdata cleaned.ffindex -d foo.ffdata -i foo.ffindex\n"
                     FFINDEX_COPYRIGHT,
-                    program_name, MAX_FILENAME_LIST_FILES, program_name);
+                    basename(program_name), MAX_FILENAME_LIST_FILES, basename(program_name));
 }
 
 int main(int argn, char **argv)
--- a/src/ffindex.c
+++ b/src/ffindex.c
@@ -373,7 +373,7 @@ ffindex_entry_t* ffindex_bsearch_get_ent
 ffindex_index_t* ffindex_index_parse(FILE *index_file, size_t num_max_entries)
 {
   if(num_max_entries == 0)
-    num_max_entries = FFINDEX_MAX_INDEX_ENTRIES_DEFAULT;
+    num_max_entries = ffindex_max_index_entries();
 
   size_t nbytes = sizeof(ffindex_index_t) + (sizeof(ffindex_entry_t) * num_max_entries);
   ffindex_index_t *index = (ffindex_index_t *)mmap(0, nbytes, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);