Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 106aedb

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 9c38b1e + 7fe5fc9 commit 106aedb

29 files changed

Lines changed: 4069 additions & 1267 deletions

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ set(DF_VERSION_MINOR "34")
5353
set(DF_VERSION_PATCH "05")
5454
set(DF_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}")
5555

56-
set(DFHACK_RELEASE "1e")
56+
set(DFHACK_RELEASE "1f")
5757

5858
set(DFHACK_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}-r${DFHACK_RELEASE}")
5959
add_definitions(-DDFHACK_VERSION="${DFHACK_VERSION}")
@@ -103,6 +103,7 @@ ENDIF()
103103

104104
# use shared libraries for protobuf
105105
ADD_DEFINITIONS(-DPROTOBUF_USE_DLLS)
106+
ADD_DEFINITIONS(-DLUA_BUILD_AS_DLL)
106107

107108
if(UNIX)
108109
add_definitions(-D_LINUX)

depends/lua/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
PROJECT ( lua C )
22
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
33

4+
# TODO: make this RelWithDebInfo only
5+
ADD_DEFINITIONS(-DLUA_USE_APICHECK)
6+
47
IF(WIN32)
58
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE )
69
ELSE()
@@ -76,8 +79,13 @@ src/lzio.c
7679
)
7780
LIST(APPEND SRC_LIBLUA ${HDR_LIBLUA})
7881

79-
ADD_LIBRARY ( lua STATIC EXCLUDE_FROM_ALL ${SRC_LIBLUA} )
82+
ADD_LIBRARY ( lua SHARED EXCLUDE_FROM_ALL ${SRC_LIBLUA} )
8083
TARGET_LINK_LIBRARIES ( lua ${LIBS})
84+
85+
install(TARGETS lua
86+
LIBRARY DESTINATION ${DFHACK_LIBRARY_DESTINATION}
87+
RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION})
88+
8189
IDE_FOLDER(lua "Depends")
8290

8391
#SET ( SRC_LUA src/lua.c )

depends/lua/include/luaconf.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,20 @@
151151
** the libraries, you may want to use the following definition (define
152152
** LUA_BUILD_AS_DLL to get it).
153153
*/
154+
#ifdef __cplusplus
155+
#define LUA_API_EXTERN extern "C"
156+
#else
157+
#define LUA_API_EXTERN extern
158+
#endif
154159
#if defined(LUA_BUILD_AS_DLL)
155-
#if defined(LUA_CORE) || defined(LUA_LIB)
156-
#define LUA_API __declspec(dllexport)
160+
#if defined(_MSC_VER)
161+
#if defined(LUA_CORE) || defined(LUA_LIB)
162+
#define LUA_API __declspec(dllexport) LUA_API_EXTERN
163+
#else
164+
#define LUA_API __declspec(dllimport) LUA_API_EXTERN
165+
#endif
157166
#else
158-
#define LUA_API __declspec(dllimport)
167+
#define LUA_API LUA_API_EXTERN __attribute__ ((visibility("default")))
159168
#endif
160169
#else
161170
#ifdef __cplusplus

