dworkin / dgd

Dworkin's Game Driver, an object-oriented database management system originally used to run MUDs.
https://www.dworkin.nl/dgd/
GNU Affero General Public License v3.0
103 stars 31 forks source link

switch will not match case single item statements in some cases. #87

Closed knubo closed 8 months ago

knubo commented 8 months ago

The following code does not match 0 in the switch.

int bink() {
  int size, i;
  object ob;
  string sizestr;

  sizestr = "Change me";

  size = 0;
  switch (size) {
  case 0:
    sizestr = "tiny ";
    break;
  case 1: sizestr = "little "; break;
  case 2: sizestr = "small "; break;
  case 3..5: sizestr = ""; break;
  case 6: sizestr = "large "; break;
  case 7: sizestr = "big "; break;
  case 8: sizestr = "huge "; break;
  }

  write("Huh:"+sizestr+"\n");
  return size;
}

Whereas a much simpler case do work:


void working_switch() {
  int s,i;
  string x;

  s = 0;

  switch(s) {
  case 0:
    x = "0 case";
    break;
  case 1:
    write("Huh\n");
    break;
  }

  write(x);
}

Found on Viking.

geirpg commented 8 months ago

Further investigation of the bug:

switch(size) { case 0: sizestr = "tiny";break; case 1..2: sizestr = "little";break; case 3: sizestr ="small ";break; }

this will fail for case 0. If case 3 is instead 3..4, everything will work just fine.

//geirpg / Moreldir@vikingmud

dworkin commented 8 months ago

It looks like this happens when DGD converts a range switch into an int switch.

dworkin commented 8 months ago

This was broken by my solution for issue #70. I have a fix, I'll push it when I have the opportunity.

dworkin commented 8 months ago

Should be fixed by b28cea435a3f9be2bfc7891c8e924b82e926a69a.

knubo commented 8 months ago

The mud now went down with an exit code of 134. Is it possible that this fix creates a pointer problem?

dworkin commented 8 months ago

Exit code 134 indicates that it ended with an abort, not with a segmentation fault. Was there anything in the log?

geirpg commented 8 months ago

So. We have two log entries, from our driver logs: 2024-01-21 14:05:40 viking-test startmud[107633] Driver went down with exit code 134 and in the driver error log: Fatal error: cannot create swap file "/run/shm/viking-swap"

mount | grep shm: tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64) Looks fairly local to me, but haven't been able to confirm with server root.

dworkin commented 8 months ago

/run/shm/viking-swap but the the grep finds /dev/shm, not /run/shm. This must have been an issue with the previous DGD version 1.4.* also?

knubo commented 8 months ago

We haven't had the test mud running on this host for long.

ed_tmpfile = "/run/shm/viking-ed"; / proto editor tmpfile / swap_file = "/run/shm/viking-swap"; / swap file /

So we should point these to /dev/shm? Not /run/shm?

dworkin commented 8 months ago

Going by the abort error message, /run/shm does not even exist. So yes, change it to /dev/shm.

dworkin commented 8 months ago

I assume that both the switch issue and the fatal swap file problem have been solved.

geirpg commented 8 months ago

Yes. We're running 1.7.1 completely stable and error free now. Thank you for swift response and fix.

dworkin commented 8 months ago

Excellent. I will wrap up those fixes in a new release.