mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Make amalgamtion the default when building.
This way we can support fewer build configurations. Also, remove all undefined behavior due to use of memcpy with NULL pointers. GCC was exploiting this to remove NULL checks in some builds.
This commit is contained in:
		| @@ -23,6 +23,13 @@ | ||||
| #include <janet.h> | ||||
| #include "tests.h" | ||||
|  | ||||
| #ifdef JANET_WINDOWS | ||||
| #include <windows.h> | ||||
| #define chdir(x) _chdir(x) | ||||
| #else | ||||
| #include <unistd.h> | ||||
| #endif | ||||
|  | ||||
| extern const unsigned char *janet_gen_boot; | ||||
| extern int32_t janet_gen_boot_size; | ||||
|  | ||||
| @@ -63,13 +70,37 @@ int main(int argc, const char **argv) { | ||||
|     janet_def(env, "boot/config", janet_wrap_table(opts), "Boot options"); | ||||
|  | ||||
|     /* Run bootstrap script to generate core image */ | ||||
|     const char *boot_file; | ||||
|     const char *boot_filename; | ||||
| #ifdef JANET_NO_SOURCEMAPS | ||||
|     boot_file = NULL; | ||||
|     boot_filename = NULL; | ||||
| #else | ||||
|     boot_file = "boot.janet"; | ||||
|     boot_filename = "boot.janet"; | ||||
| #endif | ||||
|     status = janet_dobytes(env, janet_gen_boot, janet_gen_boot_size, boot_file, NULL); | ||||
|  | ||||
|     chdir(argv[1]); | ||||
|  | ||||
|     FILE *boot_file = fopen("src/boot/boot.janet", "rb"); | ||||
|     if (NULL == boot_file) { | ||||
|         fprintf(stderr, "Could not open src/boot/boot.janet\n"); | ||||
|         exit(1); | ||||
|     } | ||||
|  | ||||
|     /* Slurp file into buffer */ | ||||
|     fseek(boot_file, 0, SEEK_END); | ||||
|     size_t boot_size = ftell(boot_file); | ||||
|     fseek(boot_file, 0, SEEK_SET); | ||||
|     unsigned char *boot_buffer = malloc(boot_size); | ||||
|     if (NULL == boot_buffer) { | ||||
|         fprintf(stderr, "Failed to allocate boot buffer\n"); | ||||
|         exit(1); | ||||
|     } | ||||
|     if (!fread(boot_buffer, 1, boot_size, boot_file)) { | ||||
|         fprintf(stderr, "Failed to read into boot buffer\n"); | ||||
|         exit(1); | ||||
|     } | ||||
|     fclose(boot_file); | ||||
|  | ||||
|     status = janet_dobytes(env, boot_buffer, boot_size, boot_filename, NULL); | ||||
|  | ||||
|     /* Deinitialize vm */ | ||||
|     janet_deinit(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose