Jump to page: 1 2
Thread overview
[Issue 17868] add pragma(crt_con/destructor[, priority])
Oct 02, 2017
anonymous4
Oct 03, 2017
Martin Nowak
Oct 04, 2017
Rainer Schuetze
Oct 04, 2017
Martin Nowak
[Issue 17868] add pragma(crt_con/destructor)
Oct 05, 2017
Martin Nowak
Oct 05, 2017
Martin Nowak
Oct 06, 2017
Walter Bright
Feb 19, 2020
Mathias LANG
October 02, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=17747

--
October 02, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> ---
This looks terrible (the original feature I mean). Do we really want to add this to D? Can't someone just use a C/C++ compiler?

--
October 03, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

--- Comment #2 from Martin Nowak <code@dawg.eu> ---
(In reply to Steven Schveighoffer from comment #1)
> This looks terrible (the original feature I mean). Do we really want to add this to D? Can't someone just use a C/C++ compiler?

What's terrible about that?

It's necessary for low-level integrations, and as it isn't standardized between C compilers it would be very helpful to make it at least uniformly accessible in D.

It is definitely needed in any case, and obviously gdc/ldc already support it (each with their own syntax). So this enhancement is mainly about dmd and a portable syntax between D compilers.

--
October 04, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

--- Comment #3 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Why is it terrible? Because absolute numbers are used for ordering, with no central determination of who should use what number. D is far more sane on this subject.

Why is it needed? Can't you just use your local C compiler to add the functions? If it's so different and possibly not supported, why do we want D to get involved here?

file.d:
extern(C) void myModulector()
{
   // construct
}

extern(C) void myModuledtor()
{
   // destroy
}

file.c:
constructor (1) // no idea of syntax exactly.
void myModulector();

destructor(1)
void myModuledtor();

--
October 04, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario@gmx.de

--- Comment #4 from Rainer Schuetze <r.sagitario@gmx.de> ---
I guess these construction/destruction mechanisms are a special case of putting function pointers into specific sections of the data segment. I'd prefer to not implement the special case, but the more general https://issues.dlang.org/show_bug.cgi?id=16300

This enables "system programming" by not adding every special case to the compiler as it is done so far.

--
October 04, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

--- Comment #5 from Steven Schveighoffer <schveiguy@yahoo.com> ---
I've changed my mind a bit on this. It's OK to have a pragma that allows stuffing function pointers into a section for compiler purposes, obviously we already have custom pragmas anyway.

But I still am leary of adopting the "integer priority" as an official API for it.

What may be better is:

pragma(ctr_constructor[, custom args])

Where custom args would vary based on what the compiler supports. This way, the ctr_constructor part is standardized, but the custom args obviously depend on support from the specific compiler. Use version statements as needed.

--
October 04, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

--- Comment #6 from Martin Nowak <code@dawg.eu> ---
(In reply to Rainer Schuetze from comment #4)
> This enables "system programming" by not adding every special case to the compiler as it is done so far.

It's a common enough use case to warrant a separate pragma.
Also just adding pointers to a section is not enough, the section needs to be
flagged accordingly for this to work (e.g. on OSX and ELF).
See WIP https://github.com/MartinNowak/dmd/tree/fix17868.

> Where custom args would vary based on what the compiler supports. This way, the ctr_constructor part is standardized, but the custom args obviously depend on support from the specific compiler. Use version statements as needed.

Version statements for pragmas are a pain, you need to add a forwarding function or repeat the implementations.

version (DMD)
   pragma(constructor, 1234)
   void func() { /* repeat */ }
else
   pragma(constructor)
   void func() { /* repeat */ }

Pragma arguments don't expand AliasSeq tuples, so that cannot be used either.

Also priority support is platform/linker dependent, not compiler dependent. IMO simply making it only do sth. on supported platforms is an easy solution to this.

I'd rather drop support for priorities instead of complicating the usage, leaving priorities to GDC/LDC's non-standard intrinsics. We're not that likely to ever need it, but then again it would be cheap to just implement it right away, and someone coming from C/C++ might want to use it.

--
October 05, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|add                         |add
                   |pragma(crt_con/destructor[, |pragma(crt_con/destructor)
                   |priority])                  |

--
October 05, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

--- Comment #7 from Martin Nowak <code@dawg.eu> ---
Let's drop the priority for now, too much hassle to debug OMF and optlink, wasn't supportable on OSX anyhow.

--
October 06, 2017
https://issues.dlang.org/show_bug.cgi?id=17868

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> ---
What's the difference between this and `shared static this()` ?

--
« First   ‹ Prev
1 2