Commit bfea693c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Deal with cases when we can't write out a pyc file

(previously we would just throw an assert)
parent 4afb0656
...@@ -966,10 +966,16 @@ AST_Module* parse(const char* fn) { ...@@ -966,10 +966,16 @@ AST_Module* parse(const char* fn) {
#define MAGIC_STRING_LENGTH 4 #define MAGIC_STRING_LENGTH 4
#define CHECKSUM_LENGTH 4 #define CHECKSUM_LENGTH 4
static void _reparse(const char* fn, const std::string& cache_fn) { enum class ParseResult {
FILE* parser = popen(getParserCommandLine(fn).c_str(), "r"); SUCCESS,
PYC_UNWRITABLE,
};
static ParseResult _reparse(const char* fn, const std::string& cache_fn) {
FILE* cache_fp = fopen(cache_fn.c_str(), "w"); FILE* cache_fp = fopen(cache_fn.c_str(), "w");
assert(cache_fp); if (!cache_fp)
return ParseResult::PYC_UNWRITABLE;
FILE* parser = popen(getParserCommandLine(fn).c_str(), "r");
fwrite(MAGIC_STRING, 1, MAGIC_STRING_LENGTH, cache_fp); fwrite(MAGIC_STRING, 1, MAGIC_STRING_LENGTH, cache_fp);
...@@ -997,6 +1003,7 @@ static void _reparse(const char* fn, const std::string& cache_fn) { ...@@ -997,6 +1003,7 @@ static void _reparse(const char* fn, const std::string& cache_fn) {
fwrite(&bytes_written, 1, CHECKSUM_LENGTH, cache_fp); fwrite(&bytes_written, 1, CHECKSUM_LENGTH, cache_fp);
fclose(cache_fp); fclose(cache_fp);
return ParseResult::SUCCESS;
} }
// Parsing the file is somewhat expensive since we have to shell out to cpython; // Parsing the file is somewhat expensive since we have to shell out to cpython;
...@@ -1058,7 +1065,12 @@ AST_Module* caching_parse(const char* fn) { ...@@ -1058,7 +1065,12 @@ AST_Module* caching_parse(const char* fn) {
if (!good) { if (!good) {
fclose(fp); fclose(fp);
_reparse(fn, cache_fn); auto result = _reparse(fn, cache_fn);
if (result == ParseResult::PYC_UNWRITABLE) {
if (VERBOSITY())
printf("Unable to write to %s, falling back to non-caching parse\n", cache_fn.c_str());
return parse(fn);
}
code = stat(cache_fn.c_str(), &cache_stat); code = stat(cache_fn.c_str(), &cache_stat);
assert(code == 0); assert(code == 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment