Skip to content

Commit 98f6c12

Browse files
committed
CogVM source as per VMMaker.oscog-eem.3667
Fix Nico Papagna's BitBlt clipping bug which was due to use on int variables on 64-bits so that negative values were truncated to extremely high positive values, defeating the clipping logic. As a result redefine the coordinate parameters of the surface functions to take sqInts. Change the signature of sqResolverGetAddressInfoResultSize to eliminate a warning. Slang: avoid adding struct type aliases for abstract classes, eliminating some warnings in the ThreadeedFFI plugins.
1 parent de2f171 commit 98f6c12

File tree

17 files changed

+447
-448
lines changed

17 files changed

+447
-448
lines changed

platforms/Cross/plugins/ExampleSurfacePlugin/sqMemorySurface.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "../SurfacePlugin/SurfacePlugin.h"
66

77
typedef struct memSurface {
8-
int width, height, depth, stride;
8+
sqInt width, height, depth, stride;
99
void *bits;
1010
} memSurface;
1111

@@ -17,7 +17,8 @@ static fn_ioFindSurface findSurface = 0;
1717
extern struct VirtualMachine *interpreterProxy;
1818

1919
/******************* Surface manager entry points *******************/
20-
static int memGetSurfaceFormat(sqIntptr_t handle, int *w, int *h, int *d, int *msbFlag) {
20+
static int memGetSurfaceFormat(sqIntptr_t handle, sqInt *w, sqInt *h, sqInt *d, sqInt *msbFlag)
21+
{
2122
memSurface *ms = (memSurface *) handle;
2223
*w = ms->width;
2324
*h = ms->height;
@@ -26,22 +27,18 @@ static int memGetSurfaceFormat(sqIntptr_t handle, int *w, int *h, int *d, int *m
2627
return 1;
2728
}
2829

29-
static sqIntptr_t memLock(sqIntptr_t handle, int *stride, int x, int y, int w, int h){
30+
static sqIntptr_t memLock(sqIntptr_t handle, sqInt *stride, sqInt x, sqInt y, sqInt w, sqInt h)
31+
{
3032
/* Locking can be safely ignored for memory surfaces but we need to fill in
3133
the stride and return the bits */
3234
memSurface *ms = (memSurface *) handle;
3335
*stride = ms->stride;
3436
return (sqIntptr_t)ms->bits;
3537
}
3638

37-
static int memUnlock(sqIntptr_t handle, int x, int y, int w, int h){
38-
return 1; /* ignored */
39-
}
39+
static int memUnlock(sqIntptr_t handle, sqInt x, sqInt y, sqInt w, sqInt h){ return 1; /* ignored */ }
4040

41-
static int memShow(sqIntptr_t handle, int x, int y, int w, int h) {
42-
/* unsupported */
43-
return 0;
44-
}
41+
static int memShow(sqIntptr_t handle, sqInt x, sqInt y, sqInt w, sqInt h) { /* unsupported */ return 0; }
4542

4643
static sqSurfaceDispatch memSurfaceDispatch = {
4744
1,
@@ -54,7 +51,7 @@ static sqSurfaceDispatch memSurfaceDispatch = {
5451

5552
/******************* primitive entry points *******************/
5653

57-
int memCreateSurfaceWidthHeightDepth(int w, int h, int d) {
54+
int memCreateSurfaceWidthHeightDepth(sqInt w, sqInt h, int d) {
5855
memSurface *ms;
5956
int id;
6057
/* since I'm lazy I'll only deal with d >= 8 */
@@ -124,4 +121,3 @@ int memInitialize(void) {
124121
if(!findSurface) return 0;
125122
return 1;
126123
}
127-

platforms/Cross/plugins/SocketPlugin/SocketPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void sqSocketSetReusable(SocketPtr s);
9494
void sqResolverGetAddressInfoHostSizeServiceSizeFlagsFamilyTypeProtocol(char *hostName, sqInt hostSize, char *servName, sqInt servSize,
9595
sqInt flags, sqInt family, sqInt type, sqInt protocol);
9696
sqInt sqResolverGetAddressInfoSize(void);
97-
void sqResolverGetAddressInfoResultSize(char *addr, sqInt addrSize);
97+
void sqResolverGetAddressInfoResultSize(unsigned char *addr, sqInt addrSize);
9898
sqInt sqResolverGetAddressInfoFamily(void);
9999
sqInt sqResolverGetAddressInfoType(void);
100100
sqInt sqResolverGetAddressInfoProtocol(void);

platforms/Cross/plugins/SqueakFFIPrims/sqFFI.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* PROJECT: Squeak foreign function interface
33
* FILE: sqFFI.h
44
* CONTENT: Declarations for the foreign function interface's surface support
5-
plus optional declaration of the sqFFITestFuncs.c test suite.
5+
* plus optional declaration of the sqFFITestFuncs.c test suite.
66
*
77
* AUTHOR: Andreas Raab (ar)
88
* ADDRESS: Walt Disney Imagineering, Glendale, CA
@@ -39,9 +39,9 @@ void initSurfacePluginFunctionPointers();
3939
void initManualSurfaceFunctionPointers
4040
(fn_ioRegisterSurface, fn_ioUnregisterSurface, fn_ioFindSurface);
4141
int createManualSurface
42-
(int width, int height, int rowPitch, int depth, int isMSB);
42+
(sqInt width, sqInt height, sqInt rowPitch, sqInt depth, sqInt isMSB);
4343
int destroyManualSurface(int surfaceID);
44-
int setManualSurfacePointer(int surfaceID, void* ptr);
44+
int setManualSurfacePointer(int surfaceID, void *ptr);
4545
void doFFILogCallout(sqInt externalFunctionName);
4646

4747

platforms/Cross/plugins/SqueakFFIPrims/sqManualSurface.c

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ void initSurfacePluginFunctionPointers()
4242
it may be touched directly from Squeak code to set/clear "ptr", and also
4343
treated as a generic surface via BitBlt's use of the SurfacePlugin. */
4444
typedef struct {
45-
int width;
46-
int height;
47-
int rowPitch;
48-
int depth;
49-
int isMSB;
50-
void* ptr;
51-
int isLocked;
45+
sqInt width;
46+
sqInt height;
47+
sqInt rowPitch;
48+
sqInt depth;
49+
sqInt isMSB;
50+
void *ptr;
51+
sqInt isLocked;
5252
} ManualSurface;
5353

5454
/* Create the dispatch-table that SurfacePlugin will use to interact with
5555
instances of "struct ManualSurface" */
56-
static int manualSurfaceGetFormat(sqIntptr_t, int*, int*, int*, int*);
57-
static sqIntptr_t manualSurfaceLock(sqIntptr_t, int *, int, int, int, int);
58-
static int manualSurfaceUnlock(sqIntptr_t, int, int, int, int);
59-
static int manualSurfaceShow(sqIntptr_t, int, int, int, int);
56+
static int manualSurfaceGetFormat(sqIntptr_t, sqInt *, sqInt *, sqInt *, sqInt *);
57+
static sqIntptr_t manualSurfaceLock(sqIntptr_t, sqInt *, sqInt, sqInt, sqInt, sqInt);
58+
static int manualSurfaceUnlock(sqIntptr_t, sqInt, sqInt, sqInt, sqInt);
59+
static int manualSurfaceShow(sqIntptr_t, sqInt, sqInt, sqInt, sqInt);
6060
static sqSurfaceDispatch manualSurfaceDispatch = {
6161
1,
6262
0,
@@ -68,7 +68,9 @@ static sqSurfaceDispatch manualSurfaceDispatch = {
6868

6969
/* sqSurfaceDispatch functions *****************************************************************************/
7070

71-
int manualSurfaceGetFormat(sqIntptr_t surfaceArg, int* width, int* height, int* depth, int* isMSB) {
71+
int
72+
manualSurfaceGetFormat(sqIntptr_t surfaceArg, sqInt *width, sqInt *height, sqInt *depth, sqInt *isMSB)
73+
{
7274
ManualSurface* surface = (ManualSurface *)surfaceArg;
7375
*width = surface->width;
7476
*height = surface->height;
@@ -78,7 +80,9 @@ int manualSurfaceGetFormat(sqIntptr_t surfaceArg, int* width, int* height, int*
7880
return 1;
7981
}
8082

81-
sqIntptr_t manualSurfaceLock(sqIntptr_t surfaceArg, int *pitch, int x, int y, int w, int h) {
83+
sqIntptr_t
84+
manualSurfaceLock(sqIntptr_t surfaceArg, sqInt *pitch, sqInt x, sqInt y, sqInt w, sqInt h)
85+
{
8286
ManualSurface* surface = (ManualSurface *)surfaceArg;
8387
/* Ideally, would be atomic. But it doens't matter for the forseeable future,
8488
since it is only called via BitBlt primitives. */
@@ -100,30 +104,34 @@ sqIntptr_t manualSurfaceLock(sqIntptr_t surfaceArg, int *pitch, int x, int y, in
100104
return (sqIntptr_t)(surface->ptr);
101105
}
102106

103-
int manualSurfaceUnlock(sqIntptr_t surfaceArg, int x, int y, int w, int h) {
107+
int
108+
manualSurfaceUnlock(sqIntptr_t surfaceArg, sqInt x, sqInt y, sqInt w, sqInt h)
109+
{
104110
ManualSurface* surface = (ManualSurface *)surfaceArg;
105111
surface->isLocked = 0;
106112
DPRINTF(("Unlocked Surface: %" PRIxSQPTR " Rect: %ld %ld %ld %ld\n", (sqIntptr_t) surface, x, y, w, h));
107113
return 1;
108114
}
109115

110-
int manualSurfaceShow(sqIntptr_t surfaceArg, int x, int y, int w, int h) {
111-
/* Unsupported */
112-
return 0;
113-
}
116+
int
117+
manualSurfaceShow(sqIntptr_t surfaceArg, sqInt x, sqInt y, sqInt w, sqInt h) { /* Unsupported */ return 0; }
114118

115119
/* primitive interface functions (i.e. called from Squeak) *********************************************/
116120

117121
/* Answer non-negative surfaceID if successful, and -1 for failure. */
118-
int createManualSurface(int width, int height, int rowPitch, int depth, int isMSB) {
122+
int
123+
createManualSurface(sqInt width, sqInt height, sqInt rowPitch, sqInt depth, sqInt isMSB)
124+
{
119125
ManualSurface* newSurface;
120126
int surfaceID, result;
121127

122-
if (width < 0) return -1;
123-
if (height < 0) return -1;
124-
if (rowPitch < (width*depth)/8) return -1;
125-
if (depth < 1 || depth > 32) return -1;
126-
if (!registerSurface) return -1; /* failure... couldn't init function-pointer */
128+
if (width < 0
129+
|| height < 0
130+
|| rowPitch < (width * depth)
131+
|| depth < 1
132+
|| depth > 32
133+
|| !registerSurface)
134+
return -1;
127135

128136
newSurface = (ManualSurface*)malloc(sizeof(ManualSurface));
129137
if (!newSurface) return -1;
@@ -144,20 +152,23 @@ int createManualSurface(int width, int height, int rowPitch, int depth, int isMS
144152
return surfaceID;
145153
}
146154

147-
int destroyManualSurface(int surfaceID) {
155+
int
156+
destroyManualSurface(int surfaceID)
157+
{
148158
if (!unregisterSurface) return 0; /* failure... couldn't init function-pointer */
149159
return unregisterSurface(surfaceID);
150160
}
151161

152-
int setManualSurfacePointer(int surfaceID, void* ptr) {
153-
sqIntptr_t surfaceHandle;
162+
int
163+
setManualSurfacePointer(int surfaceID, void* ptr)
164+
{
154165
ManualSurface *surface;
155-
int result;
156-
if (!findSurface) return FALSE; /* failure... couldn't init function-pointer */
157-
result = findSurface(surfaceID, NULL, &surfaceHandle);
158-
if (!result) return FALSE; /* failed to find surface */
159-
surface = (ManualSurface*)surfaceHandle;
160-
if (surface->isLocked) return FALSE; /* can't set pointer while surface is locked */
166+
if (!findSurface)
167+
return FALSE; /* failure... couldn't init function-pointer */
168+
if (!findSurface(surfaceID, NULL, (sqIntptr_t *)&surface))
169+
return FALSE; /* failed to find surface */
170+
if (surface->isLocked)
171+
return FALSE; /* can't set pointer while surface is locked */
161172
surface->ptr = ptr;
162173
DPRINTF(("Set Surface: %lx Pointer: %" PRIxSQPTR "\n", surfaceID, (sqIntptr_t)ptr));
163174
return TRUE;

platforms/Cross/plugins/SurfacePlugin/SurfacePlugin.c

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ EXPORT(long) initialiseModule(void);
6767
EXPORT(long) shutdownModule(void);
6868

6969
/* critical FXBlt entry points */
70-
EXPORT(int) ioGetSurfaceFormat (int surfaceID, int* width, int* height, int* depth, int* isMSB);
71-
EXPORT(sqIntptr_t) ioLockSurface (int surfaceID, int *pitch, int x, int y, int w, int h);
72-
EXPORT(int) ioUnlockSurface(int surfaceID, int x, int y, int w, int h);
70+
EXPORT(int) ioGetSurfaceFormat (int surfaceID, sqInt *width, sqInt *height, sqInt *depth, sqInt *isMSB);
71+
EXPORT(sqIntptr_t) ioLockSurface (int surfaceID, sqInt *pitch, sqInt x, sqInt y, sqInt w, sqInt h);
72+
EXPORT(int) ioUnlockSurface(int surfaceID, sqInt x, sqInt y, sqInt w, sqInt h);
7373

7474
/* interpreter entry point */
75-
EXPORT(int) ioShowSurface(int surfaceID, int x, int y, int w, int h);
75+
EXPORT(int) ioShowSurface(int surfaceID, sqInt x, sqInt y, sqInt w, sqInt h);
7676

7777
/* client entry points */
7878
EXPORT(int) ioRegisterSurface(sqIntptr_t surfaceHandle, sqSurfaceDispatch *fn, int *surfaceID);
@@ -83,14 +83,16 @@ EXPORT(int) ioFindSurface(int surfaceID, sqSurfaceDispatch *fn, sqIntptr_t *surf
8383
/* ioGetSurfaceFormat:
8484
Return information describing the given surface.
8585
Return true if successful, false otherwise. */
86-
EXPORT(int) ioGetSurfaceFormat (int surfaceID, int* width, int* height, int* depth, int* isMSB)
86+
EXPORT(int) ioGetSurfaceFormat (int surfaceID, sqInt *width, sqInt *height, sqInt *depth, sqInt *isMSB)
8787
{
8888
SqueakSurface *surface;
89-
if(surfaceID < 0 || surfaceID >= maxSurfaces) FAIL;
89+
if (surfaceID < 0 || surfaceID >= maxSurfaces)
90+
FAIL;
9091
surface = surfaceArray + surfaceID;
91-
if(surface->dispatch == NULL) FAIL;
92+
if (!surface->dispatch)
93+
FAIL;
9294
/* Allow getSurfaceFormat to be defaulted to 0 */
93-
if(!surface->dispatch->getSurfaceFormat)
95+
if (!surface->dispatch->getSurfaceFormat)
9496
return -1;
9597
return surface->dispatch->getSurfaceFormat(surface->handle, width, height, depth, isMSB);
9698
}
@@ -99,41 +101,48 @@ EXPORT(int) ioGetSurfaceFormat (int surfaceID, int* width, int* height, int* dep
99101
Lock the bits of the surface.
100102
Return a pointer to the actual surface bits,
101103
or NULL on failure. */
102-
EXPORT(sqIntptr_t) ioLockSurface (int surfaceID, int *pitch, int x, int y, int w, int h)
104+
EXPORT(sqIntptr_t) ioLockSurface (int surfaceID, sqInt *pitch, sqInt x, sqInt y, sqInt w, sqInt h)
103105
{
104106
SqueakSurface *surface;
105-
if(surfaceID < 0 || surfaceID >= maxSurfaces) FAIL;
107+
if (surfaceID < 0 || surfaceID >= maxSurfaces)
108+
FAIL;
106109
surface = surfaceArray + surfaceID;
107-
if(surface->dispatch == NULL) FAIL;
108-
if(!surface->dispatch->lockSurface) FAIL;
110+
if (!surface->dispatch)
111+
FAIL;
112+
if (!surface->dispatch->lockSurface)
113+
FAIL;
109114
return surface->dispatch->lockSurface(surface->handle, pitch, x, y, w, h);
110115
}
111116

112117
/* ioUnlockSurface:
113118
Unlock the bits of the surface.
114119
The return value is ignored. */
115-
EXPORT(int) ioUnlockSurface(int surfaceID, int x, int y, int w, int h)
120+
EXPORT(int) ioUnlockSurface(int surfaceID, sqInt x, sqInt y, sqInt w, sqInt h)
116121
{
117122
SqueakSurface *surface;
118-
if(surfaceID < 0 || surfaceID >= maxSurfaces) FAIL;
123+
if (surfaceID < 0 || surfaceID >= maxSurfaces)
124+
FAIL;
119125
surface = surfaceArray + surfaceID;
120-
if(surface->dispatch == NULL) FAIL;
126+
if (!surface->dispatch)
127+
FAIL;
121128
/* Allow unlockSurface to be defaulted to 0 */
122-
if(!surface->dispatch->unlockSurface)
129+
if (!surface->dispatch->unlockSurface)
123130
return -1;
124131
return surface->dispatch->unlockSurface(surface->handle, x, y, w, h);
125132
}
126133

127134
/* ioShowSurface:
128135
Transfer the bits of a surface to the screen. */
129-
EXPORT(int) ioShowSurface(int surfaceID, int x, int y, int w, int h)
136+
EXPORT(int) ioShowSurface(int surfaceID, sqInt x, sqInt y, sqInt w, sqInt h)
130137
{
131138
SqueakSurface *surface;
132-
if(surfaceID < 0 || surfaceID >= maxSurfaces) FAIL;
139+
if (surfaceID < 0 || surfaceID >= maxSurfaces)
140+
FAIL;
133141
surface = surfaceArray + surfaceID;
134-
if(surface->dispatch == NULL) FAIL;
142+
if (!surface->dispatch)
143+
FAIL;
135144
/* Allow showSurface to be defaulted to 0 */
136-
if(!surface->dispatch->showSurface)
145+
if (!surface->dispatch->showSurface)
137146
-1;
138147
return surface->dispatch->showSurface(surface->handle, x, y, w, h);
139148
}
@@ -147,9 +156,11 @@ EXPORT(int) ioRegisterSurface(sqIntptr_t surfaceHandle, sqSurfaceDispatch *fn, i
147156
{
148157
int index;
149158

150-
if(!fn) return 0;
151-
if(fn->majorVersion != 1 && fn->minorVersion != 0) return 0;
152-
if(numSurfaces == maxSurfaces) {
159+
if (!fn)
160+
return 0;
161+
if (fn->majorVersion != 1 && fn->minorVersion != 0)
162+
return 0;
163+
if (numSurfaces == maxSurfaces) {
153164
maxSurfaces = maxSurfaces * 2 + 10;
154165
surfaceArray = realloc(surfaceArray, sizeof(SqueakSurface) * maxSurfaces);
155166
for(index = numSurfaces; index < maxSurfaces; index++){
@@ -159,10 +170,11 @@ EXPORT(int) ioRegisterSurface(sqIntptr_t surfaceHandle, sqSurfaceDispatch *fn, i
159170
index = numSurfaces;
160171
} else {
161172
for(index = 0; index < maxSurfaces; index++)
162-
if(surfaceArray[index].dispatch == NULL)
173+
if (surfaceArray[index].dispatch == NULL)
163174
break;
164175
}
165-
if(index >= maxSurfaces) return 0; /* should not happen */
176+
if (index >= maxSurfaces)
177+
return 0; /* should not happen */
166178
surfaceArray[index].handle = surfaceHandle;
167179
surfaceArray[index].dispatch = fn;
168180
*surfaceID = index;
@@ -176,9 +188,11 @@ EXPORT(int) ioRegisterSurface(sqIntptr_t surfaceHandle, sqSurfaceDispatch *fn, i
176188
EXPORT(int) ioUnregisterSurface(int surfaceID)
177189
{
178190
SqueakSurface *surface;
179-
if(surfaceID < 0 || surfaceID >= maxSurfaces) return 0;
191+
if (surfaceID < 0 || surfaceID >= maxSurfaces)
192+
return 0;
180193
surface = surfaceArray + surfaceID;
181-
if(surface->dispatch == NULL) return 0;
194+
if (!surface->dispatch)
195+
return 0;
182196
surface->handle = 0;
183197
surface->dispatch = NULL;
184198
numSurfaces--;
@@ -193,10 +207,13 @@ EXPORT(int) ioUnregisterSurface(int surfaceID)
193207
EXPORT(int) ioFindSurface(int surfaceID, sqSurfaceDispatch *fn, sqIntptr_t *surfaceHandle)
194208
{
195209
SqueakSurface *surface;
196-
if(surfaceID < 0 || surfaceID >= maxSurfaces) return 0;
210+
if (surfaceID < 0 || surfaceID >= maxSurfaces)
211+
return 0;
197212
surface = surfaceArray + surfaceID;
198-
if(surface->dispatch == NULL) return 0;
199-
if(fn && fn != surface->dispatch) return 0;
213+
if (!surface->dispatch)
214+
return 0;
215+
if (fn && fn != surface->dispatch)
216+
return 0;
200217
*surfaceHandle = surface->handle;
201218
return 1;
202219
}
@@ -225,7 +242,8 @@ EXPORT(long) initialiseModule() {
225242

226243
EXPORT(long) shutdownModule() {
227244
/* This module can only be shut down if no surfaces are registered */
228-
if(numSurfaces != 0) return 0;
245+
if (numSurfaces != 0)
246+
return 0;
229247
free(surfaceArray);
230248
return 1;
231249
}

0 commit comments

Comments
 (0)