Re: Sample source code for D

2011-03-27 Thread Ishan Thilina
@ David:

I'm looking for example code that explains specific pieces of functionality :)

@Lutger:

Those two links were really helpful :). Thank you :)


Re: std.conv.to can't convert to bool?

2011-03-27 Thread Andrej Mitrovic
Wow not a minute later and I get bitten by my own solution. A C
function returned 1 for a supported feature, and -1 otherwise. And of
course -1 got converted to true, so then I had a bug in my code.

Damn silly C functions which return -1 when they should return 0.

Or damn me for not RTFM'ing.


std.conv.to can't convert to bool?

2011-03-27 Thread Andrej Mitrovic
import std.stdio;
import std.conv : to;

void main()
{
uint state = 1;
writeln( to!bool(state) );
}

D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(99): Error: template 
std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && 
isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S))) does not match any 
function template declaration
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(99): Error: template 
std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && 
isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S))) cannot deduce 
template function from argument types !(bool)(uint)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(99): Error: template 
instance errors instantiating template
boolConv.d(9): Error: template instance std.conv.to!(bool).to!(uint) error 
instantiating

What's the big problem with converting an int/uint to bool? I'm using a cast 
for now.


Re: Techniques on debugging runtime errors?

2011-03-27 Thread Andrej Mitrovic
I've found the problem and the solution, see this post:
http://www.kvraudio.com/forum/viewtopic.php?p=4467686#4467686

I completely forgot that the VST standard has at least two different
implementations, v2.3 and v2.4. And I've also forgot that I need to
ask the DLL if it supports calling one of two different function
implementations. The problem was I was calling a function that's only
defined in the v2.4 standard, but this vendor-specific DLL conforms to
v2.3 and didn't have it.

So luckily this wasn't such a big problem at all. Yay! :)


Re: Techniques on debugging runtime errors?

2011-03-27 Thread Daniel Green

On 3/27/2011 7:58 PM, Andrej Mitrovic wrote:

Actually it looks like I can recreate this bug in non-realtime mode as
well. I forgot that I can actually process audio at whatever timing I
want to (I haven't touched this project in a while..). Oddly enough I
can call various DLL functions but it fails the second I try to pass
some audio data to it. Other plugins work fine. I wonder what I'm
missing here..

Are you passing D data to a C or C++ dll?

It may be related to size and alignment of any data passed.  When I 
wrote wrappers for freetype2 I used long for my dll calls forgetting 
that long and int are the same size for C.


It could also be Structured Exception Handling used by Windows.


Re: Techniques on debugging runtime errors?

2011-03-27 Thread Andrej Mitrovic
Actually it looks like I can recreate this bug in non-realtime mode as
well. I forgot that I can actually process audio at whatever timing I
want to (I haven't touched this project in a while..). Oddly enough I
can call various DLL functions but it fails the second I try to pass
some audio data to it. Other plugins work fine. I wonder what I'm
missing here..


Techniques on debugging runtime errors?

2011-03-27 Thread Andrej Mitrovic
I have this sort of runtime error in a fairly involved project:
---
main.exe - Application Error
---
The instruction at "0x0411b00e" referenced memory at "0x0020". The memory 
could not be "read".
---

Background info:
Its a realtime app, and I can't really run a debugger since there's a 
high-priority thread being started by a device driver, and stepping through 
code would immediately break the app. 

The app loads a DLL that processes some audio in real-time. Loading a DLL from 
one vendor runs perfectly, audio gets processed and I can hear back the result. 
But loading a DLL from a different vendor gives me this  runtime error. Another 
thing is I can show the GUI (if its available) of either DLLs, (generally audio 
plugins do come with GUI's). Both plugins show the GUI and I can interact with 
it with no issues. But trying to process audio on one of the DLLs fails.

I've tried it with over a dozen vendor DLLs. So far there's only one that 
fails. Its not so uncommon for an audio processing plugin to fail, but I'd like 
to know _why_. There are many plugin hosts on the market, and I've tried this 
specific DLL with a few of them, it seems to work. So something with my piece 
of the code might be wrong.

My real question is: how do I even begin to debug code that needs to run in 
realtime? There's no memory debugger for D2 that I know of (maybe Vlad will 
port his Diamond to D2 one day :) ), I've tried using a stacktrace but its not 
of much help, all I get back is this:

00 D:\dev\projects\sequencer\src\.\stacktrace\stacktrace.d::57(0) 
_D10stacktrace10stacktrace10StackTrace32UnhandeledExceptionFilterHandlerWPvZi
01 UnhandledExceptionFilter
02 ValidateLocale

Wrapping my main() inside a try{}catch{} doesn't help either, even if I try to 
catch Throwable's. So it might be an exception thrown from within a DLL. Or 
not. :)

