On 2012-07-27, trijezdci <
trij...@gmail.com> wrote:
>> IMHO it goes against the spirit of the M2 language
>> drawing such runtime constructs into the standard.
>
> I think you misunderstood. There is nothing runtime here. It says "to
> statically check". This means, if the pragma is present in the scope of
> the foreign function definition and you make a call to the foreign
> function, then either of two things would happen:
I do understand that. I mean to allow it for general use.
> - if the format string in your call is not a compile-time expression, the
> - compiler would report that.
For the "pedantics", that should be switchable again, preferably cmdline (I
use pedantic functionality sometimes to get to know the strengths and
weaknesses of a large body of source, just like turning on runtime checks)
> It is very much in the spirit of Wirthian languages to do as much as
> possible during compile-time to increase safety at runtime. In this
> respect such a feature would be within the spirit of the language.
That is. Maybe I should be more direct to state what I would prefer:
It is just not in the Wirthian spirit to call such constructs from the main
modules. It should be confined to the implementation of an lowlevel
interfacing module only, and such symbol should not be exportable to non
lowlevel modules.
IOW you can only call a proper M2 version of an open array type, which can
then in turn try to transform it to printf. This avoids litering unsafe
calls all through the mainmodule, and reduces the number of calls (AND their
usage) confining such constructs to a handful of lowlevel module's
implementations.
> I'd agree that it would be against the style of the language to add proper
> syntax for such a feature, but we are talking about an optional pragma,
> that is to say, a recommendation to implementors "if you feel strong
> enough about checking this type of dangerous FFI call, then here is how
> you should do it".
Avoid having to many of them in the first place. I think the time can be
better spent making that possible. Automated checking only makes sense if
you assume it will be a regularly used construct in general code, instead of
an isolated feature to interface some more ackward parts of the system.
>> it will probably break at the first new GNU extension to the syntax, so
>> it means you will have to have some setting to turn checking off,
>> otherwise the standard might already be broken by design before the first
>> compiler comes out.
>
> No, that wouldn't be the case for a couple of reasons.
>
> First, any extensions that might be added are extremely unlikely to break
> existing format strings.
> Therefore, any existing calls that the compiler
> verified and cleared as a result of the pragma would continue to compile
> fine even after the format specifier syntax had been extended. The only
> impact at that point would be that if you wanted to make use of the
> additional format syntax in your foreign function calls, then the compiler
> would likely report a mismatch.
I was more thinking that the first use of such an extension (like an extra
value before or after the letter) would only leave an user the choice to
turn off the checking. Most will do so globally.
(added later: I see the grammar specification feature fixes that, see below
for comment on that)
> Second, the whole reason why we have been thinking about a grammar or
> regular expression based pragma is that it is under user control what the
> compiler should check for in the format string. So, if extensions are
> added to the format string syntax of a C function you want to call, and
> you would like to make use of this additional format string syntax, then
> you would want to update the grammar or regular expression definitions in
> the pragma to teach the compiler the additional syntax.
Scary, and a terrible burden on the compiler builder (for doubtful benefit
IMHO), but it does fix the above concern so that the checking feature at
least is not broken by default as I was scared for. I hope you make it an
optional part to enforce this.
>> Not having a safe construct will only force people
>> to use the dirty one, also for non C interfacing
>
> No, because support for unsafe variadic parameters is limited to foreign
> function interfaces only.
True.
> If you want to implement a variadic procedure in Modula-2, then you have
> to use a type safe variadic formal parameter in the procedure header.
> Type safe variadic formal parameters can be used for foreign function
> interfaces as well, but they do not cover the printf use case, so if you
> want to call printf style C functions then the only way to do so is via
> the unsafe facility which must be imported from SYSTEM btw.
>
> hope this clarifies
The worst bits are defanged yes. Still don't like it, or consider it an
elegant solution, but so be it.