bool add_user(const osm_user_id_t uid, const char* name) {
     std::unordered_map<osm_user_id_t, std::string>::const_iterator it = uid_name.find(uid);
     if (it == uid_name.end()) {
         std::string str_name(name);
         uid_name[uid] = str_name;
         return true;
     }
     return false;
 }
Beispiel #2
0
    int* StatsTable::FindLocation(const char* name)
    {
        // Get the static StatsTable
        StatsTable *table = StatsTable::current();
        if(!table)
        {
            return NULL;
        }

        // Get the slot for this thread.  Try to register
        // it if none exists.
        int slot = table->GetSlot();
        if(!slot && !(slot = table->RegisterThread("")))
        {
            return NULL;
        }

        // Find the counter id for the counter.
        std::string str_name(name);
        int counter = table->FindCounter(str_name);

        // Now we can find the location in the table.
        return table->GetLocation(counter, slot);
    }
Beispiel #3
0
 // (PHP-CALLBACK entry-point) This manually gets a lock where needed but
 // avoids holding one most of the time as this can be a quite slow operation.
 void runCallback() {
   hphp_session_init(Treadmill::SessionKind::Watchman);
   auto context = g_context.getNoCheck();
   SCOPE_EXIT {
     hphp_context_exit();
     hphp_session_exit();
     {
       std::lock_guard<std::mutex> g(s_sharedDataMutex);
       processNextUpdate();
     }
   };
   try {
     std::string json_data;
     {
       std::lock_guard<std::mutex> g(s_sharedDataMutex);
       if (m_unprocessedCallbackData.empty()) {
         return;
       }
       auto& data = m_unprocessedCallbackData.back();
       json_data = toJson(data);
       m_unprocessedCallbackData.pop_back();
     }
     bool initial;
     auto unit = lookupUnit(
       String(m_callbackFile.c_str()).get(),
       "",
       &initial,
       Native::s_noNativeFuncs);
     if (!unit) {
       throw std::runtime_error(
         folly::sformat("Unit '{}' no longer exists.", m_callbackFile));
     }
     auto unit_result = Variant::attach(context->invokeUnit(unit));
     auto func = Unit::loadFunc(String(m_callbackFunc.c_str()).get());
     if (!func) {
       throw std::runtime_error(
         folly::sformat("Callback '{}' no longer exists", m_callbackFunc));
     }
     String str_path(m_path.c_str());
     String str_query(m_query.c_str());
     String str_name(m_name.c_str());
     String str_json_data(json_data.c_str());
     String str_socket_path(m_socketPath.c_str());
     TypedValue args[] = {
       str_path.toCell(),
       str_query.toCell(),
       str_name.toCell(),
       str_json_data.toCell(),
       str_socket_path.toCell(),
     };
     tvDecRefGen(
         context->invokeFuncFew(func,
                                nullptr, // thisOrCls
                                nullptr, // invName
                                5, // argc
                                args)
     );
   } catch(Exception& e) {
     if (m_error.empty()) {
       m_error = e.getMessage();
     }
   } catch(Object& e) {
     if (m_error.empty()) {
       try {
         m_error = e->invokeToString().data();
       } catch(...) {
         m_error = "PHP exception which cannot be turned into a string";
       }
     }
   } catch(const std::exception& e) {
     if (m_error.empty()) {
       m_error = folly::exceptionStr(e).toStdString();
     }
   } catch(...) {
     if (m_error.empty()) {
       m_error = "Unknown error (non std::exception)";
     }
   }
 }
Beispiel #4
0
static void err_msg_char_name(const char *msg, const char *name, linepos_t epoint) {
    new_error(SV_CONDERROR, current_file_list, epoint);
    adderror(msg);
    str_name((const uint8_t *)name, strlen(name));
}
Beispiel #5
0
static void err_msg_str_name(const char *msg, const str_t *name, linepos_t epoint) {
    new_error(SV_ERROR, current_file_list, epoint);
    adderror(msg);
    if (name) str_name(name->data, name->len);
}
 int Group::find_dset_ndattr(const char * ndattr_name, Dataset** dset)
 {
   std::string str_name(ndattr_name);
   return this->find_dset_ndattr(str_name, dset);
 }
 HardLink* Group::new_hardlink(const char * name)
 {
   std::string str_name(name);
   return this->new_hardlink(str_name);
 }
 Group* Group::new_group(const char * name)
 {
   std::string str_name(name);
   return this->new_group(str_name);
 }
 Dataset* Group::new_dset(const char* name)
 {
   std::string str_name(name);
   return this->new_dset(str_name);
 }