I've attached a first cut implementation of alloca for tcc. This one allocates cleanly straight off the stack - no monkeying with malloc() at all. It currently doesn't actually call the bounds-checking functions, though I know in principle what it needs to call. Runs on Linux; _may_ work on Windows, but I suspect that there's some oddities involving page access that would need to be accounted for.
My thanks to those who have sent me constructive criticism! --- David A. Wheeler
alloca.S
Description: Binary data
#ifndef _ALLOCA_H #define _ALLOCA_H #define alloca(x) __alloca_tcc_builtin(x) void * __alloca_tcc_builtin(unsigned x); #endif
#include "alloca.h"
#include <stdio.h>
main()
{
char *p = alloca(16);
strcpy(p,"123456789012345");
printf("p is %s\n", p);
char *q = alloca(0);
if (q) printf("Whups!");
else printf("Hooray, got that right.\n");
char *demo = "This is a test. This is only a test.\n";
printf("Test: %s\n", strcpy(alloca(strlen(demo)+1),demo) );
}
_______________________________________________ Tinycc-devel mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/tinycc-devel
