Skip to content

Commit

Permalink
Clean up sqUnixMain.c:imgInit and move the input event semaphore inde…
Browse files Browse the repository at this point in the history
…x code

to where it belongs.
  • Loading branch information
eliotmiranda committed May 19, 2024
1 parent 0168290 commit 2eefa41
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
21 changes: 16 additions & 5 deletions platforms/unix/vm/sqUnixEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@

#define IEB_SIZE 64 /* must be power of 2 */

typedef struct
{
int x, y;
} SqPoint;

typedef struct { int x, y; } SqPoint;
SqPoint mousePosition= { 0, 0 }; /* position at last motion event */
int swapBtn= 0; /* 1 to swap yellow and blue buttons */

Expand Down Expand Up @@ -152,6 +148,21 @@ static sqInt getButtonState(void)
}


/*** event handling ***/
sqInt inputEventSemaIndex= 0;

/* set asynchronous input event semaphore */
sqInt
ioSetInputSemaphore(sqInt semaIndex)
{
if ((semaIndex == 0) || (noEvents == 1))
success(false);
else
inputEventSemaIndex= semaIndex;
return true;
}


static void signalInputEvent(void)
{
#if DEBUG_EVENTS
Expand Down
21 changes: 9 additions & 12 deletions platforms/unix/vm/sqUnixMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -2152,34 +2152,33 @@ imgInit(void)
/* read the image file and allocate memory for Squeak heap */
int fd;
struct stat sb;
char imagePath[MAXPATHLEN];

// first check for an embedded image

void *handle = dlopen(NULL, RTLD_NOW);
void *embeddedImage;
if (handle && (embeddedImage = dlsym(handle,"embeddedImage"))) {
strcpy(shortImageName,dlsym(handle,"embeddedImageName"));
fd = ((char *)embeddedImage)[0] == GZIPMagic0 && ((char *)embeddedImage)[1] == GZIPMagic1
? ImageIsEmbeddedAndCompressed
: ImageIsEmbedded;
unsigned long *imageSize = dlsym(handle,"embeddedImageSize");
unsigned long *compressedSize = dlsym(handle,"embeddedCompressedDataSize");
dlclose(handle);
noteEmbeddedImage(embeddedImage,
*(unsigned long *)dlsym(handle,"embeddedImageSize"),
*imageSize,
compressedSize ? *compressedSize : 0);
dlclose(handle);
sb.st_size = imageSize;
}
else {

char imagePath[MAXPATHLEN];
sq2uxPath(shortImageName, strlen(shortImageName), imagePath, MAXPATHLEN - 1, 1);
if (-1 == stat(imagePath, &sb) || (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
if (-1 == stat(imagePath, &sb)
|| (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode)))
imageNotFound(imagePath); // imageNotFound will exit
}
fd = sqImageFileOpen(imagePath, "rb"); // sqImageFileOpen handles the errors. fd is valid here
#ifdef DEBUG_IMAGE
printf("fstat(%d) => %d\n", fd, fstat(fd, &sb));
#endif

recordFullPathForImageName(shortImageName); /* full image path */
}

Expand All @@ -2188,14 +2187,12 @@ imgInit(void)
else
extraMemory= DefaultHeapSize * 1024 * 1024;
#ifdef DEBUG_IMAGE
if (fd != ImageIsEmbedded)
printf("image size %ld + heap size %ld (useMmap = %d)\n", (long)sb.st_size, extraMemory, useMmap);
printf("image size %ld + heap size %ld (useMmap = %d)\n", (long)sb.st_size, extraMemory, useMmap);
#endif
#if SPURVM
readImageFromFileHeapSizeStartingAt(fd, 0, 0);
#else
if (fd != ImageIsEmbedded)
extraMemory += (long)sb.st_size;
extraMemory += (long)sb.st_size;
readImageFromFileHeapSizeStartingAt(fd, extraMemory, 0);
#endif
sqImageFileClose(fd);
Expand Down
1 change: 0 additions & 1 deletion platforms/unix/vm/sqUnixMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

extern char imageName[];
extern char shortImageName[];
extern sqInt inputEventSemaIndex;
extern char vmPath[];
extern char *exeName;
extern char **argVec;
Expand Down

0 comments on commit 2eefa41

Please sign in to comment.