I'm a complete newbie when it comes to runtime bugs like these. Any good 
resources, something to read, or techniques, to figure this out? Something 
tells me I'll just have to dive in neck-deep into the disassembly..


Re: Assertion failure: '!vthis->csym' on line 703 in file 'glue.c'

2011-03-27 Thread nrgyzer
== Auszug aus bearophile (bearophileh...@lycos.com)'s Artikel
> nrgyzer:
> > In my tests, that code above doesn't produces the assertion
failure,
> > but my original source code looks very similar.
> You may have to start over then. I suggest to duplicate the whole
code, and then start on the copied version removing modules and lines
of code, compiling it every time you remove something, making sure
you keep seeing the error message every time, and undoing the change
when you see the error vanish or change.
> Bye,
> bearophile

That's a bit mysterious... I replaced firstModule with the source
which produces the error. Now... when I run my test application, I
get the same failure - but... that's not all - when I restore
firstModule to the version which didn't produce the failure, I just
get the same error. When I copy the source files to a new location
and compile it, I didn't get the error.
It seems that there is anything like a cache, but I removed all
produced (obj, rsp...) files, expect the exe- and d-files. Thus I
think there should be something like a cache.
I currently haven't any idea what I can do to reproduce the failure
efficently.


Re: null Vs [] return arrays

2011-03-27 Thread bearophile
Jonathan M Davis:

> the compiler can likely make 
> assumptions about null that it can't make about [], since it probably treats 
> [] more generally without worrying about the fact that it happens to be empty 
> as far as optimizations go - that and there _is_ a semantic difference 
> between 
> null and [] if you're messing with the ptr property, so Walter may think that 
> it's best for null to not be turned into the same thing as [] automatically.

Thank you for your answer. I have added a low-priority enhancement request.

Bye,
bearophile


Re: Assertion failure: '!vthis->csym' on line 703 in file 'glue.c'

2011-03-27 Thread bearophile
nrgyzer:

> In my tests, that code above doesn't produces the assertion failure,
> but my original source code looks very similar.

You may have to start over then. I suggest to duplicate the whole code, and 
then start on the copied version removing modules and lines of code, compiling 
it every time you remove something, making sure you keep seeing the error 
message every time, and undoing the change when you see the error vanish or 
change.

Bye,
bearophile


Re: Assertion failure: '!vthis->csym' on line 703 in file 'glue.c'

