Skip to content

Commit

Permalink
CogVM source as per FileAttributesPlugin.oscog-eem.57
Browse files Browse the repository at this point in the history
Recind the rush of blood to the head.  Since the specialObjectsArray was only
changed in Squeak in January make primitiveFileMasks use WordArray only when
available (a WordArray is smaller and faster to access).  Also, thanks to Pierce
fix the regression in forgetting to export the first switch-hitting version.

Use common code for string return.
  • Loading branch information
eliotmiranda committed Sep 7, 2020
1 parent e58cec1 commit b6f3f2f
Showing 1 changed file with 74 additions and 95 deletions.
169 changes: 74 additions & 95 deletions src/plugins/FileAttributesPlugin/FileAttributesPlugin.c
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.2799 uuid: 80ed3233-a0ed-4818-ad21-8311a85e70f9
VMPluginCodeGenerator VMMaker.oscog-eem.2800 uuid: a6116113-df13-435d-968d-e9b111676754
from
FileAttributesPlugin FileAttributesPlugin.oscog-eem.56 uuid: b6bd12ab-9540-4cea-9032-a39fb4fb7308
FileAttributesPlugin FileAttributesPlugin.oscog-eem.57 uuid: 6f82e8ad-42c9-484c-8b96-2c7b400f9208
*/
static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.56 uuid: b6bd12ab-9540-4cea-9032-a39fb4fb7308 " __DATE__ ;
static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.57 uuid: 6f82e8ad-42c9-484c-8b96-2c7b400f9208 " __DATE__ ;



Expand Down Expand Up @@ -68,9 +68,6 @@ static char __buildInfo[] = "FileAttributesPlugin FileAttributesPlugin.oscog-eem


/*** Constants ***/
#if !defined(PharoVM) /* Allow this to be overridden on the compiler command line */
# define PharoVM 0
#endif
#define PrimErrBadArgument 3
#define PrimErrNoCMemory 10
#define PrimErrNoMemory 9
Expand All @@ -97,7 +94,7 @@ EXPORT(sqInt) primitiveClosedir(void);
EXPORT(sqInt) primitiveFileAttribute(void);
EXPORT(sqInt) primitiveFileAttributes(void);
EXPORT(sqInt) primitiveFileExists(void);
static sqInt primitiveFileMasks(void);
EXPORT(sqInt) primitiveFileMasks(void);
EXPORT(sqInt) primitiveLogicalDrives(void);
EXPORT(sqInt) primitiveOpendir(void);
EXPORT(sqInt) primitivePathMax(void);
Expand All @@ -112,7 +109,6 @@ static sqInt readLinkintomaxLength(char *cPathName, char *cLinkPtr, size_t maxLe
EXPORT(sqInt) setInterpreter(struct VirtualMachine *anInterpreter);
static sqInt sizeOfFaPath(void);
static sqInt sizeOfFaPathPtr(void);
static sqInt stringFromCString(const char *aCString);


/*** Variables ***/
Expand All @@ -121,7 +117,6 @@ static sqInt stringFromCString(const char *aCString);
static void * (*arrayValueOf)(sqInt oop);
static sqInt (*classArray)(void);
static sqInt (*classByteArray)(void);
static sqInt (*classString)(void);
static sqInt (*classWordArray)(void);
static sqInt (*failed)(void);
static void * (*firstIndexableField)(sqInt oop);
Expand All @@ -134,6 +129,7 @@ static sqInt (*isKindOf)(sqInt oop, char *aString);
static sqInt (*isBytes)(sqInt oop);
static sqInt (*methodReturnBool)(sqInt boolean);
static sqInt (*methodReturnInteger)(sqInt integer);
static sqInt (*methodReturnString)(char *aCString);
static sqInt (*methodReturnValue)(sqInt oop);
static sqInt (*nilObject)(void);
static sqInt (*popthenPush)(sqInt nItems, sqInt oop);
Expand All @@ -153,7 +149,6 @@ static sqInt (*storePointerofObjectwithValue)(sqInt index, sqInt oop, sqInt valu
extern void * arrayValueOf(sqInt oop);
extern sqInt classArray(void);
extern sqInt classByteArray(void);
extern sqInt classString(void);
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 16)
extern sqInt classWordArray(void);
#else
Expand All @@ -170,6 +165,7 @@ extern sqInt isKindOf(sqInt oop, char *aString);
extern sqInt isBytes(sqInt oop);
extern sqInt methodReturnBool(sqInt boolean);
extern sqInt methodReturnInteger(sqInt integer);
extern sqInt methodReturnString(char *aCString);
extern sqInt methodReturnValue(sqInt oop);
extern sqInt nilObject(void);
extern sqInt popthenPush(sqInt nItems, sqInt oop);
Expand All @@ -192,7 +188,7 @@ extern sqInt storePointerofObjectwithValue(sqInt index, sqInt oop, sqInt valuePo
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.56 " INT_EXT;
static const char *moduleName = "FileAttributesPlugin FileAttributesPlugin.oscog-eem.57 " INT_EXT;
static void * sCLPfn;
static void * sCOFfn;
static int hasSecurityPlugin = 1;
Expand Down Expand Up @@ -746,77 +742,79 @@ primitiveFileExists(void)
/* Answer an array (or word array) of well known file masks */

/* FileAttributesPlugin>>#primitiveFileMasks */
static sqInt
EXPORT(sqInt)
primitiveFileMasks(void)
{
sqInt * masks;
int * masks1;
sqInt masksArray;
sqInt masksObj;
sqInt maybeClassWordArray;
sqInt nilObj;


# if PharoVM
/* begin primitiveFileMasksAsArray */
masksArray = instantiateClassindexableSize(classArray(), 8);
if (!masksArray) {
primitiveFailFor(PrimErrNoMemory);
goto l1;
}
masks = ((sqInt *) (firstIndexableField(masksArray)));
nilObj = nilObject();
# if defined(S_IFSOCK)
masks[1] = (integerObjectOf(S_IFSOCK));
# else
masks[1] = nilObj;
# endif
# if defined(S_IFLNK)
masks[2] = (integerObjectOf(S_IFLNK));
# else
masks[1] = nilObj;
# endif
masks[3] = (integerObjectOf(S_IFREG));
# if defined(S_IFBLK)
masks[4] = (integerObjectOf(S_IFBLK));
# else
masks[1] = nilObj;
# endif
masks[5] = (integerObjectOf(S_IFDIR));
masks[6] = (integerObjectOf(S_IFCHR));
# if defined(S_IFIFO)
masks[7] = (integerObjectOf(S_IFIFO));
# else
masks[1] = nilObj;
# endif
methodReturnValue(masksArray);
maybeClassWordArray = classWordArray();
if (maybeClassWordArray == (nilObject())) {
/* begin primitiveFileMasksAsArray */
masksArray = instantiateClassindexableSize(classArray(), 8);
if (!masksArray) {
primitiveFailFor(PrimErrNoMemory);
goto l1;
}
masks = ((sqInt *) (firstIndexableField(masksArray)));
nilObj = nilObject();
# if defined(S_IFSOCK)
masks[1] = (integerObjectOf(S_IFSOCK));
# else
masks[1] = nilObj;
# endif
# if defined(S_IFLNK)
masks[2] = (integerObjectOf(S_IFLNK));
# else
masks[1] = nilObj;
# endif
masks[3] = (integerObjectOf(S_IFREG));
# if defined(S_IFBLK)
masks[4] = (integerObjectOf(S_IFBLK));
# else
masks[1] = nilObj;
# endif
masks[5] = (integerObjectOf(S_IFDIR));
masks[6] = (integerObjectOf(S_IFCHR));
# if defined(S_IFIFO)
masks[7] = (integerObjectOf(S_IFIFO));
# else
masks[1] = nilObj;
# endif
methodReturnValue(masksArray);
l1: /* end primitiveFileMasksAsArray */;
# else /* PharoVM */
/* begin primitiveFileMasksAsWordArray */
masksObj = instantiateClassindexableSize(classWordArray(), 8);
if (!masksObj) {
primitiveFailFor(PrimErrNoMemory);
goto l2;
}
masks1 = ((int *) (firstIndexableField(masksObj)));
masks1[0] = S_IFMT;
# if defined(S_IFSOCK)
masks1[1] = S_IFSOCK;
# endif
# if defined(S_IFLNK)
masks1[2] = S_IFLNK;
# endif
masks1[3] = S_IFREG;
# if defined(S_IFBLK)
masks1[4] = S_IFBLK;
# endif
masks1[5] = S_IFDIR;
masks1[6] = S_IFCHR;
# if defined(S_IFIFO)
masks1[7] = S_IFIFO;
# endif
methodReturnValue(masksObj);
l2: /* end primitiveFileMasksAsWordArray */;
# endif /* PharoVM */
}
else {
/* begin primitiveFileMasksAsWordArrayUsing: */
masksObj = instantiateClassindexableSize(maybeClassWordArray, 8);
if (!masksObj) {
primitiveFailFor(PrimErrNoMemory);
goto l2;
}
masks1 = ((int *) (firstIndexableField(masksObj)));
masks1[0] = S_IFMT;
# if defined(S_IFSOCK)
masks1[1] = S_IFSOCK;
# endif
# if defined(S_IFLNK)
masks1[2] = S_IFLNK;
# endif
masks1[3] = S_IFREG;
# if defined(S_IFBLK)
masks1[4] = S_IFBLK;
# endif
masks1[5] = S_IFDIR;
masks1[6] = S_IFCHR;
# if defined(S_IFIFO)
masks1[7] = S_IFIFO;
# endif
methodReturnValue(masksObj);
l2: /* end primitiveFileMasksAsWordArrayUsing: */;
}
return 0;
}

Expand Down Expand Up @@ -1148,7 +1146,7 @@ primitiveSymlinkChangeOwner(void)
EXPORT(sqInt)
primitiveVersionString(void)
{
popthenPush(1, stringFromCString("2.0.9"));
methodReturnString("2.0.9");
return 0;
}

Expand Down Expand Up @@ -1253,7 +1251,6 @@ setInterpreter(struct VirtualMachine *anInterpreter)
arrayValueOf = interpreterProxy->arrayValueOf;
classArray = interpreterProxy->classArray;
classByteArray = interpreterProxy->classByteArray;
classString = interpreterProxy->classString;
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 16)
classWordArray = interpreterProxy->classWordArray;
#else
Expand All @@ -1272,6 +1269,7 @@ setInterpreter(struct VirtualMachine *anInterpreter)
isBytes = interpreterProxy->isBytes;
methodReturnBool = interpreterProxy->methodReturnBool;
methodReturnInteger = interpreterProxy->methodReturnInteger;
methodReturnString = interpreterProxy->methodReturnString;
methodReturnValue = interpreterProxy->methodReturnValue;
nilObject = interpreterProxy->nilObject;
popthenPush = interpreterProxy->popthenPush;
Expand Down Expand Up @@ -1320,26 +1318,6 @@ sizeOfFaPathPtr(void)
}


