Re: setjmp / longjmp

2015-04-27 Thread ketmar via Digitalmars-d-learn
On Sun, 26 Apr 2015 21:45:41 +0100, Stewart Gordon wrote:

 On 26/04/2015 06:56, ketmar wrote:
 snip
 you shouldn't use setjmp/longjmp in D. use exceptions instead.
 something like this:
 snip
 
 True in the general case.  Still, there must be some reason that trying
 it in D causes an AV (even if I disable the GC).  I remain curious about
 what that reason is.

i believe this has something to do with exception frames. but it needs 
further investigation.

signature.asc
Description: PGP signature


Re: std.json questions

2015-04-27 Thread Pierre Krafft via Digitalmars-d-learn

On Saturday, 25 April 2015 at 18:30:33 UTC, Baz wrote:

On Saturday, 25 April 2015 at 09:56:25 UTC, tired_eyes wrote:
I think this is ugly and clunky approach, what is the 
beautiful one?


What you clearly need is a serializer:

look at these:

http://wiki.dlang.org/Libraries_and_Frameworks#Serialization

and also:

https://github.com/search?utf8=✓q=serializer+language%3ADtype=Repositoriesref=searchresults

some of them might have an API to save load an object or a 
struct in a single call.


Also http://code.dlang.org/search?q=json


Re: C++ interface problem

2015-04-27 Thread extrawurst via Digitalmars-d-learn

On Monday, 27 April 2015 at 07:37:23 UTC, Laeeth Isharc wrote:

On Sunday, 26 April 2015 at 15:49:46 UTC, extrawurst wrote:

I hope someone can tell me where my bug is.
I am linking to a dynamic library with C++ interfaces:

```
//alias S = ulong;
struct S
{
 ulong data;
}

extern(C) I getI();

extern(C++) interface I
{
 void foo();
 S bar();
}
```

now the question is why does it crash to access bar() in both 
cases? (using alias aswell as the struct)
The C++ class S is a POD class (it contains only 64bits of 
data and is compiled byte aligned)
The call to bar() from D just crashes on win32, the interface 
works fine on osx 64bit.
Any help would be welcome! Is this even possible to solve ? I 
have no access to the library code so I am not able to build 
the C++ lib with like DMC or something...


Long always 64 bit in D but varies with architecture in C.  See 
here:

http://wiki.dlang.org/Converting_C_.h_Files_to_D_Modules

Core.stdc.config has alias for the C type that you can use in 
place of long.


Thought about that too and tried uint aswell. does not work 
either..


Re: C++ interface problem

2015-04-27 Thread extrawurst via Digitalmars-d-learn

On Monday, 27 April 2015 at 16:24:16 UTC, Benjamin Thaut wrote:

Am 27.04.2015 um 17:16 schrieb extrawurst:

On Monday, 27 April 2015 at 13:14:21 UTC, Benjamin Thaut wrote:

On Monday, 27 April 2015 at 13:08:33 UTC, extrawurst wrote:


Don't ask me about the compiler, like stated above I have no 
control

over the binaries, it is proprietary.


Thats bad to start with.



the C++ class basically is:

```
class S
{
union SteamID_t
   {
   struct SteamIDComponent_t
   {
   uint32m_unAccountID : 32;
   unsigned intm_unAccountInstance : 20;
   unsigned intm_EAccountType : 4;
   EUniversem_EUniverse : 8;
   } m_comp;

   uint64 m_unAll64Bits;
   } m_steamid;
}
```


Where is the fuction declaratiosn for bar? If bar is not 
virtual you
can not use a extern(C++) Interface. If bar is non-virtual 
you have to

use a extern(C++) class.


of course it is all virtual. it is a c++-interface. and 
everything works

fine under osx, that would not be the case otherwise, right ?


It depends on the compiler, I don't know the vtbl layout on 
OSX. Does the class have a virtual destructor? If you would 
post a bit more of S declaration I wouldn't have to guess into 
the blue. Not knowing the compiler your third party library was 
compiled with doesn't really help either.


