Thread overview
[phobos] phobos commit, revision 1837
Aug 12, 2010
dsource.org
Aug 12, 2010
Michel Fortin
Aug 12, 2010
Jacob
Aug 12, 2010
Don Clugston
Aug 12, 2010
Jacob
Aug 12, 2010
Don Clugston
August 12, 2010
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
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
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
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
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
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