Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
neverbot committed Sep 2, 2024
2 parents 230e1a0 + 5e67e62 commit ea1f796
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,14 @@ Object *Comm::user()
obj : (Object *) NULL;
}

/*
* return the number of connections
*/
eindex Comm::numUsers()
{
return nusers;
}

/*
* return an array with all user objects
*/
Expand Down
3 changes: 2 additions & 1 deletion src/comm.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of DGD, https://github.com/dworkin/dgd
* Copyright (C) 1993-2010 Dworkin B.V.
* Copyright (C) 2010-2022 DGD Authors (see the commit log for details)
* Copyright (C) 2010-2024 DGD Authors (see the commit log for details)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -90,6 +90,7 @@ class Comm {
static void connect(Frame *f, Object *obj, char *addr, unsigned short port);
static void connectDgram(Frame *f, Object *obj, int uport, char *addr,
unsigned short port);
static eindex numUsers();
static Array *listUsers(Dataspace*);
static bool isConnection(Object*);
static bool save(int);
Expand Down
44 changes: 42 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,41 @@ Uint Config::dconv(char *buf, char *rbuf, const char *layout, Uint n)
case 'e':
i = ALGN(i, ealign);
ri = ALGN(ri, realign);
if (sizeof(eindex) == resize) {
switch (sizeof(eindex)) {
case sizeof(char):
buf[i] = rbuf[ri];
break;

case sizeof(short):
buf[i + header.s[0]] = rbuf[ri + rheader.s[0]];
buf[i + header.s[1]] = rbuf[ri + rheader.s[1]];
break;

case sizeof(Int):
buf[i + header.i[0]] = rbuf[ri + rheader.i[0]];
buf[i + header.i[1]] = rbuf[ri + rheader.i[1]];
buf[i + header.i[2]] = rbuf[ri + rheader.i[2]];
buf[i + header.i[3]] = rbuf[ri + rheader.i[3]];
break;
}
} else if (sizeof(eindex) == sizeof(short)) {
buf[i + header.s[0]] = (UCHAR(rbuf[ri]) == 0xff) ? -1 : 0;
buf[i + header.s[1]] = rbuf[ri];
} else if (resize == sizeof(char)) {
j = (UCHAR(rbuf[ri]) == 0xff) ? -1 : 0;
buf[i + header.i[0]] = j;
buf[i + header.i[1]] = j;
buf[i + header.i[2]] = j;
buf[i + header.i[3]] = rbuf[ri];
} else {
j = (UCHAR(rbuf[ri + rheader.s[0]] &
rbuf[ri + rheader.s[1]]) == 0xff) ? -1 : 0;
buf[i + header.i[0]] = j;
buf[i + header.i[1]] = j;
buf[i + header.i[2]] = rbuf[ri + rheader.s[0]];
buf[i + header.i[3]] = rbuf[ri + rheader.s[1]];
}
i += sizeof(eindex);
ri += resize;
break;
Expand Down Expand Up @@ -1292,6 +1327,7 @@ bool Config::includes()
puts("# define ST_DATAGRAMPORTS 24\t/* datagram ports */\012");
puts("# define ST_TELNETPORTS\t25\t/* telnet ports */\012");
puts("# define ST_BINARYPORTS\t26\t/* binary ports */\012");
puts("# define ST_NUSERS\t27\t/* # users */\012");

puts("\012# define O_COMPILETIME\t0\t/* time of compilation */\012");
puts("# define O_PROGSIZE\t1\t/* program size of object */\012");
Expand Down Expand Up @@ -1952,6 +1988,10 @@ bool Config::statusi(Frame *f, LPCint idx, Value *v)
}
break;

case 27: /* ST_NUSERS */
PUT_INTVAL(v, Comm::numUsers());
break;

default:
return FALSE;
}
Expand All @@ -1970,8 +2010,8 @@ Array *Config::status(Frame *f)

try {
EC->push();
a = Array::createNil(f->data, 27);
for (i = 0, v = a->elts; i < 27; i++, v++) {
a = Array::createNil(f->data, 28);
for (i = 0, v = a->elts; i < 28; i++, v++) {
statusi(f, i, v);
}
EC->pop();
Expand Down
14 changes: 5 additions & 9 deletions src/interpret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ unsigned short Frame::switchInt(char *pc)
while (l < h) {
m = (l + h) >> 1;
p = pc + 4 * m;
FETCH2S(p, num);
num = FETCH2S(p, num);
if (sp->number == num) {
return FETCH2U(p, l);
} else if (sp->number < num) {
Expand Down Expand Up @@ -1589,12 +1589,10 @@ unsigned short Frame::switchRange(char *pc)
while (l < h) {
m = (l + h) >> 1;
p = pc + 4 * m;
num = FETCH1S(p);
if (sp->number < num) {
if (sp->number < FETCH1S(p)) {
h = m; /* search in lower half */
} else {
num = FETCH1S(p);
if (sp->number <= num) {
if (sp->number <= FETCH1S(p)) {
return FETCH2U(p, l);
}
l = m + 1; /* search in upper half */
Expand All @@ -1606,12 +1604,10 @@ unsigned short Frame::switchRange(char *pc)
while (l < h) {
m = (l + h) >> 1;
p = pc + 6 * m;
FETCH2S(p, num);
if (sp->number < num) {
if (sp->number < FETCH2S(p, num)) {
h = m; /* search in lower half */
} else {
FETCH2S(p, num);
if (sp->number <= num) {
if (sp->number <= FETCH2S(p, num)) {
return FETCH2U(p, l);
}
l = m + 1; /* search in upper half */
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

# define VERSION "DGD 1.7.4"
# define VERSION "DGD 1.7.5"

0 comments on commit ea1f796

Please sign in to comment.