Re: How to avoid invalid memory operation errors (and more) in DLLs?

2015-01-18 Thread Heinz via Digitalmars-d-learn

On Wednesday, 14 January 2015 at 13:51:08 UTC, John Colvin wrote:

Would it be possible for you to file this as a bug at 
issues.dlang.org ?


While trying to file this issue, I was simplifing my test case 
and in the process I was able to make it not crash, but now 
core.thread.Thread.getThis().name() is always empty, even if i 
__gshared everything so i guess this is one of those non 
trackable, non fixable issues that default TLS introduced.


This is so confusing and frustrating right now, I can't report 
this as a bug because I was able to fix the crash, but I wasn't 
able to obtain the desired results in my program, maybe a 
programming or implementation error?


I'm taking a break right now with D, I've been stuck for too long 
with these threading/tls issues. I need vacations.


How to avoid invalid memory operation errors (and more) in DLLs?

2014-12-25 Thread Heinz via Digitalmars-d-learn

Hello everyone,

I'm making a big framework with D2 (DMD 2.066.1) and I've been
encountering many errors related to threads in DLLs.

My program flow is a main exe wich statically loads a main dll,
then this main dll dynamically loads an extra dll and then this
extra dll dynamically loads a final dll. Inside this flow i only
create 2 threads for a total of 3 including the main thread.
Using the included debugger in DMD, it shows that 5 threads are
created but i can't understand why the extra 2 are spanned.

The problem is that in the final dll whenever i make calls to
functions exclusive to this dll i get "invalid memory operation"
errors. I don't know if this is TLS related but i have __gshared
everywhere in my framework and compiling with -vtls shows no tls
globals.

While trying to debug the program i found a bug (i think) present
in all DMD2 latest versions: I named all threads so i could
identify them in the debugging process by assigning the
core.thread.Thread.name property. But in the already mentioned
final dll, whenever i try to get the core.thread.Thread.name
property to print it, the whole program crashes.
Luckily i was able to reproduce this bug by making a very simple
and scaled down demo. It's flow is similar to my real program: A
main exe statically loads a main dll and then the main dll
dynamically loads an auxiliary dll from wich i try to print the
thread's name but the whole demo crashes.

Here's the test case i made, it includes binaries and source
code:
https://dl.dropboxusercontent.com/u/2351331/dll-tls%20test_case.zip

Just run the program and type the word "magic", it will load up
to the auxiliary dll wich will try to print the current thread
name but it will crash.
If anyone with more experience in DLL matters could confirm if
the above behavior is indeed a bug i'll be greatly appreciated.

Finally, if possible, i'd like to receive suggestions on how to
avoid extra threads from being created and avoid memory operation
errors in DLLs.

Thank you guys for your time (and brains) and i hope you had a
great x-mas.


Re: Symbol Undefined _D2rt12__ModuleInfoZ

2013-12-10 Thread Heinz
I always have the same problems (ModuleInfoZ, initZ, etc) when 
using import modules (.di files) wich i then have to include in 
the compilation process to get rid of linking errors. I do not 
know if this is the case.


Re: Modify const reference data

2013-12-09 Thread Heinz
Wow, i didn't know i could cast out constness from an lvalue. 
This is what i needed. I'll try it in my code as soon as i can. 
Thanks.


Yep, it compiles and works! By the way, i forgot to call b.foo() 
in my example. Thanks for your help guys.


Re: Modify const reference data

2013-12-09 Thread Heinz
Apparently the OP intended to set it in foo(). If the data is 
actually mutable and there really is no way other than going 
against the type system, foo() must be called at least once and 
can be implemented like this:


public void foo()
{
abc = [1,2,3,4];
cast(ubyte*)data = abc.ptr;
}

// ...

B b = new B();
b.foo();
b.print(); // now OK

Ali


Wow, i didn't know i could cast out constness from an lvalue. 
This is what i needed. I'll try it in my code as soon as i can. 
Thanks.


Re: Modify const reference data

2013-12-08 Thread Heinz
Duhhh! i got the pink avatar by default. That sucks. Pink is just 
not my color.


Modify const reference data

2013-12-08 Thread Heinz

[DMD 2.064.2]

Hello,

I've been strugling with a solution before bothering you guys 
here (again). I have my own complex code but i made a VERY simple 
test case to reproduce my problem, here's the code:


private import std.stdio;

class A
{
private const ubyte* data;
private ubyte[] abc;

this()
{
abc = [1,2,3,4];
data = cast(const ubyte*)abc.ptr;
}

public void print()
{
for(size_t i = 0; i < 4; i++)
{
writefln("%d", data[i]);
}
}
}

class B
{
private const ubyte* data;
private ubyte[] abc;

this()
{
data = cast(const ubyte*)abc.ptr;
}

public void foo()
{
abc = [1,2,3,4];
}

public void print()
{
for(size_t i = 0; i < 4; i++)
{
writefln("%d", data[i]);
}
}
}

void main()
{
A a = new A();
a.print(); // OK.

B b = new B();
b.print(); // Crash.
}

The thing is that i can not use the data that const variable 
"data" in class B is referencing because in my original code i 
get "Invalid Memory Operation", in the test case i get "access 
violation" but it doesn't matter the name of the exception, the 
only thing that matters is that the exception raises for the same 
reason. I understand that i should not modify the const data 
outside a constructor but by stricts reason i can't avoid that.


Do you guys have any other aproach to get away with this? (modify 
a const reference data and then manipulate that data). THANK YOU 
very much in advance. D2 learner by the way.


Re: Chris E. Miller ToolTip (D1)

2013-11-14 Thread Heinz
You have to manually set the tooltip's max width to a fixed value 
using the tooltip handle and Win32 API, by doing this you're 
telling the tooltip object it is a multiline tooltip and from now 
on it will accept \r\n as end of line:


ttip = new ToolTip;
SendMessageA(ttip.handle, TTM_SETMAXTIPWIDTH, 0, 250);
ttip.setToolTip(find, "a=n (not approved)\r\no=n (not 
outlooked)\r\nt>0 (total > 0));


That's it, it works (i tested it).

By the way, the DFL version on Chris' site is for D1 but there's 
this version for D2 (i use both): 
https://github.com/Rayerd/dfl/tree/master/win32/dfl


What's the deal with import files in D2?

2013-11-13 Thread Heinz
I come from D1 DMD1.030 programming era and i use import files 
(.di files) a lot as companion for my custom static libs (.lib). 
But now in D2 (and apparently in later D1 versions) they seem to 
be causing a lot of trouble, i mean, what's their purpose if i 
still have to compile them to get rid of undefined symbols mainly 
Module_Init, Module_Info and Module_Ctor.
Or is this a problem with the -lib switch that forgets to include 
those symbols in static libs? I mention this because i'm also 
getting symbol errors for my class(es) Ctors as well. It seems 
that some symbols are not being included in static libs. 
(happends in the newly released DMD2.064.2 as well).


I hope you have experienced the same to understand what i mean.


Re: directx bindings problem

2013-10-29 Thread Heinz

On Tuesday, 29 October 2013 at 19:40:40 UTC, Benjamin Thaut wrote:

So I found it. Its actually your fault.

IXAudio2Voice isn't a COM interface. That means it should _not_ 
inherit from IUnkown. But if it isn't a COM interface it can't 
be a regular D interface either, because if it is a regular 
D-Interface it will not have a v-table layout that conforms 
with C++. That means you have to put "extern(C++)" in front of 
IXAudio2Voice to make it work.


So to make stuff work you should change

interface IXAudio2Voice : IUnknown

to

extern(C++) interface IXAudio2Voice

Then everything works fine.

Tip for the future: Using the "Microsoft Symbol Server" and the 
Visual Studio Debugger you can easily verify if your COM 
interfaces call the correct methods or if you messed up the 
declarations.


Kind Regards
Benjamin Thaut


Whoa! This did the trick with XAudio2! Thank you very much. I'll 
have the C++ linkage in mind for the rest of the DirectX APIs. 
One question: Should the other interfaces like IXAudio2 for 
example use extern(C++) whether they are COM interfaces or not?


I'll also take your tip. I got the link for the symbol server. Do 
you have a link for a tutorial or something for the Visual Studio 
Debugger? I'd like more info about it. I assume the debug 
information from DMD is compatible with this debugger, right?


Thank you again for your help and time.


Re: directx bindings problem

2013-10-29 Thread Heinz

I have the exact same problem with XAudio2 in my own code. Code
compiles and run but doesn't output any sound. I tried your code
but it's the same as mine, runs but doesn't sound.

I'm using in my code the bindings from
http://www.dsource.org/projects/bindings/wiki/DirectX

Can't really understand what's going on with XAudio/COM in D2.


Re: How to translate this C++ preprocessor declaration in D?

2013-05-24 Thread Heinz
Guys, i also did a templated version that yields the same output 
as the C++ program:



import std.stdio;

template makeId(char[4] id)
{
const makeId = id[0] << 24 | id[1] << 16 | id[2] << 8 | id[3];
}

const kPIHostBlendModeSignature = makeId!("8BIM");
const PIPowerPCCarbonCodeProperty = makeId!("ppcb");
const PIPowerPCMachOCodeProperty = makeId!("mach");
const PICodeMacIntel32Property = makeId!("mi32");
const PICodeMacIntel64Property = makeId!("mi64");

void main()
{
writefln(kPIHostBlendModeSignature);
writefln(PIPowerPCCarbonCodeProperty);
writefln(PIPowerPCMachOCodeProperty);
writefln(PICodeMacIntel32Property);
writefln(PICodeMacIntel64Property);
}


Thanks for your help.


Re: How to translate this C++ preprocessor declaration in D?

2013-05-24 Thread Heinz
If it really has single quotes then it is a multi-character 
literal, value of which happens to be implementation-dependent. 
What is actually in place of asdf there? May be we can guess 
the intent better.


Ali


Here're some examples:

#define kPIHostBlendModeSignature   '8BIM'
#define PIPowerPCCarbonCodeProperty 'ppcb'
#define PIPowerPCMachOCodeProperty  'mach'
#define PICodeMacIntel32Property'mi32'
#define PICodeMacIntel32Property'mi64'

I'm porting the Photoshop SDK (CS6) to D. I already compiled a 
hybrid plugin with DMC and DMD (it works) but now i want to make 
native D plugins.


How to translate this C++ preprocessor declaration in D?

2013-05-24 Thread Heinz

Hi,

I'm porting a C++ header (i'm not a C++ programmer) and came with 
the following declaration:


#define my_id 'asdf'

How does this translate to D?

Thanks


Re: What sync object should i use?

2013-05-14 Thread Heinz

To Steven:


1. D mutex locks are re-entrant.  That is, you can do:

synchronized(mutex)
{
   synchronized(mutex)
   {
  ...
   }
}

and all is fine.


Hmmm, i guess this is what the docs meant by "mutexes are 
recursive", i didn't get it at first but now i do.
To test this i wrapped SetLoop() in synchronized(cond.mutex) and 
called it from consumer wich was already all wrapped by the same 
synchronized(cond.mutex), i thought at first it was going to be a 
deadlock but i guess this is what you mean because it works like 
a charm.


Thanks for your code example, i'll update my code with your 
suggestions. But there's one thing i don't understand in your 
example: If the producer is inside a while() generating multiple 
messages once in a while then when the lock is released in the 
consumer, the producer will replace "my_variable" a couple of 
times with the latest message until consumer gets to wait() 
again. That's why i locked the whole consumer, to sync all 
messages. Am i wrong here?


To Sean:

Let's back up a minute.  Can you be more specific about what 
you're trying to do?  I think you shouldn't need to use the 
"loop" var at all, but I'm not entirely sure.  Also, loop and 
my_variable will be thread-local given how they're declared.


Fair enough, i uploaded a bunch of code hoping that experienced 
programmers like you to understand right away what i'm doing.


I have this "main loop" wich is named here as my consumer 
function. I didn't want this main loop to be cycling all the time 
if there was nothing to do. So i needed an event object 
(condition/mutex) that locked the loop until any of the 2 program 
events (or both) occur:


1) A custom program message was sent by producer to main loop to 
notify for example mouse move, key press, timer tick, etc.
2) The user explicitly want to do something else (execute custom 
code or perform an action not covered by program messages) or did 
something that now needs to be processed inside the main loop. In 
this case the user calls SetLoop(true) to notify the main loop 
and then do what the user want.


That's why i have and need both types of messages: bool loop; and 
Object my_variable;


My code seems to work fine but i did not know if it was the best 
approach. Now i know after your help that i can and must protect 
both messages with the condition's mutex and have all in sync. 
Also i learned that wait() and notify() must be inside a lock.


To ALL:

Sorry for my incompetence. I'm not new to D but i am to D2 and 
multithreading. I got stuck in D1, specially in the DMD1.030 era 
(those were the most stable and beautiful times) but now i 
decided it was time to evolve. So far, learning D2 and 
multithreading hasn't been easy, but with your help guys i've 
accomplished many things.


Thank you again for your support.


Re: What sync object should i use?

2013-05-14 Thread Heinz
Guys, this is a precise example of what i'm trying to do. You'll 
notice that there're 2 ways of waking up the consumer:


