Thread overview
sort and shared
Jan 21, 2011
Adam Conner-Sax
Jan 21, 2011
Adam Conner-Sax
Jan 24, 2011
Adam Conner-Sax
January 21, 2011
The following code:

import std.algorithm;

class Foo  {
private:
  int id_;
public:
  shared int id() const { return id_; }
}


static bool compare(in shared(Foo) a, in shared(Foo) b)
{
  return (a.id() < b.id());
}

void main()
{
  shared Foo a,b,c;
  shared(Foo)[] uFooArray = [a,b,c];
  sort!(compare)(uFooArray);
}

fails to compile with

usr/local/src/dmd2/src/phobos/std/conv.d(295): Error: function
object.Object.toString () is not callable using argument types ()


whereas if I just take all the shared away it compiles fine.  I imagine that this is somewhere to do with a string function being called on an element of the array and then there's no shared version of that method.

Is there a fix? Or a different way to call sort?  I can cast away shared for the sort but since in the actual application I have a reason for it, that's a bit worrisome.

Thanks!

Adam


Adam
January 21, 2011
On Thu, 20 Jan 2011 21:14:06 -0500, Adam Conner-Sax <adam_conner_sax@yahoo.com> wrote:

> The following code:
>
> import std.algorithm;
>
> class Foo  {
> private:
>   int id_;
> public:
>   shared int id() const { return id_; }
> }
>
>
> static bool compare(in shared(Foo) a, in shared(Foo) b)
> {
>   return (a.id() < b.id());
> }
>
> void main()
> {
>   shared Foo a,b,c;
>   shared(Foo)[] uFooArray = [a,b,c];
>   sort!(compare)(uFooArray);
> }
>
> fails to compile with
>
> usr/local/src/dmd2/src/phobos/std/conv.d(295): Error: function
> object.Object.toString () is not callable using argument types ()
>
>
> whereas if I just take all the shared away it compiles fine.  I imagine that
> this is somewhere to do with a string function being called on an element of
> the array and then there's no shared version of that method.
>
> Is there a fix? Or a different way to call sort?  I can cast away shared for
> the sort but since in the actual application I have a reason for it, that's a
> bit worrisome.
>
> Thanks!

This should be fixed in svn.  I encountered a very similar issue, and implemented a fix.  This will be fixed in the next release:

http://d.puremagic.com/issues/show_bug.cgi?id=4901

-Steve
January 21, 2011
Thanks!

I tried to apply that patch and rebuild phobos (I changed the file, remade libphobos2.a, put it in /usr/local/lib).  That worked but I still get my error. I might have done the applying or rebuilding wrong though, especially since once I did that, even with the casting away of shared, I get some linker errors.

I'll wait for the next release, I guess, and in the meantime cast away "shared" and be very afraid.

Is there any way to fix it otherwise by making the elts printable?

Adam
January 21, 2011
On Fri, 21 Jan 2011 10:04:56 -0500, Adam Conner-Sax <adam_conner_sax@yahoo.com> wrote:

> Thanks!
>
> I tried to apply that patch and rebuild phobos (I changed the file, remade
> libphobos2.a, put it in /usr/local/lib).  That worked but I still get my error. I
> might have done the applying or rebuilding wrong though, especially since once I
> did that, even with the casting away of shared, I get some linker errors.
>
> I'll wait for the next release, I guess, and in the meantime cast away "shared"
> and be very afraid.
>
> Is there any way to fix it otherwise by making the elts printable?

Hm... it's a simple patch.  Maybe there is something different I'm not seeing.

I'll see if I can reproduce with my build.

-Steve
January 21, 2011
On Fri, 21 Jan 2011 10:09:18 -0500, Steven Schveighoffer <schveiguy@yahoo.com> wrote:

> On Fri, 21 Jan 2011 10:04:56 -0500, Adam Conner-Sax <adam_conner_sax@yahoo.com> wrote:
>
>> Thanks!
>>
>> I tried to apply that patch and rebuild phobos (I changed the file, remade
>> libphobos2.a, put it in /usr/local/lib).  That worked but I still get my error. I
>> might have done the applying or rebuilding wrong though, especially since once I
>> did that, even with the casting away of shared, I get some linker errors.
>>
>> I'll wait for the next release, I guess, and in the meantime cast away "shared"
>> and be very afraid.
>>
>> Is there any way to fix it otherwise by making the elts printable?
>
> Hm... it's a simple patch.  Maybe there is something different I'm not seeing.
>
> I'll see if I can reproduce with my build.

Compiled your code and ran it without error (well, got a segfault because the elements are all null), so I think maybe the patch wasn't applied properly on your machine.

I guess all I can recommend is either to get phobos from svn or wait for the next release.

-Steve
January 24, 2011
Thanks.

I'll wait for now since (gulp!) casting away shared just for the sort works  and I'm not sure what I'm doing wrong with the patching.

Adam