Jump to page: 1 2
Thread overview
is there any trait to check if variable is __gshared?
Mar 26, 2014
ketmar
Mar 26, 2014
Adam D. Ruppe
Mar 26, 2014
bearophile
Mar 26, 2014
ketmar
Mar 26, 2014
bearophile
Mar 26, 2014
ketmar
Mar 26, 2014
bearophile
Mar 26, 2014
Adam D. Ruppe
Mar 26, 2014
ketmar
Mar 26, 2014
Andrej Mitrovic
Mar 26, 2014
ketmar
Mar 26, 2014
Andrej Mitrovic
Mar 26, 2014
ketmar
Mar 26, 2014
Ali Çehreli
Mar 26, 2014
ketmar
March 26, 2014
is there any trait to check if variable is __gshared? typeof()
for '__gshared int' returns just 'int', whereas for 'shared int'
it returns 'shared(int)'. can i check for __gshared storage class
somehow?
March 26, 2014
I don't think so. Since __gshared isn't part of the type (unlike shared), you can't check for it with is(typeof()) and .stringof is only giving me the name.
March 26, 2014
ketmar:
> is there any trait to check if variable is __gshared?

There isn't. It could be added to D if there's a significant reason. Why do you need it?

Bye,
bearophile
March 26, 2014
> Why do you need it?
i need to iterate over all module variables and 'register' (read: generate some wrappers) only for shared and __gshared ones, avoiding TLS.

sure i can write a big WARNING in documentation, but i want to check it in compile time too.

that's kind of 'in-game command console' module and i want to be able to write:
mixin(CMDCON_REGISTER_VARS!modulename);
which will iterate over all module vars and 'register' in console those which names stars with 'cvar_' and which are either 'shared' or '__gshared'.

sorry for the messy explanation.
March 26, 2014
ketmar:

> i need to iterate over all module variables and 'register' (read: generate some wrappers) only for shared and __gshared ones, avoiding TLS.

But why do you need to avoid the thread-local ones while crating your wrappers? (If your need is real, you can ask for the trait in the main D newsgroup).

Bye,
bearophile
March 26, 2014
> But why do you need to avoid the thread-local ones while crating your wrappers?
'cause i need only 'old-style' globals in my console. there is no guarantee from which thread console command will be executed, and i don't really need TLS vars in it. that is the 'tech requirement'.

> (If your need is real, you can ask for the trait in the main D newsgroup).
alas, i can't really explain why this is necessary for everyone (to be included in language). except that if we have such powerfull metaprogramming abilities we should be able to access any piece of 'type definition' (ok, technically __gshared is an attribute, i think) info that compiler knows.

i think that '__gshared' should be part of type info, just like 'shared' is. variable can't be both 'shared' and '__gshared' anyway.

i'll think about asking that though.
March 26, 2014
ketmar:

> 'cause i need only 'old-style' globals in my console. there is no guarantee from which thread console command will be executed, and i don't really need TLS vars in it. that is the 'tech requirement'.

Is the -vtls compiler switch enough?

Bye,
bearophile
March 26, 2014
On Wednesday, 26 March 2014 at 15:58:32 UTC, bearophile wrote:
> Is the -vtls compiler switch enough?

The JSON output with -X will also tell you if it is gshared.

But in both cases you'd have to run the compiler twice and read the output instead of just getting the info at compile time from inside D.
March 26, 2014
> Is the -vtls compiler switch enough?
it's calling the external utility. i can use full blown D parser than. what i want is to be able to do that thing in compile time, just with metaprogramming.
March 26, 2014
On 3/26/14, ketmar <nobodyherethismailsucks@gmail.com> wrote:
> is there any trait to check if variable is __gshared? typeof()
> for '__gshared int' returns just 'int', whereas for 'shared int'
> it returns 'shared(int)'. can i check for __gshared storage class
> somehow?

Please file this as an enhancement request to bugzilla[1]. Thanks!

[1] : https://d.puremagic.com/issues/enter_bug.cgi?product=D
« First   ‹ Prev
1 2