Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 12, 2010 [phobos] phobos commit, revision 1837 | ||||
---|---|---|---|---|
| ||||
phobos commit, revision 1837 user: Don Clugston msg: Some functions need to be public. Revealed by patch to bug 314. http://www.dsource.org/projects/phobos/changeset/1837 |
August 12, 2010 [phobos] phobos commit, revision 1837 | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsource.org | Le 2010-08-12 ? 4:37, dsource.org a ?crit : > phobos commit, revision 1837 > > > user: Don Clugston > > msg: > Some functions need to be public. Revealed by patch to bug 314. > > http://www.dsource.org/projects/phobos/changeset/1837 From the changelog: --- public // These functions are accessed by mixed-in code { import std.c.stdlib : calloc, realloc, free; import core.exception : onOutOfMemoryError; } --- Is it reasonable to have to import publicly everything you need for every mixin in every module? Won't this pollute the global namespace? And won't this break a selective import like this one? --- import std.signal : Signal; --- Perhaps import could be added directly in the template instead: --- template Signal(T1...) { import std.c.stdlib : calloc, realloc, free; import core.exception : onOutOfMemoryError; ... } --- This is a working but undocumented feature (perhaps it's an accident that it works), see: <http://d.puremagic.com/issues/show_bug.cgi?id=2179> From my limited testing however, it seems that this import always import the symbols publicly. :-( -- Michel Fortin michel.fortin at michelf.com http://michelf.com/ |
August 12, 2010 [phobos] phobos commit, revision 1837 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | Or the template mixin could use fully qualified names.
On 12 aug 2010, at 13:04, Michel Fortin wrote:
> Le 2010-08-12 ? 4:37, dsource.org a ?crit :
>
>> phobos commit, revision 1837
>>
>>
>> user: Don Clugston
>>
>> msg:
>> Some functions need to be public. Revealed by patch to bug 314.
>>
>> http://www.dsource.org/projects/phobos/changeset/1837
>
> From the changelog:
>
> ---
> public // These functions are accessed by mixed-in code
> {
> import std.c.stdlib : calloc, realloc, free;
> import core.exception : onOutOfMemoryError;
> }
> ---
>
> Is it reasonable to have to import publicly everything you need for every mixin in every module? Won't this pollute the global namespace? And won't this break a selective import like this one?
>
> ---
> import std.signal : Signal;
> ---
>
> Perhaps import could be added directly in the template instead:
>
> ---
> template Signal(T1...)
> {
> import std.c.stdlib : calloc, realloc, free;
> import core.exception : onOutOfMemoryError;
> ...
> }
> ---
>
> This is a working but undocumented feature (perhaps it's an accident that it works), see: <http://d.puremagic.com/issues/show_bug.cgi?id=2179>
>
> From my limited testing however, it seems that this import always import the symbols publicly. :-(
>
> --
> Michel Fortin
> michel.fortin at michelf.com
> http://michelf.com/
>
>
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
August 12, 2010 [phobos] phobos commit, revision 1837 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | On 12 August 2010 13:04, Michel Fortin <michel.fortin at michelf.com> wrote: > Is it reasonable to have to import publicly everything you need for every mixin in every module? Won't this pollute the global namespace? And won't this break a selective import like this one? > > --- > import std.signal : Signal; > --- Yes. > Perhaps import could be added directly in the template instead: > --- > template Signal(T1...) > { > ? ? ? ?import std.c.stdlib : calloc, realloc, free; > ? ? ? ?import core.exception : onOutOfMemoryError; > ? ? ? ?... > } > --- > > This is a working but undocumented feature (perhaps it's an accident that it works), see: <http://d.puremagic.com/issues/show_bug.cgi?id=2179> That's a great idea! I forgot about that. > > From my limited testing however, it seems that this import always import the symbols publicly. :-( Not exactly. It only imports it into the scope where the mixin is. It's exactly as if you'd aliased the symbol (alias std.c.stdlib.calloc calloc;) as a member of that scope. class Input { mixin Signal!(int, int) click; mixin Signal!(char) keyDown; void buzz() { auto zzz = calloc(int.sizeof, 6); // This is OK } } void fuzz() { auto zzz = calloc(int.sizeof, 6); // Fails: calloc was not imported into this scope. } But I think that's still too much namespace pollution. A static import is much cleaner, though unfortunately it imports into the whole module, not just the local scope. I'll check in a fix. |
August 12, 2010 [phobos] phobos commit, revision 1837 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob | On 12 August 2010 13:11, Jacob <doob at me.com> wrote:
> Or the template mixin could use fully qualified names.
That works only because bug 314 hasn't been fixed.
|
August 12, 2010 [phobos] phobos commit, revision 1837 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | Oh, I didn't know that.
On 12 aug 2010, at 14:59, Don Clugston wrote:
> On 12 August 2010 13:11, Jacob <doob at me.com> wrote:
>> Or the template mixin could use fully qualified names.
>
> That works only because bug 314 hasn't been fixed.
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
Copyright © 1999-2021 by the D Language Foundation