Re: Bitfileds Error: no identifier for declarator

2021-10-27 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 28 October 2021 at 05:20:35 UTC, data pulverizer 
wrote:

Hi,

I am trying to compile the following items:

[...]


Try renaming debug to something else


Re: Bitfileds Error: no identifier for declarator

2021-10-27 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 28 October 2021 at 05:51:27 UTC, Imperatorn wrote:
On Thursday, 28 October 2021 at 05:20:35 UTC, data pulverizer 
wrote:

Hi,

I am trying to compile the following items:

[...]


Try renaming debug to something else


uint, "debugflag",1,


Re: Bitfileds Error: no identifier for declarator

2021-10-27 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 28 October 2021 at 05:20:35 UTC, data pulverizer 
wrote:



I am trying to compile the following items:

struct sxpinfo_struct {
  mixin(bitfields!(
// ...
uint, "debug",1,
// ...
}
```

But I get the error...



`debug` is a language keyword, try a different one, like "debug_".

That error message though, much wow.


Re: Bitfileds Error: no identifier for declarator

2021-10-27 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 28 October 2021 at 05:20:35 UTC, data pulverizer 
wrote:

Hi,

I am trying to compile the following items ...


Sorry forgot to prepend:

```
enum SEXPTYPE
{
  NILSXP = 0,
  SYMSXP = 1,
  LISTSXP = 2,
  CLOSXP = 3,
  ENVSXP = 4,
  PROMSXP = 5,
  LANGSXP = 6,
  SPECIALSXP = 7,
  BUILTINSXP = 8,
  CHARSXP = 9,
  LGLSXP = 10,
  INTSXP = 13,
  REALSXP = 14,
  CPLXSXP = 15,
  STRSXP = 16,
  DOTSXP = 17,
  ANYSXP = 18,
  VECSXP = 19,
  EXPRSXP = 20,
  BCODESXP = 21,
  EXTPTRSXP = 22,
  WEAKREFSXP = 23,
  RAWSXP = 24,
  S4SXP = 25,
  NEWSXP = 30,
  FREESXP = 31,
  FUNSXP = 99
}
```

In case someone is trying to replicate the error.


Bitfileds Error: no identifier for declarator

2021-10-27 Thread data pulverizer via Digitalmars-d-learn

Hi,

I am trying to compile the following items:


```
import std.bitmanip: bitfields;

enum TYPE_BITS = 5;
enum NAMED_BITS = 16;

struct sxpinfo_struct {
  mixin(bitfields!(
SEXPTYPE, "type", TYPE_BITS,
uint, "scalar",   1,
uint, "obj",  1,
uint, "alt",  1,
uint, "gp",  16,
uint, "mark", 1,
uint, "debug",1,
uint, "trace",1,
uint, "spare",1,
uint, "gcgen",   1,
uint, "gccls",   3,
uint, "named",  NAMED_BITS,
uint, "extra",  32 - NAMED_BITS));
}
```

But I get the error:

```
Error: no identifier for declarator `uint`
Error: identifier or integer expected inside `debug(...)`, not `)`
Error: found `@` when expecting `)`
Error: no identifier for declarator `safe`
Error: declaration expected, not `return`
Error: no identifier for declarator `void`
Error: identifier or integer expected inside `debug(...)`, not 
`uint`

Error: found `v` when expecting `)`
Error: declaration expected, not `)`
Error: declaration expected, not `assert`
Error: basic type expected, not `cast`
Error: found `cast` when expecting `;`
Error: declaration expected, not `(`
```

All referencing the `bitfields` `mixin`, more specifically the 
last two lines but I think it's actually referencing the expanded 
`mixin` rather than my declaration.


Thanks


Re: Are there anything like leetcode.com but that supports D?

2021-10-27 Thread Dr Machine Code via Digitalmars-d-learn
On Thursday, 28 October 2021 at 01:29:41 UTC, Siarhei Siamashka 
wrote:
On Sunday, 24 October 2021 at 05:46:48 UTC, Dr Machine Code 
wrote:

I'd like that to some friends getting start with programming.


There are also websites, which host programming competitions.

Beginners friendly:
 * https://atcoder.jp/
 * https://www.codechef.com/

Higher difficulty:
 * https://codeforces.com/
 * https://codingcompetitions.withgoogle.com/kickstart

All of them support D language.


Sounds good, thank you too


Linker issues with struct postblit

2021-10-27 Thread Thomas Gregory via Digitalmars-d-learn
I am a maintainer of the 
[dhtslib](https://github.com/blachlylab/dhtslib) package and I 
have been running into issues with a new implementation of 
reference counting we are using.


Below is the implementation (which is basically our replacement 
for `RefCounted`).

```d
/// Template struct that wraps an htslib
/// pointer and reference counts it and then
/// destroys with destroyFun when it goes
/// truly out of scope
struct SafeHtslibPtr(T, alias destroyFun)
if(!isPointer!T && isSomeFunction!destroyFun)
{
@safe @nogc nothrow:

/// data pointer
T * ptr;
/// reference counting
shared int* refct;

/// initialized?
bool initialized;

/// ctor that respects scope
this(T * rawPtr) @trusted return scope
{
this.ptr = rawPtr;
this.refct = cast(shared int *) calloc(int.sizeof,1);
(*this.refct) = 1;
this.initialized = true;
}

/// postblit that respects scope
this(this) @trusted return scope
{
if(initialized)atomicOp!"+="(*this.refct, 1);
}

/// allow SafeHtslibPtr to be used as
/// underlying ptr type
alias getRef this;

/// get underlying data pointer
@property nothrow pure @nogc
ref inout(T*) getRef() inout return
{
return ptr;
}

/// take ownership of underlying data pointer
@property nothrow pure @nogc
T* moveRef()
{
T * ptr;
move(this.getRef, ptr);
return ptr;
}

/// dtor that respects scope
~this() @trusted return scope
{

if(!this.initialized) return;
if(atomicOp!"-="(*this.refct, 1)) return;
if(this.ptr){
free(cast(int*)this.refct);
/// if destroy function return is void
/// just destroy
/// else if return is int
/// destroy then check return value
/// else don't compile
static if(is(ReturnType!destroyFun == void))
destroyFun(this.ptr);
else static if(is(ReturnType!destroyFun == int))
{
auto err = destroyFun(this.ptr);
if(err != 0)
hts_log_errorNoGC!__FUNCTION__("Couldn't 
destroy/close "~T.stringof~" * data using function 
"~__traits(identifier, destroyFun));

}else{
static assert(0, "HtslibPtr doesn't recognize 
destroy function return type");

}
}
}
}
```
This can be used as such to reference count a pointer created 
from the c library [htslib](https://github.com/samtools/htslib) 
as such:

```d
/// bam1_t is a struct from c bindings
/// bam_destroy1 is a function to clean up a bam1_t *
/// that is created from the c bindings
alias Bam1 = SafeHtslibPtr!(bam1_t, bam_destroy1);
auto b = Bam1(bam_init1());
```

The issue presents with `SAMRecord`:
```d
struct SAMRecord
{
/// Backing SAM/BAM row record
Bam1 b;

/// Corresponding SAM/BAM header data
SAMHeader h;

```
dhtslib itself builds fine on both dmd and ldc compilers but when 
it is used as a dependency it seems to have issues building on 
any compiler that is not ldc > v1.24.0:

```
_D39TypeInfo_S7dhtslib3sam6record9SAMRecord6__initZ: error: 
undefined reference to 
`_D7dhtslib3sam6record9SAMRecord15__fieldPostblitMFNbNiNlNeZv'

```
Though I only experience this when trying to create an array of 
`SAMRecord`s.


One solution I have found is using `std.array.Appender` instead 
of arrays.
Another solution I have found is to define an explicit postblit 
for `SAMReader`:

```
this(this)
{
this.h = h;
this.b = b;
}
```

Looking through ldc changelogs, the closest thing I could 
attribute this to is this change for ldc-1.25.0:
- Struct TypeInfos are emitted into referencing object files 
only, and special TypeInfo member functions into the owning 
object file only. (#3491)


I suspect this is something to do with the alias'd function in 
`SafeHtslibPtr`. Is there something I should be doing differently?




Re: Are there anything like leetcode.com but that supports D?

2021-10-27 Thread Siarhei Siamashka via Digitalmars-d-learn

On Sunday, 24 October 2021 at 05:46:48 UTC, Dr Machine Code wrote:

I'd like that to some friends getting start with programming.


There are also websites, which host programming competitions.

Beginners friendly:
 * https://atcoder.jp/
 * https://www.codechef.com/

Higher difficulty:
 * https://codeforces.com/
 * https://codingcompetitions.withgoogle.com/kickstart

All of them support D language.


Re: What is D's "__debugbreak()" equivalent?

2021-10-27 Thread Adam D Ruppe via Digitalmars-d-learn

On Wednesday, 27 October 2021 at 17:07:31 UTC, H. S. Teoh wrote:

asm { int 3; }


yeah that's how i do it in dmd too


Re: What is D's "__debugbreak()" equivalent?

2021-10-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 10/27/21 12:54 PM, Simon wrote:
Microsofts C++ compiler provides the __debugbreak function, which on x86 
emits interrupt 3, which will cause the debugger to halt. What is the 
equivalent in D? I tried using raise(SIGINT) from core.stdc.signal, but 
that just closes the debugger (I thought that was the same, seems like I 
was wrong).


SIGINT is not an interrupt, it's a POSIX signal.

Inline asm maybe?  https://dlang.org/spec/iasm.html

-Steve


Re: What is D's "__debugbreak()" equivalent?

2021-10-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 27, 2021 at 04:54:49PM +, Simon via Digitalmars-d-learn wrote:
> Microsofts C++ compiler provides the __debugbreak function, which on
> x86 emits interrupt 3, which will cause the debugger to halt. What is
> the equivalent in D? I tried using raise(SIGINT) from
> core.stdc.signal, but that just closes the debugger (I thought that
> was the same, seems like I was wrong).

Why not just:

asm { int 3; }

?

Just tested in gdb, it worked.


T

-- 
MASM = Mana Ada Sistem, Man!


What is D's "__debugbreak()" equivalent?

2021-10-27 Thread Simon via Digitalmars-d-learn
Microsofts C++ compiler provides the __debugbreak function, which 
on x86 emits interrupt 3, which will cause the debugger to halt. 
What is the equivalent in D? I tried using raise(SIGINT) from 
core.stdc.signal, but that just closes the debugger (I thought 
that was the same, seems like I was wrong).


Re: Analyze debug condition in template

2021-10-27 Thread novice2 via Digitalmars-d-learn

On Wednesday, 27 October 2021 at 08:14:29 UTC, Kagamin wrote:
...
Then the logger can inspect symbols in the template argument 
and compare their names to the function name.



Aha, thank you, i will try!


Re: Analyze debug condition in template

2021-10-27 Thread Kagamin via Digitalmars-d-learn

You can do something like
```d
enum LogSettings
{
  func1,func2,func3
}

alias logger!LogSettings logf;

void func1()
{
  logf(...);
}
```

Then the logger can inspect symbols in the template argument and 
compare their names to the function name.


Re: Error: Could not open 'libcmt.lib'

2021-10-27 Thread bauss via Digitalmars-d-learn

On Monday, 25 October 2021 at 14:43:06 UTC, Willem wrote:
Just starting out new with D.  Up until now I have been using 
Python and a bit of OCaml.


Error when linking: "lld-link: error: could not open 
'libcmt.lib': no such file or directory"


What I did:  I installed the complete D setup in my Windows 10 
PC -- including VS 2019.


From the command line "C:\D\dmd2vars64.bat" I was able to 
creating a simple program with "dub init hello"


When executing it with "dub run hello" I get following error:

"lld-link: error: could not open 'libcmt.lib': no such file or 
directory"


However -- running "dub run --arch=x86" did work

dmd --version
DMD64 D Compiler v2.098.0-dirty

dub --version
DUB version 1.27.0, built on Oct 10 2021

Searching the forum it appear to be related to MS runtimes... 
but I have not yet been able to resolve it. Any suggestions 
would be greatly appreciated.


Many Thanks.


C++ runtime needs to be installed I believe.


Re: TimeoutException for connecting to MySQL using a hunt-entity.

2021-10-27 Thread bauss via Digitalmars-d-learn

On Monday, 25 October 2021 at 12:54:32 UTC, greenbyte wrote:

On Monday, 25 October 2021 at 07:45:26 UTC, Imperatorn wrote:

On Friday, 22 October 2021 at 11:42:34 UTC, greenbyte wrote:

Hi, all!

I use the hunt-entity library to work with MySQL. I get the 
hunt.Exceptions.TimeoutException: "Timeout in 30 secs" when 
trying to connect. I configured MySQL and ran the code from 
the instructions https://github.com/huntlabs/hunt-entity


MySQL:
mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server 
- GPL)


DUB:
version 1.25.0, built on Apr 23 2021

In dub.json enabled "hunt-entity": "~>2.7.3"


And also of course triple check your credentials etc.


Yes. When credentials don't match, I have AccessDenied 
exception.


Are you able to connect to the mysql using something else like a 
heidisql?


Just to isolate whether the issue is mysql configuration or an 
actual problem with the package.


Re: std.zip expand: memory allocation failed

2021-10-27 Thread bauss via Digitalmars-d-learn
On Tuesday, 26 October 2021 at 13:43:36 UTC, Steven Schveighoffer 
wrote:

On 10/26/21 2:32 AM, bauss wrote:

On Monday, 25 October 2021 at 22:38:38 UTC, Imperatorn wrote:
On Monday, 25 October 2021 at 20:50:40 UTC, Steven 
Schveighoffer wrote:

On 10/24/21 8:00 AM, Selim Ozel wrote:

It turns out my computer was literally running out of 
memory as the file was getting unzipped. For some reasonĀ  
to uncompress a 1-gig file with uncompressed size of 4-gig, 
Zip Archive of D-Lang tries to use more than 16 gig of RAM. 
I don't know why. Maybe I missed something. I use a Windows 
10, DMD v2.091 with x86_mscoff.


Wait, x86 is 32-bit. Max address space is 4GB. So maybe it 
was just trying to use 4GB and running out of memory?


-Steve


Good catch, but still, should it use so much memory?


Definitely not. It shouldn't use a lot of memory when 
unzipping as it should be done in chunks!


You guys aren't getting it:

```
ubyte[] expand(ArchiveMember de);
Decompress the contents of a member.
Fills in properties extractVersion, flags, compressionMethod, 
time, crc32, compressedSize, expandedSize, expandedData[], 
name[], extra[].

```

Where is it supposed to store that `ubyte[]`?

-Steve


It's not supposed, but a new implementation can utilize something 
like a stream.