Re: How to debug (potential) GC bugs?

2016-10-03 Thread Kagamin via Digitalmars-d-learn
On Saturday, 1 October 2016 at 00:06:05 UTC, Matthias Klumpp 
wrote:

I do none of those things in my code though...


`grep "~this" *.d` gives nothing? It can be a struct with 
destructor stored in a class. Can you observe the error? Try to 
set a breakpoint at onInvalidMemoryOperationError 
https://github.com/dlang/druntime/blob/master/src/core/exception.d#L559 and see what stack leads to it.


Unfortunately for having deterministic memory management, I 
would essentially need to develop GC-less, and would loose 
classes. This means many nice features of D aren't available, 
e.g. I couldn't use interfaces (AFAIK they don't work on 
structs) or constraints.


Not necessarily. You only need to dispose the resources in time, 
like in C#. But if you don't have destructors, you have nothing 
to dispose.


Strangely after switching from the GDC compiler to the LDC 
compiler, all crashes observed at Ubuntu are gone.


Sounds not good.


Re: How to debug (potential) GC bugs?

2016-10-03 Thread Kagamin via Digitalmars-d-learn
On Sunday, 25 September 2016 at 16:23:11 UTC, Matthias Klumpp 
wrote:
For Ubuntu, some modifications on the code were needed, and 
apparently for them the code is currently crashing in the GC 
collection thread: http://paste.debian.net/840490/


Oh, wait, what do you mean by crashing?


Re: How to debug (potential) GC bugs?

2016-10-03 Thread Kagamin via Digitalmars-d-learn
If it's heap corruption, GC has debugging option -debug=SENTINEL 
- for buffer overrun checks. Also that particular stack trace 
shows that object being destroyed is allocated in bin 512, i.e. 
its size is between 256 and 512 bytes.


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 10:03:30 UTC, dm wrote:
Why so strange default behavior do not kill other threads in 
case some of threads raise exception?

But thanks anyway.


AFAIK, on posix you should join the child thread, and when you 
do, the stored exception is rethrown in the joining thread.


Re: Visual Studio Linker Problem

2016-10-19 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 18 October 2016 at 18:18:16 UTC, Jason C. Wells wrote:

I'm not sure where LIB was set.


At least in vs2013 it's taken from registry somewhere 
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft 
SDKs\Windows\v8.1 (maybe v10 in your case).


Re: dmd 2.072.0 beta 2 no size because of forward reference

2016-10-21 Thread Kagamin via Digitalmars-d-learn

https://github.com/dlang/dmd/pull/5500 maybe this


How to muldiv in D?

2016-11-21 Thread Kagamin via Digitalmars-d-learn

Can't find a function for it.


Re: How to muldiv in D?

2016-11-22 Thread Kagamin via Digitalmars-d-learn

Yep, I need muldiv for long values on x86-64.


Re: Char representation

2016-11-22 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 22 November 2016 at 13:29:47 UTC, RazvanN wrote:

Given the following code:

 char[5] a = ['a', 'b', 'c', 'd', 'e'];
 alias Range = char[];
 writeln(is(ElementType!Range == char));

One would expect that the program will print true. In fact, it 
prints false and I noticed that if Range is char[], wchar[], 
dchar[], string, wstring, dstring
Unqual!(ElementType!Range) is dchar. I find it odd that the 
internal representation for char and string is dchar. Is this a 
bug?


Here's the reading: 
https://forum.dlang.org/post/nh2o9i$hr0$1...@digitalmars.com


Re: spam in bugzilla

2016-11-24 Thread Kagamin via Digitalmars-d-learn

Maybe connect a service like https://twitter.com/StopForumSpam ?


Re: Catch block not hit in unittest

2016-11-24 Thread Kagamin via Digitalmars-d-learn

Linux? Probably another bug.
Try this:
unittest
{
import core.exception : UnicodeException;
void f()
{
string ret;
int i = -1;
ret ~= i;
}

try
{
f();
}
catch(UnicodeException e)
{
assert(e.msg == "Invalid UTF-8 sequence");
}
}


Re: How to create a UTF16 text file on Windows?

2016-11-17 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 16 November 2016 at 22:43:55 UTC, lafoldes wrote:

Hi,
I'd like to create a UTF16 text file on Windows 7, using 
std.stdio.File and std.stdio.File.write... functions (so no 
binary write, no Win32 functions).


I was experimenting with variations of this code…:

