Thread overview
some problems!
Sep 29, 2004
aelmetwaly
Sep 29, 2004
Regan Heath
OMF/COFF (was some problems!)
Sep 29, 2004
J C Calvarese
September 29, 2004
// Questions
Hi there,
Please I need advice on the following subjects:

1- Some macro #defines are deficult to implement on D. eg.:
 #define rvaDLLName  szName
 don't tell me to do a global search and replace! the code is generic and
need to still generic

.
2- How I can implement template functions in D. eg.:
 in C++:
 template <class T> void DumpOptionalHeader(T* pImageOptionalHeader);
 I converted it to:
 template DumpOptionalHeader(T = IMAGE_OPTIONAL_HEADER32) {
 void DumpOptionalHeader(T* pImageOptionalHeader)  // 'T' is
IMAGE_OPTIONAL_HEADER32/64
 { ... } }
 Is this right? or is there any beter way?


3- The following code compile in C++ but not in D and compiler give outside
array bounds error. why?
 in C++:
 typedef struct DATASYM32 {
  unsigned short  reclen;         // Record length
  unsigned short  rectyp;         // S_LDATA32, S_GDATA32 or S_PUB32
  CV_uoff32_t     off;
  unsigned short  seg;
  CV_typ_t        typind;         // Type index
  unsigned char   name[1];        // Length-prefixed name
 } DATASYM32;
 typedef DATASYM32 PUBSYM32;

 PCSTR pszUndecoratedName = (PCSTR)&pDataSym32->name[1]; // < == NOTE this

 I converted it to but the markered array line give outside array bounds
error [0..1]
 struct DATASYM32 {
     ushort  reclen;         // Record length
     ushort  rectyp;         // S_LDATA32, S_GDATA32 or S_PUB32
     CV_uoff32_t     off;
     ushort  seg;
     CV_typ_t        typind;         // Type index
     ubyte   name[2];        // Length-prefixed name // originally, it was
name[1] but the code below
         // gives outside of array bounds error although it compiles wright
in C++. ??!!!
 } ;
 alias DATASYM32 PUBSYM32;


 PCSTR pszUndecoratedName = cast(PCSTR)&pDataSym32.name[1];


4- about primitive types in C++ is:
 unsigned long => ulong or uint ?
 and other types, and it's equivelent in d ?


5- Is there any documentation or references about OMF lib format on the
internet. maybe I can relate the data
 structures with the new Microsoft COFF archive format!


September 29, 2004
On Mon, 20 Sep 2004 21:37:33 +0300, aelmetwaly <aelmetwaly@gawab.com> wrote:
> // Questions
> Hi there,
> Please I need advice on the following subjects:
>
> 1- Some macro #defines are deficult to implement on D. eg.:
>  #define rvaDLLName  szName
>  don't tell me to do a global search and replace! the code is generic and
> need to still generic

Can't you use 'alias' or typedef eg.

alias szName rvaDLLName;
typedef szName rvaDLLName;

> 2- How I can implement template functions in D. eg.:
>  in C++:
>  template <class T> void DumpOptionalHeader(T* pImageOptionalHeader);
>  I converted it to:
>  template DumpOptionalHeader(T = IMAGE_OPTIONAL_HEADER32) {
>  void DumpOptionalHeader(T* pImageOptionalHeader)  // 'T' is
> IMAGE_OPTIONAL_HEADER32/64
>  { ... } }
>  Is this right? or is there any beter way?

That looks right, tho I wish there was a slightly shorter way to do it, something like:

template(T = IMAGE_OPTIONAL_HEADER32) DumpOptionalHeader(T* pImageOptionalHeader) {
}

basically if the template only contains 1 function we shouldn't need to repeat the template/function name, and the {} for the template aren't really necessary either.

This may be ambiguous to parse however, only Walter could say for sure.

> 3- The following code compile in C++ but not in D and compiler give outside
> array bounds error. why?
>  in C++:
>  typedef struct DATASYM32 {
>   unsigned short  reclen;         // Record length
>   unsigned short  rectyp;         // S_LDATA32, S_GDATA32 or S_PUB32
>   CV_uoff32_t     off;
>   unsigned short  seg;
>   CV_typ_t        typind;         // Type index
>   unsigned char   name[1];        // Length-prefixed name
>  } DATASYM32;
>  typedef DATASYM32 PUBSYM32;
>
>  PCSTR pszUndecoratedName = (PCSTR)&pDataSym32->name[1]; // < == NOTE this

So it looks to me like the string resides in the memory after the "unsigned char name[1]" array, which itself simply holds the length of the string?

>  I converted it to but the markered array line give outside array bounds
> error [0..1]
>  struct DATASYM32 {
>      ushort  reclen;         // Record length
>      ushort  rectyp;         // S_LDATA32, S_GDATA32 or S_PUB32
>      CV_uoff32_t     off;
>      ushort  seg;
>      CV_typ_t        typind;         // Type index
>      ubyte   name[2];        // Length-prefixed name // originally, it was
> name[1] but the code below
>          // gives outside of array bounds error although it compiles wright
> in C++. ??!!!
>  } ;
>  alias DATASYM32 PUBSYM32;
>
>
>  PCSTR pszUndecoratedName = cast(PCSTR)&pDataSym32.name[1];

In order to stop D doing bounds checking you have to either:
1. compile using -release.
2. stop using an array.

#1 will likely solve the problem right now, but you'll never be able to do a debug build again, so #2 is IMO the better solution, try this...

struct DATASYM32 {
  ushort reclen;
  ushort rectyp;
  CV_uoff32_t off;
  ushort  seg;
  CV_typ_t typind;
  ubyte name;
}
alias DATASYM32 PUBSYM32;

PCSTR pszUndecoratedName = cast(PCSTR)(&pDataSym32.name + ubyte.sizeof);

I think that is correct. Someone will no doubt correct me if I am wrong.

> 4- about primitive types in C++ is:
>  unsigned long => ulong or uint ?
>  and other types, and it's equivelent in d ?

See
http://www.digitalmars.com/d/type.html

> 5- Is there any documentation or references about OMF lib format on the
> internet. maybe I can relate the data
>  structures with the new Microsoft COFF archive format!

I have no idea :)

Regards,
Regan

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
September 29, 2004
aelmetwaly wrote:
> // Questions
> Hi there,
> Please I need advice on the following subjects:
> 
...
> 5- Is there any documentation or references about OMF lib format on the
> internet. maybe I can relate the data
>  structures with the new Microsoft COFF archive format!

I think I've read that the Standalone OpenWatcom Tools (http://cmeerw.org/prog/owtools/) can be helpful when trying to use COFF and OMF together, but I might be remembering it wrong.

The website mentions both OMF and COFF:

dmpobj.exe (68 kB - Sun, 09 Nov 2003) (Open Watcom *OMF* Dump Utility)

support for COFF libraries (including Microsoft's new-style *COFF* import libraries)

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/