Plan 9 from Bell Labs’s /usr/web/sources/contrib/de0u/root/sys/src/cmd/squeak/Cross/plugins/SqueakFFIPrims/sqFFIPlugin.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/****************************************************************************
*   PROJECT: Squeak threaded foreign function interface
*   FILE:    sqFFIPlugin.c
*   CONTENT: C support code for the threaded FFIPlugin
*
*   AUTHOR:  Eliot Miranda
*
*****************************************************************************/

#include <stdio.h>
#if !WIN32 && !__FreeBSD__
# include <alloca.h>
#endif
#include <string.h>

#ifdef _MSC_VER
# define alloca _alloca
#endif

/* this is a stub through which floating-point register arguments can be loaded
 * prior to an FFI call proper.  e.g. on the PowerPC this would be declared as
 *	extern void loadFloatRegs(double, double, double, double,
 *	                          double, double, double, double);
 * and called with the appropriate values necessary to load the floating-point
 * argument registers.  Immediately after the actual call is made, using the
 * undisturbed register contents created by the call of loadFloatRegs.
 */
void
loadFloatRegs(void) { return; }

static FILE *ffiLogFile = NULL;

int
ffiLogFileNameOfLength(void *nameIndex, int nameLength)
{
	if (nameIndex && nameLength) {
		char *fileName;
		FILE *fp;

		if (!(fileName = alloca(nameLength+1)))
			return 0;
		strncpy(fileName, nameIndex, nameLength);
		fileName[nameLength] = 0;
		/* attempt to open the file and if we can't, fail */
		if (!(fp = fopen(fileName, "at")))
			return 0;
		/* close the old log file if needed and use the new one */
		if (ffiLogFile)
			fclose(ffiLogFile);
		ffiLogFile = fp;
		fprintf(ffiLogFile, "------- Log started -------\n");
		fflush(fp);
	}
	else {
		if (ffiLogFile)
			fclose(ffiLogFile);
		ffiLogFile = NULL;
	}
	return 1;
}

int
ffiLogCallOfLength(void *nameIndex, int nameLength)
{
    if (!ffiLogFile)
		return 0;
    fprintf(ffiLogFile, "%.*s\n", nameLength, (char *)nameIndex);
    fflush(ffiLogFile);
	return 1;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].