www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - is there any trait to check if variable is __gshared?

reply "ketmar" <nobodyherethismailsucks gmail.com> writes:
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?
Mar 26 2014
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
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.
Mar 26 2014
prev sibling next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Mar 26 2014
parent reply "ketmar" <nobodyherethismailsucks gmail.com> writes:
 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.
Mar 26 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Mar 26 2014
parent reply "ketmar" <nobodyherethismailsucks gmail.com> writes:
 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.
Mar 26 2014
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Mar 26 2014
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
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.
Mar 26 2014
prev sibling parent "ketmar" <nobodyherethismailsucks gmail.com> writes:
 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.
Mar 26 2014
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 26 Mar 2014 11:52:29 -0400, ketmar  
<nobodyherethismailsucks gmail.com> wrote:

 i think that '__gshared' should be part of type info, just like 'shared'  
 is. variable can't be both 'shared' and '__gshared' anyway.
The point of __gshared is it's an override of the type info. There are some cases where you need shared data, but you don't want the type system to know that. Usually it's for "safety checks off" code. -Steve
Mar 26 2014
prev sibling next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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
Mar 26 2014
parent "ketmar" <nobodyherethismailsucks gmail.com> writes:
 Please file this as an enhancement request to bugzilla[1]. 
 Thanks!
just did it: https://d.puremagic.com/issues/show_bug.cgi?id=12475 please check if i did it right and feel free to correct anything. i'm not english-speaking creature and i have no big expirience in doing public requests to big project. tnx.
Mar 26 2014
prev sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 3/26/14, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:
 Please file this as an enhancement request to bugzilla[1]. Thanks!

 [1] : https://d.puremagic.com/issues/enter_bug.cgi?product=D
Ok filed as: https://d.puremagic.com/issues/show_bug.cgi?id=12474
Mar 26 2014
parent reply "ketmar" <nobodyherethismailsucks gmail.com> writes:
 Ok filed
argh. should i (or moderators) close my report as duplicate then?
Mar 26 2014
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 03/26/2014 10:44 AM, ketmar wrote:
 Ok filed
argh. should i (or moderators) close my report as duplicate then?
Yes, please resolve it as a duplicate of the other bug (bug 12474). Ali
Mar 26 2014
parent "ketmar" <nobodyherethismailsucks gmail.com> writes:
 Yes, please resolve it as a duplicate of the other bug (bug 
 12474).
done.
Mar 26 2014