From a33677ce044a3c3911a48a98900ae87e9c1cc00d Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja.osipov@gmail.com>
Date: Tue, 29 Apr 2014 19:18:08 +0400
Subject: [PATCH] Fix gh-279: Tarantool crash on Mac OS X

Add pagezero-size magic to link flags on Mac OS X,
as is required by LuaJIT.
The flag was dropped in my patch which changed the linking
scheme for the main executable.
On the same token, check for return value of luaL_newstate(),
and panic if it returns NULL, this should simplify
problem analysis in the future.
---
 src/CMakeLists.txt     | 6 ++++--
 src/box/CMakeLists.txt | 4 ----
 src/lua/init.cc        | 5 +++--
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9d6f2b7b00..410580ca1c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -158,8 +158,10 @@ target_link_libraries(tarantool
     ${common_libraries}
     -rdynamic)
 
-if (module_link_flags)
+# Necessary to make LuaJIT work on Darwin, see
+# http://luajit.org/install.html
+if (TARGET_OS_DARWIN)
     set_target_properties(tarantool PROPERTIES
-        LINK_FLAGS ${module_link_flags})
+        LINK_FLAGS "-pagezero_size 10000 -image_base 100000000")
 endif()
 install (TARGETS tarantool DESTINATION bin)
diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt
index 600f848a2b..0bf3dcc0f3 100644
--- a/src/box/CMakeLists.txt
+++ b/src/box/CMakeLists.txt
@@ -1,7 +1,3 @@
-if (TARGET_OS_DARWIN)
-    set(module_link_flags "-pagezero_size 10000 -image_base 100000000")
-endif()
-
 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/box/lua)
 
 include_directories(${SOPHIA_INCLUDE_DIR})
diff --git a/src/lua/init.cc b/src/lua/init.cc
index 6be42b410f..06102f8f31 100644
--- a/src/lua/init.cc
+++ b/src/lua/init.cc
@@ -262,8 +262,9 @@ void
 tarantool_lua_init()
 {
 	lua_State *L = luaL_newstate();
-	if (L == NULL)
-		return;
+	if (L == NULL) {
+		panic("failed to initialize Lua");
+	}
 	luaL_openlibs(L);
 	/*
 	 * Search for Lua modules, apart from the standard
-- 
GitLab