Skip to content

Commit

Permalink
[PATCH] compile warnings fixed; bugfixes at 64 bit platforms; Mac OS …
Browse files Browse the repository at this point in the history
…X specific bugfixes
  • Loading branch information
david_meiners committed Jul 30, 2014
1 parent 24368bf commit ff1c465
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 51 deletions.
15 changes: 10 additions & 5 deletions CMakeLists.txt
Expand Up @@ -14,12 +14,17 @@ include_directories(
"${PROJECT_SOURCE_DIR}/inc"
)

set(CL_REFLECT_BIN_DIRECTORY "${PROJECT_SOURCE_DIR}/cmake-build/${CMAKE_SYSTEM}/bin")
set(CL_REFLECT_LIB_DIRECTORY "${PROJECT_SOURCE_DIR}/cmake-build/${CMAKE_SYSTEM}/lib")
set(CL_REFLECT_GEN_DIRECTORY "${PROJECT_SOURCE_DIR}/cmake-build/${CMAKE_SYSTEM}/gen")
if(DEFINED CMAKE_INSTALL_PREFIX)
set(CL_REFLECT_BASE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_PREFIX}")
else(DEFINED CMAKE_INSTALL_PREFIX)
set(CL_REFLECT_BASE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/binary/${CMAKE_BUILD_TYPE}")
endif(DEFINED CMAKE_INSTALL_PREFIX)

# Sets binary output direcotry to cmake-build/${CMAKE_SYSTEM}/bin, sets lib output directory
# to cmake-build/${CMAKE_SYSTEM}/lib
set(CL_REFLECT_BIN_DIRECTORY "${CL_REFLECT_BASE_OUTPUT_DIRECTORY}/bin")
set(CL_REFLECT_LIB_DIRECTORY "${CL_REFLECT_BASE_OUTPUT_DIRECTORY}/lib")
set(CL_REFLECT_GEN_DIRECTORY "${CL_REFLECT_BASE_OUTPUT_DIRECTORY}/gen")

# Sets binary output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CL_REFLECT_BIN_DIRECTORY}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CL_REFLECT_LIB_DIRECTORY}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CL_REFLECT_LIB_DIRECTORY}")
Expand Down
2 changes: 1 addition & 1 deletion inc/clcpp/clcpp.h
Expand Up @@ -124,7 +124,7 @@ namespace clcpp

// type field used in printf/scanf
#define CLCPP_SIZE_TYPE_HEX_FORMAT "lX"
#define CLCPP_POINTER_TYPE_HEX_FORMAT "lX"
#define CLCPP_POINTER_TYPE_HEX_FORMAT "llX"

#else

Expand Down
2 changes: 2 additions & 0 deletions src/clReflectCore/DatabaseBinarySerialiser.cpp
Expand Up @@ -128,6 +128,7 @@ namespace
case (cldb::meta::FIELD_TYPE_BASIC): CopyBasicFields(db, dest, source, table.size(), type.packed_size, type.size, field.size); break;
case (cldb::meta::FIELD_TYPE_NAME): CopyStridedData<CopyNameToHash>(db, dest, source, table.size(), type.packed_size, type.size, field.size); break;
case (cldb::meta::FIELD_TYPE_STRING): CopyStridedData<CopyStringToHash>(db, dest, source, table.size(), type.packed_size, type.size, field.size); break;
default: break;
}
}
}
Expand Down Expand Up @@ -315,6 +316,7 @@ namespace
case (cldb::meta::FIELD_TYPE_BASIC): CopyBasicFields(db, dest, source, table.size(), type.size, type.packed_size, field.size); break;
case (cldb::meta::FIELD_TYPE_NAME): CopyStridedData<CopyHashToName>(db, dest, source, table.size(), type.size, type.packed_size, field.size); break;
case (cldb::meta::FIELD_TYPE_STRING): CopyStridedData<CopyHashToString>(db, dest, source, table.size(), type.size, type.packed_size, field.size); break;
default: break;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/clReflectCore/Logging.cpp
Expand Up @@ -271,6 +271,7 @@ void logging::Log(StreamHandle handle, Tag tag, bool do_prefix, const char* form
{
case (TAG_WARNING): strcat(prefix, "WARNING: "); break;
case (TAG_ERROR): strcat(prefix, "ERROR: "); break;
default: break;
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/clReflectCpp/clcpp.cpp
Expand Up @@ -19,8 +19,13 @@

#elif defined(CLCPP_PLATFORM_POSIX)

extern "C" void * dlopen(const char * __path, int __mode);
extern "C" void * dlsym(void * handle, const char * name);
#if defined(__linux__)
extern "C" void * dlopen(const char * __path, int __mode);
extern "C" void * dlsym(void * handle, const char * name);
#elif defined(__APPLE__)
// os x linker will bind it
extern int start_base_address_hack __asm("section$start$__TEXT$__text");
#endif

#endif

Expand Down Expand Up @@ -299,8 +304,12 @@ namespace
#if defined(CLCPP_PLATFORM_WINDOWS)
return (clcpp::pointer_type)GetModuleHandleA(0);
#elif defined(CLCPP_PLATFORM_POSIX)
void * global_symbols = dlopen(0, 0);
return (clcpp::pointer_type)dlsym(global_symbols, "_start");
#if defined(__linux__)
void * global_symbols = dlopen(0, 0);
return (clcpp::pointer_type)dlsym(global_symbols, "_start");
#elif defined(__APPLE__)
return (clcpp::pointer_type) &start_base_address_hack;
#endif
#endif
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/clReflectExport/CppExport.cpp
Expand Up @@ -46,7 +46,7 @@ namespace
// casting job.
#define POINTER_TO_HASH(p) ((cldb::u32) ((clcpp::pointer_type) (p)))

#define HASH_TO_POINTER(h) ((void*) (h))
#define HASH_TO_POINTER(h) ((void*) ((clcpp::pointer_type) h))

// A basic malloc allocator implementation
class Malloc : public clcpp::IAllocator
Expand Down Expand Up @@ -339,7 +339,7 @@ namespace
// When the last constant gets written, the constant count gets overwritten with
// the constant pointer and should no longer be updated
if (cur_count != nb_constants)
(parent->*carray)[nb_constants - 1] = (CHILD_TYPE*)cur_count;
(parent->*carray)[nb_constants - 1] = (CHILD_TYPE*)((clcpp::pointer_type)cur_count);
}
}
}
Expand Down Expand Up @@ -925,6 +925,8 @@ namespace
case (clcpp::Primitive::KIND_CLASS):
LOG(main, WARNING, "Class field '%s' within '%s' couldn't find type reference to '%s'\n", primitive.name.text, primitive.parent->name.text, unresolved);
break;
default:
break;
}
}
else
Expand Down Expand Up @@ -1521,6 +1523,8 @@ namespace
case clcpp::Primitive::KIND_TEXT_ATTRIBUTE:
LogPrimitive((clcpp::TextAttribute&)attr);
break;
default:
break;
}
}

