From 59dcb9cbea8fb70ab933fd10d35582b08cd13f37 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 3 Oct 2016 18:06:46 -0700 Subject: edify: Move State.script and State.errmsg to std::string. This way we kill a few strdup() and free() calls. Test: 1. recovery_component_test still passes; 2. Applying an update with the new updater works; 3. The error code in a script with abort("E310: xyz") is recorded into last_install correctly. Change-Id: Ibda4da5937346e058a0d7cc81764d6f02920010a --- edify/expr.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'edify/expr.h') diff --git a/edify/expr.h b/edify/expr.h index 886347991..f045d9386 100644 --- a/edify/expr.h +++ b/edify/expr.h @@ -18,6 +18,7 @@ #define _EXPRESSION_H #include +#include #include "error_code.h" #include "yydefs.h" @@ -26,20 +27,20 @@ typedef struct Expr Expr; -typedef struct { +struct State { + State(const std::string& script, void* cookie); + + // The source of the original script. + const std::string& script; + // Optional pointer to app-specific data; the core of edify never // uses this value. void* cookie; - // The source of the original script. Must be NULL-terminated, - // and in writable memory (Evaluate may make temporary changes to - // it but will restore it when done). - char* script; - // The error message (if any) returned if the evaluation aborts. - // Should be NULL initially, will be either NULL or a malloc'd - // pointer after Evaluate() returns. - char* errmsg; + // Should be empty initially, will be either empty or a string that + // Evaluate() returns. + std::string errmsg; // error code indicates the type of failure (e.g. failure to update system image) // during the OTA process. @@ -50,8 +51,7 @@ typedef struct { CauseCode cause_code = kNoCause; bool is_retry = false; - -} State; +}; #define VAL_STRING 1 // data will be NULL-terminated; size doesn't count null #define VAL_BLOB 2 -- cgit v1.2.3