import std.stdio;

int main(string[] argv)
{
auto output = File("wide_text.txt", "wt");
output.writeln!wstring("A"w);
return 0;
}


What C runtime do you use?


Re: an extremely naive question regarding synchronized...

2016-11-16 Thread Kagamin via Digitalmars-d-learn

  static MySingleton get() {
if (instance_ is null) {
  synchronized {
if (instance_ is null) {
  atomicStore(instance_, new MySingleton);
}
  }
}
return instance_;
  }

This should work fine and faster.


Re: Why is three safety levels need in D?

2016-11-18 Thread Kagamin via Digitalmars-d-learn

On Thursday, 17 November 2016 at 17:18:27 UTC, Nordlöw wrote:
Why does D need both `@safe`, `@trusted` and `@system` when 
Rust seems to get by with only safe (default) and `unsafe`?


Rust has 3 levels of safety: the code inside unsafe block is 
@system, and the unsafe block as a whole is a @trusted wrapper 
providing safe interface to be called by safe code. The rationale 
for function-level safety is better encapsulation: the function 
accesses only its parameters and nothing more, but unsafe block 
has access to all visible local variables of its function, not 
only those it works with. D supports Rust-style unsafe blocks 
with @trusted lambdas.


Re: Memory allocation failed. Why?

2016-11-21 Thread Kagamin via Digitalmars-d-learn

On Monday, 21 November 2016 at 11:22:40 UTC, ag0aep6g wrote:
Who could "someone" be? It's a self-contained example, and buf 
doesn't leave the test function.


Anything in .data and .bss sections and stack. See 
https://issues.dlang.org/show_bug.cgi?id=15723


As for GC compaction: 
https://issues.dlang.org/show_bug.cgi?id=3284


Re: RDMD can't eval code because of missing cstream module

2016-11-21 Thread Kagamin via Digitalmars-d-learn

https://github.com/dlang/tools/commit/5ed4f176f41b7559c64cf525c07ccf13ca3a5160 
this?


Re: ACM paper: CPU is the new bottleneck

2016-10-31 Thread Kagamin via Digitalmars-d-learn
On the other hand if you do more IO, you can have higher CPU load 
due to compression and serialization.


Re: When to call GC.{add,remove}Range in containers?

2016-10-10 Thread Kagamin via Digitalmars-d-learn

On Monday, 10 October 2016 at 07:12:10 UTC, Nordlöw wrote:

should not be scanned by the GC.


Shouldn't be a problem.


Re: [Semi-OT] I don't want to leave this language!

2016-12-07 Thread Kagamin via Digitalmars-d-learn

On Monday, 5 December 2016 at 20:25:00 UTC, Ilya Yaroshenko wrote:
Good D code should be nothrow, @nogc, and betterC. BetterC 
means that it must not require DRuntime to link and to start.


Without runtime you won't have asserts (C has them), bounds 
checking, array casts, string switch. Doesn't sound good to me. 
And why is it a requirement at all? C and C++ already depend on 
their quite huge runtimes already. Why D shouldn't?


Re: BetterC classes

2016-12-20 Thread Kagamin via Digitalmars-d-learn
On Friday, 16 December 2016 at 18:29:33 UTC, Ilya Yaroshenko 
wrote:

Undefined symbols for architecture x86_64:
  "__D14TypeInfo_Class6__vtblZ", referenced from:
  __D8cppclass2Hw7__ClassZ in cppclass-7ed89bd.o


By using typeid you request the class' TypeInfo, and it pulls 
quite a lot.


Re: BetterC classes

2016-12-22 Thread Kagamin via Digitalmars-d-learn
It looks more like a reference from C++ class TypeInfo to Class 
TypeInfo vtable, which is legit since the C++ class TypeInfo is a 
D class derived from Class TypeInfo. What's not good is a 
reference to the C++ class TypeInfo in the first place.


Re: BetterC classes

2016-12-22 Thread Kagamin via Digitalmars-d-learn

On Thursday, 22 December 2016 at 09:01:21 UTC, Kagamin wrote:
It looks more like a reference from C++ class TypeInfo to Class 
TypeInfo vtable, which is legit since the C++ class TypeInfo is 
a D class derived from Class TypeInfo.


Or just an instance of Class TypeInfo, so its initializer needs 
Class TypeInfo vtable.


Re: COM2D Wrapper

2017-03-28 Thread Kagamin via Digitalmars-d-learn

