summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-11-02 23:51:23 +0800
committerruki <[email protected]>2019-11-02 23:51:23 +0800
commitb0a7b7a70cafc7988a33e1856147622b0ea92559 (patch)
treebeecf055fd33bc2824f985b9f12af87fcd7f088d
parent4f932ba407833f9559a23037958c7388cc22d2e0 (diff)
fix ffi for linux
-rw-r--r--core/src/demo/xmake.lua1
-rw-r--r--core/src/xmake/ffi.c53
-rw-r--r--core/src/xmake/ffi.h46
-rw-r--r--core/src/xmake/machine.c4
-rw-r--r--core/src/xmake/makefile1
-rw-r--r--xmake/core/base/bytes.lua14
6 files changed, 8 insertions, 111 deletions
diff --git a/core/src/demo/xmake.lua b/core/src/demo/xmake.lua
index 2e26afb6e..b1b178dde 100644
--- a/core/src/demo/xmake.lua
+++ b/core/src/demo/xmake.lua
@@ -27,6 +27,7 @@ target("demo")
-- add links
if is_plat("windows") then
add_links("ws2_32", "advapi32", "shell32")
+ add_ldflags("/export:malloc", "/export:free")
elseif is_plat("android") then
add_links("m", "c")
elseif is_plat("macosx") then
diff --git a/core/src/xmake/ffi.c b/core/src/xmake/ffi.c
deleted file mode 100644
index a863e9489..000000000
--- a/core/src/xmake/ffi.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*!A cross-platform build utility based on Lua
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Copyright (C) 2015 - 2019, TBOOX Open Source Group.
- *
- * @author ruki
- * @file ffi.c
- *
- */
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * includes
- */
-#include "xmake.h"
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * extern
- */
-__tb_extern_c_enter__
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * wrap and export interfaces for ffi
- */
-__tb_export__ void* xm_ffi_malloc(unsigned long size)
-{
- return (void*)tb_malloc((tb_size_t)size);
-}
-__tb_export__ void xm_ffi_free(void* data)
-{
- tb_free(data);
-}
-tb_void_t xm_ffi_bind()
-{
- // avoid to be optimized
- tb_used(&xm_ffi_malloc);
- tb_used(&xm_ffi_free);
-}
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * extern
- */
-__tb_extern_c_leave__
diff --git a/core/src/xmake/ffi.h b/core/src/xmake/ffi.h
deleted file mode 100644
index a9885e53b..000000000
--- a/core/src/xmake/ffi.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*!A cross-platform build utility based on Lua
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Copyright (C) 2015 - 2019, TBOOX Open Source Group.
- *
- * @author ruki
- * @file ffi.h
- *
- */
-#ifndef XM_FFI_H
-#define XM_FFI_H
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * includes
- */
-#include "prefix.h"
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * extern
- */
-__tb_extern_c_enter__
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * interfaces
- */
-
-/// bind ffi
-tb_void_t xm_ffi_bind(tb_noarg_t);
-
-/* //////////////////////////////////////////////////////////////////////////////////////
- * extern
- */
-__tb_extern_c_leave__
-
-#endif
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index c022ce6ab..4319023cc 100644
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -29,7 +29,6 @@
* includes
*/
#include "xmake.h"
-#include "ffi.h"
#if defined(TB_CONFIG_OS_WINDOWS)
# include <windows.h>
# include <io.h>
@@ -693,9 +692,6 @@ xm_machine_ref_t xm_machine_init()
}
#endif
- // bind ffi interfaces
- xm_ffi_bind();
-
// ok
ok = tb_true;
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 269db0c0b..b3028e984 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -12,7 +12,6 @@ xmake_CONFIG = y
# core files
xmake_C_FILES += \
- ffi \
xmake \
machine \
os/argv \
diff --git a/xmake/core/base/bytes.lua b/xmake/core/base/bytes.lua
index 17ed435ce..3b1fa141a 100644
--- a/xmake/core/base/bytes.lua
+++ b/xmake/core/base/bytes.lua
@@ -30,8 +30,8 @@ local utils = require("base/utils")
-- define ffi interfaces
ffi.cdef[[
- void* xm_ffi_malloc(unsigned long size);
- void xm_ffi_free(void* data);
+ void* malloc(size_t size);
+ void free(void* data);
]]
-- new a bytes instance
@@ -55,7 +55,7 @@ function _instance.new(...)
-- bytes(size, ptr [, manage]): mounts buffer on existing storage (manage memory or not)
local manage = arg3
if manage then
- instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ptr), ffi.C.xm_ffi_free)
+ instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ptr), ffi.C.free)
instance._MANAGED = true
else
instance._CDATA = ffi.cast("unsigned char*", ptr)
@@ -63,8 +63,8 @@ function _instance.new(...)
end
else
-- bytes(size): allocates a buffer of given size
- ptr = ffi.C.xm_ffi_malloc(size)
- instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ptr), ffi.C.xm_ffi_free)
+ ptr = ffi.C.malloc(size)
+ instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ptr), ffi.C.free)
instance._MANAGED = true
end
instance._SIZE = size
@@ -97,7 +97,7 @@ function _instance.new(...)
for _, b in ipairs(args) do
instance._SIZE = instance._SIZE + b:size()
end
- instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ffi.C.xm_ffi_malloc(instance._SIZE)), ffi.C.xm_ffi_free)
+ instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ffi.C.malloc(instance._SIZE)), ffi.C.free)
local offset = 0
for _, b in ipairs(args) do
ffi.copy(instance._CDATA + offset, b:cdata(), b:size())
@@ -112,7 +112,7 @@ function _instance.new(...)
for _, b in ipairs(args) do
instance._SIZE = instance._SIZE + b:size()
end
- instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ffi.C.xm_ffi_malloc(instance._SIZE)), ffi.C.xm_ffi_free)
+ instance._CDATA = ffi.gc(ffi.cast("unsigned char*", ffi.C.malloc(instance._SIZE)), ffi.C.free)
local offset = 0
for _, b in ipairs(args) do
ffi.copy(instance._CDATA + offset, b._CDATA, b:size())