use of struct vs class

mark mark at qtrac.eu
Sat Mar 7 13:22:05 UTC 2020


I've now gone back to using structs direct without pointers but 
I'm still doing something wrong.

struct Deb {
     string name;
     ...
     RedBlackTree!string tags;

     bool valid() { return !(name.empty || description.empty); }

     void clear() { name = ""; ...; tags.clear; }
}

RedBlackTree!(Deb, (a, b) => a.name < b.name) debs;

Deb deb;
auto file = File(filename);
foreach(line; file.byLine) {
     line = strip(line);
     if (line.empty) {
         if (deb.valid)
             debs.insert(deb); // XXX
         else // report incomplete
         deb.clear;
         continue;
     }
     ...
}
if (deb.valid)
     debs.insert(deb);

This compiles & crashes with "Program exited with code -11".

What I'm trying to do but clearly don't understand is this:

1. create a struct
repeat:
  2.1. populate the struct
  2.2. copy the struct into an rbtree // XXX
  2.3. clear the original struct
  2.4. loop

At XXX does a copy take place? I thought it did with structs?

Anyway, here's the backtrace:

$ gdb DebFind
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
...
Reading symbols from DebFind...done.
(gdb) run
Starting program: /home/mark/app/d/debfind/DebFind
[Thread debugging using libthread_db enabled]
Using host libthread_db library 
"/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff6e02700 (LWP 2366)]
...

Thread 1 "DebFind" received signal SIGSEGV, Segmentation fault.
0x0000555555701ef0 in 
_D3std9container6rbtree__T12RedBlackTreeTAyaVQea5_61203c2062Vbi0ZQBn5emptyMFNaNbNdNiNfZb (this=0x0)
     at 
/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/../import/std/container/rbtree.d:967
967	        return _end.left is null;
(gdb) bt
#0  0x0000555555701ef0 in 
_D3std9container6rbtree__T12RedBlackTreeTAyaVQea5_61203c2062Vbi0ZQBn5emptyMFNaNbNdNiNfZb (this=0x0)
     at 
/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/../import/std/container/rbtree.d:967
#1  0x0000555555701a11 in 
qtrac.debfind.model.Model.readPackageFile(immutable(char)[]) 
(this=0x0, filename=...) at model.d:66
warning: (Internal error: pc 0x55555591b874 in read in psymtab, 
but not in symtab.)

warning: (Internal error: pc 0x55555591b820 in read in psymtab, 
but not in symtab.)

warning: (Internal error: pc 0x55555591b874 in read in psymtab, 
but not in symtab.)

#2  0x0000555555701671 in 
qtrac.debfind.model.Model.initialize(int) (this=0x0, 
maxDebNamesForWord=100) at model.d:31
warning: (Internal error: pc 0x55555591b874 in read in psymtab, 
but not in symtab.)

#3  0x00005555557045b0 in 
_D5qtrac7debfind9appwindow9AppWindow6__ctorMFC3gtk11ApplicationQnZCQCnQCkQCfQBy (this=0x7ffff7ece630, application=0x7ffff7ed1360) at appwindow.d:31
#4  0x0000555555722819 in 
_D5qtrac7debfind3app4mainFAAyaZ__T12__dgliteral2TC3gio11ApplicationQnZQBkMFQBaZv (GioApplication=0x7ffff7ed1360) at app.d:16
#5  0x000055555575be54 in 
_D7gobject8DClosureQj__T17d_closure_marshalTDFC3gio11ApplicationQnZvZQBtUPSQCv1c5types8GClosurePSQDrQwQw6GValuekQrPvQcZv (closure=0x555555c37690, return_value=0x0, n_param_values=1, param_values=0x7ffff7ef46e0, invocation_hint=0x7fffffffd710 "\b", marshal_data=0x0) at DClosure.d:122
#6  0x00007ffff419410d in g_closure_invoke () at 
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#7  0x00007ffff41a705e in  () at 
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#8  0x00007ffff41af715 in g_signal_emit_valist () at 
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#9  0x00007ffff41b012f in g_signal_emit () at 
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
warning: (Internal error: pc 0x55555591b874 in read in psymtab, 
but not in symtab.)

#10 0x00007fffee148b95 in  () at 
/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
warning: (Internal error: pc 0x55555591b874 in read in psymtab, 
but not in symtab.)

#11 0x00007fffee148da6 in g_application_run () at 
/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
warning: (Internal error: pc 0x55555591b874 in read in psymtab, 
but not in symtab.)

#12 0x000055555591b875 in warning: (Internal error: pc 
0x55555591b874 in read in psymtab, but not in symtab.)

_D3gio11ApplicationQn3runMFAAyaZiwarning: (Internal error: pc 
0x55555591b874 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x55555591b874 in read in psymtab, 
but not in symtab.)

  (warning: (Internal error: pc 0x55555591b874 in read in psymtab, 
but not in symtab.)

this=0x7ffff7ed1360, warning: (Internal error: pc 0x55555591b874 
in read in psymtab, but not in symtab.)

argv=...)warning: (Internal error: pc 0x55555591b874 in read in 
psymtab, but not in symtab.)

  at Application.dwarning: (Internal error: pc 0x55555591b874 in 
read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x55555591b874 in read in psymtab, 
but not in symtab.)

:931
#13 0x0000555555722760 in D main (args=...) at app.d:18


And thanks for helping!


More information about the Digitalmars-d-learn mailing list