Skip to content

Commit

Permalink
Combine read and fxUseSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Nov 13, 2023
1 parent 4d020f0 commit 9f6616b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 49 deletions.
38 changes: 17 additions & 21 deletions xsnap/sources/xsnap-worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,17 +574,27 @@ int main(int argc, char* argv[])
fxTestRecord(mxTestRecordParam, nsbuf + 1, nslen - 1);
#endif
path = nsbuf + 1;
snapshot.stream = fopen(path, "rb");
xsSuspendMetering(machine);
if (path[0] == '@') {
int fd = atoi(path + 1);
int tmpfd = dup(fd);
if (tmpfd < 0) {
snapshot.stream = NULL;
} else {
snapshot.stream = fdopen(tmpfd, "rb");
}
} else {
snapshot.stream = fopen(path, "rb");
}

if (snapshot.stream) {
xsDeleteMachine(machine);
machine = xsReadSnapshot(&snapshot, "xsnap", NULL);
fxUseSnapshot(machine, &snapshot);
fclose(snapshot.stream);
} else {
snapshot.error = errno;
}
else
snapshot.error = errno;

if (snapshot.error) {
fprintf(stderr, "cannot read snapshot %s: %s\n",
fprintf(stderr, "cannot restore snapshot %s: %s\n",
path, strerror(snapshot.error));
// TODO: dynamically build error message including Exception message.
int writeError = fxWriteNetString(toParent, "!", "", 0);
Expand All @@ -599,7 +609,6 @@ int main(int argc, char* argv[])
c_exit(E_IO_ERROR);
}
}
xsResumeMetering(machine, fxMeteringCallback, interval);
break;

case 'w':
Expand Down Expand Up @@ -642,19 +651,6 @@ int main(int argc, char* argv[])
fprintf(stderr, "%s\n", fxWriteNetStringError(writeError));
c_exit(E_IO_ERROR);
}
path = nsbuf + 1;
snapshot.stream = fopen(path, "rb");
if (snapshot.stream) {
fxUseSnapshot(machine, &snapshot);
fclose(snapshot.stream);
}
else
snapshot.error = errno;
if (snapshot.error) {
fprintf(stderr, "cannot restore snapshot %s: %s\n",
path, strerror(snapshot.error));
c_exit(E_IO_ERROR);
}
} else {
// TODO: dynamically build error message including Exception message.
int writeError = fxWriteNetString(toParent, "!", "", 0);
Expand Down
29 changes: 1 addition & 28 deletions xsnap/sources/xsnap.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,7 @@ struct xsSnapshotRecord {
(_THE)->firstJump = __HOST_JUMP__.nextJump; \
break; \
} while(1)

// xsBooleanValue (*meterCallback)(xsMachine*, xsUnsignedValue) = (_THE)->meterCallback; \
// xsUnsignedValue meterInterval = (_THE)->meterInterval; \
#define xsSuspendMetering(_THE) \
do { \
fxEndMetering(_THE); \
(_THE)->stack = __HOST_JUMP__.stack, \
(_THE)->scope = __HOST_JUMP__.scope, \
(_THE)->frame = __HOST_JUMP__.frame, \
(_THE)->code = __HOST_JUMP__.code, \
(_THE)->firstJump = __HOST_JUMP__.nextJump;

#define xsResumeMetering(_THE, _CALLBACK, _STEP) \
__HOST_JUMP__.nextJump = (_THE)->firstJump; \
__HOST_JUMP__.stack = (_THE)->stack; \
__HOST_JUMP__.scope = (_THE)->scope; \
__HOST_JUMP__.frame = (_THE)->frame; \
__HOST_JUMP__.environment = NULL; \
__HOST_JUMP__.code = (_THE)->code; \
__HOST_JUMP__.flag = 0; \
(_THE)->firstJump = &__HOST_JUMP__; \
fxBeginMetering(_THE, _CALLBACK, _STEP); \
break; \
} while(1)


#define xsGetCurrentMeter(_THE) \
fxGetCurrentMeter(_THE)
#define xsSetCurrentMeter(_THE, _VALUE) \
Expand All @@ -86,8 +61,6 @@ struct xsSnapshotRecord {
#else
#define xsBeginMetering(_THE, _CALLBACK, _STEP)
#define xsEndMetering(_THE)
#define xsSuspendMetering(_THE)
#define xsResumeMetering(_THE, _CALLBACK, _STEP)
#define xsPatchHostFunction(_FUNCTION,_PATCH)
#define xsMeterHostFunction(_COUNT) (void)(_COUNT)
#define xsGetCurrentMeter(_THE) 0
Expand Down

0 comments on commit 9f6616b

Please sign in to comment.