[PATCH] win32: add include/getopt.h with static implementation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] win32: add include/getopt.h with static implementation

tinycc-devel mailing list
Patch is attached. If there are no objections, I'll push it in few days.

From the commit message:

This is a POSIX compliant implementation of getopt (short options).

It passes all tests of gnu getopt in posixly-correct mode, with
additional safeguards against out-of-bounds access (optind, optpos).
Reset is supported via optind or optreset.

For simplicity, the implementation is static at the header, and it
uses stdio.h and string.h (could be avoided with some more code).
_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

0001-win32-add-include-getopt.h-with-static-implementatio.patch (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] win32: add include/getopt.h with static implementation

Michael Matz-4
Hello,

On Fri, 26 Jul 2019, avih via Tinycc-devel wrote:

> Patch is attached. If there are no objections, I'll push it in few days.

But why?  TCC is a compiler, it doesn't generally provide a C library.  
Use newlib or musl or the like for that.

The underlying objection is basically the answer to the question "where
do you stop?"  So we then would have getopt.  Why would we not have nftw,
or regexec/regcompile, or getcwd, or any of the other POSIX functions?

So, please no.


Ciao,
Michael.

>
> From the commit message:
>
> This is a POSIX compliant implementation of getopt (short options).
>
> It passes all tests of gnu getopt in posixly-correct mode, with
> additional safeguards against out-of-bounds access (optind, optpos).
> Reset is supported via optind or optreset.
>
> For simplicity, the implementation is static at the header, and it
> uses stdio.h and string.h (could be avoided with some more code).

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] win32: add include/getopt.h with static implementation

tinycc-devel mailing list
Hi Michael,

> > Patch is attached. If there are no objections, I'll push it in few days.
>
> But why? TCC is a compiler, it doesn't generally provide a C library.
> Use newlib or musl or the like for that.

You know as well as anyone that the Windows build of tcc is more than
that. It's a self contained vertical package which includes everything
required to build many programs without further dependencies. So your
statement, while correct in general, is not so true for Windows.

Most CLI programs process arguments, and getopt is the standard.


> The underlying objection is basically the answer to the question "where
> do you stop?"

Indeed that is the real question, and the only relevant question IMHO,
to which I don't have an answer, but I think it's along the lines of
"small and generally useful, not full blown".

I'm not familiar with TCC guidelines, official or not, to use it with
newlib or musl. If there were such then I'd agree getopt should not be
part of tcc itself, but I think it's not trivial on Windows, and this
patch is very small in the grand scheme of things, and provides a very
useful functionality.


> So, please no.

So do you have a concrete answer to "where do we stop", or guidelines
to use musl or newlib with tcc for windows?

If yes, then the text should be incorporated into the repo IMO.

If no, then I think getopt has good value and low risk/complexity,
which IMHO makes it worth including for the Windows build.

Cheers,
Avi

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] win32: add include/getopt.h with static implementation

Christian Jullien-3
In reply to this post by tinycc-devel mailing list
This my THIRD attempt to reply to this thread since Jul, 26. The two prev. attempts never reached the list.
Hope this one will work and go to the list!

As I said previously (basically the same as Michael):

Hello, I speak only for my name.
Currently, the win32 port serves two purposes:
- provide a tcc ~C90 compiler on windows
- add "some" support to write windows compatible applications

As I'm aware of, the win32 port is not targeted to support POSIX applications.
While getopt is great, it introduces a third category and the gap from POSIX is huge. For example, among others, I would love to have mmap.

For this reason and unless the group decides to add more POSIX support for windows, I don't see the need to add getopt.h on win32.

You're welcome to add a new repository somewhere where you and others can push POSIX extensions for win32 port.

That said, if the group decides that's a good idea, I will not protest but, in this case put getopt.h in a new directory like include/posix to make it clear.

C.

Le : 31 juillet 2019 à 19:21 (GMT +02:00)
De : "avih via Tinycc-devel" <[hidden email]>
À : "[hidden email]" <[hidden email]>, "Michael Matz" <[hidden email]>
Cc : "avih" <[hidden email]>
Objet : Re: [Tinycc-devel] [PATCH] win32: add include/getopt.h with static implementation


Hi Michael,

> > Patch is attached. If there are no objections, I'll push it in few days.
>
> But why? TCC is a compiler, it doesn't generally provide a C library.
> Use newlib or musl or the like for that.

You know as well as anyone that the Windows build of tcc is more than
that. It's a self contained vertical package which includes everything
required to build many programs without further dependencies. So your
statement, while correct in general, is not so true for Windows.

Most CLI programs process arguments, and getopt is the standard.


> The underlying objection is basically the answer to the question "where
> do you stop?"

Indeed that is the real question, and the only relevant question IMHO,
to which I don't have an answer, but I think it's along the lines of
"small and generally useful, not full blown".

I'm not familiar with TCC guidelines, official or not, to use it with
newlib or musl. If there were such then I'd agree getopt should not be
part of tcc itself, but I think it's not trivial on Windows, and this
patch is very small in the grand scheme of things, and provides a very
useful functionality.


> So, please no.

So do you have a concrete answer to "where do we stop", or guidelines
to use musl or newlib with tcc for windows?

If yes, then the text should be incorporated into the repo IMO.

If no, then I think getopt has good value and low risk/complexity,
which IMHO makes it worth including for the Windows build.

Cheers,
Avi



_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] win32: add include/getopt.h with static implementation

tinycc-devel mailing list
> On Wednesday, July 31, 2019, 8:55:18 PM GMT+3, Christian JULLIEN <[hidden email]> wrote:
>
> This my THIRD attempt to reply to this thread since Jul, 26. The
> two prev. attempts never reached the list. Hope this one will work
> and go to the list!

It did, at least to me (but I was addressed). FWIW, I don't recall seeing
prior replies from you, though I also don't see my reply from today at:
https://lists.nongnu.org/archive/html/tinycc-devel/2019-07/index.html
But the fact that you got it probably means it got through. Not sure
what's up with the list manager...

> As I said previously (basically the same as Michael): ...

> As I'm aware of, the win32 port is not targeted to support POSIX
> applications. While getopt is great, it introduces a third category
> and the gap from POSIX is huge. For example, among others, I would
> love to have mmap.

Indeed. Though when I now think about it again, I'd say the definition
of tcc on Windows would be "like MinGW, but smaller, and extensible to
some extent with additional MinGW headers".

FWIW, MinGW does include getopt.h at its root include dir (I assume
implemented at glibc).

> That said, if the group decides that's a good idea, I will not protest
> but, in this case put getopt.h in a new directory like include/posix
> to make it clear.

Hmm... and make it a default include path? otherwise
`#include <getopt.h>` would not work out of the box, which kind of
defeats its purpose and usefullness IMO.

But anyway, indeed the main question to answer first and foremost is
what's the desirable scope of tcc on windows, and once it's answered
clearly, then hopefully the rest would be easy to derive.

Avi

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] win32: add include/getopt.h with static implementation

Christian Jullien-3
In reply to this post by tinycc-devel mailing list
You're right! After defining what tcc is, it will be easier to decide how it evolves.
Let me start a definition:

Tcc is a C compiler implementing a large subset of C90.
It add some gcc and VisualC extensions to ease port from those compilers
It supports different 32 and 64bit processor architectures (mainly x86, x86_64, ARM, Aarch64)
It currently supports mainstream Linux distributions and most recent version of Windows.
On Linux, it uses system includes and libraries that generally come pre-installed. The windows port comes with its own ssubset of includes and libraries to provide a standalone C compiler. A more complete Windows subset is provided by external package shared with migw64.

So, I think we can add without problems:
- C90 missing features
- gcc or VisualC extensions
- more? processor backend
- fixes to support more Linux distribs



Le : 31 juillet 2019 à 20:58 (GMT +02:00)
De : "avih" <[hidden email]>
À : "[hidden email]" <[hidden email]>, "Michael Matz" <[hidden email]>, "Christian JULLIEN" <[hidden email]>
Objet : Re: RE : Re: [Tinycc-devel] [PATCH] win32: add include/getopt.h with static implementation


> On Wednesday, July 31, 2019, 8:55:18 PM GMT+3, Christian JULLIEN <[hidden email]> wrote:
>
> This my THIRD attempt to reply to this thread since Jul, 26. The
> two prev. attempts never reached the list. Hope this one will work
> and go to the list!

It did, at least to me (but I was addressed). FWIW, I don't recall seeing
prior replies from you, though I also don't see my reply from today at:
https://lists.nongnu.org/archive/html/tinycc-devel/2019-07/index.html
But the fact that you got it probably means it got through. Not sure
what's up with the list manager...

> As I said previously (basically the same as Michael): ...

> As I'm aware of, the win32 port is not targeted to support POSIX
> applications. While getopt is great, it introduces a third category
> and the gap from POSIX is huge. For example, among others, I would
> love to have mmap.

Indeed. Though when I now think about it again, I'd say the definition
of tcc on Windows would be "like MinGW, but smaller, and extensible to
some extent with additional MinGW headers".

FWIW, MinGW does include getopt.h at its root include dir (I assume
implemented at glibc).

> That said, if the group decides that's a good idea, I will not protest
> but, in this case put getopt.h in a new directory like include/posix
> to make it clear.

Hmm... and make it a default include path? otherwise
`#include <getopt.h>` would not work out of the box, which kind of
defeats its purpose and usefullness IMO.

But anyway, indeed the main question to answer first and foremost is
what's the desirable scope of tcc on windows, and once it's answered
clearly, then hopefully the rest would be easy to derive.

Avi

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel