Re: performance issues with SIMD function

2023-11-04 Thread Bogdan via Digitalmars-d-learn

On Friday, 3 November 2023 at 15:32:08 UTC, Sergey wrote:

On Friday, 3 November 2023 at 15:11:31 UTC, Bogdan wrote:

Hi everyone,

I was playing around with the intel-intrinsics library, trying 
to improve the speed of a simple area function. I could not 
see any performance improvements from the non-SIMD 
implementation. The SIMD version is a little bit slower even 
with LDC2 and --o3. Can anyone help me to understand what I am 
missing?


Thanks!
Bogdan


In your SIMD algorithm has not so many gain from using SIMD. 
The length of the loop is the same.
Also probably compiler applying some optimizations in regular 
versions, that doing almost the same.


I think it was from the way I was running the benchmark:

```d
  
  auto begin = Clock.currTime;
  foreach (i; 0..100_000) {
res1 = areaMeters(polygon);
  }
  writeln("No SIMD ", Clock.currTime - begin);

  
  begin = Clock.currTime;
  foreach (i; 0..100_000) {
res2 = areaMetersSimd2(polygon);
  }
  writeln("SIMD", Clock.currTime - begin);

```

gives me:
```
  No SIMD 1 sec, 80 ms, 765 μs, and 1 hnsec
  SIMD1 sec, 120 ms, 765 μs, and 1 hnsec
```


```d
  
  auto begin = Clock.currTime;
  res1 = areaMeters(polygon);
  writeln("No SIMD ", Clock.currTime - begin);

  
  begin = Clock.currTime;
  res2 = areaMetersSimd2(polygon);
  writeln("SIMD", Clock.currTime - begin);

```


gives me:
```
  No SIMD 19 μs and 3 hnsecs
  SIMD16 μs and 8 hnsecs
```






performance issues with SIMD function

2023-11-03 Thread Bogdan via Digitalmars-d-learn

Hi everyone,

I was playing around with the intel-intrinsics library, trying to 
improve the speed of a simple area function. I could not see any 
performance improvements from the non-SIMD implementation. The 
SIMD version is a little bit slower even with LDC2 and --o3. Can 
anyone help me to understand what I am missing?



```D


///
double areaMeters(const double[2][] coordinates) @safe pure {
  if (coordinates.length <= 2) {
return 0;
  }

  ///
  double rad(const double a) pure @safe @nogc {
return a * PI / 180;
  }

  double result = 0;
  enum radius = 6_378_137;

  foreach(i; 0 .. coordinates.length - 1) {
auto p1 = coordinates[i];
auto p2 = coordinates[i + 1];

result += rad(p2[0] - p1[0]) * (2 + sin(rad(p1[1])) + 
sin(rad(p2[1])));

  }

  return result * radius * radius / 2;
}

double areaMetersSimd(const double[2][] coordinates) @safe pure {
  if (coordinates.length <= 2) {
return 0;
  }

  __m128d pi_2 = cast(__m128d)[PI, PI];
  __m128d pattern180_2 = cast(__m128d)[180., 180.];

  double result = 0;
  enum radius = 6_378_137;

  foreach(i; 0 .. coordinates.length - 1) {
auto p1 = _mm_div_pd(_mm_mul_pd(cast(__m128d) coordinates[i], 
pi_2), pattern180_2);
auto p2 = _mm_div_pd(_mm_mul_pd(cast(__m128d) coordinates[i + 
1], pi_2), pattern180_2);

auto diff = _mm_sub_sd(p1, p2);

result += diff[0] * (2 + sin(p1[1]) + sin(p2[1]));
  }

  return result * radius * radius / 2;
}


```


CPU info:
```
cat /proc/cpuinfo
processor   : 0
vendor_id   : AuthenticAMD
cpu family  : 23
model   : 113
model name  : AMD Ryzen 7 3800X 8-Core Processor
stepping: 0
microcode   : 0x8701030
cpu MHz : 3741.289
cache size  : 512 KB
physical id : 0
siblings: 16
core id : 0
cpu cores   : 8
apicid  : 0
initial apicid  : 0
fpu : yes
fpu_exception   : yes
cpuid level : 16
wp  : yes
flags   : fpu vme de pse tsc msr pae mce cx8 apic sep 
mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall 
nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl 
nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq 
monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes 
xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy 
abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce 
topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb 
cat_l3 cdp_l3 hw_pstate ssbd mba ibpb stibp vmmcall fsgsbase bmi1 
avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni 
xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total 
cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt 
lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid 
decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif 
v_spec_ctrl umip rdpid overflow_recov succor smca sev sev_es
bugs: sysret_ss_attrs spectre_v1 spectre_v2 
spec_store_bypass retbleed smt_rsb srso

bogomips: 7784.95
TLB size: 3072 4K pages
clflush size: 64
cache_alignment : 64
address sizes   : 43 bits physical, 48 bits virtual
power management: ts ttp tm hwpstate cpb eff_freq_ro [13] [14]
```

Thanks!
Bogdan


std.process execute always returns -11 on linuxkit kernel

2022-02-25 Thread Bogdan via Digitalmars-d-learn

Hi everyone,

I am trying to build dub in a docker container on a Mac M1 and 
unfortunately all processes started with the `execute` function 
from `std.process` always fails with -11. Because of this the 
`build.d` or `dub` are unusable on this environment.


The container that I am using is stared like this:

docker run -it  --platform linux/amd64 --volume \`pwd\`:/app 
ubuntu:21.04


and it does not matter if I use ldc or dmd, this makes me think 
that is an issue with the kernel itself.



So far I was able to find out that the segfault happens in the 
child process while calling the poll function:


https://github.com/dlang/phobos/blob/master/std/process.d#L1069

Does anyone know how I could debug/fix this issue?

Bogdan


Debugging linker errors

2021-08-08 Thread Bogdan via Digitalmars-d-learn

Hi,

I tried to update my server from dmd v2.096.1 to v2.097 and I 
started getting this linker error:


```
Linking...
/usr/bin/ld: 
.dub/build/executable-ssl11-debug-linux.posix-x86_64-dmd_v2.097.2-beta.1-7651E13F70724FF6B1F8D8B61B1AEABD/gis-collective-api.o: in function `_D3std6traits__T6fqnSymS5crateZ11adjustIdentFAyaZQe':
/usr/include/dmd/phobos/std/traits.d:737: undefined reference to 
`_D3std9algorithm9searching__T8skipOverZ__TQnTAyaTQeZQxFNaNfKQpQrZb'
/usr/bin/ld: /usr/include/dmd/phobos/std/traits.d:737: undefined 
reference to 
`_D3std9algorithm9searching__T8skipOverZ__TQnTAyaTQeZQxFNaNfKQpQrZb'

collect2: error: ld returned 1 exit status
Error: linker exited with status 1
/usr/bin/dmd failed with exit code 1.
```

What's the best aproach on debugging linker errors with DMD on 
linux?



Best,
Bogdan


Re: Checking for manifest constants

2021-03-06 Thread bogdan via Digitalmars-d-learn
On Friday, 5 March 2021 at 14:42:07 UTC, Petar Kirov [ZombineDev] 
wrote:

On Friday, 5 March 2021 at 08:23:09 UTC, Bogdan wrote:

[...]


I suggest this:

enum globalConfig = 32;
int globalValue = 22;
immutable globaImmutablelValue = 22;

enum isManifestConstant(alias symbol) =
  __traits(compiles, { enum e = symbol; }) &&
  !__traits(compiles, { const ptr =  });

unittest {
  struct Test {
enum config = 3;
int value = 2;
  }

  static assert(isManifestConstant!(Test.config));
  static assert(isManifestConstant!(mixin("Test.config")));

  static assert(isManifestConstant!(globalConfig));
  static assert(isManifestConstant!(mixin("globalConfig")));

  static assert(!isManifestConstant!(Test.value));
  static assert(!isManifestConstant!(mixin("Test.value")));

  static assert(!isManifestConstant!(globalValue));
  static assert(!isManifestConstant!(mixin("globalValue")));

  static assert(!isManifestConstant!(globaImmutablelValue));
  static 
assert(!isManifestConstant!(mixin("globaImmutablelValue")));

}


Thanks!

I ended using this:
```

/// Check if a member is manifest constant
enum isManifestConstant(T, string name) = 
isManifestConstant!(__traits(getMember, T, name));


/// ditto
enum isManifestConstant(alias symbol) = __traits(compiles, { enum 
e = symbol; }) &&

  !__traits(compiles, { const ptr =  });

```

It looks like mixin does not work well with protected/private 
members


Checking for manifest constants

2021-03-05 Thread Bogdan via Digitalmars-d-learn
I was using a trick with dmd to check for manifest constants 
which worked until dmd v2.094. Yesterday I tried it on the latest 
compiler and it failed with:



source/introspection/manifestConstant.d(37,28): Error: need this 
for name of type string
source/introspection/type.d(156,13): Error: value of this is not 
known at compile time


any ideas how to fix it? or, is it a bug with dmd?

```

/// Check if a member is manifest constant
bool isManifestConstant(T, string name)() {
  mixin(`return is(typeof(T.init.` ~ name ~ `)) && 
!is(typeof(` ~ name ~ `));`);

}

/// ditto
bool isManifestConstant(alias T)() {
  return is(typeof(T)) && !is(typeof());
}

enum globalConfig = 32;
int globalValue = 22;

unittest {
  struct Test {
enum config = 3;
int value = 2;
  }

  static assert(isManifestConstant!(Test.config));
  static assert(isManifestConstant!(Test, "config"));
  static assert(isManifestConstant!(globalConfig));

  static assert(!isManifestConstant!(Test.value));
  static assert(!isManifestConstant!(Test, "value"));
  static assert(!isManifestConstant!(globalValue));
}

void main() {}


```




dub git dependencies

2021-02-28 Thread bogdan via Digitalmars-d-learn

Hi,

I remember that I saw a while ago some PRs related to adding a 
git url for a dependency in the dub's package.json. I looked 
today in the docs and I can't find any info about this. What is 
the progress for this feature? Can we use it already?


https://dub.pm/package-format-json.html#version-syntax


Bogdan


Re: initialize float4 (core.simd)

2019-10-06 Thread Bogdan via Digitalmars-d-learn

On Sunday, 6 October 2019 at 11:53:29 UTC, NaN wrote:


You should probably have a look at this...

https://github.com/AuburnSounds/intel-intrinsics


Thanks, that looks quite useful.
Also, it seems that I need to use either LDC or GDC instead of 
DMD. :)


Re: initialize float4 (core.simd)

2019-10-06 Thread Bogdan via Digitalmars-d-learn

On Saturday, 21 September 2019 at 14:31:15 UTC, Stefan Koch wrote:

On Saturday, 21 September 2019 at 13:42:09 UTC, Bogdan wrote:

Well, this seems to be working:


float[4] doSimd(float[4] values, float delta)
{
  float4 v_delta = delta;

  float4 v_values = __simd(XMM.ADDPS,
   __simd(XMM.LODAPS, values[0]),
   v_delta);

  return [v_values[0], v_values[1],v_values[2],v_values[3]];
}


Not sure if it's correct though.


float4 x;
float x1, x2, x3, x4;
x[0] = x1;
x[1] = x2;
x[2] = x3;
x[3] = x4;


Thank you! That also seems to be working.
Turns out that using this method for drawing a rectangle is about 
twice as slow than a naive implementation, so I'm almost 
certainly doing something silly/wrong. :)


Re: initialize float4 (core.simd)

2019-09-21 Thread Bogdan via Digitalmars-d-learn

Well, this seems to be working:


float[4] doSimd(float[4] values, float delta)
{
  float4 v_delta = delta;

  float4 v_values = __simd(XMM.ADDPS,
   __simd(XMM.LODAPS, values[0]),
   v_delta);

  return [v_values[0], v_values[1],v_values[2],v_values[3]];
}


Not sure if it's correct though.


Re: initialize float4 (core.simd)

2019-09-21 Thread Bogdan via Digitalmars-d-learn

Here's a cleaned up version:

```
import std.stdio;
import core.simd;

void main()
{
  float[4] values = [1.0f, 2.0f, 3.0f, 4.0f];
  float delta = 15.0f;

  writeln(doSimd(values, delta));

}

float[4] doSimd(float[4] values, float delta)
{
  float4 v_delta = delta;
  float4 v_values = values;

  v_values = __simd(XMM.ADDPS, v_values, v_delta);

  return [v_values[0], v_values[1],v_values[2],v_values[3]];
}
```

The problem is with initializing v_values.


initialize float4 (core.simd)

2019-09-21 Thread Bogdan via Digitalmars-d-learn
I'm trying to understand how to use the `core.simd` 
functionality, and I'm having trouble initializing a float4 
vector.


Here's my example code:

```
import std.stdio;
import core.simd;

void main()
{
  float[4] values = [1.0f, 2.0f, 3.0f, 4.0f];
  float delta = 15.0f;

  writeln(doSimd(values, delta));

}

float[4] doSimd(float[4] values, float delta)
{
  float4 v_delta = delta;
  float4 v_values = values;

  // ... do SIMD ...

  return [v_delta[0], v_delta[0],v_delta[0],v_delta[0]];
}
```

Compilation is failing with the following error:

```
source/app.d(16,21): Error: cannot implicitly convert expression 
values of type float[4] to __vector(float[4])

dmd failed with exit code 1.
```
How do you initialize a float4 with some useful data?




Re: Creating a RedBlackTree

2019-05-15 Thread Bogdan via Digitalmars-d-learn

On Wednesday, 15 May 2019 at 13:19:36 UTC, drug wrote:

You can use predicate for this purpose:
```
auto rbt = redBlackTree!((a, b) => a.ID < b.ID, KeyController);
```

https://run.dlang.io/is/CNRTQf


Even better, thank you!


Re: Creating a RedBlackTree

2019-05-15 Thread Bogdan via Digitalmars-d-learn

On Wednesday, 15 May 2019 at 13:15:50 UTC, Stefan Koch wrote:

Key controller cannot be compared by less
which is why it fails, give it an opCmp and it'll work.


Works fine, thank you! For some reason, I thought that this 
template uses references:

```
enum KeyID: uint
{
KEY_A,
KEY_S,
KEY_D,
KEY_W
}

struct KeyController
{
KeyID ID;
bool isDown;

	int opCmp(ref const KeyController other) const {return this.ID - 
other.ID;}

}

void main()
{
KeyController[] monitoredKeys = [{KeyID.KEY_A}];

auto rbt = redBlackTree!KeyController;

rbt.insert(monitoredKeys);
writeln(rbt);
monitoredKeys[0].isDown = true;
writeln(rbt);
}
```

Output:
```
RedBlackTree([const(KeyController)(KEY_A, false)])
RedBlackTree([const(KeyController)(KEY_A, false)])
```






Creating a RedBlackTree

2019-05-15 Thread Bogdan via Digitalmars-d-learn
I don't have any experience with using templates. Is it possible 
to create a RB tree containing structs, where the nodes are 
ordered by one struct member?


```
import std.stdio;
import std.container;

enum KeyID: uint
{
KEY_A,
KEY_S,
KEY_D,
KEY_W
}

struct KeyController
{
KeyID ID;
bool isDown;
}


void main()
{
auto rbt = redBlackTree!KeyController;
}

```

When I run this I get a compile error:
```
Error: template instance 
`std.container.rbtree.RedBlackTree!(KeyController)` does not 
match template declaration RedBlackTree(T, alias less = "a < b", 
bool allowDuplicates = false) if 
(is(typeof(binaryFun!less(T.init, T.init

```



Re: Compile time mapping

2019-05-12 Thread Bogdan via Digitalmars-d-learn

On Sunday, 12 May 2019 at 17:53:56 UTC, Bastiaan Veelo wrote:
If I understand your question correctly, you have two enums of 
equal length, and you want to convert members across enums 
according to their position, right?


My question was very vague, sorry about that.

In my use case I'd like to map SDL2 keyboard scan codes to my own 
game input keyboard codes. The two enums would look something 
like this:


```
enum SDL_Scancode
{
SDL_SCANCODE_UNKNOWN = 0,
SDL_SCANCODE_A = 4,
SDL_SCANCODE_B = 5,
SDL_SCANCODE_C = 6,
SDL_SCANCODE_D = 7,
}

enum MY_Scancode
{
  KEY_A,
  KEY_B,
  KEY_C,
  KEY_D,
}
```

The two enums are not of equal length, so in the end I just 
decided to create an immutable array of type My_Scancode[] where 
the index is an SDL_Scancode and the value is the corresponding 
MY_Scancode enum member. I'm ok with using some memory for this, 
as long as it's as fast as possible.


Compile time mapping

2019-05-11 Thread Bogdan via Digitalmars-d-learn
What would be the most straight-forward way of mapping the 
members of an enum to the members of another enum (one-to-one 
mapping) at compile time?


Re: Consume binary files

2018-03-10 Thread Bogdan via Digitalmars-d-learn
On Saturday, 10 March 2018 at 18:49:48 UTC, Jonathan M Davis 
wrote:

Check out

https://dlang.org/phobos/std_bitmanip.html#peek 
https://dlang.org/phobos/std_bitmanip.html#read


They can be used to read integral values from a range of 
ubytes. You can use either std.file.read or std.stdio.File to 
read from the file and than those functions from std.bitmanip 
to convert the ubytes to integrals. std.file.read would be the 
easiest to use, since it just gives you a single dynamic array 
to deal with, but it does mean reading in the entire file at 
once.


- Jonathan M Davis


Yes, thank you! That's much better, even if the source buffer 
gets consumed.


Re: Consume binary files

2018-03-10 Thread Bogdan via Digitalmars-d-learn
... I accidentally posted that before it was complete because I 
kept pressing TAB in order to indent ...


Anyway, I'd like to know if there exists such a thing as

```
int a = stream.ReadInt32();
```


Consume binary files

2018-03-10 Thread Bogdan via Digitalmars-d-learn
I'm working on a pet project which involves reading various 
structure types, or just multi-byte values (uin32_t, uint16_t, 
etc) from files, or just from ubyte arrays.


Here's how I've been dealing with some of these situations so far:

