Add interface function gedcom_init(), to avoid problem with GCONV_PATH
authorPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 17 Mar 2002 13:04:19 +0000 (13:04 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 17 Mar 2002 13:04:19 +0000 (13:04 +0000)
modification (see note in encoding.c).

gedcom/encoding.c
gedcom/encoding.h
gedcom/multilex.c

index 9e4e9199561ca0778914aedf7ed89dff227d7628..d97f63c99aec7a971be936f73b92dd45125d4003 100644 (file)
@@ -102,6 +102,25 @@ void cleanup_encodings()
 /* Let function be called before main() */
 void update_gconv_search_path() __attribute__ ((constructor));
 
 /* Let function be called before main() */
 void update_gconv_search_path() __attribute__ ((constructor));
 
+/* Note:
+
+   The environment variable GCONV_PATH has to be adjusted before the very
+   first call of iconv_open.  For the most general case, it means that we
+   have to make our own constructor here (in case some of the other library
+   constructors would use iconv_open).
+
+   However, it looks like a change of an environment variable in a constructor
+   doesn't always survive until the main() function.  This is the case if
+   the environment variable is a new one, for which there was no room yet
+   in the initial environment.  The initial environment is located on the
+   stack, but when variables are added, it is moved to the heap (to be able
+   to grow).  Now, the main function takes again the one from the stack, not
+   from the heap, so changes are lost.
+
+   For this, the function below will also be called in gedcom_init(), which
+   needs to be called as early as possible in the program.
+ */
+
 void update_gconv_search_path()
 {
   char *gconv_path;
 void update_gconv_search_path()
 {
   char *gconv_path;
index 6623e61d3b8e15a7f8463eb9d45677408567aea6..9eb40bae81ae20fbf8b19d3d47385ee25bf57a9c 100644 (file)
@@ -37,5 +37,6 @@ char* to_internal(char* str, size_t len,
                  char* output_buffer, size_t out_len);
 void init_encodings();
 void set_encoding_width(ENCODING enc);
                  char* output_buffer, size_t out_len);
 void init_encodings();
 void set_encoding_width(ENCODING enc);
+void update_gconv_search_path();
 
 #endif /* __ENCODING_H */
 
 #endif /* __ENCODING_H */
index 42b9f5000613e95c959b32e226e89578e1a2fe4a..727c17959cb8f7aa03a6c9040ecf415e91d0cedf 100644 (file)
@@ -105,6 +105,11 @@ int determine_encoding(FILE* f)
   }
 }
 
   }
 }
 
+void gedcom_init()
+{
+  update_gconv_search_path();
+}
+
 int gedcom_parse_file(char* file_name)
 {
   ENCODING enc;
 int gedcom_parse_file(char* file_name)
 {
   ENCODING enc;