From e0827ce54f048bd17b9b777ed86c2d7333f68d54 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 31 Mar 2014 11:31:25 +0300 Subject: [PATCH] Add base support for Lua object overcommit --- include/library/lua-class.hpp | 3 ++- include/lua/bitmap.hpp | 3 +++ include/lua/unsaferewind.hpp | 1 + src/lua/callback.cpp | 2 ++ src/lua/gui-rqueue.cpp | 1 + src/lua/gui-text-cf.cpp | 3 +++ src/lua/gui-tilemap.cpp | 1 + src/lua/ibind.cpp | 2 ++ src/lua/iconv.cpp | 1 + src/lua/inputmovie.cpp | 3 +++ src/lua/loadfile.cpp | 1 + src/lua/memory-compare.cpp | 1 + src/lua/memory.cpp | 1 + src/lua/memory2.cpp | 2 ++ src/lua/zip.cpp | 1 + 15 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/library/lua-class.hpp b/include/library/lua-class.hpp index 8bbdf448..2ec814ea 100644 --- a/include/library/lua-class.hpp +++ b/include/library/lua-class.hpp @@ -211,7 +211,8 @@ template class _class : public class_base { template T* _create(state& _state, U... args) { - void* obj = _state.newuserdata(sizeof(T)); + size_t overcommit = T::overcommit(args...); + void* obj = _state.newuserdata(sizeof(T) + overcommit); load_metatable(_state); _state.setmetatable(-2); T* _obj = reinterpret_cast(obj); diff --git a/include/lua/bitmap.hpp b/include/lua/bitmap.hpp index 1a7d5201..91e59843 100644 --- a/include/lua/bitmap.hpp +++ b/include/lua/bitmap.hpp @@ -16,6 +16,7 @@ struct lua_palette { std::vector colors; lua_palette(lua::state& L); + static size_t overcommit() { return 0; } ~lua_palette(); threads::lock palette_mutex; std::string print(); @@ -31,6 +32,7 @@ struct lua_palette struct lua_bitmap { lua_bitmap(lua::state& L, uint32_t w, uint32_t h); + static size_t overcommit(uint32_t w, uint32_t h) { return 0; } ~lua_bitmap(); size_t width; size_t height; @@ -52,6 +54,7 @@ struct lua_bitmap struct lua_dbitmap { lua_dbitmap(lua::state& L, uint32_t w, uint32_t h); + static size_t overcommit(uint32_t w, uint32_t h) { return 0; } ~lua_dbitmap(); size_t width; size_t height; diff --git a/include/lua/unsaferewind.hpp b/include/lua/unsaferewind.hpp index 6f602f39..b3c94905 100644 --- a/include/lua/unsaferewind.hpp +++ b/include/lua/unsaferewind.hpp @@ -7,6 +7,7 @@ struct lua_unsaferewind { lua_unsaferewind(lua::state& L); + static size_t overcommit() { return 0; } std::vector state; uint64_t frame; uint64_t lag; diff --git a/src/lua/callback.cpp b/src/lua/callback.cpp index c43cb186..5a080b4f 100644 --- a/src/lua/callback.cpp +++ b/src/lua/callback.cpp @@ -8,6 +8,7 @@ namespace { public: lua_callbacks_list(lua::state& L); + static size_t overcommit() { return 0; } static int create(lua::state& L, lua::parameters& P); int index(lua::state& L, lua::parameters& P); int newindex(lua::state& L, lua::parameters& P); @@ -17,6 +18,7 @@ namespace { public: lua_callback_obj(lua::state& L, const std::string& name); + static size_t overcommit(const std::string& name) { return 0; } int _register(lua::state& L, lua::parameters& P); int _unregister(lua::state& L, lua::parameters& P); int _call(lua::state& L, lua::parameters& P); diff --git a/src/lua/gui-rqueue.cpp b/src/lua/gui-rqueue.cpp index 11db40d0..78adfc88 100644 --- a/src/lua/gui-rqueue.cpp +++ b/src/lua/gui-rqueue.cpp @@ -12,6 +12,7 @@ namespace struct lua_renderqueue { lua_renderqueue(lua::state& L, uint32_t width, uint32_t height) throw(); + static size_t overcommit(uint32_t width, uint32_t height) { return 0; } ~lua_renderqueue() throw() {} lua_render_context* get() { return &lctx; } std::string print() diff --git a/src/lua/gui-text-cf.cpp b/src/lua/gui-text-cf.cpp index 51fe9b9e..ea5dce4f 100644 --- a/src/lua/gui-text-cf.cpp +++ b/src/lua/gui-text-cf.cpp @@ -19,6 +19,9 @@ namespace lua_customfont(lua::state& L, const std::string& filename, const std::string& filename2); lua_customfont(lua::state& L); lua_customfont(lua::state& L, empty_font_tag tag); + static size_t overcommit() { return 0; } + static size_t overcommit(const std::string& filename, const std::string& filename2) { return 0; } + static size_t overcommit(empty_font_tag tag) { return 0; } ~lua_customfont() throw(); static int create(lua::state& L, lua::parameters& P); static int load(lua::state& L, lua::parameters& P); diff --git a/src/lua/gui-tilemap.cpp b/src/lua/gui-tilemap.cpp index 93befbe3..0cd3aaf1 100644 --- a/src/lua/gui-tilemap.cpp +++ b/src/lua/gui-tilemap.cpp @@ -31,6 +31,7 @@ namespace struct tilemap { tilemap(lua::state& L, size_t _width, size_t _height, size_t _cwidth, size_t _cheight); + static size_t overcommit(size_t _width, size_t _height, size_t _cwidth, size_t _cheight) { return 0; } ~tilemap() { threads::alock h(lock); diff --git a/src/lua/ibind.cpp b/src/lua/ibind.cpp index d6f34871..edf78cc0 100644 --- a/src/lua/ibind.cpp +++ b/src/lua/ibind.cpp @@ -7,6 +7,7 @@ class lua_inverse_bind { public: lua_inverse_bind(lua::state& L, const std::string& name, const std::string& cmd); + static size_t overcommit(const std::string& name, const std::string& cmd) { return 0; } std::string print() { return ikey.getname(); @@ -53,6 +54,7 @@ class lua_command_bind { public: lua_command_bind(lua::state& L, const std::string& cmd, int idx1, int idx2); + static size_t overcommit(const std::string& cmd, int idx1, int idx2) { return 0; } ~lua_command_bind(); std::string print() { diff --git a/src/lua/iconv.cpp b/src/lua/iconv.cpp index d5afabcb..ae10dadc 100644 --- a/src/lua/iconv.cpp +++ b/src/lua/iconv.cpp @@ -58,6 +58,7 @@ namespace { public: lua_iconv(lua::state& L, const char* from, const char* to); + static size_t overcommit(const char* from, const char* to) { return 0; } ~lua_iconv() throw(); int call(lua::state& L, lua::parameters& P); static int create(lua::state& L, lua::parameters& P); diff --git a/src/lua/inputmovie.cpp b/src/lua/inputmovie.cpp index f5f76233..bedf52b6 100644 --- a/src/lua/inputmovie.cpp +++ b/src/lua/inputmovie.cpp @@ -17,6 +17,7 @@ namespace friend class lua_inputmovie; public: lua_inputframe(lua::state& L, controller_frame _f); + static size_t overcommit(controller_frame _f) { return 0; } int get_button(lua::state& L, lua::parameters& P) { unsigned port, controller, button; @@ -391,6 +392,8 @@ namespace public: lua_inputmovie(lua::state& L, const controller_frame_vector& _v); lua_inputmovie(lua::state& L, controller_frame& _f); + static size_t overcommit(const controller_frame_vector& _v) { return 0; } + static size_t overcommit(controller_frame& _f) { return 0; } int copy_movie(lua::state& L, lua::parameters& P) { return _copy_movie(L, P); diff --git a/src/lua/loadfile.cpp b/src/lua/loadfile.cpp index 776038ce..aa000dd2 100644 --- a/src/lua/loadfile.cpp +++ b/src/lua/loadfile.cpp @@ -150,6 +150,7 @@ namespace { public: lua_file_reader(lua::state& L, std::istream* strm); + static size_t overcommit(std::istream* strm) { return 0; } ~lua_file_reader() { delete &s; diff --git a/src/lua/memory-compare.cpp b/src/lua/memory-compare.cpp index 270e1719..81e30941 100644 --- a/src/lua/memory-compare.cpp +++ b/src/lua/memory-compare.cpp @@ -25,6 +25,7 @@ namespace { public: compare_obj(lua::state& L, uint64_t addr, uint64_t size, uint64_t rows, uint64_t stride); + static size_t overcommit(uint64_t addr, uint64_t size, uint64_t rows, uint64_t stride) { return 0; } static int create(lua::state& L, lua::parameters& P); int call(lua::state& L, lua::parameters& P); private: diff --git a/src/lua/memory.cpp b/src/lua/memory.cpp index da7c39f5..0002637d 100644 --- a/src/lua/memory.cpp +++ b/src/lua/memory.cpp @@ -65,6 +65,7 @@ class lua_mmap_struct { public: lua_mmap_struct(lua::state& L); + static size_t overcommit() { return 0; } ~lua_mmap_struct() { diff --git a/src/lua/memory2.cpp b/src/lua/memory2.cpp index e6f4405f..22a4d98f 100644 --- a/src/lua/memory2.cpp +++ b/src/lua/memory2.cpp @@ -52,6 +52,7 @@ namespace { public: lua_vma(lua::state& L, memory_region* r); + static size_t overcommit(memory_region* r) { return 0; } int info(lua::state& L, lua::parameters& P); template int rw(lua::state& L, lua::parameters& P); template int scattergather(lua::state& L, lua::parameters& P); @@ -76,6 +77,7 @@ namespace { public: lua_vma_list(lua::state& L); + static size_t overcommit() { return 0; } static int create(lua::state& L, lua::parameters& P); int index(lua::state& L, lua::parameters& P); int newindex(lua::state& L, lua::parameters& P); diff --git a/src/lua/zip.cpp b/src/lua/zip.cpp index fc8e3bb6..d8390f48 100644 --- a/src/lua/zip.cpp +++ b/src/lua/zip.cpp @@ -8,6 +8,7 @@ namespace { public: lua_zip_writer(lua::state& L, const std::string& filename, unsigned compression); + static size_t overcommit(const std::string& filename, unsigned compression) { return 0; } ~lua_zip_writer() { if(w) delete w;