/
Condition cond; // Previously instantiated.
bool loop = false; // This variable determine if the consumer 
should take the next iteration or wait until a thread calls 
SetLoop(true).
Object my_variable; // A value used for comunicating producer and 
consumer. It's not a prerequisite to be set for an iteration to 
happen.


// This function is called by multiple threads.
void SetLoop(bool val)
{
if(val != loop)
{
loop = val;
if(loop)
cond.notify(); // Wake up consumer in case it was 
waiting.
}
}

// This function is called by multiple threads.
bool GetLoop()
{
return loop;
}

void MyConsumer()
{
while(true)
{
synchronized(cond.mutex)
{
if(loop == false)
cond.wait(); // Wait for producer or 
SetLoop(true).

if(my_variable !is null)
{
/*
...
Call private function 1. SetLoop(true/false) might be called 
here.

...
*/
my_variable = null; // Lock is useful here for setting 
my_variable.

}

// These conditions are intentionally placed here.
if(loop == false)
continue; // Jump to next iteration. Please note that 
cond.mutex gets released and reaquired in the next iteration.

else
loop = false; // Reset waiting on every iteration. Can be 
modified by private function 2 below.


/*
...
			Call private function 2. SetLoop(true/false) might be called 
here.

...
*/
}
}
}

void MyProducer()
{
while(true)
{
if(/* Some other condition */)
{
			synchronized(cond.mutex) // Lock is useful here for setting 
my_variable.

{
my_variable = /* Some value */;
cond.notify(); // Wake up consumer in case it 
was waiting.
}
}
}
}
/

Wouldn't wrapping all the lines in "SetLoop()" inside a 
"synchronized(cond.mutex)" statement produce a deadlock because 
it might be called by private functions 1 or 2? Should i only 
wrap cond.notify() or is it of no meaning in this case? Like this:


void SetLoop(bool val)
{
if(val != loop)
{
loop = val;
if(loop)
{
synchronized(cond.mutex)
cond.notify(); // Wake up consumer in case it 
was waiting.
}
}
}

Synchronization of variable "loop" doesn't seem important in this 
case. Do you still recommend to use an extra mutex to set it? 
like this:


void SetLoop(bool val)
{
synchronized(extra_mutex)
{
if(val != loop)
{
loop = val;
if(loop)
{
synchronized(cond.mutex)
cond.notify(); // Wake up consumer in 
case it was waiting.
}
}
}
}

void MyConsumer()
{
//...
if(loop == false)
continue;
else
{
synchronized(extra_mutex)
loop = false;
}
//...
}

Thank you guys so much for your time and your expertise.


Re: What sync object should i use?

2013-05-14 Thread Heinz

On Monday, 13 May 2013 at 21:04:23 UTC, Juan Manuel Cabo wrote:

There is one thing that should definitely added to the 
documentation, and that is what happens when one issues a 
notify while the thread hasn't yet called Condition.wait().


I can confirm that under Win32 calling notify() before wait()
internally signals the condition and then calling wait() returns
immediately and actually does not wait. This is the expected
behavior and is actually how Win32 events work.

On Tuesday, 14 May 2013 at 08:58:31 UTC, Dmitry Olshansky wrote:

Have to lock it otherwise you have a race condition on a 
condition variable (wow!).


Ok, i'll lock it just in case. It also makes me feel my code is
more robust. This will do right?

...
synchronized(cond.mutex)
 cond.notify();
...

My internal bool variable that affects the condition (the one
that decides if the consumer thread should wait) must be setable
at any moment by any thread so i leave it outside the lock. Also,
after setting this variable i immediately call notify() with
mutex unlocked. That's why it is working i think.

Doesn't prove anything, it could happen that you just miss a 
notification, for instance. Another common case is that it so 
happens that wait will (with luck) always happen before any of 
notify and notifications come spaced out in time.


True, i guess my code work 100% as needed because of its
implementation, in my case it doesn't matter if i miss a
notification because the result of that notification gets
evaluated in the next loop inside a while, but still most
probably as you say wait() is always happening before a
notification.
A classic producer-consumer program must lock both calls, i do
understand that.


Re: What sync object should i use?

2013-05-13 Thread Heinz
BTW, given recent discussion on memory barriers, I think my 
previous statement that the mutex does not need to be locked to 
call notify is probably incorrect.


Haven't had any issues calling notify outside a synchronized 
statement, even from multiple threads. At least this works under 
Win32 with my producer thread all wrapped inside synchronized(). 
Only a single consumer thread is inside synchronized() but then i 
have 2 more threads making naked calls to notify(). Not a single 
crash.


Re: What sync object should i use?

2013-05-13 Thread Heinz

Ok, here's a summary in case someone else is in the same need:

1) Want to know what "mutex/condition" are, how do they work and 
when to use them? Here's a good resource: 
http://stackoverflow.com/a/4742236


2) If you come to the question "Why a condition needs a mutex?": 
http://stackoverflow.com/questions/2763714/why-do-pthreads-condition-variable-functions-require-a-mutex


3) Need a working example in D? (by Steven Schveighoffer): 
http://forum.dlang.org/thread/j7sdte$25qm$1...@digitalmars.com


Re: What sync object should i use?

2013-05-13 Thread Heinz

On Monday, 13 May 2013 at 19:41:48 UTC, Heinz wrote:

Hi,

I'm looking for an object in "core.sync" whose internal counter 
can be 0 or 1 (signaled/not signaled), just like Event Objects 
in Win32 
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396%28v=vs.85%29.aspx). 
The object must be waitable and able to notify waiters. A 
semaphore is the most similar thing but its internal counter 
can range from 0 to x. I can perfectly create and use an event 
under Win32 for my needs but i do not know their counterparts 
in FreeVSD, Linux and OSX; that's why i'm trying to use an 
already implemented object from the runtime.


This is what i'm trying to do:

void MyFunc()
{

}


Damn, i hit enter and posted before completion, fail! Here's the 
code:


/
bool do_loop;

// This function runs in its own thread.
void MyFunc()
{
while(true)
{
if(!do_loop)
myobject.wait(); // Wait for sync object.
// ... Do other stuff. "do_loop" can be set to false again here.
}
}

// This one is called by different threads.
void loop(bool val)
{
do_loop = val;
if(do_loop) // Release sync object if it is waiting.
myobject.notify();
}
/

The idea is that i have a code that loops and do a lot of stuff 
but sometimes i don't want it to loop so i set do_loop to false. 
When i want it to loop i set do_loop to true and release the 
waiting object.
The problem of using a semaphore is that if i call loop() with 
true multiple times, my code will perform extra loops until the 
internal counter gets to 0, that's why i need a 0-1 sync object.


Any suggestions?

Thank you in advance.


Re: What sync object should i use?

2013-05-13 Thread Heinz
On Monday, 13 May 2013 at 19:49:51 UTC, Steven Schveighoffer 
wrote:
On Mon, 13 May 2013 15:41:47 -0400, Heinz  
wrote:



Hi,

I'm looking for an object in "core.sync" whose internal 
counter can be 0 or 1 (signaled/not signaled), just like Event 
Objects in Win32 
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396%28v=vs.85%29.aspx). 
The object must be waitable and able to notify waiters. A 
semaphore is the most similar thing but its internal counter 
can range from 0 to x. I can perfectly create and use an event 
under Win32 for my needs but i do not know their counterparts 
in FreeVSD, Linux and OSX; that's why i'm trying to use an 
already implemented object from the runtime.


This is what i'm trying to do:

void MyFunc()
{

}


core.sync.condition and core.sync.mutex

I'd point at the docs, but they are poor.

Search online for docs on how mutexes and conditions work.  
It's very similar to Windows events.


-Steve


Thanks Steve for your quick reply. You answered me before i fixed 
my post.
I'll take a look at what you say and post again here in case i 
have other questions.


What sync object should i use?

2013-05-13 Thread Heinz

Hi,

I'm looking for an object in "core.sync" whose internal counter 
can be 0 or 1 (signaled/not signaled), just like Event Objects in 
Win32 
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396%28v=vs.85%29.aspx). 
The object must be waitable and able to notify waiters. A 
semaphore is the most similar thing but its internal counter can 
range from 0 to x. I can perfectly create and use an event under 
Win32 for my needs but i do not know their counterparts in 
FreeVSD, Linux and OSX; that's why i'm trying to use an already 
implemented object from the runtime.


This is what i'm trying to do:

void MyFunc()
{

}


Re: AES-NI

2012-12-08 Thread Heinz
On Saturday, 8 December 2012 at 17:11:37 UTC, Alex Rønne Petersen 
wrote:

On 08-12-2012 18:08, Heinz wrote:

Hi,
Are AES-NI instruction set supported by the D inline assembler?
If not, can they be used by inserting raw data (the 
corresponding

opcodes)? Does anyone know the opcodes for the instruction set?
Thanks


Yes, they are supported.

And yes, you can insert raw machine code with the db, dw, dd, 
and dq directives. The opcodes can be found in the Intel manual.


Thanks for your answer. By supported you mean i can use the 
mnemonic (AESENC, AESDEC, etc) inside an ASM statement or must i 
insert the raw machine code with db, dw, etc?


Just in case i've been looking for the corresponding machine 
codes and can not find them, i've searched even in Intel's AES 
whitepaper with no luck.


AES-NI

2012-12-08 Thread Heinz

Hi,
Are AES-NI instruction set supported by the D inline assembler?
If not, can they be used by inserting raw data (the corresponding
opcodes)? Does anyone know the opcodes for the instruction set?
Thanks


Re: Using templates to declare function prototypes

2011-07-30 Thread Heinz
Thanks, extern(System) seems to do the job under windows at least, i hope it
switch to extern(C) for other systems, can't test it right now. The System 
version
works even with the old DMD 1.030. If this defined version is that old then why 
it
is not documented yet with newer releases?

Thank you for this solution.


Using templates to declare function prototypes

2011-07-30 Thread Heinz
Hello D community!!!

I'm porting the NVIDIA CUDA headers to D. The CUDA platform runs on multiple
OS, so functions prototypes (in the D way) are declared as "extern(Windows)
..." for MS Windows and "extern(C) ..." for other OS'es.

The thing is that there's no "alias extern(X) myextern;" in D to be used like
this:

version(Windows)
alias extern(Windows) myextern;
else
alias extern(C) myextern;

...
myextern void cudaFunct1();
myextern uint cudaFunct2(byte*);

...The C way to accomplish this is:

#ifdef _WIN32
#define CUDAAPI __stdcall
#else
#define CUDAAPI
#endif
...
CUresult CUDAAPI cuInit(unsigned int Flags);

It is a bit redundant and dirty to declare all the functions twice. So i made
a template to declare functions prototypes with the corresponding naming
convention, here's what i got:

template CUDAAPI(R, P ...)
{
version(Windows)
alias extern(Windows) R function(P) CUDAAPI;
else
alias extern(C) R function(P) CUDAAPI;
}
...
CUDAAPI!(CUresult, uint) cuInit;

This code actually compiles since its syntax is correct but when linking i
relize that the linker is still looking for the "extern(D)" symbol and by any
means, no matter where i place the extern(X), the compiler is generating the D
mangled symbol (_D5cudad4cuda6cuInitPWkZE5cudad4cuda8CUresult, at least the
template is inserted in the context).
I've tried with DMD 1.030 and the latest 1.069, both with the same result.

I also did a mixin flavored template that also compiles but is even worse
because the linker is still stuck with a templated/D mangled symbol, take a 
look:

template CUDAAPI(string N, R, P ...)
{
version(Windows)
mixin("extern(Windows) R " ~ N ~ "(P);");
}
...
mixin CUDAAPI!("cuInit", CUresult, uint);

The generated symbol for this code is:
__D5cudad4cuda55__T7CUDAAPIVG6aa6_6375496e6974TE5cud
ad4cuda8CUresultTkZ6cuInitWkZE5cudad4cuda8CUresult@4. As you can see, the
symbol is still recognized as a template so i discard this code.

I found templates to be a very interesting case of study, templates give
languages the fun or the exciting part of programming by presenting challenges
in code complexity but still i can not get some parts of my code to work.

Any aproach or ideas on how to accomplish this template or multi extern
declaration?

Thank you so much for reading.


Re: Cycle detected between modules with ctors/dtors

2011-04-24 Thread Heinz
I haven't faced this myself. DMD is complaining about module Ctors and Dtors, so
the bug must be there. But, i'm very curious about the scenario you mention,
nested classes accessing its outer class:

How are you referring the parent class from the child classes?
Use the "outer" property of the child classes and see if that helps a bit.


Re: Additional path for libs

2011-02-24 Thread Heinz
Andrej,

Thanks for the reply. I already tried /SCANLIB before with no
success.
I couldn't find a solution so i'm sticking to the classic method of
declaring each lib in the dmd command line.
Lib paths at command line could be added to OPTLINK, it should work
in the same way the DMD -I argument work. This is beyond our scope
anyway, this is a task for Walter.

Thanks anyway.


Additional path for libs

2011-02-23 Thread Heinz
Hey!

May be a silly situation but i'm trying to append a search path for
libraries from the command line. I'm running under win32 with
DMD/OPTLINK and i use a batch file for compilation of my project.
Adding the path to sc.ini won't help because the project' sources
might be moving around in different machines and folders so i'm
trying to set a path relative to the sources when invoking dmd.
Copying sc.ini to the source path won't help much because DMD might
be in different locations at other machines and also the idea is
not to mess with the config file.
Setting the LIB enviroment variable doesn't produce a positive
result.
Here's my batch file:

---
@ echo on
set LIB=..\lib
dmd -O -release -inline -ofdemo.exe -I..\import main.d main.def
pause
---

The libs are called from sources with pragma(lib, "mylib.lib");
Any tips on how to accomplish this, if possible?

BIG THANKS


Re: ASM access to array

2011-02-04 Thread Heinz
bearophile,

Thank you so much for all your help. It seems you're very into ASM.
I kept the D_InlineAsm_X86 in my code as you suggested. The code i gave here was
just an example. But my code's version implementation looks like this:

version(D_InlineAsm_X86)
{
// ASM Code.
}
else
{
// D code.
}

This results in a much robust code. You were right about it.
You are right too about the "load-load-load processing-processing-processing
store-store-store instead a load-processing-store load-processing-store
load-processing-store" thing. I'll modify my code to this model, though it will
require to move some elements to the stack but no big deal, i think this won't
hurt performance as it is designed to work this way.

-Does ASM kill inlining for the function where the asm block is present or for 
the
whole compilation?
-In your opinion, How badly can be if function inlining is not present? some 
docs
from the net: http://www.parashift.com/c++-faq-lite/inline-functions.html

Cheers,

Heinz


Re: ASM access to array

2011-02-03 Thread Heinz
Thanks 4 the code (this goes to Matthias Pleh too):

Both codes work amazingly fine after modifying them a bit to work with DMD1.030.
This helped me a lot!
Still don't know how the asm version implicitly returns a value (no return 
keyword
needed). It seems that the returned value is EAX, not the variable "value". To
return "value", first the content of EAX should be moved to "value", right? (mov
value, EAX;)

I found this site: http://www.swansontec.com/sregisters.html
It helped me to resolve optimal register usage. It also details wich registers 
can
use offsets.

I finally ended with this ASM code:

// I have to rotate every int of an uint[3]. For some reason i can't directly
reference the array pointer so i create a local variable to the function.

void myFunct()
{
uint* p = myarray.ptr;
asm
{
mov EBX, p;

mov EAX, [EBX + 4];
rol EAX, 8;
mov [EBX + 4], EAX;

mov EAX, [EBX + 8];
rol EAX, 16;
mov [EBX + 8], EAX;

mov EAX, [EBX + 12];
rol EAX, 24;
mov [EBX + 12], EAX;
}
}

Hope this helps someone else.
Cheers.

Heinz


Re: ASM access to array

2011-02-01 Thread Heinz
Wow, thanks for the reply. Changing the 'enum dsize' to 'uint dsize = 4;' seems 
to
produce some results...i guess it's working now (i have no way to verify it is
working but looks like bits are being rotated by rol). One thing, if i replace
dsize with 4 in all lines, the code compiles but again it does nothing, weird 
uh?

Is D_InlineAsm_X86 really needed? I saw it is listed in the predefined versions
table. Is this version for custom use or is it used internally by the compiler 
to
specify that inline ASM is available or not? Inline ASM is always available 
right?

Anyway, thanks for the code. I was wondering: Is there any other way to directly
use operands with class members, array items in this case? I mean, for variables
local to functions i use the variables as if they were in a D code statement, 
but
in your code we have to create local variables and move them between registers,
the values are moved too.

// LOCAL VARIABLE EXAMPLE
void MyFunct()
{
uint temp;
asm
{
rol temp, 8;
}
}

If i'm going to create local pointers and constants and move them across 
registers
then, to accomplish the same result, would it be better (or the same) to create 
2
local ints, rol them and then move them to their respective place (this way the
compiler might generate better code):

// EXAMPLE
class MyClass
{
private uint[] array;

private void MyFunc()
{
uint a = array[0], b = array[1];
asm
{
rol a, 8;
rol b, 16
}
array[0] = a;
array[1] = b;
}
}

Thanks 4 everything!!!


ASM access to array

2011-02-01 Thread Heinz
Hi there,
Although i've been coding in D for the last 5 years, i've never got my hands
into ASM until now. I'm trying to use the inline assembler now and i'm trying
to apply opcodes to a class member, an uint array but don't know how. This is
what i've been trying to accomplish:

class MyClass
{
private uint[] array;

private void MyFunc()
{
asm
{
rol array[1], 8;
rol array[2], 16
}
}
}

The above code complains about type/size. However, it seems to work with
single uint variables local to the function. I've tried moving the values to
EBX and ECX then applying rol to these registers. The code compile and run but
does nothing at all.
Any ideas or guide? A good doc about asm with D?
BIG THXS!!!


Re: Example Attached

2009-02-13 Thread Heinz
torhu Wrote:

> On 10.02.2009 19:51, Heinz wrote:
> > Heinz Wrote:
> >
> > I attached a rar file with the sources just to see what i'm talking about. 
> > The example is from the DMD site. Included is the extern D (ok) and the 
> > extern C (fails). To compile open "compile.bat" and to run the programs use 
> > "run.bat".
> 
> Try this:
> alias extern (C) void function(void*) MyDLL_Initialize_fp;
> alias extern (C) void function() MyDLL_Terminate_fp;
> alias extern (C) MyClass function() getMyClass_fp;

Haha! cool man, thanx, it works.
I never though it could be the type but adding extern(C), the program treats 
variables as C function pointers. I had no idea at all that i can create 
extern(C) variables to be trated as C type. I learned something new today!
Thanks again.



Example Attached

2009-02-10 Thread Heinz
Heinz Wrote:

> Hello everyone.
> I've been using DLL's in D for a long time but just recently i'm having a 
> problem. Lets see if someone can help me a bit.
> 
> I have several lines of code but i'll use an example from the DMD site wich 
> is almost the same come.
> 
> Read the DMD site about DLL's here: http://www.digitalmars.com/d/1.0/dll.html
> 
> Check for the section "D code calling D code in DLLs".
> 
> If you extern(C) all exports in mydll.d and change all symbols in test.d to 
> their C respectives, when running you'll get access violation.
> 
> Any ideas?

I attached a rar file with the sources just to see what i'm talking about. The 
example is from the DMD site. Included is the extern D (ok) and the extern C 
(fails). To compile open "compile.bat" and to run the programs use "run.bat".


mydll.rar
Description: application/rar


DLL €rror: D calling D extern(C) code

2009-02-10 Thread Heinz
Hello everyone.
I've been using DLL's in D for a long time but just recently i'm having a 
problem. Lets see if someone can help me a bit.

I have several lines of code but i'll use an example from the DMD site wich is 
almost the same come.

Read the DMD site about DLL's here: http://www.digitalmars.com/d/1.0/dll.html

Check for the section "D code calling D code in DLLs".

If you extern(C) all exports in mydll.d and change all symbols in test.d to 
their C respectives, when running you'll get access violation.

Any ideas?


Re: switch off GC?

2009-02-08 Thread Heinz
Tim M Wrote:

> On Wed, 04 Feb 2009 15:38:45 +1300, Weed  wrote:
> 
> > It is possible to disable GC?
> >
> > That it has not been included in result binary for an increasing
> > performance of ref operations and reduction of the size of the binary
> >
> > I have not found the answer in google.
> 
> 
> To anyone here that disables there GC: Whats you reason for doing this?  
> (Note: I don't want to know possible requirements but just your reason  
> just out of interest)

Just for interest in some optimization:
I disable it (but replace it) in DLL's, i mean, there's no need to have 2 GC 
running at a time (one for the exe and one for the DLL), so i disable the one 
in the dll and then replace it with the same from the exe. I link my dll with 
gcstub.obj to use a dummy gc so file size is smaller.
So after all...i never disable gc.

GC is a good feature, i always use it in executables but when i do a gc full 
collect under heavy load programs (great amount of mb of ram) the thing gets 
quiet slow.


Can i safely cast void* from void[]?

2009-02-08 Thread Heinz
Hi,

I remember i read around the D site that dinamic arrays can be stored in system 
memory in a 'non contiguous' way (different locations). I was trying to find 
again that page but haven't had any lucky. I'm not crazy, i know i saw it.

Anyway, i need this info to ensure that i can/can't cast from void[] to void*. 
I'm working with D dinamic arrays but i need to work this data then with 
windows API's, these functions take void* as parameters. I pass params of type 
cast(void*)void[] and have had no problems at the moment. But, what if data in 
the array is not stored contiguously? windows functions will crash right?

I hope you get the idea, and i hope someone to answer me. Thanx.