www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - New linker error with xml2

reply ollie <ollie home.net> writes:
I have been seeing a new linker error while building xml2.

  OPTLINK (R) for Win32  Release 8.00.12
  Copyright (C) Digital Mars 1989-2010  All rights reserved.
  http://www.digitalmars.com/ctg/optlink.html
  sxmltest.obj(sxmltest)
   Error 42: Symbol Undefined
   _D3alt7zstring22__T9KeyValRecTAyaTAyaZ9KeyValRec
   8opEqualsMxFKxS3alt7zstring22__T9KeyValRecTAyaTAyaZ9KeyValRecZb

   (demangled for your convenience)
   const(bool function(ref const(alt.zstring.KeyValRec!(immutable(char)[],
immutable(char)[]).KeyValRec))) alt.zstring.KeyValRec!(immutable(char)[],
immutable(char)[]).KeyValRec.opEquals

The error starts with commit:
  
  commit 751353c8217596726ab219b7d3a690e8950e409e
  Author: k-hara <k.hara.pg gmail.com>
  Date:   Sat Aug 24 15:07:18 2013 +0900

To compile xml2, I have made the following changes:

  change struct Array member toConstArray from  safe to  trusted because
  pointers cannot be transformed into arrays in safe code.

  changed several occurences of 'delete this;' to 'this.destroy();'

  changed auto doc = new Document(TagData("catalog");
  to      auto td = TagData("catalog");
          auto doc = new Document(td);
  because of an lvalue problem. (should td be allocated on heap instead?)

  changed some readln to return to a string instead of passing a string.

I am using Win32 with Walter's snn.lib with HeapAlloc calls and obviously
git head for dmd etal. Anyone have any ideas why dmd would generate that
template function for test\sxml.d after that commit but not before?
Aug 28 2013
next sibling parent ollie <ollie home.net> writes:
If anyone is interested, here is the patch I use to compile xml2:

diff --git a/alt/zstring.d b/alt/zstring.d
index 356cfda..e021cca 100644
--- a/alt/zstring.d
+++ b/alt/zstring.d
   -674,7 +674,7    struct Array(T)
     }
 
     /// Return  unwriteable slice of the buffer.
-    const(T[]) toConstArray() const  safe  property nothrow
+    const(T[]) toConstArray() const  trusted  property nothrow
     {
 		if (ptr_ !is null)
 			return ptr_[0..length_];
   -1350,7 +1350,8    struct PackedArray(T)
 /// Element of sortable array of pairs on key
 struct KeyValRec(K,V)
 {
-	alias KeyValRec!(K,V) SameType;
+//	alias KeyValRec!(K,V) SameType;
+    alias SameType = KeyValRec!(K,V);
 
     K id;
     V value;
   -1723,4 +1724,4    unittest
     put(cd["standalone"]);
     put(cd["encoding"]);
 
-}
\ No newline at end of file
+}
diff --git a/build.bat b/build.bat
index 4be9aaf..052d670 100644
--- a/build.bat
+++ b/build.bat
   -1,7 +1,7   
 rem Delete all outputs
 del xmlp.lib sxmltest.exe bookstest.exe conformance.exe 2>NUL
 
-dmd -property -lib -ofxmlp.lib -O -noboundscheck -release -w ^
+dmd -lib -ofxmlp.lib -O -noboundscheck -release -w ^
 	"alt/zstring.d" "std/xml1.d" "std/xml2.d" ^
 	"std/xmlp/arraydom.d" "std/xmlp/arraydombuild.d"  "std/xmlp/builder.d" ^
 	"std/xmlp/domparse.d" "std/xmlp/dtdtype.d" ^
   -17,15 +17,15    dmd -property -lib -ofxmlp.lib -O -noboundscheck -release
-w ^
 
 IF ERRORLEVEL 1 exit /B
 
-dmd -property -ofsxmltest -O -noboundscheck -release "./test/sxml"  xmlp.lib
+dmd -ofsxmltest -O -noboundscheck -release "./test/sxml"  xmlp.lib
 
 IF ERRORLEVEL 1 exit /B
 