On Monday, 27 March 2017 at 21:02:05 UTC, Nierjerson wrote:
Anyone can help get this working? I think the issue maybe that 
the interface pointer returned by the COM interface is "C-like" 
and doesn't match what D expects an interface to be. I get 
access violations when trying to call the functions on the 
returned interfaces. Not sure about this though.


First write code that works, then write generator for it. It 
won't work the other way around.


Re: std.digest toHexString

2017-03-20 Thread Kagamin via Digitalmars-d-learn

On Monday, 20 March 2017 at 15:46:10 UTC, Adam D. Ruppe wrote:

On Monday, 20 March 2017 at 15:38:26 UTC, Kagamin wrote:
This explicit slice won't work, because a slice of a fixed 
size array results in a fixed size array.


No, it doesn't. int[4] a; typeof(a[] == int[])

You can try yourself in the compiler, it is easy to verify.


https://dpaste.dzfl.pl/eafa86c5426d


Re: Is it std.regex, or is it me.

2017-03-20 Thread Kagamin via Digitalmars-d-learn
A file stream would be another example of a thing that can't be 
naturally const even if you opened it for reading.


Re: std.digest toHexString

2017-03-20 Thread Kagamin via Digitalmars-d-learn
On Monday, 20 March 2017 at 04:03:20 UTC, Vladimir Panteleev 
wrote:

https://issues.dlang.org/show_bug.cgi?id=9279

Has it not been fixed?


That's specific to the return statement. Like you can assign an 
address of a local variable, but you can't return it.


Re: std.digest toHexString

2017-03-20 Thread Kagamin via Digitalmars-d-learn

On Thursday, 16 March 2017 at 17:50:45 UTC, Adam D. Ruppe wrote:
string s = func()[]; // I'd allow it, at least the user wrote 
`[]` meaning they realized it was stack data and presumably 
knows what that means about the slice's lifetime


This explicit slice won't work, because a slice of a fixed size 
array results in a fixed size array.


There's no reason to allow this buggy code though. Also 
programmer didn't necessarily mean it. It could be a typographic 
error or a result of refactoring. Even if programmer wanted to 
write invalid code, what for? Yet this particular code doesn't 
need to be allowed to allow writing invalid code: one can still 
cast a number to pointer and do whatever he wants.


Re: how to make interface with return auto

2017-04-03 Thread Kagamin via Digitalmars-d-learn
Or if you want to completely abstract it: 
https://forum.dlang.org/post/iqxkelatusfocfotp...@forum.dlang.org


Re: Testing D codes

2017-04-04 Thread Kagamin via Digitalmars-d-learn
Same as anywhere else. Integration test is a test that connects 
to a deployed system, which is different from unittest only in 
philosophical aspect.


Re: is char[] faster than string?

2017-04-06 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 5 April 2017 at 21:58:16 UTC, Inquie wrote:

What I am looking for is something like StringBuilder in C#.


If you want it to not copy data on expand, there's nothing like 
that in D yet. I wrote one for myself :)


Re: Testing D codes

2017-04-06 Thread Kagamin via Digitalmars-d-learn

https://github.com/ikod/dlang-requests/blob/master/tests/app.d


Re: Testing D codes

2017-04-07 Thread Kagamin via Digitalmars-d-learn

On Thursday, 6 April 2017 at 13:49:11 UTC, Russel Winder wrote:
Is there any need for the unittest block in the application 
created to run the integration tests?


If you don't care to call each and all of them by hand. Test 
frameworks are handy for extensive testing, builtin unittests 
work best for the most basic stuff.


Re: GC: Understanding potential sources of false pointers

2017-04-20 Thread Kagamin via Digitalmars-d-learn

https://issues.dlang.org/show_bug.cgi?id=15723


Re: GC: Understanding potential sources of false pointers

2017-04-22 Thread Kagamin via Digitalmars-d-learn
On Thursday, 20 April 2017 at 20:26:06 UTC, Nick Sabalausky 
(Abscissa) wrote:

