diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index 64840640a4..7312a4d26e 100755 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -1,10 +1,13 @@ # distutils: langauge = c++ -import threading -import os +# cython: language_level = 3 from libcpp cimport bool from libcpp.string cimport string from params_pxd cimport Params as c_Params +import os +import threading +from common.basedir import PARAMS + cdef enum TxType: PERSISTENT = 1 CLEAR_ON_MANAGER_START = 2 @@ -81,11 +84,11 @@ class UnknownKeyName(Exception): cdef class Params: cdef c_Params* p - def __cinit__(self, d=None, persistent_params=False): - if d is not None: - self.p = new c_Params(d.encode()) + def __cinit__(self, d=PARAMS, bool persistent_params=False): + if persistent_params: + self.p = new c_Params(True) else: - self.p = new c_Params(persistent_params) + self.p = new c_Params(d.encode()) def __dealloc__(self): del self.p diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index 73839a6381..6c01598bd2 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -23,17 +23,17 @@ namespace { -template -T* null_coalesce(T* a, T* b) { - return a != NULL ? a : b; +std::string getenv_default(const char* env_var, const char* default_val) { + const char* env_val = getenv(env_var); + return std::string(env_val != NULL ? env_val : default_val); } -static const char* default_params_path = null_coalesce(const_cast(getenv("PARAMS_PATH")), "/data/params"); +const std::string default_params_path = getenv_default("PARAMS_PATH", "/data/params"); #ifdef QCOM -static const char* persistent_params_path = null_coalesce(const_cast(getenv("PERSISTENT_PARAMS_PATH")), "/persist/comma/params"); +const std::string persistent_params_path = getenv_default("PERSISTENT_PARAMS_PATH", "/persist/comma/params"); #else -static const char* persistent_params_path = default_params_path; +const std::string persistent_params_path = default_params_path; #endif } //namespace @@ -99,8 +99,7 @@ static int ensure_dir_exists(std::string path) { Params::Params(bool persistent_param){ - const char * path = persistent_param ? persistent_params_path : default_params_path; - params_path = std::string(path); + params_path = persistent_param ? persistent_params_path : default_params_path; } Params::Params(std::string path) {