aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2016-05-23 13:42:40 -0500
committerTianjie Xu2016-05-23 14:24:28 -0500
commit84478e88234b68e457e18877ba9542029e5c7865 (patch)
treee4884c5c70dcde2cb1a346f8f7259839826c6f85 /edify/expr.cpp
parent8a55c653458c2d33af506b193e658faf8f88bfa3 (diff)
parent50f6417317f9e327ed76abaf34512370f8376245 (diff)
downloadplatform-bootable-recovery-84478e88234b68e457e18877ba9542029e5c7865.tar.gz
platform-bootable-recovery-84478e88234b68e457e18877ba9542029e5c7865.tar.xz
platform-bootable-recovery-84478e88234b68e457e18877ba9542029e5c7865.zip
resolve merge conflicts of 50f6417 to nyc-dev-plus-aosp
Change-Id: I42c127f7946e678acf6596f6352f090abc0ca019
Diffstat (limited to 'edify/expr.cpp')
-rw-r--r--edify/expr.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/edify/expr.cpp b/edify/expr.cpp
index c34342f7..ecb1bea1 100644
--- a/edify/expr.cpp
+++ b/edify/expr.cpp
@@ -21,6 +21,11 @@
21#include <stdarg.h> 21#include <stdarg.h>
22#include <unistd.h> 22#include <unistd.h>
23 23
24#include <string>
25
26#include <android-base/stringprintf.h>
27#include <android-base/strings.h>
28
24#include "expr.h" 29#include "expr.h"
25 30
26// Functions should: 31// Functions should:
@@ -36,7 +41,7 @@ char* Evaluate(State* state, Expr* expr) {
36 Value* v = expr->fn(expr->name, state, expr->argc, expr->argv); 41 Value* v = expr->fn(expr->name, state, expr->argc, expr->argv);
37 if (v == NULL) return NULL; 42 if (v == NULL) return NULL;
38 if (v->type != VAL_STRING) { 43 if (v->type != VAL_STRING) {
39 ErrorAbort(state, "expecting string, got value type %d", v->type); 44 ErrorAbort(state, kArgsParsingFailure, "expecting string, got value type %d", v->type);
40 FreeValue(v); 45 FreeValue(v);
41 return NULL; 46 return NULL;
42 } 47 }
@@ -494,15 +499,29 @@ Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]) {
494 return args; 499 return args;
495} 500}
496 501
502static void ErrorAbortV(State* state, const char* format, va_list ap) {
503 std::string buffer;
504 android::base::StringAppendV(&buffer, format, ap);
505 free(state->errmsg);
506 state->errmsg = strdup(buffer.c_str());
507 return;
508}
509
497// Use printf-style arguments to compose an error message to put into 510// Use printf-style arguments to compose an error message to put into
498// *state. Returns NULL. 511// *state. Returns nullptr.
499Value* ErrorAbort(State* state, const char* format, ...) { 512Value* ErrorAbort(State* state, const char* format, ...) {
500 char* buffer = reinterpret_cast<char*>(malloc(4096)); 513 va_list ap;
501 va_list v; 514 va_start(ap, format);
502 va_start(v, format); 515 ErrorAbortV(state, format, ap);
503 vsnprintf(buffer, 4096, format, v); 516 va_end(ap);
504 va_end(v); 517 return nullptr;
505 free(state->errmsg); 518}
506 state->errmsg = buffer; 519
507 return NULL; 520Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) {
521 va_list ap;
522 va_start(ap, format);
523 ErrorAbortV(state, format, ap);
524 va_end(ap);
525 state->cause_code = cause_code;
526 return nullptr;
508} 527}