libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

rewrite try_dlopen (1)


From: Ralf Wildenhues
Subject: rewrite try_dlopen (1)
Date: Mon, 4 Oct 2004 01:13:17 +0200
User-agent: Mutt/1.5.6+20040722i

This is the first step at rewriting try_dlopen:
It moves the code which parses the .la file out of
try_dlopen in to a separate function.

I have deliberately not changed the function code
except for necessary pointer changes, so that the
change is easier to check.  I find the parsing code
ugly, but a rewrite should come later.  Also, I
think try_dlopen shall shrink further.

Regards,
Ralf


2004-10-03  Ralf Wildenhues <address@hidden>

        * libltdl/ltdl.c (try_dlopen): Move .la file parsing
        part.. (parse_dotla_file): ..here.  Adjust.


Index: libltdl/ltdl.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/ltdl.c,v
retrieving revision 1.217
diff -u -r1.217 ltdl.c
--- libltdl/ltdl.c      1 Oct 2004 10:24:18 -0000       1.217
+++ libltdl/ltdl.c      3 Oct 2004 23:10:37 -0000
@@ -913,6 +913,117 @@
   return 0;
 }
 
+/* Read the .la file FILE. */
+static int
+parse_dotla_file(FILE *file, char **dlname, char **libdir, char **deplibs,
+    char **old_name, int *installed)
+{
+  int          errors = 0;
+  size_t       line_len = LT_FILENAME_MAX;
+  char *       line = MALLOC (char, line_len);
+
+  if (!line)
+    {
+      LT__SETERROR (FILE_NOT_FOUND);
+      return 1;
+    }
+
+  while (!feof (file))
+    {
+      if (!fgets (line, (int) line_len, file))
+       {
+         break;
+       }
+
+      /* Handle the case where we occasionally need to read a line
+        that is longer than the initial buffer size.  */
+      while ((line[LT_STRLEN(line) -1] != '\n') && (!feof (file)))
+       {
+         line = REALLOC (char, line, line_len *2);
+         if (!line)
+           {
+             fclose (file);
+             ++errors;
+             goto cleanup;
+           }
+         if (!fgets (&line[line_len -1], (int) line_len +1, file))
+           {
+             break;
+           }
+         line_len *= 2;
+       }
+
+      if (line[0] == '\n' || line[0] == '#')
+       {
+         continue;
+       }
+
+#undef  STR_DLNAME
+#define STR_DLNAME     "dlname="
+      if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0)
+       {
+         errors += trim (dlname, &line[sizeof (STR_DLNAME) - 1]);
+       }
+
+#undef  STR_OLD_LIBRARY
+#define STR_OLD_LIBRARY        "old_library="
+      else if (strncmp (line, STR_OLD_LIBRARY,
+           sizeof (STR_OLD_LIBRARY) - 1) == 0)
+       {
+         errors += trim (old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]);
+       }
+#undef  STR_LIBDIR
+#define STR_LIBDIR     "libdir="
+      else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0)
+       {
+         errors += trim (libdir, &line[sizeof(STR_LIBDIR) - 1]);
+       }
+
+#undef  STR_DL_DEPLIBS
+#define STR_DL_DEPLIBS "dependency_libs="
+      else if (strncmp (line, STR_DL_DEPLIBS,
+           sizeof (STR_DL_DEPLIBS) - 1) == 0)
+       {
+         errors += trim (deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]);
+       }
+      else if (streq (line, "installed=yes\n"))
+       {
+         *installed = 1;
+       }
+      else if (streq (line, "installed=no\n"))
+       {
+         *installed = 0;
+       }
+
+#undef  STR_LIBRARY_NAMES
+#define STR_LIBRARY_NAMES "library_names="
+      else if (!*dlname && strncmp (line, STR_LIBRARY_NAMES,
+           sizeof (STR_LIBRARY_NAMES) - 1) == 0)
+       {
+         char *last_libname;
+         errors += trim (dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]);
+         if (!errors
+             && *dlname
+             && (last_libname = strrchr (*dlname, ' ')) != 0)
+           {
+             last_libname = lt__strdup (last_libname + 1);
+             if (!last_libname)
+               {
+                 ++errors;
+                 goto cleanup;
+               }
+             MEMREASSIGN (*dlname, last_libname);
+           }
+       }
+
+      if (errors)
+       return 1;
+    }
+cleanup:
+  return errors;
+}
+
+/* Try to open FILENAME as a module. */
 static int
 try_dlopen (lt_dlhandle *phandle, const char *filename)
 {
@@ -1025,8 +1136,6 @@
       char *   old_name = 0;
       char *   libdir   = 0;
       char *   deplibs  = 0;
-      char *    line    = 0;
-      size_t   line_len;
 
       /* if we can't find the installed flag, it is probably an
         installed libtool archive, produced with an old version
@@ -1082,110 +1191,12 @@
          goto cleanup;
        }
 
-      line_len = LT_FILENAME_MAX;
-      line = MALLOC (char, line_len);
-      if (!line)
-       {
-         fclose (file);
-         ++errors;
-         goto cleanup;
-       }
-
       /* read the .la file */
-      while (!feof (file))
-       {
-         if (!fgets (line, (int) line_len, file))
-           {
-             break;
-           }
-
-         /* Handle the case where we occasionally need to read a line
-            that is longer than the initial buffer size.  */
-         while ((line[LT_STRLEN(line) -1] != '\n') && (!feof (file)))
-           {
-             line = REALLOC (char, line, line_len *2);
-             if (!line)
-               {
-                 fclose (file);
-                 ++errors;
-                 goto cleanup;
-               }
-             if (!fgets (&line[line_len -1], (int) line_len +1, file))
-               {
-                 break;
-               }
-             line_len *= 2;
-           }
-
-         if (line[0] == '\n' || line[0] == '#')
-           {
-             continue;
-           }
-
-#undef  STR_DLNAME
-#define STR_DLNAME     "dlname="
-         if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0)
-           {
-             errors += trim (&dlname, &line[sizeof (STR_DLNAME) - 1]);
-           }
-
-#undef  STR_OLD_LIBRARY
-#define STR_OLD_LIBRARY        "old_library="
-         else if (strncmp (line, STR_OLD_LIBRARY,
-                           sizeof (STR_OLD_LIBRARY) - 1) == 0)
-           {
-             errors += trim (&old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]);
-           }
-#undef  STR_LIBDIR
-#define STR_LIBDIR     "libdir="
-         else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0)
-           {
-             errors += trim (&libdir, &line[sizeof(STR_LIBDIR) - 1]);
-           }
-
-#undef  STR_DL_DEPLIBS
-#define STR_DL_DEPLIBS "dependency_libs="
-         else if (strncmp (line, STR_DL_DEPLIBS,
-                           sizeof (STR_DL_DEPLIBS) - 1) == 0)
-           {
-             errors += trim (&deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]);
-           }
-         else if (streq (line, "installed=yes\n"))
-           {
-             installed = 1;
-           }
-         else if (streq (line, "installed=no\n"))
-           {
-             installed = 0;
-           }
-
-#undef  STR_LIBRARY_NAMES
-#define STR_LIBRARY_NAMES "library_names="
-         else if (! dlname && strncmp (line, STR_LIBRARY_NAMES,
-                                       sizeof (STR_LIBRARY_NAMES) - 1) == 0)
-           {
-             char *last_libname;
-             errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]);
-             if (!errors
-                 && dlname
-                 && (last_libname = strrchr (dlname, ' ')) != 0)
-               {
-                 last_libname = lt__strdup (last_libname + 1);
-                 if (!last_libname)
-                   {
-                     ++errors;
-                     goto cleanup;
-                   }
-                 MEMREASSIGN (dlname, last_libname);
-               }
-           }
-
-         if (errors)
-           break;
-       }
+      if (parse_dotla_file(file, &dlname, &libdir, &deplibs,
+           &old_name, &installed) != 0)
+       errors++;
 
       fclose (file);
-      FREE (line);
 
       /* allocate the handle */
       *phandle = (lt_dlhandle) lt__zalloc (sizeof (lt__handle));




reply via email to

[Prev in Thread] Current Thread [Next in Thread]