(even if it's from a C lib)


Same for D: .rdata is fine, but afaik you have only strings 
there, the rest - .data, .bss, .tls will suffer the same issue.


Re: Best way to manage non-memory resources in current D, ex: database handles.

2017-03-09 Thread Kagamin via Digitalmars-d-learn
Unique is probably not good for database connection: you then 
can't have connection in two variables, also if it holds a 
reference to GC-allocated memory, it can't be put to GC-allocated 
memory, since when that GC-allocated memory is collected, Unique 
will try to destroy its possibly already freed object resulting 
in use after free. RefCounted is ok, it has calls to GC in order 
to be scanned for GC references, though destructors during 
collection are called in a different thread, so the counter can 
be decremented incorrectly. Phobos tends to have specialized 
types like File and RcString, but they have the same problem with 
reference counting during collections.


Re: Best way to manage non-memory resources in current D, ex: database handles.

2017-03-09 Thread Kagamin via Digitalmars-d-learn

RefCounted is ok


If GC methods it calls are legal during collection.


Re: Always std.utf.validate, or rely on exceptions?

2017-03-02 Thread Kagamin via Digitalmars-d-learn

On Thursday, 2 March 2017 at 17:03:01 UTC, Kagamin wrote:
Functions working with strings usually assume valid utf and can 
behave incorrectly on malformed utf.


Or rather they report an unrecoverable error terminating the 
process.


Re: Always std.utf.validate, or rely on exceptions?

2017-03-02 Thread Kagamin via Digitalmars-d-learn

On Thursday, 2 March 2017 at 16:20:30 UTC, SimonN wrote:
Should I always validate text from files manually with 
std.utf.validate?


Or should I memorize which functions throw, then validate 
manually whenever I call the non-throwing UTF functions? What 
is the pattern behind what throws and what asserts false?


If you expect file with malformed utf that can cause you trouble 
and want to handle it gracefully, pass its content through 
validator and catch exception from validator. Functions working 
with strings usually assume valid utf and can behave incorrectly 
on malformed utf.


Re: Best memory management D idioms

2017-03-07 Thread Kagamin via Digitalmars-d-learn

On Sunday, 5 March 2017 at 20:54:06 UTC, XavierAP wrote:
What I want to learn (not debate) is the currently available 
types, idioms etc. whenever one wants deterministic memory 
management.


There's nothing like that of C++. Currently you have Unique, 
RefCounted, scoped and individual people efforts on this. BTW, do 
you want to manage non-memory resources with these memory 
management mechanisms too?


Re: D Debug101

2017-07-29 Thread Kagamin via Digitalmars-d-learn

People who don't use IDE, use printf debugging.


Re: D Debug101

2017-07-31 Thread Kagamin via Digitalmars-d-learn

gdb wants dwarf debug info, windows uses codeview.


Re: Is std.xml seriously broken, or is it me?

2017-07-31 Thread Kagamin via Digitalmars-d-learn

On Sunday, 30 July 2017 at 03:16:35 UTC, Mike wrote:

It appears `onStartTag` does not handle the root element.


Looks like a bug. Until the module is replaced, bug reports are 
still accepted for it.


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 15 August 2017 at 15:19:02 UTC, Steven Schveighoffer 
wrote:
However, I'm not sure about the postblit being called 
afterward. Does a postblit need to be marked shared in order to 
work for shared types?


Ideally yes, but it's difficult to come up with a good shared 
postblit, send and receive is probably the only use case for it :)


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 15 August 2017 at 21:27:49 UTC, Arek wrote:

Yes, but this doesn't compile:

import std.stdio;
import std.concurrency;

struct A
{
int t;
int r;
int method() shared
{
return 0;
}
}

void consumer()
{
shared a = receiveOnly!(shared A)();
}

void main()
{
auto cons = spawn();
send(cons, shared A());
}


AIU you use struct as a Unique-like wrapper for shared class 
object. Extract the object and send it, then wrap again on 
arrival.


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-15 Thread Kagamin via Digitalmars-d-learn

https://github.com/dlang/phobos/blob/master/std/variant.d#L623
memcpy(, cast(const(void*)) , rhs.sizeof);

should be ok to cast unconditionally


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-16 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 12:58:25 UTC, Steven 
Schveighoffer wrote:
Use cases don't matter. What matters is: is it proper for 
Variant to call the postblit (as it does currently) without 
regard for the qualifiers?


Looks like it isn't, https://dpaste.dzfl.pl/183e6dae9867 - shared 
reference counter with (probably) good enough postblit.


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-15 Thread Kagamin via Digitalmars-d-learn

On Monday, 14 August 2017 at 20:13:28 UTC, Arek wrote:
If I can ensure the uniqueness of the object, there is no need 
to "share" it or synchronize the access.


You use manually managed multithreading, that's why you need 
shared. And because compiler can't verify uniqueness, you are 
requested to do it manually by casting.


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-15 Thread Kagamin via Digitalmars-d-learn

On Monday, 14 August 2017 at 22:22:58 UTC, Arek wrote:

I've found some simple workaround for this problem:

import std.stdio;
import std.concurrency;

struct Envelope(T) if (is(T == class)) // for simplicity of 
this example, only classes

{
shared(T)[] obj;

this(shared T o)
{
this.obj = [o];
}

T get() @property nothrow @nogc
{
return cast() obj[0];
}
}

class A
{

}

void consumer()
{
auto r = receiveOnly!(Envelope!(A))();
writeln("Got: ", typeof(r).stringof);
}

void main()
{
auto cons = spawn();
auto o = Envelope!A(new A());
send(cons, o);
}

Shared object can be encapsulated in the array. In case of 
other (non-class) types the pointer can be used, and get() 
should return ref to the pointed object (after stripping off 
the shared qualifier).


Rather like this:

struct Sendable(T)
{
shared T o;
alias o this;
}

import std.concurrency;

class A
{
int method() shared;
}

void consumer()
{
shared A a = receiveOnly!(Sendable!(A))();
}

void producer()
{
auto cons = spawn();
shared A a = new shared A();
send(cons, Sendable!A(a));
}


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-15 Thread Kagamin via Digitalmars-d-learn

Well, no wrapper is actually needed here:

class A
{
int method() shared;
}

void consumer()
{
shared a = receiveOnly!(shared A)();
}

void producer()
{
auto cons = spawn();
send(cons, new shared A());
}


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-17 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 13:14:55 UTC, Steven 
Schveighoffer wrote:
But that isn't a concern for Variant. It is only calling the 
postblit, which does work.


Shouldn't it call destructor when it goes out of scope?


Re: C style 'static' functions

2017-07-19 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 19 July 2017 at 15:28:50 UTC, Steven Schveighoffer 
wrote:
I'm not so sure of that. Private functions still generate 
symbols. I think in C, there is no symbol (at least in the 
object file) for static functions or variables.


They generate hidden symbols. That's just how it implements 
private functions in C: you can't do anything else without 
mangling. You probably can't compile two C units into one object 
file if they have static functions with the same name - this 
would require mangling to make two symbols different.


Re: unittest blocks not being run inside of class and struct templates

2017-07-25 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 25 July 2017 at 02:48:57 UTC, NoBigDeal256 wrote:
What is the standard way of testing class templates in the 
context of a library where some of the classes may never 
actually be used by the library itself?


Write a test and instantiate whatever templates you want to test.

class Test(T) {
}

unittest {
auto t=new Test!int;
assert(t.method1()==1);
}


Re: Why structs and classes instanciations are made differently ?

2017-07-25 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 25 July 2017 at 15:56:45 UTC, Houdini wrote:
Yes, but it isn't the default way in C++ to do dynamic 
instanciation.


https://github.com/isocpp/CppCoreGuidelines this? It's only 2 
years old. The new operator predates it by decades.


Re: Why structs and classes instanciations are made differently ?

2017-07-25 Thread Kagamin via Digitalmars-d-learn

On Monday, 24 July 2017 at 15:21:54 UTC, Houdini wrote:
D is very similar to C++ (and also grabs godd ideas from 
Python), but I have a naive question : why does Walter Bright 
chose to instanciate classes like in Java ?


C++ is big, there's always something you don't know about it. 
Java actually instantiates classes the C++ way: 
http://en.cppreference.com/w/cpp/language/new


Re: C style 'static' functions

2017-07-19 Thread Kagamin via Digitalmars-d-learn

Try a newer compiler, this was fixed recently.


Re: C++ Interfacing:'static' array function parameter contradiction

2017-04-28 Thread Kagamin via Digitalmars-d-learn

Report a bug.


Re: GC: Understanding potential sources of false pointers

2017-04-25 Thread Kagamin via Digitalmars-d-learn

They are for static data an thread-local storage.


Re: using shared effectively in a producer/consumer situation.

2017-04-25 Thread Kagamin via Digitalmars-d-learn

On Sunday, 23 April 2017 at 20:33:48 UTC, Kevin Balbas wrote:

Is this the correct way to do it?
 cast to shared, send to main thread, cast away shared?


Yes, as long as the thing is unique, you can cast it to shared or 
immutable just fine.


Re: OT: What causes the Segfault in the following?

2017-08-04 Thread Kagamin via Digitalmars-d-learn

On Friday, 4 August 2017 at 02:38:10 UTC, Andrew Edwards wrote:
OK, I was is indeed the problem. I was thinking for some reason 
that s gets initialized inside nk_color_hex_rgb()


Usually C functions don't allocate memory. And when they do, they 
do it in unique ways, which is a PITA, that's why the caller is 
usually responsible for memory management.


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-22 Thread Kagamin via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=6585 is this fixed too? 
How various opIndex will behave now?


Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-17 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 16 August 2017 at 23:15:10 UTC, crimaniak wrote:
I wonder if it possible and usable to make some template to 
support this pattern, where we give mutex(es), shared object(s) 
and delegate to operate with objects as non-shared.


https://dpaste.dzfl.pl/8b3b05c8ec0a like this? Not sure if it 
helps, don't forget that it's a casted shared object.


Re: Cannot implicitly convert expression (struct this)

2017-06-23 Thread Kagamin via Digitalmars-d-learn

On Thursday, 22 June 2017 at 09:57:44 UTC, Andre Pany wrote:

This line raises the error:
TestStruct s2 = TestStruct(Reason.FU);
Error: cannot implicitly convert expression ("Fu") of type 
Reason to InitialEnum!(Reason)


While this line is working fine:
TestStruct s1 = {reason: Reason.FU};


I think these should be equivalent, report a bug.


Re: How to get rid of const / immutable poisoning (and I didn't even want to use them...)

2017-05-23 Thread Kagamin via Digitalmars-d-learn

https://dpaste.dzfl.pl/74d67cfca3e8


Re: Searching strings with indexOf vs countUntil

2017-05-25 Thread Kagamin via Digitalmars-d-learn
I would guess indexOf returns a value suitable for indexing, 
therefore it counts code units, while countUntil counts range 
elements - code points in case of a string. Also number of code 
points is not suitable for indexing an utf8 string, it can be 
used to allocate a dstring, but not so much for anything else. 
What do you use the resulting value for?


Re: difference between x = Nullable.init and x.nullify

2017-06-03 Thread Kagamin via Digitalmars-d-learn

On Saturday, 3 June 2017 at 06:19:29 UTC, Jonathan M Davis wrote:
Assigning Nullable!Test.init is equivalent to setting the 
internal value to Test.init and setting _isNull to false.


Eh? Does it mean Nullable is default initialized to some non-null 
default value?


Re: difference between x = Nullable.init and x.nullify

2017-06-05 Thread Kagamin via Digitalmars-d-learn

On Sunday, 4 June 2017 at 08:51:44 UTC, Jonathan M Davis wrote:
On Saturday, 3 June 2017 at 06:19:29 UTC, Jonathan M Davis 
wrote:
> Assigning Nullable!Test.init is equivalent to setting the 
> internal value to Test.init and setting _isNull to false.



T _value;
bool _isNull = true;


So it was a typo that Nullable.init sets _isNull to false?


Re: Generic operator overloading for immutable types?

2017-06-14 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 13 June 2017 at 19:29:26 UTC, Gary Willoughby wrote:
Is it possible for the `result` variable in the following code 
to be returned as an immutable type if it's created by adding 
two immutable types?


Why do you even want that? Such plain data structure is 
implicitly convertible to any const flavor: 
https://dpaste.dzfl.pl/c59c4c7131b2


Re: alloca without runtime?

2017-05-04 Thread Kagamin via Digitalmars-d-learn

You can try ldc and llvm intrinsics
http://llvm.org/docs/LangRef.html#alloca-instruction
http://llvm.org/docs/LangRef.html#llvm-stacksave-intrinsic


Re: Access Violation when passing the result of a C function directly to a D function?

2017-09-15 Thread Kagamin via Digitalmars-d-learn
On Friday, 15 September 2017 at 04:01:13 UTC, Timothy Foster 
wrote:
am I required to save the result of a C function to variable 
before passing it into another function or?


No. You probably have stack corruption. Does it crash if 
FMOD_System_Create returns ok?


Re: Bug in D!!!

2017-08-30 Thread Kagamin via Digitalmars-d-learn

It can't work this way. You can try std.variant.


Re: Protection attribute in another module

2017-08-30 Thread Kagamin via Digitalmars-d-learn

Something like mixin("__traits(getProtection, A."~member~")")


Re: dispatcher

2017-09-06 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 6 September 2017 at 05:57:18 UTC, Psychological 
Cleanup wrote:
I'm thinking that I might have to create an extra thread that 
monitors for when a call needs to occur and does so.


Would work.
If your code doesn't conflict with GC, it's fine to work in an 
unregistered thread.


Re: wrapping a C style delegate

2017-08-25 Thread Kagamin via Digitalmars-d-learn
You're not specific enough. What would be semantics of such 
wrapper?


Re: Bug in D!!!

2017-08-31 Thread Kagamin via Digitalmars-d-learn
On Thursday, 31 August 2017 at 00:49:22 UTC, EntangledQuanta 
wrote:

I've already implemented a half ass library solution.


It can be improved alot.


Re: Transitive const and function pointers/delegates

2017-08-31 Thread Kagamin via Digitalmars-d-learn

It's const(int delegate(char))


Re: xml utf-8 encoding error

2017-08-29 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 29 August 2017 at 04:41:34 UTC, graw-prog wrote:

< Content-Type: text/xml; charset="utf-8"


Should be
Content-Type: text/xml; charset=utf-8


Re: Protection attribute in another module

2017-08-29 Thread Kagamin via Digitalmars-d-learn
You iterate over string literals: 
https://dlang.org/spec/traits.html#allMembers


Re: Deprecation of toUTF16

2017-08-31 Thread Kagamin via Digitalmars-d-learn

import std.conv;
auto ws=s.to!wstring;


Re: xml utf-8 encoding error

2017-08-29 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 29 August 2017 at 15:55:50 UTC, Adam D. Ruppe wrote:

http://dpldocs.info/experimental-docs/source/std.net.curl.d.html#L2470


Ow, annotated sources, cool.

pre {
box-sizing: border-box;
overflow: auto;
max-width: 800px; /* The script sets the real one */
max-width: calc(80vw - 16em - 4em);
}
Hmm... AFAIK free side space on pages is left so that the content 
is not too wide in characters, not because people like free side 
space :) But for preformatted text such limit makes little sense, 
it's only for word-wrapped text. I'd say code should take all the 
width it wants.


Re: ESR on post-C landscape

2017-11-22 Thread Kagamin via Digitalmars-d-learn
Also 
http://ithare.com/chapter-vb-modular-architecture-client-side-programming-languages-for-games-including-resilience-to-reverse-engineering-and-portability/ scroll to the part about language choice.


Re: weird exception on windows

2017-12-16 Thread Kagamin 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


Regression in 2.072?


Re: Clarity about extern(Windows)/extern(System)

2017-12-18 Thread Kagamin via Digitalmars-d-learn

On Sunday, 17 December 2017 at 13:36:15 UTC, Mike Parker wrote:
My limited testing on a 64-bit Linux VM shows no problems when 
binding a C function as extern(C) or extern(Windows), and the 
disassembly looks the same.


64-bit ABI fixed calling convention proliferation, only one cc is 
used there.


Re: Why is there no std.stream anymore?

2017-12-14 Thread Kagamin via Digitalmars-d-learn

Or this https://run.dlang.io/is/MO9Wiy


Re: Why is there no std.stream anymore?

2017-12-14 Thread Kagamin via Digitalmars-d-learn

On Monday, 11 December 2017 at 23:33:44 UTC, Seb wrote:

---
void main(string[] args)
{
import std.conv, std.range, std.stdio;
foreach (d; 
File(__FILE_FULL_PATH__).byChunk(4096).join.take(5)) {

writefln("%s", d.to!char);
}
}
---


A variant: https://run.dlang.io/is/2TUQBv


Re: Global variable type does not match previous declaration

2017-12-14 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 21:38:49 UTC, Satoshi wrote:

What means this error and how to solve it?

object.d-mixin-1072(1112): Error: Global variable type does not 
match previous declaration with same mangled name: 
_D10TypeInfo_m6__initZ


Try to write typeinfo as is without mixin.


Re: weird exception on windows

2017-12-14 Thread Kagamin via Digitalmars-d-learn

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

:)


Re: Clarity about extern(Windows)/extern(System)

2017-12-18 Thread Kagamin via Digitalmars-d-learn

From https://gcc.godbolt.org/

__attribute__((stdcall))
int square(int num) {
return num * num;
}

_Z6squarei:
  push ebp
  mov ebp, esp
  mov eax, DWORD PTR [ebp+8]
  imul eax, DWORD PTR [ebp+8]
  pop ebp
  ret 4


Re: Clarity about extern(Windows)/extern(System)

2017-12-18 Thread Kagamin via Digitalmars-d-learn

https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/x86-Function-Attributes.html#index-functions-that-pop-the-argument-stack-on-x86-32-3
 looks like gcc doesn't see it as OS dependent.


Re: Write native GUI applications for Windows

2017-12-18 Thread Kagamin via Digitalmars-d-learn

On Monday, 18 December 2017 at 10:08:13 UTC, Andrey wrote:
Is core.sys.windows.windows equals fully to C WinApi, do you 
know?


Should be enough for most things.


Re: weird exception on windows

2017-12-15 Thread Kagamin via Digitalmars-d-learn

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?


Re: weird exception on windows

2017-12-15 Thread Kagamin via Digitalmars-d-learn
You can also try to call `exists` somewhere before this part of 
code.


Re: weird exception on windows

2017-12-15 Thread Kagamin via Digitalmars-d-learn

Try printf debugging in case argument is invalid.


Re: weird exception on windows

2017-12-15 Thread Kagamin via Digitalmars-d-learn

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


Re: weird exception on windows

2017-12-15 Thread Kagamin via Digitalmars-d-learn

That said, tempCString code is suspicious:
https://github.com/dlang/phobos/blob/master/std/internal/cstring.d#L221
If unittest-versioned exists calls release-versioned tempCString, 
it will corrupt the stack. Try to replace 16 with 256 there and 
recompile your code.


Re: Class instance becoming null after calling bindings to C code???

2017-11-17 Thread Kagamin via Digitalmars-d-learn

And https://github.com/Extrawurst/DerelictFmod/issues/1


Re: COM/OLE advanced questions

2017-11-03 Thread Kagamin via Digitalmars-d-learn
On Thursday, 2 November 2017 at 14:22:56 UTC, Guillaume Piolat 
wrote:
Question 1. Is it mandatory to inherit from 
core.sys.windows.unknwn.IUnknown, or just having an interface 
named "IUnknown" validate it for being a COM interface?


   If yes, then how am I supposed to use COM interfaces in 
other OSes? core.sys.windows.unknwn.IUnknown is defined under 
version(Windows).


I suppose you will need a bunch of definitions. One strange thing 
is that core.sys.windows defines GUID with alignment 1, which I 
expect to differ on other platforms.



   I wonder what the exact compiler hook is.


I only looks at the name.

Question 2. If this fails, may I emulate COM vtable layout with 
extern(C++) class? I wonder what the exact differences are 
anyway between extern(C++) and the special IUnknown.


Depends on implementation. XPCOM uses straight C++ ABI on linux, 
so look what you want to work with.


Question 3. It seems I can inherit both from A D object and a 
COM interface. What will be the choosen layout?


Shouldn't matter, interface defines ABI, how it's implemented is 
irrelevant - that's the very idea behind COM. It's actually legal 
to implement interfaces with composition, the caller still 
doesn't see anything.


Re: Parallel reads on std.container.array.Array

2017-12-08 Thread Kagamin via Digitalmars-d-learn
On Friday, 8 December 2017 at 07:34:53 UTC, Arun Chandrasekaran 
wrote:
I was wondering if std.container.array.Array supports 
threadsafe parallel reads similar to std::vector.


No, your code can also fail on a system with inconsistent cache 
because data written by writing thread can remain in its cache 
and not reach shared memory in time or reading threads can read 
from their stale cache.


Re: Check whether a file is empty.

2017-12-08 Thread Kagamin via Digitalmars-d-learn
Other functions that can be used for this are 
GetFileInformationByHandle, GetFileSizeEx, SetFilePointerEx or 
File.size in phobos.


Re: Shared and race conditions

2017-12-04 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 29 November 2017 at 16:13:13 UTC, Wanderer wrote:

static void getId(shared IdGen!(MyId)* g)
{
writeln("next: ", g.next());
writeln("next: ", g.next());
}


writeln synchronizes on stdout, so your code is mostly 
serialized, good example of a very subtle race condition.


Re: Shared and race conditions

2017-12-04 Thread Kagamin via Digitalmars-d-learn
A lock on stdout works as a barrier: threads may hit it 
simultaneously, but pass it one by one in a queue with a time gap 
between them.


<    1   2   3   4   5   6   7   8   9   >