Expand Down
85 changes: 57 additions & 28 deletions src/clReflectExport/MapFileParser.cpp
Expand Up @@ -171,36 +171,31 @@ namespace
}


void AddFunctionAddress(cldb::Database& db, const std::string& function_name, const std::string& function_signature, unsigned int function_address)
bool AddFunctionAddress(cldb::Database& db, const std::string& function_name, const std::string& function_signature, clcpp::pointer_type function_address, bool is_this_call, bool is_const)
{
if (function_address == 0)
return;
return false;

// Find where the return type ends
size_t func_pos = function_signature.find(function_name);
if (func_pos == std::string::npos)
{
LOG(main, ERROR, "Couldn't locate function name in signature for '%s'", function_name.c_str());
return;
return false;
}

// Skip the return parameter as it can't be used to overload a function
bool is_this_call = false;
const char* ptr = function_signature.c_str();
MatchParameter(db, ptr, ptr + func_pos, is_this_call);

// Isolate the parameters in the signature
size_t l_pos = function_signature.find('(', func_pos);
if (l_pos == std::string::npos)
{
LOG(main, ERROR, "Couldn't locate left bracket in signature for '%s'", function_name.c_str());
return;
return false;
}
size_t r_pos = function_signature.find(')', l_pos);
if (r_pos == std::string::npos)
{
LOG(main, ERROR, "Couldn't locate right bracket in signature for '%s'", function_name.c_str());
return;
return false;
}

std::vector<cldb::Field> parameters;
Expand All @@ -211,7 +206,7 @@ namespace
if (rsep == std::string::npos)
{
LOG(main, ERROR, "Function declaration says it's __thiscall but no type found in the name of '%s'", function_name.c_str());
return;
return false;
}

// Construct the type name
Expand All @@ -223,11 +218,12 @@ namespace
cldb::Field this_parameter;
this_parameter.type = db.GetName(type_name);
this_parameter.qualifier.op = cldb::Qualifier::POINTER;
this_parameter.qualifier.is_const = is_const;
parameters.push_back(this_parameter);
}

// Parse the parameters
ptr = function_signature.c_str() + l_pos + 1;
const char* ptr = function_signature.c_str() + l_pos + 1;
const char* end = function_signature.c_str() + r_pos;
while (ptr < end)
{
Expand All @@ -249,9 +245,11 @@ namespace
if (function.unique_id == unique_id)
{
function.address = function_address;
break;
return true;
}
}

return false;
}


Expand All @@ -267,7 +265,7 @@ namespace
}


void AddGetTypeAddress(cldb::Database& db, const std::string& function_name, unsigned int function_address, bool is_get_type)
void AddGetTypeAddress(cldb::Database& db, const std::string& function_name, clcpp::pointer_type function_address, bool is_get_type)
{
if (function_address == 0)
return;
Expand Down Expand Up @@ -309,7 +307,7 @@ namespace
}


void AddClassImplFunction(cldb::Database& db, const std::string& function_signature, unsigned int function_address, bool is_constructor)
void AddClassImplFunction(cldb::Database& db, const std::string& function_signature, clcpp::pointer_type function_address, bool is_constructor)
{
if (function_address == 0)
return;
Expand Down Expand Up @@ -379,13 +377,13 @@ namespace
}


void AddConstructFunction(cldb::Database& db, const std::string& function_signature, unsigned int function_address)
void AddConstructFunction(cldb::Database& db, const std::string& function_signature, clcpp::pointer_type function_address)
{
AddClassImplFunction(db, function_signature, function_address, true);
}


void AddDestructFunction(cldb::Database& db, const std::string& function_signature, unsigned int function_address)
void AddDestructFunction(cldb::Database& db, const std::string& function_signature, clcpp::pointer_type function_address)
{
AddClassImplFunction(db, function_signature, function_address, false);
}
Expand Down Expand Up @@ -435,13 +433,13 @@ namespace
}


unsigned int ParseAddressField(const char* line, const char* function_name)
clcpp::pointer_type ParseAddressField(const char* line, const char* function_name)
{
// First parse the address as hex
char token[1024];
line = SkipWhitespace(line);
line = ConsumeToken(line, ' ', token, sizeof(token));
unsigned int function_address = hextoi(token);
clcpp::pointer_type function_address = hextoi(token);

// Double-check that the map file knows this is a function
line = SkipWhitespace(line);
Expand Down Expand Up @@ -486,32 +484,45 @@ namespace
if (IsConstructFunction(function_name))
{
std::string function_signature = UndecorateFunctionSignature(token);
unsigned int function_address = ParseAddressField(line, function_name.c_str());
clcpp::pointer_type function_address = ParseAddressField(line, function_name.c_str());
AddConstructFunction(db, function_signature, function_address);
}
else if (IsDestructFunction(function_name))
{
std::string function_signature = UndecorateFunctionSignature(token);
unsigned int function_address = ParseAddressField(line, function_name.c_str());
clcpp::pointer_type function_address = ParseAddressField(line, function_name.c_str());
AddDestructFunction(db, function_signature, function_address);
}
else if (IsGetTypeFunction(function_name))
{
unsigned int function_address = ParseAddressField(line, function_name.c_str());
clcpp::pointer_type function_address = ParseAddressField(line, function_name.c_str());
AddGetTypeAddress(db, function_name, function_address, true);
}
else if (IsGetTypeNameHashFunction(function_name))
{
unsigned int function_address = ParseAddressField(line, function_name.c_str());
clcpp::pointer_type function_address = ParseAddressField(line, function_name.c_str());
AddGetTypeAddress(db, function_name, function_address, false);
}

// Otherwise see if it's a function in the database
else if (const cldb::Function* function = db.GetFirstPrimitive<cldb::Function>(function_name.c_str()))
{
std::string function_signature = UndecorateFunctionSignature(token);
unsigned int function_address = ParseAddressField(line, function_name.c_str());
AddFunctionAddress(db, function_name, function_signature, function_address);
std::string function_signature = UndecorateFunctionSignature(token);
clcpp::pointer_type function_address = ParseAddressField(line, function_name.c_str());

bool is_this_call = false;
const char* ptr = function_signature.c_str();
size_t func_pos = function_signature.find(function_name);

if (func_pos == std::string::npos)
{
LOG(main, ERROR, "Couldn't locate function name in signature for '%s'", function_name.c_str());
return;
}

// Skip the return parameter as it can't be used to overload a function
cldb::Field returnValue = MatchParameter(db, ptr, ptr + func_pos, is_this_call);
AddFunctionAddress(db, function_name, function_signature, function_address, is_this_call, returnValue.qualifier.is_const);
}
}

Expand Down Expand Up @@ -723,7 +734,25 @@ namespace
// Otherwise see if it's a function in the database
else if (const cldb::Function* function = db.GetFirstPrimitive<cldb::Function>(function_name.c_str()))
{
AddFunctionAddress(db, function_name, function_signature, function_address);
size_t const_pos = function_signature.rfind("const");
const bool is_function_const = const_pos == (function_signature.size() - 5);

// try to add as this call (member function of class / struct etc.)
if(AddFunctionAddress(db, function_name, function_signature, function_address, true, is_function_const) == false)
{
LOG(main, WARNING, "Couldn't store address for function with signature '%s' as this_call. Try to find static version of function.\n", function_signature.c_str());

// if it is not a method then it has to be a static method or "not member function"
const bool isAddressStored = AddFunctionAddress(db, function_name, function_signature, function_address, false, is_function_const);
if(isAddressStored == false)
{
LOG(main, ERROR, "Couldn't store address for function with signature '%s'. No static or \"this call\" function with same unique id found ! \n", function_signature.c_str());
}
else
{
LOG(main, INFO, "Static Function with same unique id found and address stored for function with signature '%s' ! \n", function_signature.c_str());
}
}
}
}

Expand Down Expand Up @@ -802,7 +831,7 @@ namespace
{
bool text_region = false;

unsigned long function_address, function_size;
clcpp::pointer_type function_address, function_size;
char signature_buffer[1024];

while (const char* line = ReadLine(fp))
Expand Down

0 comments on commit ff1c465

Please sign in to comment.