2011-03-27 Thread nrgyzer
== Auszug aus David Nadlinger (s...@klickverbot.at)'s Artikel
> On 3/26/11 11:08 PM, bearophile wrote:
> > I suggest to copy your code, and then keep removing lines from
your copy, making sure it keep showing the same compiler error. In
some time you will probably be able to produce a small program, fit
for this newsgroup or even for Bugzilla. (There are tools to do this
reduction automatically in Python, I think).
> You don't necessarily need fancy tools to do that – as I recently
> pointed out in another thread, the Tigris »delta« tool worked
fine for
> me on several occasions (http://delta.tigris.org/). Just write a
simple
> shell script looking for the error message in the compiler output,
and
> delta will try to automatically reduce the file for you.
> There is some room for improvement though when you have an actual
> lexer/parser available for heuristically determining what pieces of
code
> to delete – this might be a nice demonstration project for a D
parsing
> library.
> David

I figured out what produces the error - "import
dcollections.LinkList;" (declared as private) in one source file. But
I'm still unable to reproduce that error in a sample-application.
What I currently can say, that I have two source files like:

module firstModule;

private {
   import dcollections.LinkList;
   LinkList!(uint) myPrivateList;
}

static this() {
   myPrivateList = new LinkList!(uint);
}

module secondModule;

import firstModule;
import dcollections.LinkList;

LinkList!(uint) list;

void main(string[] args) {
   list = new LinkList!(uint);
}

In my tests, that code above doesn't produces the assertion failure,
but my original source code looks very similar.


Re: null Vs [] return arrays

2011-03-27 Thread Jonathan M Davis
On 2011-03-27 11:42, bearophile wrote:
> Kagamin:
> > [] is not null, it's an array of 0 elements, what is done exactly.
> > edx points to the allocated array.
> 
> I don't understand what you say. I think the caller of foo() and bar()
> receive the same thing, two empty registers. I think that cast(int[])null
> and cast(int[])[] are the same thing for D.
> 
> void main() {
> assert(cast(int[])null == cast(int[])null);
> auto a1 = cast(int[])null;
> a1 ~= 1;
> auto a2 = 1 ~ cast(int[])null;
> }

What I would _expect_ the difference between a null array and an empty one to 
be would be that the null one's ptr property would be null, whereas the empty 
one wouldn't be. But dmd treats them pretty much the same. empty returns true 
for both. You can append to both. The null one would be a guaranteed memory 
reallocation when you append to it whereas the empty one may not be, but their 
behavior is almost identical.

How that affects the generated assembly code, I don't know. Particularly if 
you're compiling with -inline and and -O, the compiler can likely make 
assumptions about null that it can't make about [], since it probably treats 
[] more generally without worrying about the fact that it happens to be empty 
as far as optimizations go - that and there _is_ a semantic difference between 
null and [] if you're messing with the ptr property, so Walter may think that 
it's best for null to not be turned into the same thing as [] automatically.

- Jonathan M Davis


Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Jonathan M Davis
On 2011-03-27 13:20, Jacob Carlborg wrote:
> On 2011-03-27 21:24, Ishan Thilina wrote:
> > @Jacob:
> > 
> > An error comes when the " ./dvm install dvm" command is given.
> > 
> > "
> > ./dvm: error while loading shared libraries: libz.so.1: cannot open
> > shared object file: No such file or directory
> 
> You don't have libz installed? Oh, you're running 64bit, you need to
> install 32bit libraries. I also forgot to mention that DVM currently
> only installs the 32bit version of DMD. The 64bit version is quite new,
> don't know if it's experimental, alpha or beta.

Probably alpha. I believe that it mostly works, but there are still plenty of 
bugs to find, I'm sure.

However, depending on what you mean by "installing" the compiler, there is no 
32-bit vs 64-bit version. Only the libraries differ. There is only a 32-bit 
binary for the compiler, and you pass it -m64 if you want it to compile 64-bit 
binaries. So, if your tool deals with the compiler only, then 32-bit vs 64-bit 
is currently a moot point. On the other hand, if it deals with the standard 
libraries too (as it probably does), then 32-bit vs 64-bit _is_ an issue, but 
it isn't an issue for the compiler itself. And unless you're not using the 
standard dmd.conf as part of switching compilers, there would already be a 
difference in the library layout once 64-bit compilation was introduced, since 
the 32-bit Phobos was moved from dmd2/linux/lib to dmd2/linux/lib32 (with the 
64-bit version in dmd2/linux/lib64). And if you made the lib32 change, then 
having it work with 64-bit is likely trivial. And if you didn't make such a 
change, you're going to have to eventually. Personally, I don't see tha alpha 
quality of the 64-bit code generation to be a reason not to support it. It's 
been released. But then again, I don't use your tool at all and find no need 
for it, so it's not like I'm one of your users.

- Jonathan M Davis


Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Jacob Carlborg

On 2011-03-27 21:24, Ishan Thilina wrote:

@Jacob:

An error comes when the " ./dvm install dvm" command is given.

"
./dvm: error while loading shared libraries: libz.so.1: cannot open shared 
object
file: No such file or directory


You don't have libz installed? Oh, you're running 64bit, you need to 
install 32bit libraries. I also forgot to mention that DVM currently 
only installs the 32bit version of DMD. The 64bit version is quite new, 
don't know if it's experimental, alpha or beta.




@Trass3r:

No, dmd.conf in the dmd2/linux/bin is there safely


--
/Jacob Carlborg


Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Jonathan M Davis
On 2011-03-27 12:24, Ishan Thilina wrote:
> No, dmd.conf in the dmd2/linux/bin is there safely

Perhaps druntime got messed up then. Is

dmd2/src/druntime/import/object.di

there? Or did you ever mess with your dmd.conf? If you're using the default 
and you've left files in place without trying to do stuff like move libraries 
to /usr/lib, then it should work just fine. If you messed with dmd.conf or you 
moved the standard libraries or source around without changing your dmd.conf, 
then it's not going to be able to find the source or libraries.

- Jonathan M Davis


Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Ishan Thilina
@Jacob:

An error comes when the " ./dvm install dvm" command is given.

"
./dvm: error while loading shared libraries: libz.so.1: cannot open shared 
object
file: No such file or directory
"

@Trass3r:

No, dmd.conf in the dmd2/linux/bin is there safely


Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Jacob Carlborg

On 2011-03-27 12:28, Ishan Thilina wrote:

When I give "dmd untitled.d" command in my ubuntu maverick 64 bit laptop I get
the following error.

"
object.d: Error: module object is in file 'object.d' which cannot be read
import path[0] = /etc/../../src/phobos
import path[1] = /etc/../../src/druntime/import
"

I tried all morning to solve this problem, tried every google result I could
find. Checked the mail archive to solve this problem. But I still couldn't get
rid of that error.I anybody can help me, it would be a great help.

I followed the steps in http://www.digitalmars.com/d/2.0/dmd-linux.html .I
first used the command "cp dmd2/linux/bin/dmd.conf /etc
" . Then I gave "sudo apt-get install gcc-multilib g++-multilib libc6-i386
libc6-dev-i386" command.

Thank you :)


