This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Loading cygwin1.dll from MinGW and MSVC


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]