Kind Regards
Benjamin


here is the shortened version of the returned class CSteamID:
https://gist.github.com/Extrawurst/936f56ceaa87cf287257

this is the shortened interface (no destructors in the rest of 
the code either):

https://gist.github.com/Extrawurst/b20dc5ab84132ecab30d

the method `GetFriendByIndex` is the one crashing on win32.


Re: Weird OSX issue

2015-04-27 Thread Kagamin via Digitalmars-d-learn
On Friday, 24 April 2015 at 18:37:40 UTC, Steven Schveighoffer 
wrote:

_D4core6thread6Thread5startMFZv
_D4core6thread6Thread5startMFNbZC4core6thread6Thread


Maybe it will be better understandable if you demangle these 
symbols?


Re: C++ interface problem

2015-04-27 Thread Laeeth Isharc via Digitalmars-d-learn

On Sunday, 26 April 2015 at 15:49:46 UTC, extrawurst wrote:

I hope someone can tell me where my bug is.
I am linking to a dynamic library with C++ interfaces:

```
//alias S = ulong;
struct S
{
  ulong data;
}

extern(C) I getI();

extern(C++) interface I
{
  void foo();
  S bar();
}
```

now the question is why does it crash to access bar() in both 
cases? (using alias aswell as the struct)
The C++ class S is a POD class (it contains only 64bits of data 
and is compiled byte aligned)
The call to bar() from D just crashes on win32, the interface 
works fine on osx 64bit.
Any help would be welcome! Is this even possible to solve ? I 
have no access to the library code so I am not able to build 
the C++ lib with like DMC or something...


Long always 64 bit in D but varies with architecture in C.  See 
here:

http://wiki.dlang.org/Converting_C_.h_Files_to_D_Modules

Core.stdc.config has alias for the C type that you can use in 
place of long.


Re: C++ interface problem

2015-04-27 Thread Benjamin Thaut via Digitalmars-d-learn

On Monday, 27 April 2015 at 13:08:33 UTC, extrawurst wrote:


Don't ask me about the compiler, like stated above I have no 
control over the binaries, it is proprietary.


Thats bad to start with.



the C++ class basically is:

```
class S
{
union SteamID_t
{
struct SteamIDComponent_t
{
uint32  m_unAccountID : 32;
unsigned intm_unAccountInstance : 20;
unsigned intm_EAccountType : 4;
EUniverse   m_EUniverse : 8;
} m_comp;

uint64 m_unAll64Bits;
} m_steamid;
}
```


Where is the fuction declaratiosn for bar? If bar is not virtual 
you can not use a extern(C++) Interface. If bar is non-virtual 
you have to use a extern(C++) class.


Re: C++ interface problem

2015-04-27 Thread Benjamin Thaut via Digitalmars-d-learn

On Monday, 27 April 2015 at 11:00:23 UTC, extrawurst wrote:


Thought about that too and tried uint aswell. does not work 
either..


Please post the c++ declarations as well. Which c++ compiler do 
you use for win32? (dmc or msvc)


Kind Regards
Benjamin


Re: C++ interface problem

2015-04-27 Thread extrawurst via Digitalmars-d-learn

On Monday, 27 April 2015 at 12:56:57 UTC, Benjamin Thaut wrote:

On Monday, 27 April 2015 at 11:00:23 UTC, extrawurst wrote:


Thought about that too and tried uint aswell. does not work 
either..


Please post the c++ declarations as well. Which c++ compiler do 
you use for win32? (dmc or msvc)


Kind Regards
Benjamin


Don't ask me about the compiler, like stated above I have no 
control over the binaries, it is proprietary.


the C++ class basically is:

```
class S
{
union SteamID_t
{
struct SteamIDComponent_t
{
uint32  m_unAccountID : 32;
unsigned intm_unAccountInstance : 20;
unsigned intm_EAccountType : 4;
EUniverse   m_EUniverse : 8;
} m_comp;

uint64 m_unAll64Bits;
} m_steamid;
}
```


Re: @disable assignment of [] literal?

2015-04-27 Thread Kagamin via Digitalmars-d-learn

Use a different type to match empty slice instead of void[]?

struct ArrayWrapper(T)
{
T t;

this(T t)
{
assert(t !is null);
}

@disable this(typeof(null));
@disable this(ArrayWrapper[]); //should match []

typeof(this) opAssign(T val)
{
assert(t !is null);
this.t = val;

return this;
}

@disable typeof(this) opAssign(typeof(null));
@disable typeof(this) opAssign(ArrayWrapper[]); //should 
match []

}


Re: Weird OSX issue

2015-04-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 4/25/15 3:07 AM, Dan Olson wrote:

Jacob Carlborg d...@me.com writes:


On 2015-04-24 20:37, Steven Schveighoffer wrote:


So am I going crazy? Or is dmd doing things differently depending on
where its environment is? Any compiler gurus out there understand why
the symbol is different?

I don't want to file a bug with this, because it seems dependent on
installation location, would possibly not be reproducible.


I can't reproduce this with DMD from DVM (compiler is installed in the
user home directory).


I have lots of version laying around and they all worked fine on the
posted code.

But maybe a clue here...

$ ~/dmd2.066.0/osx/bin/dmd mod1.d
$ nm mod1.o | grep start
  U _D4core6thread6Thread5startMFZv
$ dmd mod1.d
$ nm mod1.o | grep start
  U _D4core6thread6Thread5startMFNbZC4core6thread6Thread

--- a/src/core/thread.d
+++ b/src/core/thread.d
@@ -587,7 +587,7 @@ class Thread
   * Throws:
   *  ThreadException if the thread fails to start.
   */
-final Thread start()
+final Thread start() nothrow
  in
  {
  assert( !next  !prev );

I wonder if dmd -v will show where its picking up stuff.



Thank you. It is something I missed. Lo and behold:

dmd -v mod1.d:

...

importcore.thread   (/usr/share/dmd/src/druntime/import/core/thread.di)

...

~/Downloads/dmd2/osx/bin/dmd -v mod1.d:

...

importcore.thread 
(/Users/steves/Downloads/dmd2/osx/bin/../../src/druntime/import/core/thread.d)


...

Hm... thread.di vs thread.d (and I didn't notice before because all the 
other imports were .d, I just glanced over that detail).


And so, let's see here:

ls -l /usr/share/dmd/src/druntime/import/core/thread.*

-rw-rw-r--   1 steves  staff  157781 Mar 24 10:44 thread.d
-rw-rw-r--+  1 steves  staff   31382 Feb 24  2014 thread.di

Hey, looky there :)

So, looking at time machine (love that feature), I found that when I 
installed 2.066, back in October, we had switched to using thread.d 
instead of thread.di. But the installer did not erase the old thread.di.


BTW, found this: https://github.com/D-Programming-Language/druntime/pull/865

So I think the issue here is that the pkg installer on OSX does not 
clean up the target directory if it already exists (or at least 
purposely remove thread.di). Will look into fixing that. At least now, 
it works properly, thanks (did a rm -rf /usr/share/dmd and reinstall).


-Steve



Re: C++ interface problem

2015-04-27 Thread extrawurst via Digitalmars-d-learn

On Monday, 27 April 2015 at 13:14:21 UTC, Benjamin Thaut wrote:

On Monday, 27 April 2015 at 13:08:33 UTC, extrawurst wrote:


Don't ask me about the compiler, like stated above I have no 
control over the binaries, it is proprietary.


Thats bad to start with.



the C++ class basically is:

```
class S
{
union SteamID_t
{
struct SteamIDComponent_t
{
uint32  m_unAccountID : 32;
unsigned intm_unAccountInstance : 20;
unsigned intm_EAccountType : 4;
EUniverse   m_EUniverse : 8;
} m_comp;

uint64 m_unAll64Bits;
} m_steamid;
}
```


Where is the fuction declaratiosn for bar? If bar is not 
virtual you can not use a extern(C++) Interface. If bar is 
non-virtual you have to use a extern(C++) class.


of course it is all virtual. it is a c++-interface. and 
everything works fine under osx, that would not be the case 
otherwise, right ?


Re: C++ interface problem

2015-04-27 Thread Benjamin Thaut via Digitalmars-d-learn

Am 27.04.2015 um 17:16 schrieb extrawurst:

On Monday, 27 April 2015 at 13:14:21 UTC, Benjamin Thaut wrote:

On Monday, 27 April 2015 at 13:08:33 UTC, extrawurst wrote:


Don't ask me about the compiler, like stated above I have no control
over the binaries, it is proprietary.


Thats bad to start with.



the C++ class basically is:

```
class S
{
union SteamID_t
{
struct SteamIDComponent_t
{
uint32m_unAccountID : 32;
unsigned intm_unAccountInstance : 20;
unsigned intm_EAccountType : 4;
EUniversem_EUniverse : 8;
} m_comp;

uint64 m_unAll64Bits;
} m_steamid;
}
```


Where is the fuction declaratiosn for bar? If bar is not virtual you
can not use a extern(C++) Interface. If bar is non-virtual you have to
use a extern(C++) class.


of course it is all virtual. it is a c++-interface. and everything works
fine under osx, that would not be the case otherwise, right ?


It depends on the compiler, I don't know the vtbl layout on OSX. Does 
the class have a virtual destructor? If you would post a bit more of S 
declaration I wouldn't have to guess into the blue. Not knowing the 
compiler your third party library was compiled with doesn't really help 
either.


Kind Regards
Benjamin


Re: @disable assignment of [] literal?

2015-04-27 Thread Meta via Digitalmars-d-learn

On Monday, 27 April 2015 at 14:30:26 UTC, Kagamin wrote:

Use a different type to match empty slice instead of void[]?

struct ArrayWrapper(T)
{
T t;

this(T t)
{
assert(t !is null);
}

@disable this(typeof(null));
@disable this(ArrayWrapper[]); //should match []

typeof(this) opAssign(T val)
{
assert(t !is null);
this.t = val;

return this;
}

@disable typeof(this) opAssign(typeof(null));
@disable typeof(this) opAssign(ArrayWrapper[]); //should 
match []

}


That won't work because I want to catch the [] literal, which is 
of type void[] and not ArrayWrapper[].


Reducing source code: weak+alias values in array

2015-04-27 Thread Jens Bauer via Digitalmars-d-learn
I was wondering if there's a way to reduce my bulky startup files 
a bit.


If using the GNU Assembler (GAS), then one can reduce the code 
using a macro like this:



/* The EXC macro makes a weak+alias for the
 * symbol 'value', then it stores the value in memory: */
.macro  EXC value,defaultValue
.ifnb   \defaultValue
.weakref\value,\defaultValue
.else
.weakref\value,defaultExceptionVector
.endif
.4byte  \value
.endm


/* The exception vector now looks quite simple: */
isr_vector:
.4byte  _stack
EXC Reset_Handler,defaultResetHandler
EXC NMI_Handler
EXC HardFault_Handler
EXC MemManage_Handler
EXC BusFault_Handler
EXC UsageFault_Handler
.4byte  0
.4byte  0
.4byte  0
.4byte  0
EXC SVC_Handler
EXC DebugMon_Handler
.4byte  0
EXC PendSV_Handler
EXC SysTick_Handler

An example on one of my bulky startup files:
https://github.com/jens-gpio/MCU/blob/master/startup/stm/stm32f439_startup.d

I was thinking about alias (Tuple) or similar, but I'm not sure 
it would work if not declaring the label weak+alias in advance. 
Any thoughts ?
(Other suggestions on how to reduce the source code size are also 
welcome).