-dmd -property -ofbookstest -O -noboundscheck -release "./test/books" xmlp.lib
+dmd -ofbookstest -O -noboundscheck -release "./test/books" xmlp.lib
 
 IF ERRORLEVEL 1 exit /B
 
-dmd -property -ofconformance -O -noboundscheck -release ^
+dmd -ofconformance -O -noboundscheck -release ^
 	"./test/conformance.d"  std/xmlp/jisx0208.d xmlp.lib
 
 IF ERRORLEVEL 1 exit /B
diff --git a/std/xml1.d b/std/xml1.d
index 941c373..3799474 100644
--- a/std/xml1.d
+++ b/std/xml1.d
   -905,7 +905,7    class Tag
 		if (tag_.attr.length > 0)
 			tag_.attr.explode(del);
 		if (del)
-			delete this;
+			this.destroy();
 	}
 
 }
   -1398,7 +1398,7    abstract class Item
 	void explode(bool del)
 	{
 		if (del)
-			delete this;
+			this.destroy();
 	}
 
 }
   -1663,7 +1663,7    public:
 
 		init();
 		if (del)
-			delete this;
+			this.destroy();
 	}
 
 	/**
   -2130,4 +2130,4    void UnitTest1()
 unittest
 {
 	UnitTest1();
-}
\ No newline at end of file
+}
diff --git a/std/xmlp/arraydom.d b/std/xmlp/arraydom.d
index 0b7a34c..75e23da 100644
--- a/std/xmlp/arraydom.d
+++ b/std/xmlp/arraydom.d
   -62,7 +62,7    abstract class Item
 	void explode(bool del)
 	{
 		if (del)
-			delete this;
+			this.destroy();
 	}
 
     /// This item as text
diff --git a/std/xmlp/builder.d b/std/xmlp/builder.d
index 98cc176..3274d63 100644
--- a/std/xmlp/builder.d
+++ b/std/xmlp/builder.d
   -69,7 +69,7    abstract class Builder {
 	void explode(bool del)
 	{
 		if (del)
-			delete this;
+			this.destroy();
 	}	
 }
 
diff --git a/std/xmlp/coreprint.d b/std/xmlp/coreprint.d
index 1a81011..6cf191a 100644
--- a/std/xmlp/coreprint.d
+++ b/std/xmlp/coreprint.d
   -204,7 +204,7    struct XmlPrinter
         uintptr_t i = indent;
         buf[i++] = '<';
         buf[i++] = '/';
-        buf[i .. i + taglen] = tag;
+        buf[i .. i + taglen] = tag[];
         i += taglen;
         buf[i] = '>';
     }
   -384,7 +384,7    struct XmlPrinter
         uintptr_t i = indent;
         if(i > 0)
             buf[0..i] = ' ';
-        buf[i .. $] = s;
+        buf[i .. $] = s[];
         options.putDg(buf);
     }
 }
diff --git a/std/xmlp/linkdom.d b/std/xmlp/linkdom.d
index 582fb9b..678c2a7 100644
--- a/std/xmlp/linkdom.d
+++ b/std/xmlp/linkdom.d
   -1319,7 +1319,7    public:
 	void explode(bool del)
 	{
 		if (del)
-			delete this;
+			this.destroy();
 	}
 
     /// Not supported
diff --git a/test/Conformance.d b/test/Conformance.d
index 68dd9a6..ab7518b 100644
--- a/test/Conformance.d
+++ b/test/Conformance.d
   -755,7 +755,7    int main(string[] args)
         }
     }
     string dinp;
-    stdin.readln(dinp);
+    dinp = stdin.readln();
     return 0;
 }
 
diff --git a/test/books.d b/test/books.d
index 6c14403..7c6bd71 100644
--- a/test/books.d
+++ b/test/books.d
   -182,7 +182,8    void std_xml1(string s)
 		Book[] books;
 
 		auto xml = new DocumentParser(s);
-		auto doc = new Document(TagData("catalog"));
+        auto td = TagData("catalog");
+		auto doc = new Document(td);
 
 		scope(exit)
 		{
diff --git a/test/sxml.d b/test/sxml.d
index e3dad14..319698d 100644
--- a/test/sxml.d
+++ b/test/sxml.d
   -17,7 +17,7    import ard = std.xmlp.arraydom;
 import lnk = std.xmlp.linkdom;
 import ardb = std.xmlp.arraydombuild;
 import std.xmlp.builder;
-import alt.zstring;
+//import alt.zstring;
 
 version(GC_STATS)
 {
   -255,7 +255,8    void xml1_books(string s)
 		xml.explode(true);
 
 		// Put it back together again;
-		auto doc = new Document(TagData("catalog"));
+        auto td = TagData("catalog");
+		auto doc = new Document(td);
 		foreach(book;books)
 		{
 			auto element = new Element("book");
   -979,7 +980,7    void testDomAssembly()
 
     writeln("Dom construction. <Enter to exit>");
     string dinp;
-    stdin.readln(dinp);
+    dinp = stdin.readln;
 
 
 }
Aug 28 2013
prev sibling next sibling parent Kenji Hara <k.hara.pg gmail.com> writes:
--047d7beb93b405b73404e50e4c69
Content-Type: text/plain; charset=UTF-8

2013/8/29 ollie <ollie home.net>

 I have been seeing a new linker error while building xml2.

   OPTLINK (R) for Win32  Release 8.00.12
   Copyright (C) Digital Mars 1989-2010  All rights reserved.
   http://www.digitalmars.com/ctg/optlink.html
   sxmltest.obj(sxmltest)
    Error 42: Symbol Undefined
    _D3alt7zstring22__T9KeyValRecTAyaTAyaZ9KeyValRec
    8opEqualsMxFKxS3alt7zstring22__T9KeyValRecTAyaTAyaZ9KeyValRecZb

    (demangled for your convenience)
    const(bool function(ref const(alt.zstring.KeyValRec!(immutable(char)[],
 immutable(char)[]).KeyValRec))) alt.zstring.KeyValRec!(immutable(char)[],
 immutable(char)[]).KeyValRec.opEquals

 The error starts with commit:

   commit 751353c8217596726ab219b7d3a690e8950e409e
   Author: k-hara <k.hara.pg gmail.com>
   Date:   Sat Aug 24 15:07:18 2013 +0900

Did you rebuild xml2 library after updating/rebuilding dmd code? Because the dmd commit changes the object file places where some instantiated template code are emitted. Kenji Hara --047d7beb93b405b73404e50e4c69 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">2013= /8/29 ollie <span dir=3D"ltr">&lt;<a href=3D"mailto:ollie home.net" target= =3D"_blank">ollie home.net</a>&gt;</span><br><blockquote class=3D"gmail_quo= te" style=3D"margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:= 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-= style:solid;padding-left:1ex"> I have been seeing a new linker error while building xml2.<br> <br> =C2=A0 OPTLINK (R) for Win32 =C2=A0Release 8.00.12<br> =C2=A0 Copyright (C) Digital Mars 1989-2010 =C2=A0All rights reserved.<br> =C2=A0 <a href=3D"http://www.digitalmars.com/ctg/optlink.html" target=3D"_b= lank">http://www.digitalmars.com/ctg/optlink.html</a><br> =C2=A0 sxmltest.obj(sxmltest)<br> =C2=A0 =C2=A0Error 42: Symbol Undefined<br> =C2=A0 =C2=A0_D3alt7zstring22__T9KeyValRecTAyaTAyaZ9KeyValRec<br> =C2=A0 =C2=A08opEqualsMxFKxS3alt7zstring22__T9KeyValRecTAyaTAyaZ9KeyValRecZ= b<br> <br> =C2=A0 =C2=A0(demangled for your convenience)<br> =C2=A0 =C2=A0const(bool function(ref const(alt.zstring.KeyValRec!(immutable= (char)[], immutable(char)[]).KeyValRec))) alt.zstring.KeyValRec!(immutable(= char)[], immutable(char)[]).KeyValRec.opEquals<br> <br> The error starts with commit:<br> <br> =C2=A0 commit 751353c8217596726ab219b7d3a690e8950e409e<br> =C2=A0 Author: k-hara &lt;<a href=3D"mailto:k.hara.pg gmail.com">k.hara.pg = gmail.com</a>&gt;<br> =C2=A0 Date: =C2=A0 Sat Aug 24 15:07:18 2013 +0900<br></blockquote><div><br=
</div><div>Did you rebuild xml2 library after updating/rebuilding dmd code=

e instantiated template code are emitted.</div> </div><br></div><div class=3D"gmail_extra">Kenji Hara</div></div> --047d7beb93b405b73404e50e4c69--
Aug 28 2013
prev sibling next sibling parent ollie <ollie home.net> writes:
On Thu, 29 Aug 2013 13:11:14 +0900, Kenji Hara wrote:

 2013/8/29 ollie <ollie home.net>
 
 I have been seeing a new linker error while building xml2.


 Did you rebuild xml2 library after updating/rebuilding dmd code?
 Because the dmd commit changes the object file places where some
 instantiated template code are emitted.
 
 Kenji Hara

Thanks for the reply Kenji. Yes, because it is so fast to recompile with dmd, I always recompile both xml2 and GtkD after dmd/druntime/phobos/tools to stay ahead of changes. Using the dmpobj.exe from OpenWatcom, I searched for the missing function in the test program sxmltest.obj and xmlp.lib for compilations just before commit 751353c8217596726ab219b7d3a690e8950e409e and for git-head. The function is only emitted into sxmltest.obj as a EXTDEF record type. EXTDEF(8c) recnum:1545, offset:00010cc8h, len:009ah, chksum:00h(aa) 821 - '_D3std9exception7bailOutFNaNfAyakxAaZv' Type:0 822 - '_D3alt7zstring22__T9KeyValRecTAyaTAyaZ9KeyValRec8opEqualsMxFKxS3alt7zstring22__T9KeyValRecTA aTAyaZ9KeyValRecZb' Type:0 Thanks, ollie
Aug 28 2013
prev sibling parent ollie <ollie home.net> writes:
On Thu, 29 Aug 2013 13:11:14 +0900, Kenji Hara wrote:

 
 Did you rebuild xml2 library after updating/rebuilding dmd code?
 Because the dmd commit changes the object file places where some
 instantiated template code are emitted.
 

After looking into the problem a bit further, I have found that commit 751353c8217596726ab219b7d3a690e8950e409e, specifically the removal of !scx->scopesym->isModule() causes the function decorations to be omitted (pure nothrow safe) from the test program test\sxml.d during compilation, but retaining them during compilation of the library xmlp.lib. By explicitly adding those decorations to the opEquals function of the KeyValRec struct in alt\zstring.d, compilation succeeds with the current git-head. Time permitting, I would be interested in your insight regarding that change. My vague recollection was that those decorations were defaults if not specified. Thanks, Ollie diff from commit 751353c8217596726ab219b7d3a690e8950e409e: diff --git a/src/template.c b/src/template.c index c0e304c..9bb0411 100644 --- a/src/template.c +++ b/src/template.c -5463,8 +5463,7 void TemplateInstance::semantic(Scope *sc, Expressions *fargs) //if (scx && scx->scopesym) printf("3: scx is %s %s\n", scx->scopesym->kind(), scx->scopesym->toChars()); if (scx && scx->scopesym && scx->scopesym->members && - !scx->scopesym->isTemplateMixin() && - !scx->scopesym->isModule() + !scx->scopesym->isTemplateMixin() #if 0 // removed because it bloated compile times /* The problem is if A imports B, and B imports A, and both A * and B instantiate the same template, does the compilation of A function signature in sxmltest.obj after commit 751353c8217596726ab219b7d3a690e8950e409e: const(bool function(ref const(alt.zstring.KeyValRec!(string, string).KeyValRec))) alt.zstring.KeyValRec!(string, string).KeyValRec.opEquals function signature in xmlp.lib before and after commit and sxmltest.obj after explicitly defining decorations on opEquals definition: const(pure nothrow safe bool function(ref const(alt.zstring.KeyValRec!(string, string).KeyValRec))) alt.zstring.KeyValRec!(string, string).KeyValRec.opEquals
Sep 03 2013