Home | History | Annotate | Download | only in LD
      1 //===- ResolveInfoFactory.cpp ---------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 #include "mcld/LD/ResolveInfoFactory.h"
     10 #include <cstring>
     11 #include <cstdlib>
     12 
     13 using namespace mcld;
     14 
     15 //==========================
     16 // ResolveInfoFactory
     17 ResolveInfoFactory::entry_type*
     18 ResolveInfoFactory::produce(const ResolveInfoFactory::key_type& pKey)
     19 {
     20   entry_type* result = static_cast<entry_type*>(
     21                                     malloc(sizeof(entry_type)+pKey.size()+1));
     22   if (NULL == result)
     23     return NULL;
     24 
     25   new (result) entry_type();
     26   std::memcpy(result->m_Name, pKey.data(), pKey.size());
     27   result->m_Name[pKey.size()] = '\0';
     28   result->m_BitField &= ~ResolveInfo::RESOLVE_MASK;
     29   result->m_BitField |= (pKey.size() << ResolveInfo::NAME_LENGTH_OFFSET);
     30   return result;
     31 }
     32 
     33 void ResolveInfoFactory::destroy(ResolveInfoFactory::entry_type* pEntry)
     34 {
     35   if (NULL != pEntry) {
     36     pEntry->~entry_type();
     37     free(pEntry);
     38   }
     39 }
     40 
     41