library/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ SET(MAIN_SOURCES
5555
Core.cpp
5656
ColorText.cpp
5757
DataDefs.cpp
58+
LuaWrapper.cpp
5859
DataStatics.cpp
5960
DataStaticsCtor.cpp
61+
DataStaticsFields.cpp
6062
MiscUtils.cpp
6163
PluginManager.cpp
6264
TileTypes.cpp
@@ -195,6 +197,14 @@ ADD_CUSTOM_COMMAND(
195197

196198
ADD_CUSTOM_TARGET(generate_headers DEPENDS ${dfapi_SOURCE_DIR}/include/df/static.inc)
197199

200+
IF(UNIX)
201+
# Don't produce debug info for generated stubs
202+
SET_SOURCE_FILES_PROPERTIES(DataStatics.cpp DataStaticsCtor.cpp DataStaticsFields.cpp
203+
PROPERTIES COMPILE_FLAGS "-g0 -O1")
204+
ELSE(WIN32)
205+
ENDIF()
206+
207+
198208
# Compilation
199209

200210
ADD_DEFINITIONS(-DBUILD_DFHACK_LIB)
@@ -242,7 +252,7 @@ ENDIF()
242252
#effectively disables debug builds...
243253
SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
244254

245-
TARGET_LINK_LIBRARIES(dfhack protobuf-lite clsocket ${PROJECT_LIBS})
255+
TARGET_LINK_LIBRARIES(dfhack protobuf-lite clsocket lua ${PROJECT_LIBS})
246256
SET_TARGET_PROPERTIES(dfhack PROPERTIES LINK_INTERFACE_LIBRARIES "")
247257

248258
TARGET_LINK_LIBRARIES(dfhack-client protobuf-lite clsocket)

library/DataDefs.cpp

Lines changed: 168 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,186 @@ distribution.
3434
#include "tinythread.h"
3535
// must be last due to MS stupidity
3636
#include "DataDefs.h"
37+
#include "DataIdentity.h"
3738

3839
#include "MiscUtils.h"
3940

4041
using namespace DFHack;
4142

43+
44+
void *type_identity::do_allocate_pod() {
45+
void *p = malloc(size);
46+
memset(p, 0, size);
47+
return p;
48+
}
49+
50+
void type_identity::do_copy_pod(void *tgt, const void *src) {
51+
memmove(tgt, src, size);
52+
};
53+
54+
void *type_identity::allocate() {
55+
if (can_allocate())
56+
return do_allocate();
57+
else
58+
return NULL;
59+
}
60+
61+
bool type_identity::copy(void *tgt, const void *src) {
62+
if (can_allocate() && tgt && src)
63+
do_copy(tgt, src);
64+
else
65+
return false;
66+
}
67+
68+
void *enum_identity::do_allocate() {
69+
void *p = malloc(byte_size());
70+
memcpy(p, &first_item_value, std::min(byte_size(), sizeof(int64_t)));
71+
return p;
72+
}
73+
4274
/* The order of global object constructor calls is
4375
* undefined between compilation units. Therefore,
4476
* this list has to be plain data, so that it gets
4577
* initialized by the loader in the initial mmap.
4678
*/
47-
virtual_identity *virtual_identity::list = NULL;
79+
compound_identity *compound_identity::list = NULL;
80+
std::vector<compound_identity*> compound_identity::top_scope;
4881

49-
virtual_identity::virtual_identity(const char *dfhack_name, const char *original_name, virtual_identity *parent)
50-
: dfhack_name(dfhack_name), original_name(original_name), parent(parent),
51-
prev(NULL), vtable_ptr(NULL), has_children(true)
82+
compound_identity::compound_identity(size_t size, TAllocateFn alloc,
83+
compound_identity *scope_parent, const char *dfhack_name)
84+
: constructed_identity(size, alloc), scope_parent(scope_parent), dfhack_name(dfhack_name)
5285
{
53-
// Link into the static list. Nothing else can be safely done at this point.
54-
next = list; list = this;
86+
next = list; list = this;
87+
}
88+
89+
void compound_identity::doInit(Core *)
90+
{
91+
if (scope_parent)
92+
scope_parent->scope_children.push_back(this);
93+
else
94+
top_scope.push_back(this);
95+
}
96+
97+
std::string compound_identity::getFullName()
98+
{
99+
if (scope_parent)
100+
return scope_parent->getFullName() + "." + getName();
101+
else
102+
return getName();
55103
}
56104

57-
/* Vtable to identity lookup. */
58105
static tthread::mutex *known_mutex = NULL;
106+
107+
void compound_identity::Init(Core *core)
108+
{
109+
if (!known_mutex)
110+
known_mutex = new tthread::mutex();
111+
112+
// This cannot be done in the constructors, because
113+
// they are called in an undefined order.
114+
for (compound_identity *p = list; p; p = p->next)
115+
p->doInit(core);
116+
117+
//FIXME: ... nuked. the group was empty...
118+
/*
119+
// Read pre-filled vtable ptrs
120+
OffsetGroup *ptr_table = core->vinfo->getGroup("vtable");
121+
for (virtual_identity *p = list; p; p = p->next) {
122+
void * tmp;
123+
if (ptr_table->getSafeAddress(p->getName(),tmp))
124+
p->vtable_ptr = tmp;
125+
}
126+
*/
127+
}
128+
129+
bitfield_identity::bitfield_identity(size_t size,
130+
compound_identity *scope_parent, const char *dfhack_name,
131+
int num_bits, const bitfield_item_info *bits)
132+
: compound_identity(size, NULL, scope_parent, dfhack_name), bits(bits), num_bits(num_bits)
133+
{
134+
}
135+
136+
enum_identity::enum_identity(size_t size,
137+
compound_identity *scope_parent, const char *dfhack_name,
138+
type_identity *base_type,
139+
int64_t first_item_value, int64_t last_item_value,
140+
const char *const *keys)
141+
: compound_identity(size, NULL, scope_parent, dfhack_name),
142+
first_item_value(first_item_value), last_item_value(last_item_value),
143+
keys(keys), base_type(base_type)
144+
{
145+
}
146+
147+
struct_identity::struct_identity(size_t size, TAllocateFn alloc,
148+
compound_identity *scope_parent, const char *dfhack_name,
149+
struct_identity *parent, const struct_field_info *fields)
150+
: compound_identity(size, alloc, scope_parent, dfhack_name),
151+
parent(parent), has_children(false), fields(fields)
152+
{
153+
}
154+
155+
void struct_identity::doInit(Core *core)
156+
{
157+
compound_identity::doInit(core);
158+
159+
if (parent) {
160+
parent->children.push_back(this);
161+
parent->has_children = true;
162+
}
163+
}
164+
165+
bool struct_identity::is_subclass(struct_identity *actual)
166+
{
167+
for (; actual; actual = actual->getParent())
168+
if (actual == this) return true;
169+
170+
return false;
171+
}
172+
173+
std::string pointer_identity::getFullName()
174+
{
175+
return (target ? target->getFullName() : std::string("void")) + "*";
176+
}
177+
178+
std::string container_identity::getFullName(type_identity *item)
179+
{
180+
return "<" + (item ? item->getFullName() : std::string("void")) + ">";
181+
}
182+
183+
std::string ptr_container_identity::getFullName(type_identity *item)
184+
{
185+
return "<" + (item ? item->getFullName() : std::string("void")) + "*>";
186+
}
187+
188+
std::string bit_container_identity::getFullName(type_identity *)
189+
{
190+
return "<bool>";
191+
}
192+
193+
std::string df::buffer_container_identity::getFullName(type_identity *item)
194+
{
195+
return (item ? item->getFullName() : std::string("void")) +
196+
(size > 0 ? stl_sprintf("[%d]", size) : std::string("[]"));
197+
}
198+
199+
virtual_identity::virtual_identity(size_t size, TAllocateFn alloc,
200+
const char *dfhack_name, const char *original_name,
201+
virtual_identity *parent, const struct_field_info *fields)
202+
: struct_identity(size, alloc, NULL, dfhack_name, parent, fields), original_name(original_name),
203+
vtable_ptr(NULL)
204+
{
205+
}
206+
207+
static std::map<std::string, virtual_identity*> name_lookup;
208+
209+
void virtual_identity::doInit(Core *core)
210+
{
211+
struct_identity::doInit(core);
212+
213+
name_lookup[getOriginalName()] = this;
214+
}
215+
216+
/* Vtable to identity lookup. */
59217
std::map<void*, virtual_identity*> virtual_identity::known;
60218

61219
virtual_identity *virtual_identity::get(virtual_ptr instance_ptr)
@@ -78,8 +236,9 @@ virtual_identity *virtual_identity::get(virtual_ptr instance_ptr)
78236

79237
virtual_identity *actual = NULL;
80238

81-
for (virtual_identity *p = list; p; p = p->next) {
82-
if (strcmp(name.c_str(), p->getOriginalName()) != 0) continue;
239+
auto name_it = name_lookup.find(name);
240+
if (name_it != name_lookup.end()) {
241+
virtual_identity *p = name_it->second;
83242

84243
if (p->vtable_ptr && p->vtable_ptr != vtable) {
85244
std::cerr << "Conflicting vtable ptr for class '" << p->getName()
@@ -103,14 +262,6 @@ virtual_identity *virtual_identity::get(virtual_ptr instance_ptr)
103262
return NULL;
104263
}
105264

106-
bool virtual_identity::is_subclass(virtual_identity *actual)
107-
{
108-
for (; actual; actual = actual->parent)
109-
if (actual == this) return true;
110-
111-
return false;
112-
}
113-
114265
void virtual_identity::adjust_vtable(virtual_ptr obj, virtual_identity *main)
115266
{
116267
if (vtable_ptr) {
@@ -135,35 +286,6 @@ virtual_ptr virtual_identity::clone(virtual_ptr obj)
135286
return copy;
136287
}
137288

138-
void virtual_identity::Init(Core *core)
139-
{
140-
if (!known_mutex)
141-
known_mutex = new tthread::mutex();
142-
143-
// This cannot be done in the constructors, because
144-
// they are called in an undefined order.
145-
for (virtual_identity *p = list; p; p = p->next) {
146-
p->has_children = false;
147-
p->children.clear();
148-
}
149-
for (virtual_identity *p = list; p; p = p->next) {
150-
if (p->parent) {
151-
p->parent->children.push_back(p);
152-
p->parent->has_children = true;
153-
}
154-
}
155-
//FIXME: ... nuked. the group was empty...
156-
/*
157-
// Read pre-filled vtable ptrs
158-
OffsetGroup *ptr_table = core->vinfo->getGroup("vtable");
159-
for (virtual_identity *p = list; p; p = p->next) {
160-
void * tmp;
161-
if (ptr_table->getSafeAddress(p->getName(),tmp))
162-
p->vtable_ptr = tmp;
163-
}
164-
*/
165-
}
166-
167289
bool DFHack::findBitfieldField(unsigned *idx, const std::string &name,
168290
unsigned size, const bitfield_item_info *items)
169291
{

library/DataStatics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "df/world_data.h"
88
#include "df/ui.h"
99

10+
#include "DataIdentity.h"
11+
1012
namespace {
1113
template<class T>
1214
inline T &_toref(T &r) { return r; }
@@ -21,6 +23,8 @@ namespace {
2123
#define INIT_GLOBAL_FUNCTION_ITEM(type,name) \
2224
if (global_table_->getAddress(#name,tmp_)) name = (type*)tmp_;
2325

26+
#define TID(type) (&identity_traits< type >::identity)
27+
2428
// Instantiate all the static objects
2529
#include "df/static.inc"
2630
#include "df/static.enums.inc"

0 commit comments

Comments
 (0)