diff --git a/src/plugins/FileAttributesPlugin/FileAttributesPlugin.c b/src/plugins/FileAttributesPlugin/FileAttributesPlugin.c index 73163a53c3..c4ab73da50 100644 --- a/src/plugins/FileAttributesPlugin/FileAttributesPlugin.c +++ b/src/plugins/FileAttributesPlugin/FileAttributesPlugin.c @@ -1,9 +1,9 @@ /* Automatically generated by VMPluginCodeGenerator VMMaker.oscog-nice.2492 uuid: 8fac9bb8-92b6-41f2-8646-230a75c04ee9 from - FileAttributesPlugin FileAttributesPlugin.oscog-akg.46 uuid: 0f7242c3-9c0f-4b8b-a95f-444ce5873dcd + FileAttributesPlugin FileAttributesPlugin.oscog-akg.47 uuid: 352a23fa-7521-49aa-8801-e32b80394b9d */ -static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-akg.46 uuid: 0f7242c3-9c0f-4b8b-a95f-444ce5873dcd " __DATE__ ; +static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-akg.47 uuid: 352a23fa-7521-49aa-8801-e32b80394b9d " __DATE__ ; @@ -102,7 +102,6 @@ EXPORT(sqInt) setInterpreter(struct VirtualMachine *anInterpreter); static sqInt sizeOfFaPath(void); static sqInt sizeOfFaPathPtr(void); static sqInt stringFromCString(const char *aCString); -static void * structFromObjectsize(sqInt anObject, sqInt structSize); /*** Variables ***/ @@ -165,9 +164,9 @@ extern struct VirtualMachine* interpreterProxy; static const char *moduleName = #ifdef SQUEAK_BUILTIN_PLUGIN - "FileAttributesPlugin FileAttributesPlugin.oscog-akg.46 (i)" + "FileAttributesPlugin FileAttributesPlugin.oscog-akg.47 (i)" #else - "FileAttributesPlugin FileAttributesPlugin.oscog-akg.46 (e)" + "FileAttributesPlugin FileAttributesPlugin.oscog-akg.47 (e)" #endif ; static void * sCLPfn; @@ -504,7 +503,7 @@ pointerFrom(sqInt directoryPointerBytes) EXPORT(sqInt) primitiveChangeMode(void) { - fapath *faPath; + fapath faPath; sqInt fileNameOop; sqInt newMode; sqInt status; @@ -517,17 +516,11 @@ primitiveChangeMode(void) } # if HAVE_CHMOD - faPath = (fapath *) calloc(1, sizeof(fapath)); - if (faPath == null) { - return primitiveFailForOSError(-10 /* cantAllocateMemory */); - } - faSetStPathOop(faPath, fileNameOop); + faSetStPathOop((&faPath), fileNameOop); if (failed()) { - free(faPath); return primitiveFailureCode(); } - status = chmod(faGetPlatPath(faPath), newMode); - free(faPath); + status = chmod(faGetPlatPath((&faPath)), newMode); if (status != 0) { return primitiveFailForOSError(errno); } @@ -543,7 +536,7 @@ primitiveChangeMode(void) EXPORT(sqInt) primitiveChangeOwner(void) { - fapath *faPath; + fapath faPath; sqInt fileNameOop; sqInt groupId; sqInt ownerId; @@ -558,17 +551,11 @@ primitiveChangeOwner(void) } # if HAVE_CHOWN - faPath = (fapath *) calloc(1, sizeof(fapath)); - if (faPath == null) { - return primitiveFailForOSError(-10 /* cantAllocateMemory */); - } - faSetStPathOop(faPath, fileNameOop); + faSetStPathOop((&faPath), fileNameOop); if (failed()) { - free(faPath); return primitiveFailureCode(); } - status = chown(faGetPlatPath(faPath), ownerId, groupId); - free(faPath); + status = chown(faGetPlatPath((&faPath)), ownerId, groupId); if (status != 0) { return primitiveFailForOSError(errno); } @@ -588,18 +575,34 @@ primitiveChangeOwner(void) EXPORT(sqInt) primitiveClosedir(void) { + void *buffer; sqInt dirPointerOop; fapath *faPath; fapathptr *faPathPtr; sqInt result; + sqInt structSize; dirPointerOop = stackValue(0); - faPathPtr = (fapathptr *)structFromObjectsize(dirPointerOop, sizeof(fapathptr)); + /* begin structFromObject:size: */ + structSize = sizeof(fapathptr); + if (!((stSizeOf(dirPointerOop)) == structSize)) { + primitiveFailFor(PrimErrBadArgument); + faPathPtr = ((void *) 0); + goto l1; + } + buffer = alloca(structSize); + if (buffer == 0) { + primitiveFailFor(PrimErrNoCMemory); + } + else { + memcpy(buffer, arrayValueOf(dirPointerOop), structSize); + } + faPathPtr = buffer; + l1: /* end structFromObject:size: */; if (faPathPtr == 0) { return primitiveFailFor(PrimErrBadArgument); } if (!(faValidateSessionId(faPathPtr->sessionId))) { - free(faPathPtr); return primitiveFailFor(PrimErrBadArgument); } faPath = faPathPtr->faPath; @@ -608,9 +611,8 @@ primitiveClosedir(void) if (!(result == 0)) { return primitiveFailForOSError(result); } - free(faPathPtr); free(faPath); - popthenPush(2, dirPointerOop); + methodReturnValue(dirPointerOop); return 0; } @@ -632,7 +634,7 @@ EXPORT(sqInt) primitiveFileAttribute(void) { sqInt attributeNumber; - fapath *faPath; + fapath faPath; sqInt fileName; sqInt resultOop; @@ -643,17 +645,11 @@ primitiveFileAttribute(void) || (!(isBytes(fileName))))) { return primitiveFailFor(PrimErrBadArgument); } - faPath = (fapath *) calloc(1, sizeof(fapath)); - if (faPath == null) { - return primitiveFailForOSError(-10 /* cantAllocateMemory */); - } - faSetStPathOop(faPath, fileName); + faSetStPathOop((&faPath), fileName); if (failed()) { - free(faPath); return primitiveFailureCode(); } - resultOop = faFileAttribute(faPath, attributeNumber); - free(faPath); + resultOop = faFileAttribute((&faPath), attributeNumber); if (failed()) { return primitiveFailureCode(); } @@ -683,7 +679,7 @@ EXPORT(sqInt) primitiveFileAttributes(void) { sqInt attributeMask; - fapath *faPath; + fapath faPath; sqInt fileName; sqInt resultOop; sqInt status; @@ -697,17 +693,11 @@ primitiveFileAttributes(void) || (!(isBytes(fileName)))) { return primitiveFailFor(PrimErrBadArgument); } - faPath = (fapath *) calloc(1, sizeof(fapath)); - if (faPath == null) { - return primitiveFailForOSError(-10 /* cantAllocateMemory */); - } - faSetStPathOop(faPath, fileName); + faSetStPathOop((&faPath), fileName); if (failed()) { - free(faPath); return primitiveFailureCode(); } - status = attributeArrayformask((&resultOop), faPath, attributeMask); - free(faPath); + status = attributeArrayformask((&resultOop), (&faPath), attributeMask); if (status != 0) { return primitiveFailForOSError(status); } @@ -721,7 +711,7 @@ primitiveFileAttributes(void) EXPORT(sqInt) primitiveFileExists(void) { - fapath *faPath; + fapath faPath; sqInt fileNameOop; sqInt resultOop; @@ -729,16 +719,11 @@ primitiveFileExists(void) if (!(isBytes(fileNameOop))) { return primitiveFailFor(PrimErrBadArgument); } - faPath = (fapath *) calloc(1, sizeof(fapath)); - if (faPath == null) { - return primitiveFailForOSError(-10 /* cantAllocateMemory */); - } - faSetStPathOop(faPath, fileNameOop); + faSetStPathOop((&faPath), fileNameOop); if (failed()) { return primitiveFailureCode(); } - resultOop = faExists(faPath); - free(faPath); + resultOop = faExists((&faPath)); return methodReturnValue(resultOop); } @@ -901,7 +886,7 @@ EXPORT(sqInt) primitivePlatToStPath(void) { unsigned char *byteArrayPtr; - fapath *faPath; + fapath faPath; sqInt fileName; sqInt resultOop; @@ -910,23 +895,16 @@ primitivePlatToStPath(void) || (!(isBytes(fileName)))) { return primitiveFailFor(PrimErrBadArgument); } - faPath = (fapath *) calloc(1, sizeof(fapath)); - if (faPath == null) { - return primitiveFailForOSError(-10 /* cantAllocateMemory */); - } - faSetPlatPathOop(faPath, fileName); + faSetPlatPathOop((&faPath), fileName); if (failed()) { - free(faPath); return primitiveFailureCode(); } - resultOop = instantiateClassindexableSize(classByteArray(), faGetStPathLen(faPath)); + resultOop = instantiateClassindexableSize(classByteArray(), faGetStPathLen((&faPath))); if (!(resultOop)) { - free(faPath); return primitiveFailFor(PrimErrNoMemory); } byteArrayPtr = arrayValueOf(resultOop); - memcpy(byteArrayPtr, faGetStPath(faPath), faGetStPathLen(faPath)); - free(faPath); + memcpy(byteArrayPtr, faGetStPath((&faPath)), faGetStPathLen((&faPath))); return methodReturnValue(resultOop); } @@ -940,36 +918,48 @@ primitivePlatToStPath(void) EXPORT(sqInt) primitiveReaddir(void) { + void *buffer; sqInt dirPointerOop; fapath *faPath; fapathptr *faPathPtr; sqInt resultArray; sqInt status; + sqInt structSize; dirPointerOop = stackValue(0); - faPathPtr = (fapathptr *)structFromObjectsize(dirPointerOop, sizeof(fapathptr)); + /* begin structFromObject:size: */ + structSize = sizeof(fapathptr); + if (!((stSizeOf(dirPointerOop)) == structSize)) { + primitiveFailFor(PrimErrBadArgument); + faPathPtr = ((void *) 0); + goto l1; + } + buffer = alloca(structSize); + if (buffer == 0) { + primitiveFailFor(PrimErrNoCMemory); + } + else { + memcpy(buffer, arrayValueOf(dirPointerOop), structSize); + } + faPathPtr = buffer; + l1: /* end structFromObject:size: */; if (faPathPtr == 0) { return primitiveFailFor(PrimErrBadArgument); } if (!(faValidateSessionId(faPathPtr->sessionId))) { - free(faPathPtr); return primitiveFailForOSError(-17 /* badSessionId */); } faPath = faPathPtr->faPath; status = faReadDirectory(faPath); if (status == 1 /* noMoreData */) { - free(faPathPtr); - return popthenPush(2, nilObject()); + return methodReturnValue(nilObject()); } if (status < 0) { - free(faPathPtr); return primitiveFailForOSError(status); } + + /* no need to check the status of #processDirectory: as it will have flagged an error with interpreterProxy */ resultArray = processDirectory(faPath); - free(faPathPtr); - if (failed()) { - return primitiveFailureCode(); - } return methodReturnValue(resultArray); } @@ -980,32 +970,45 @@ primitiveReaddir(void) EXPORT(sqInt) primitiveRewinddir(void) { + void *buffer; sqInt dirPointerOop; fapath *faPath; fapathptr *faPathPtr; sqInt resultOop; sqInt status; + sqInt structSize; dirPointerOop = stackValue(0); - faPathPtr = (fapathptr *)structFromObjectsize(dirPointerOop, sizeof(fapathptr)); + /* begin structFromObject:size: */ + structSize = sizeof(fapathptr); + if (!((stSizeOf(dirPointerOop)) == structSize)) { + primitiveFailFor(PrimErrBadArgument); + faPathPtr = ((void *) 0); + goto l1; + } + buffer = alloca(structSize); + if (buffer == 0) { + primitiveFailFor(PrimErrNoCMemory); + } + else { + memcpy(buffer, arrayValueOf(dirPointerOop), structSize); + } + faPathPtr = buffer; + l1: /* end structFromObject:size: */; if (faPathPtr == 0) { return primitiveFailFor(PrimErrBadArgument); } if (!(faValidateSessionId(faPathPtr->sessionId))) { - free(faPathPtr); return primitiveFailFor(PrimErrBadArgument); } faPath = faPathPtr->faPath; status = faRewindDirectory(faPath); if (status < 0) { - free(faPathPtr); return primitiveFailForOSError(status); } + + /* no need to check the status of #processDirectory: as it will have flagged an error with interpreterProxy */ resultOop = processDirectory(faPath); - free(faPathPtr); - if (failed()) { - return primitiveFailureCode(); - } return methodReturnValue(resultOop); } @@ -1019,7 +1022,7 @@ EXPORT(sqInt) primitiveStToPlatPath(void) { unsigned char *byteArrayPtr; - fapath *faPath; + fapath faPath; sqInt fileName; sqInt resultOop; @@ -1028,23 +1031,16 @@ primitiveStToPlatPath(void) || (!(isBytes(fileName)))) { return primitiveFailFor(PrimErrBadArgument); } - faPath = (fapath *) calloc(1, sizeof(fapath)); - if (faPath == null) { - return primitiveFailForOSError(-10 /* cantAllocateMemory */); - } - faSetStPathOop(faPath, fileName); + faSetStPathOop((&faPath), fileName); if (failed()) { - free(faPath); return primitiveFailureCode(); } - resultOop = instantiateClassindexableSize(classByteArray(), faGetPlatPathByteCount(faPath)); + resultOop = instantiateClassindexableSize(classByteArray(), faGetPlatPathByteCount((&faPath))); if (!(resultOop)) { - free(faPath); return primitiveFailFor(PrimErrNoMemory); } byteArrayPtr = arrayValueOf(resultOop); - memcpy(byteArrayPtr, faGetPlatPath(faPath), faGetPlatPathByteCount(faPath)); - free(faPath); + memcpy(byteArrayPtr, faGetPlatPath((&faPath)), faGetPlatPathByteCount((&faPath))); return methodReturnValue(resultOop); } @@ -1055,7 +1051,7 @@ primitiveStToPlatPath(void) EXPORT(sqInt) primitiveSymlinkChangeOwner(void) { - fapath *faPath; + fapath faPath; sqInt fileNameOop; sqInt groupId; sqInt ownerId; @@ -1070,17 +1066,11 @@ primitiveSymlinkChangeOwner(void) } # if HAVE_CHOWN - faPath = (fapath *) calloc(1, sizeof(fapath)); - if (faPath == null) { - return primitiveFailForOSError(-10 /* cantAllocateMemory */); - } - faSetStPathOop(faPath, fileNameOop); + faSetStPathOop((&faPath), fileNameOop); if (failed()) { - free(faPath); return primitiveFailureCode(); } - status = lchown(faGetPlatPath(faPath), ownerId, groupId); - free(faPath); + status = lchown(faGetPlatPath((&faPath)), ownerId, groupId); if (status != 0) { return primitiveFailForOSError(errno); } @@ -1096,7 +1086,7 @@ primitiveSymlinkChangeOwner(void) EXPORT(sqInt) primitiveVersionString(void) { - popthenPush(1, stringFromCString("2.0.6")); + popthenPush(1, stringFromCString("2.0.7")); return 0; } @@ -1272,33 +1262,6 @@ stringFromCString(const char *aCString) } -/* Allocate memory of the requiested size and copy the contents of anObject - in to it. - anObject is expected to be bytes, e.g. ByteArray or String. - The sender is responsible for freeing the memory. - */ - - /* FileAttributesPlugin>>#structFromObject:size: */ -static void * -structFromObjectsize(sqInt anObject, sqInt structSize) -{ - void *buffer; - - buffer = 0; - if (!((stSizeOf(anObject)) == structSize)) { - primitiveFailFor(PrimErrBadArgument); - return buffer; - } - buffer = malloc(structSize); - if (buffer == 0) { - primitiveFailFor(PrimErrNoCMemory); - return buffer; - } - memcpy(buffer, arrayValueOf(anObject), structSize); - return buffer; -} - - #ifdef SQUEAK_BUILTIN_PLUGIN static char _m[] = "FileAttributesPlugin";