Skip to content

implemented getprogname() for Windows #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2018
Merged

implemented getprogname() for Windows #367

merged 1 commit into from
Jun 23, 2018

Conversation

dplanitzer
Copy link

We use GetModuleFileName() to get the filename of the process. InitOnceExecuteOnce() is used to do this once per app run.

@dplanitzer
Copy link
Author

cc @MadCoder @compnerd

PVOID *lpContext);

char *
getprogname_win32(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move below to aovid having to do a forward.

pleas fix indent, and this function should be called getprogname

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also return const char *

@@ -30,13 +30,19 @@
extern const char *__progname;
#endif /* __ANDROID */

#if defined(_WIN32)
char* getprogname_win32(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char *getprogname_win32

return progname;
}

static BOOL CALLBACK getprogname_init_once_handler(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be written (with tabs indent):

static BOOL CALLBACK
getprogname_init_once_handler(PINIT_ONCE InitOnce, PVOID Parameter,
        PVOID *lpContext)
{
...

progname[0] = '\0';
return TRUE;
} else {
char * filename;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char *filename;

@compnerd
Copy link
Member

I thought that libbsd has an implementation of this function. Can we not just use that?

@adierking
Copy link
Contributor

I thought that libbsd has an implementation of this function.

Not for Windows :(

@dplanitzer
Copy link
Author

The lack of an actually functioning getprogname() implementation In libbsd on Windows is one problem that I see with the libbsd solution. But there are additional problems:

I've identified 3 major road blocks to making libdispatch work on Windows:

a) missing getprogname() implementation

b) missing TAILQ macros

c) missing event backend implementation

libbsd doesn't help with (a) and (c) because it doesn't come with a working getprogname(), kevent nor epoll implementation for Windows. It would only help to solve issue (b). Except that issue (b) is trivial enough to solve in the context of libdispatch itself.

The general problem that I see with adding 3rd party dependencies to Swift in the context of Windows is that:

  1. Windows doesn't come with a package manager, making installation of 3rd party libs less convenient and more time consuming compared to Linux.

  2. A 3rd party dependency may have a compiling, working and tested implementation for POSIX but not necessarily for Windows, forcing someone to sit down and make things work on Windows.

  3. Windows users are not used to the idea that they would have to use a package manager to satisfy dependencies for an application before they will be able to run the app. They are used to downloading an installer that takes care of everything.

  4. Every 3rd party dependency that Swift requires increases the minimum download size of an app that was built with Swift. But the goal should be to keep this minimum runtime size as small as possible.

So I would vastly prefer that libdispatch would just provide its own implementation of the necessary getprogname() and TAILQ macros instead of dragging libbsd in just for that.

@dplanitzer
Copy link
Author

@MadCoder updated patch

Copy link
Contributor

@MadCoder MadCoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only some minor spacing remarks, will merge

progname[0] = '\0';
return TRUE;
} else {
const char * filename;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the space after the star

getprogname(void)
{
(void) InitOnceExecuteOnce(&getprogname_init_once,
getprogname_init_once_handler,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be 2 indents from the base line, and remove the space after the cast.

@@ -30,6 +30,10 @@
extern const char *__progname;
#endif /* __ANDROID */

#if defined(_WIN32)
const char* getprogname(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char *progname (mind the spaces)

@dplanitzer
Copy link
Author

cc @MadCoder fixed spacing

@MadCoder
Copy link
Contributor

@swift-ci please test

@MadCoder MadCoder merged commit 82342ee into swiftlang:master Jun 23, 2018
@dplanitzer dplanitzer deleted the getprogname_for_windows branch June 27, 2018 21:46
ktopley-apple pushed a commit that referenced this pull request Dec 6, 2018
implemented getprogname() for Windows

Signed-off-by: Kim Topley <ktopley@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants