[Patch] Loading cygwin1.dll from MinGW and MSVC

Christopher Faylor cgf-no-personal-reply-please@cygwin.com
Mon Jun 6 20:42:00 GMT 2005


On Mon, Jun 06, 2005 at 04:09:13PM -0400, Igor Pechtchanski wrote:
>I wonder if this could, perhaps, be made more transparent to the
>programmer, by introducing a static marker, for example.  Something like
>(again, modulo typos):
>
>  void
>  initialize_cygwin (int (*main) (int argc, char **argv), int argc, char **argv)
>  {
>    static int was_here = 0;
>    if (was_here) return;
>    was_here = 1;
>    struct _cygtls dummy_tls;
>    char *newargv = alloca (argc * sizeof (argv[0]));
>    for (char **av = newargv; *av; av++)
>      *av = *argv++;
>    *av = NULL;
>    initialize_main_tls (&dummy_tls);
>    cygwin_dll_init ();
>    exit (main (argc, newargv));
>  }
>
>Then main() could look like this:
>
>  int
>  main (int argc, char **argv)
>  {
>    initialize_cygwin (main, argc, argv);  /* could return */
>
>    /* do main stuff */
>    .
>    .
>    .
>    exit or return here
>  }
>
>Or is there a reason for main() to be thread-safe or for
>initialize_cygwin() to be called twice?

I guess you could do it that way.  It would look more transparent to the
end user if you did.  You'd still have to make it clear that this has to
happen first thing in the main() function or you could suffer problems
with automatic initialization or constructors.

cgf



More information about the Cygwin-patches mailing list