diff --git a/src/runtime/stringTable.cpp b/src/runtime/stringTable.cpp index 6961617966d31890d5d8254accea80121bed9ced..8fcfd0feb08d671b6c7920cb8cdce44cc2739eb2 100644 --- a/src/runtime/stringTable.cpp +++ b/src/runtime/stringTable.cpp @@ -1,6 +1,8 @@ #include "runtime/stringTable.hpp" #include "object/hiString.hpp" #include "memory/oopClosure.hpp" +#include +#include StringTable* StringTable::instance = NULL; @@ -11,6 +13,17 @@ StringTable* StringTable::get_instance() { return instance; } +bool StringTable::get_absolute_path(char* path) { + int result = readlink("/proc/self/exe", path, MAX_PATH_LENGTH); + if(result == -1) return false; + //now path = /home/user/pythonvm/src/build/railgun + //modify path = /home/user/pythonvm/src/build/lib/ + int len = strlen(path); + int base_name = 7; //strlen("railgun") + strcpy(path + len - base_name, "lib/"); + return true; +} + StringTable::StringTable() { next_str = new HiString("next"); mod_str = new HiString("__module__"); @@ -27,7 +40,13 @@ StringTable::StringTable() { setattr_str = new HiString("__setattr__"); so_pre_str = new HiString("lib"); - libdir_pre_str = new HiString("./lib/"); + char* path = new char[MAX_PATH_LENGTH]; + if (get_absolute_path(path)) { + libdir_pre_str = new HiString(path); + } else { + libdir_pre_str = new HiString("./lib/"); + } + delete[] path; empty_str = new HiString(""); so_suf_str = new HiString(".so"); pyc_suf_str = new HiString(".pyc"); diff --git a/src/runtime/stringTable.hpp b/src/runtime/stringTable.hpp index 1921ca31584085c6a97b8f1da113b0401577825c..07ba1f03e7e00fec79223496b983a03bec553b44 100644 --- a/src/runtime/stringTable.hpp +++ b/src/runtime/stringTable.hpp @@ -6,6 +6,8 @@ class OopClosure; class StringTable { private: + static const int MAX_PATH_LENGTH = 128; + static bool get_absolute_path(char* path); static StringTable* instance; StringTable();