```
/// Helper structure used to read each of the file 
descriptors in a HOG file

struct HogFileDescriptor
{
align(1):
char[13] fileName;
int fileSize;
}

ubyte[HogFileDescriptor.sizeof] buffer;

File f = File(filename, "r");

// while bytes left in file
f.rawRead(buffer);
hfd = cast(HogFileDescriptor*) buffer.ptr;



Do forum posts use any markup language?

2018-03-10 Thread Bogdan via Digitalmars-d-learn
I'd like to distinguish between regular text and code, maybe have 
quotes, etc.


Re: weird exception on windows

2018-01-05 Thread Szabo Bogdan via Digitalmars-d-learn

On Monday, 18 December 2017 at 22:49:30 UTC, unleashy wrote:
On Friday, 15 December 2017 at 21:56:48 UTC, Steven 
Schveighoffer wrote:

On 12/15/17 10:08 AM, Kagamin wrote:

Maybe this https://issues.dlang.org/show_bug.cgi?id=18084


Thanks for looking into this. I created a PR to fix.

Szabo, can you please try with this patch and see if it fixes 
your issue?


https://github.com/dlang/phobos/pull/5932

-Steve


I created the original issue in Szabo's post. I applied your 
fix, but nothing changed—the test program still crashes with 
the same exception :/


What gives?


It looks like this fix does not work:
https://github.com/dlang/phobos/pull/5932

Does anyone know how to debug this crash?





Re: weird exception on windows

2017-12-18 Thread Szabo Bogdan via Digitalmars-d-learn
On Saturday, 16 December 2017 at 12:01:49 UTC, Steven 
Schveighoffer wrote:

On 12/16/17 5:12 AM, bauss wrote:
On Saturday, 16 December 2017 at 08:07:30 UTC, Szabo Bogdan 
wrote:
On Friday, 15 December 2017 at 21:56:48 UTC, Steven 
Schveighoffer wrote:

On 12/15/17 10:08 AM, Kagamin wrote:

Maybe this https://issues.dlang.org/show_bug.cgi?id=18084


Thanks for looking into this. I created a PR to fix.

Szabo, can you please try with this patch and see if it 
fixes your issue?


https://github.com/dlang/phobos/pull/5932

-Steve


I have installed DMD 2.77.1 and I can not find the patched 
file in the phobos folder... should I try this by building 
the compiler?


It seams that I can not build phobos without compiling dmd.. 
or maybe I don't know how...


Just go and do the changes manually in your local phobos 
folder, wherever you have DMD installed, since you can't build 
phobos or dmd.


Yes, this won't get into the release for a while. So please do 
this manually (just copy the file changed by the pull over the 
existing one).


It's something that doesn't need to be compiled into the phobos 
library, as it's a misrepresentation of the actual object when 
you compile with unittests, so there is no reason to recompile 
phobos.


-Steve


I'm actually a linux and a mac user... this issue happens on a 
windows ci machine at work. I tried to update the file and 
compile phobos with that change, and I don't know how to make it 
work...


`
C:\D\dmd2\src\phobos>make -f win64.mak
cd etc\c\zlib
make -f win64.mak MODEL=64 zlib64.lib "CC=\"\Program Files 
(x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\cl""\"" 
"LIB=\"\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\bin\amd64\lib""\"" "VCDIR=\Program Files (x86)\Microsoft 
Visual Studio 10.0\VC"
"\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\bin\amd64\cl" /c /O2 /nologo /I"\Program Files 
(x86)\Microsoft Visual Studio 10.0\VC\INCLUDE" /Zl adler32.c
Error: '\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\bin\amd64\cl' not found

`

I don't know where I can find a 64bit toolchain for vs2010... I 
was expecting that dmd uses a newer compiler on windows...


I guess that the best approach for me is to wait the next beta 
release of dmd and try it then...


Thanks for the support!



Re: weird exception on windows

2017-12-16 Thread Szabo Bogdan via Digitalmars-d-learn

On Friday, 15 December 2017 at 13:56:41 UTC, Kagamin wrote:

You said tests fail?

class SourceResult
{
private const
{
string file;
size_t line;
}
	this(string fileName = __FILE__, size_t line = __LINE__, 
size_t range = 6) nothrow

{
this.file = fileName;
this.line = line;
if (!fileName.exists)
{
return;
}
}
}

unittest
{
auto result = new SourceResult("test/values.d", 26);
auto msg = result.file;
}

Does this fail too?


I can not reproduce the crash with this example...



Re: weird exception on windows

2017-12-16 Thread Szabo Bogdan via Digitalmars-d-learn
On Friday, 15 December 2017 at 21:56:48 UTC, Steven Schveighoffer 
wrote:

On 12/15/17 10:08 AM, Kagamin wrote:

Maybe this https://issues.dlang.org/show_bug.cgi?id=18084


Thanks for looking into this. I created a PR to fix.

Szabo, can you please try with this patch and see if it fixes 
your issue?


https://github.com/dlang/phobos/pull/5932

-Steve


I have installed DMD 2.77.1 and I can not find the patched file 
in the phobos folder... should I try this by building the 
compiler?


It seams that I can not build phobos without compiling dmd.. or 
maybe I don't know how...


Re: weird exception on windows

2017-12-15 Thread Szabo Bogdan via Digitalmars-d-learn

On Friday, 15 December 2017 at 09:24:07 UTC, Kagamin wrote:

Try printf debugging in case argument is invalid.


ah .. ok ...

I tried to debug the issue and it looks like the filename is 
valid and there is no null value.


I am thinking that the value is destroyed before it reach the 
`GetFileAttributesW` or during that call... but I don't see how 
that is possible.





Re: weird exception on windows

2017-12-14 Thread Szabo Bogdan via Digitalmars-d-learn

On Thursday, 14 December 2017 at 14:47:25 UTC, Kagamin wrote:

writeln(fileName);
if (!fileName.exists)
{
  return;
}

:)


I'm not sure I understand this solution...


weird exception on windows

2017-12-14 Thread Szabo Bogdan via Digitalmars-d-learn

Hi,

I noticed that sometimes on windows this line of code crashes the 
test suites.


https://github.com/gedaiu/fluent-asserts/blob/master/core/fluentasserts/core/results.d#L1072

This exception can be captured only with a debugger... is it a 
dmd bug?


```
Thread 25CC created, Entry: mswsock.7FF9011604C0
EXCEPTION_DEBUG_INFO:
   dwFirstChance: 1
   ExceptionCode: C005 (EXCEPTION_ACCESS_VIOLATION)
  ExceptionFlags: 
ExceptionAddress: 7FF9055E302C ntdll.7FF9055E302C
NumberParameters: 2
ExceptionInformation[00]:  Read
ExceptionInformation[01]:  Inaccessible Address
First chance exception on 7FF9055E302C (C005, 
EXCEPTION_ACCESS_VIOLATION)!

```

I think this is related with this issue:
https://github.com/gedaiu/fluent-asserts/issues/63

Can anyone help me with this? I don't even know how to start 
fixing this issue...


Thanks,
Bogdan



Getting the coverage data at runtime

2017-06-18 Thread Szabo Bogdan via Digitalmars-d-learn

Hi,

I am wondering if there is any way of getting the code coverage 
at runtime... As a I seen in the runtime, the .lst files are 
created inside this module dealocator:


https://github.com/dlang/druntime/blob/master/src/rt/cover.d#L152

and the `Cover[] gdata;` is private, so no way of accessing it...

I'm asking this because it would be cool to analyse the coverage 
at runtime, after each executed test, for example, to see how 
many lines are covered by a test or to check if the test hits an 
assert, which will be awesome... Or maybe to add other coverage 
formats for better integration with IDEs...


Thanks!


Re: std.algorithm can not be used inside pure functions?

2017-05-06 Thread Szabo Bogdan via Digitalmars-d-learn

On Saturday, 6 May 2017 at 15:01:16 UTC, Adam D. Ruppe wrote:

On Saturday, 6 May 2017 at 14:14:41 UTC, Szabo Bogdan wrote:
oh yes, I get it... begin and end are `SysTime`.. there is any 
workaround for this?


Don't use pure?

I don't think any of the SysTime conversion methods are pure 
since all of them call C functions which pull from the time 
zone... even if you subclassed the timezone to be pure, SysTime 
wouldn't pick that up since it uses the impure interface.


I guess you could use a casted wrapper to hack in pure too, but 
I'd say just take the keyword off.


Thanks!


Re: std.algorithm can not be used inside pure functions?

2017-05-06 Thread Szabo Bogdan via Digitalmars-d-learn

On Saturday, 6 May 2017 at 13:21:10 UTC, Adam D. Ruppe wrote:

On Saturday, 6 May 2017 at 13:19:17 UTC, Szabo Bogdan wrote:

a.begin.toISOExtString,


I believe that function is not marked pure if it is a SysTime 
because it needs to pull global timezone info.


What is the type of a.begin?


oh yes, I get it... begin and end are `SysTime`.. there is any 
workaround for this?


std.algorithm can not be used inside pure functions?

2017-05-06 Thread Szabo Bogdan via Digitalmars-d-learn

Hi,

I'm trying to write a function that saves some structs as csv 
file:


```
string toCsv(const(StatStorage) storage) {
  return storage.values
.map!(a => [ a.name, a.begin.toISOExtString, 
a.end.toISOExtString, a.status.to!string ])

.map!(a => a.join(','))
.join('\n');
}
```

I think that it's obvious that this function has no external 
state and from my understanding, it should be a pure function. 
But when I declare it as `pure` I get an error `Error: pure 
function 'trial.reporters.stats.toCsv' cannot call impure 
function 'std.array.join!(MapResult!(__lambda3, 
MapResult!(__lambda2, const(Stat)[])), char).join'`.