You can try and installing DMD with my tool, DVM: 
https://bitbucket.org/doob/dvm . It makes it easy to install and switch 
between different versions of DMD. Just run:


wget -O dvm https://bitbucket.org/doob/dvm/downloads/dvm-0.1.1-linux && 
chmod +x dvm && ./dvm install dvm


dvm install 2.052
dvm use 2.052

--
/Jacob Carlborg


Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Trass3r
"object.d: Error: module object is in file 'object.d' which cannot be  
read

Specify path to file 'object.d' with -I switch
"


Could it be you also deleted the dmd.conf in the local dmd/linux/bin?


Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Jacob Carlborg

On 2011-03-27 14:55, spir wrote:

On 03/27/2011 12:28 PM, Ishan Thilina wrote:

When I give "dmd untitled.d" command in my ubuntu maverick 64 bit
laptop I get
the following error.

"
object.d: Error: module object is in file 'object.d' which cannot be read
import path[0] = /etc/../../src/phobos
import path[1] = /etc/../../src/druntime/import
"

I tried all morning to solve this problem, tried every google result I
could
find. Checked the mail archive to solve this problem. But I still
couldn't get
rid of that error.I anybody can help me, it would be a great help.

I followed the steps in
http://www.digitalmars.com/d/2.0/dmd-linux.html .I
first used the command "cp dmd2/linux/bin/dmd.conf /etc
" . Then I gave "sudo apt-get install gcc-multilib g++-multilib
libc6-i386
libc6-dev-i386" command.

Thank you :)


First, please always post the piece of code that provokes an error. If
it's a big or complicated thing, then try to reduce it to the smallest
and simplest bit possible. Usually, doing this will let you find the
source of the problem ;-)

Second, this kind of error is caused by wrong import path (yes, the
error message could mention "import"). Typically, when one writes eg:
import range;
instead of
import std.range;
But your case is strange. Do you know object.d is the core of D's std
lib, which defines about all what you absolutely need to use when
programming in D? One does not need to import it, this is automatical.
Also, the message says the error happens in object.d itself, which is
very un-probable.
I thus suspect you named one of your own modules "object.d", which
breaks the import mechanics (for D's standard object.d and possibly for
other stdlib/phobos modules). This may be considered as a bug.

denis


The error

"object.d: Error: module object is in file 'object.d' which cannot be read"

usually happens when DMD can't find the sources or phobos.

--
/Jacob Carlborg


Re: null Vs [] return arrays

2011-03-27 Thread bearophile
Kagamin:

> [] is not null, it's an array of 0 elements, what is done exactly.
> edx points to the allocated array.

I don't understand what you say. I think the caller of foo() and bar() receive 
the same thing, two empty registers. I think that cast(int[])null and 
cast(int[])[] are the same thing for D.

void main() {
assert(cast(int[])null == cast(int[])null);
auto a1 = cast(int[])null;
a1 ~= 1;
auto a2 = 1 ~ cast(int[])null;
}

Bye,
bearophile


Re: Sample source code for D

2011-03-27 Thread Lutger Blijdestijn
Ishan Thilina wrote:

> I am a novice to D. Is there any place that I can get sample source codes
> for D ?
> 
> Thanks...!

examples from TDPL: http://erdani.com/tdpl/code/

You could browse github and dsource. Some blogposts also contain examples, 
see http://planet.dsource.org/ 


Re: Sample source code for D

2011-03-27 Thread David Nadlinger

On 3/27/11 6:59 PM, Ishan Thilina wrote:

I am a novice to D. Is there any place that I can get sample source codes for D 
?

Thanks...!


Are you looking for example code explaining specific pieces of 
functionality (e.g. Phobos), or just for applications/libraries written 
in D so you can see how the language is typically used?


David


Re: Sample source code for D

2011-03-27 Thread Ishan Thilina
Yeah, I saw them. Aren't there any other places? :)


Re: Sample source code for D

2011-03-27 Thread Kagamin
Ishan Thilina Wrote:

> I am a novice to D. Is there any place that I can get sample source codes for 
> D ?
> 
> Thanks...!

There're examples in docs for phobos and other libraries.


Re: null Vs [] return arrays

2011-03-27 Thread Kagamin
bearophile Wrote:

> I have compiled this little D2 program:
> 
> 
> int[] foo() {
> return [];
> }
> int[] bar() {
> return null;
> }
> void main() {}
> 
> 
> 
> Using DMD 2.052,  dmd -O -release -inline test2.d
> 
> This is the asm of the two functions:
> 
> _D5test23fooFZAicomdat
> L0: pushEAX
> mov EAX,offset FLAT:_D11TypeInfo_Ai6__initZ
> push0
> pushEAX
> callnear ptr __d_arrayliteralT
> mov EDX,EAX
> add ESP,8
> pop ECX
> xor EAX,EAX
> ret
> 
> _D5test23barFZAicomdat
> xor EAX,EAX
> xor EDX,EDX
> ret
> 
> Is this expected and desired? Isn't it better to compile the foo() as bar()?
> 
> Bye,
> bearophile

[] is not null, it's an array of 0 elements, what is done exactly.
edx points to the allocated array.


Re: Using D libs in C

2011-03-27 Thread Dainius (GreatEmerald)
Hmm, if I was to do it from C, I would have to deal with all the
allocation, since I don't know how large the array is going to be when
it's complete, while D doesn't need to know since it uses dynamic
arrays.


Sample source code for D

2011-03-27 Thread Ishan Thilina
I am a novice to D. Is there any place that I can get sample source codes for D 
?

Thanks...!


Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Ishan Thilina
Trass3r wrote:

>As you can see dmd.conf uses relative paths.
>That guide needs an overhaul.
>
>The easiest way is to copy the contents of the zip archive into some local
>dmd directory and add dmd/linux/bin to your PATH.
>(i.e. remove your etc/dmd.conf for now)

I did as you have said. Now a new error comes :-/.

"object.d: Error: module object is in file 'object.d' which cannot be read
Specify path to file 'object.d' with -I switch
"

@Spir:

I think you have not understood what my problem is. I'm not trying to solve a
problem with my source code. I'm having an issue in which I can'ct compile 
code( I
have compiled them using dmd in windows and they can be compiled in linux using 
GCD)