/* Answer a new String copied from a null-terminated C string.
Caution: This may invoke the garbage collector. */

/* FileAttributesPlugin>>#stringFromCString: */
static sqInt
stringFromCString(const char *aCString)
{
sqInt len;
sqInt newString;

len = strlen(aCString);
newString = instantiateClassindexableSize(classString(), len);
if (!newString) {
return primitiveFailFor(PrimErrNoMemory);
}
strncpy(arrayValueOf(newString), aCString, len);
return newString;
}


#ifdef SQUEAK_BUILTIN_PLUGIN

static char _m[] = "FileAttributesPlugin";
Expand All @@ -1352,6 +1330,7 @@ void* FileAttributesPlugin_exports[][3] = {
{(void*)_m, "primitiveFileAttribute\000\000", (void*)primitiveFileAttribute},
{(void*)_m, "primitiveFileAttributes\000\001", (void*)primitiveFileAttributes},
{(void*)_m, "primitiveFileExists\000\000", (void*)primitiveFileExists},
{(void*)_m, "primitiveFileMasks\000\377", (void*)primitiveFileMasks},
{(void*)_m, "primitiveLogicalDrives\000\377", (void*)primitiveLogicalDrives},
{(void*)_m, "primitiveOpendir\000\000", (void*)primitiveOpendir},
{(void*)_m, "primitivePathMax\000\377", (void*)primitivePathMax},
Expand Down

0 comments on commit b6f3f2f

Please sign in to comment.