What am I missing here?


Re: Stack Trace format

2017-04-30 Thread Szabo Bogdan via Digitalmars-d-learn

On Sunday, 30 April 2017 at 20:31:09 UTC, Szabo Bogdan wrote:

Hi,

I noticed that on different platforms the 
`object.Throwable.TraceInfo` has different formats. A program 
compiled on osx with ldc2 has all the TraceInfo empty... Why?


I want to parse those strings or somehow iterate trough all the 
stack elements, but if I get a different format on different 
platforms it's not that easy to determine at what position in 
the string is the address or the function name.


I would appreciate if anyone have an idea of how I can do this 
without a big headache...


Thanks!


Actually I found the `defaultTraceHandler` here:

https://github.com/dlang/druntime/blob/7caaf7cbb699a2a1944b2ac087c3b07d23db6802/src/core/runtime.d#L534


Stack Trace format

2017-04-30 Thread Szabo Bogdan via Digitalmars-d-learn

Hi,

I noticed that on different platforms the 
`object.Throwable.TraceInfo` has different formats. A program 
compiled on osx with ldc2 has all the TraceInfo empty... Why?


I want to parse those strings or somehow iterate trough all the 
stack elements, but if I get a different format on different 
platforms it's not that easy to determine at what position in the 
string is the address or the function name.


I would appreciate if anyone have an idea of how I can do this 
without a big headache...


Thanks!


Re: code review based on what I learned from D

2015-07-06 Thread Bogdan via Digitalmars-d-learn

On Sunday, 5 July 2015 at 09:46:19 UTC, ketmar wrote:

On Sun, 05 Jul 2015 21:39:23 +1200, Rikki Cattermole wrote:


Of course of course.
Valid options in failing gracefully include resetting the data 
and
informing the user. Also giving them an option to send a bug 
report to

the devs.
Point being, having it just fail on start each time is not a 
valid end

result or something else awful.


ah, i see and i fully agree.


I think that if you really are scared if your installed app will 
crash because of some assert that you wrote, it means that you 
are not confident enough with your coding skills. I use asserts 
to remember me something that I am not allowed to do.


As a developer sometimes I say that I will do this and I will 
remember to use it like that and this is almost never happens. 
When you work in a big team, this NEVER happens and not because 
people are evil, because we forget things, and it's easy to make 
mistakes.


I use asserts to fail quick, during development. If you are 
afraid to make a program that not crashes you should not be a 
programmer. I bet that everyone would prefer to  have a program 
that crash for known reasons instead from some unknown, strange, 
science-fiction bug.


And if you are really afraid of asserts in your code you can 
disable them for the release build, but I personally would not do 
that.


Bogdan


code review based on what I learned from D

2015-07-05 Thread Szabo Bogdan via Digitalmars-d-learn

Hi,

Recently while I was reviewing some swift code, a colleague left 
me the impression that I am the one with the bad habits and these 
were learned while coding in D. I still think that I proposed 
some changes to avoid some bugs but I was told that I am focusing 
on defensive programming and that is a bad thing.


The first issue that I raised was this one:

func renderCell(item: AnyObject, index: Int) {
-fatalError(renderCell has not been implemented)
+
}

where I proposed to make that method abstract or let's not remove 
the fatalError message because this method it should be never 
called.


The second issue was this:

+init(dataSource: WUPTableDataSource) {
+
+self.dataSource = dataSource
+dataSource.tableView = tableView

where I asked what happens if someone passes a dataSource that 
has a tableView set. I this class, there were set some events 
bind to the view and it was unclear what happened in that case 
and I proposed to add an assert to check if dataSource.tableView 
is not set before we set it.


For both of these issues I was told that swift is not Java and if 
the situations that I described happens, you don't want to crash 
the user app, because this will make the user unhappy.


Those things are for me, good habits that I do when I am 
programming with D. What do you think? and if I had bad ideas 
with those issues, what I can do to improve my skills?


thanks,
Bogdan







sign oauth request

2014-09-25 Thread szabo bogdan via Digitalmars-d-learn

Hi,

How I can sign a request for flickrl oauth api?
https://www.flickr.com/services/api/auth.oauth.html#request_token

there is no HMAC-SHA1 algorithm in phobos library... should I 
implement it from scratch?


Thanks,
Bogdan


Re: sign oauth request

2014-09-25 Thread szabo bogdan via Digitalmars-d-learn

which lib do you recommand?


On Thursday, 25 September 2014 at 16:19:41 UTC, H. S. Teoh via 
Digitalmars-d-learn wrote:
On Thu, Sep 25, 2014 at 03:57:36PM +, szabo bogdan via 
Digitalmars-d-learn wrote:

Hi,

How I can sign a request for flickrl oauth api?
https://www.flickr.com/services/api/auth.oauth.html#request_token

there is no HMAC-SHA1 algorithm in phobos library... should I 
implement it

from scratch?

[...]

Implementing cryptographic algorithms on your own is probably 
not a good

idea. Your safest bet is to use one of the many C authentication
libraries out there, since D can call C functions directly.


T




Re: sign oauth request

2014-09-25 Thread szabo bogdan via Digitalmars-d-learn
On Thursday, 25 September 2014 at 17:09:40 UTC, Adam D. Ruppe 
wrote:
On Thursday, 25 September 2014 at 17:03:43 UTC, John Chapman 
wrote:

http://dlang.org/phobos/std_digest_sha.html#SHA1


Not quite the same, the oauth requires hmac.

When I did this in my oauth.d for twitter and stuff, I used the 
C library mhash


check out my code:

https://github.com/adamdruppe/arsd/blob/master/oauth.d#L796

The rest of that lib is kinda sloppy and has a few dependencies 
from my other modules but feel free to use whatever looks 
useful to you.


I think mhash is GPL licensed.



it works! thanks!