Re: Using D libs in C

2011-03-27 Thread Jesse Phillips
Dainius (GreatEmerald) Wrote:

> Well, the situation is like this: D creates a list of names of files
> that should be loaded by C. C then takes the list, uses it to load the
> files, then stores both the pointers to the loaded files and the names
> of the files in an array of structs. Then when C wants to access the
> files, it asks D about which file to access, which then sends the file
> name, and C compares the known file names and on finding a match,
> accesses the file.
> So that means that the array should be pretty much read-only there,
> but C needs to know how big the newly created array of structs has to
> be. As for how long the list of file names will be - it's determined
> by the configuration, so it will be anywhere from 1 to around 300 or
> even more.

If you want to pass an array of file names to C, you must pass it as a char**, 
accomplished as bearophile has stated.

Since your C program is asking D which files to work with next why doesn't it 
load the file at that time? If the file is processed multiple times, you can 
still cache the data and just check if it is already cached.


Re: Using D libs in C

2011-03-27 Thread bearophile
Dainius (GreatEmerald):

> Well, the situation is like this: D creates a list of names of files
> that should be loaded by C. C then takes the list, uses it to load the
> files, then stores both the pointers to the loaded files and the names
> of the files in an array of structs. Then when C wants to access the
> files, it asks D about which file to access, which then sends the file
> name, and C compares the known file names and on finding a match,
> accesses the file.
> So that means that the array should be pretty much read-only there,
> but C needs to know how big the newly created array of structs has to
> be. As for how long the list of file names will be - it's determined
> by the configuration, so it will be anywhere from 1 to around 300 or
> even more.

So?

Bye,
bearophile


Module Searching Roots

2011-03-27 Thread Caligo
I'm in directory ~/root and I have 't1.d' in ~/root/src/core
directory, and nothing else.

I run:  'gdc -O3 -o t1 t1.d -B./src/core' but I get

gdc: t1.d: No such file or directory
gdc: no input files

I've tried different paths, but I can't get it work.  What's the problem?


null Vs [] return arrays

2011-03-27 Thread bearophile
I have compiled this little D2 program:


int[] foo() {
return [];
}
int[] bar() {
return null;
}
void main() {}



Using DMD 2.052,  dmd -O -release -inline test2.d

This is the asm of the two functions:

_D5test23fooFZAicomdat
L0: pushEAX
mov EAX,offset FLAT:_D11TypeInfo_Ai6__initZ
push0
pushEAX
callnear ptr __d_arrayliteralT
mov EDX,EAX
add ESP,8
pop ECX
xor EAX,EAX
ret

_D5test23barFZAicomdat
xor EAX,EAX
xor EDX,EDX
ret

Is this expected and desired? Isn't it better to compile the foo() as bar()?

Bye,
bearophile


Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread spir

On 03/27/2011 12:28 PM, Ishan Thilina wrote:

When I give "dmd untitled.d" command in my ubuntu maverick 64 bit laptop I get
the following error.

"
object.d: Error: module object is in file 'object.d' which cannot be read
import path[0] = /etc/../../src/phobos
import path[1] = /etc/../../src/druntime/import
"

I tried all morning to solve this problem, tried every google result I could
find. Checked the mail archive to solve this problem. But I still couldn't get
rid of that error.I anybody can help me, it would be a great help.

I followed the steps in http://www.digitalmars.com/d/2.0/dmd-linux.html .I
first used the command "cp dmd2/linux/bin/dmd.conf /etc
" . Then I gave "sudo apt-get install gcc-multilib g++-multilib libc6-i386
libc6-dev-i386" command.

Thank you :)


PS: I tried to compile an empty module called "object.d". This gives me pages & 
pages & pages of "undefined x" errors ;-)


denis
--
_
vita es estrany
spir.wikidot.com



Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread spir

On 03/27/2011 12:28 PM, Ishan Thilina wrote:

When I give "dmd untitled.d" command in my ubuntu maverick 64 bit laptop I get
the following error.

"
object.d: Error: module object is in file 'object.d' which cannot be read
import path[0] = /etc/../../src/phobos
import path[1] = /etc/../../src/druntime/import
"

I tried all morning to solve this problem, tried every google result I could
find. Checked the mail archive to solve this problem. But I still couldn't get
rid of that error.I anybody can help me, it would be a great help.

I followed the steps in http://www.digitalmars.com/d/2.0/dmd-linux.html .I
first used the command "cp dmd2/linux/bin/dmd.conf /etc
" . Then I gave "sudo apt-get install gcc-multilib g++-multilib libc6-i386
libc6-dev-i386" command.

Thank you :)


First, please always post the piece of code that provokes an error. If it's a 
big or complicated thing, then try to reduce it to the smallest and simplest 
bit possible. Usually, doing this will let you find the source of the problem ;-)


Second, this kind of error is caused by wrong import path (yes, the error 
message could mention "import"). Typically, when one writes eg:

import range;
instead of
import std.range;
But your case is strange. Do you know object.d is the core of D's std lib, 
which defines about all what you absolutely need to use when programming in D? 
One does not need to import it, this is automatical. Also, the message says the 
error happens in object.d itself, which is very un-probable.
I thus suspect you named one of your own modules "object.d", which breaks the 
import mechanics (for D's standard object.d and possibly for other 
stdlib/phobos modules). This may be considered as a bug.


denis
--
_
vita es estrany
spir.wikidot.com



Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Trass3r

object.d: Error: module object is in file 'object.d' which cannot be read
import path[0] = /etc/../../src/phobos
import path[1] = /etc/../../src/druntime/import


As you can see dmd.conf uses relative paths.
That guide needs an overhaul.

The easiest way is to copy the contents of the zip archive into some local  
dmd directory and add dmd/linux/bin to your PATH.

(i.e. remove your etc/dmd.conf for now)


Re: Using D libs in C

2011-03-27 Thread Dainius (GreatEmerald)
Well, the situation is like this: D creates a list of names of files
that should be loaded by C. C then takes the list, uses it to load the
files, then stores both the pointers to the loaded files and the names
of the files in an array of structs. Then when C wants to access the
files, it asks D about which file to access, which then sends the file
name, and C compares the known file names and on finding a match,
accesses the file.
So that means that the array should be pretty much read-only there,
but C needs to know how big the newly created array of structs has to
be. As for how long the list of file names will be - it's determined
by the configuration, so it will be anywhere from 1 to around 300 or
even more.


Re: Using D libs in C

2011-03-27 Thread bearophile
Dainius (GreatEmerald):

> OK, now I have a question about passing variables. In D, I have a
> dynamic array of strings and I want C to get that array. Yet C
> supports neither dynamic arrays nor strings. So is there a way to
> accomplish this?

To use a D data structure from C you need first of all to know what exactly 
those data structures are.

In this case one solution is to create (from D) a dynamic array of char*, then 
perform a map!toStringz to convert the strings to C strings, and then call the 
C code with the ptr and length of this dynamic array of pointers.

There are other solutions, according to the amount of data you want to copy or 
according to the amount of C code you want to write to access the D data 
structures.

Bye,
bearophile


Re: Using D libs in C

2011-03-27 Thread Dainius (GreatEmerald)
OK, now I have a question about passing variables. In D, I have a
dynamic array of strings and I want C to get that array. Yet C
supports neither dynamic arrays nor strings. So is there a way to
accomplish this?


object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-27 Thread Ishan Thilina
When I give "dmd untitled.d" command in my ubuntu maverick 64 bit laptop I get
the following error.

"
object.d: Error: module object is in file 'object.d' which cannot be read
import path[0] = /etc/../../src/phobos
import path[1] = /etc/../../src/druntime/import
"

I tried all morning to solve this problem, tried every google result I could
find. Checked the mail archive to solve this problem. But I still couldn't get
rid of that error.I anybody can help me, it would be a great help.

I followed the steps in http://www.digitalmars.com/d/2.0/dmd-linux.html .I
first used the command "cp dmd2/linux/bin/dmd.conf /etc
" . Then I gave "sudo apt-get install gcc-multilib g++-multilib libc6-i386
libc6-dev-i386" command.

Thank you :)