-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae1fea0
commit 1202df3
Showing
11 changed files
with
373 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#.rst: | ||
# SgFFI | ||
# ----- | ||
# | ||
# Build libffi. | ||
# | ||
# Build libffi from Sagui building. | ||
# | ||
# :: | ||
# | ||
# FFI_INCLUDE_DIR - Directory of includes. | ||
# FFI_ARCHIVE_LIB - AR archive library. | ||
# | ||
|
||
# _ | ||
# ___ __ _ __ _ _ _(_) | ||
# / __|/ _` |/ _` | | | | | | ||
# \__ \ (_| | (_| | |_| | | | ||
# |___/\__,_|\__, |\__,_|_| | ||
# |___/ | ||
# | ||
# –– cross-platform library which helps to develop web servers or frameworks. | ||
# | ||
# Copyright (c) 2016-2018 Silvio Clecio <[email protected]> | ||
# | ||
# This file is part of Sagui library. | ||
# | ||
# Sagui library is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Sagui library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with Sagui library. If not, see <http:https://www.gnu.org/licenses/>. | ||
# | ||
|
||
if (__SG_FFI_INCLUDED) | ||
return() | ||
endif () | ||
set(__SG_FFI_INCLUDED ON) | ||
|
||
set(FFI_NAME "libffi") | ||
set(FFI_VER "3.2.1") | ||
set(FFI_FULL_NAME "${FFI_NAME}-${FFI_VER}") | ||
set(FFI_URL "ftp:https://sourceware.org/pub/libffi/${FFI_FULL_NAME}.tar.gz") | ||
set(FFI_SHA256 "d06ebb8e1d9a22d19e38d63fdb83954253f39bedc5d46232a05645685722ca37") | ||
set(FFI_OPTIONS | ||
--enable-static=yes | ||
--enable-shared=no) | ||
|
||
ExternalProject_Add(${FFI_FULL_NAME} | ||
URL ${FFI_URL} ${FFI_URL_MIRROR} | ||
URL_HASH SHA256=${FFI_SHA256} | ||
TIMEOUT 15 | ||
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/lib | ||
PREFIX ${CMAKE_BINARY_DIR}/${FFI_FULL_NAME} | ||
SOURCE_DIR ${CMAKE_SOURCE_DIR}/lib/${FFI_FULL_NAME} | ||
CONFIGURE_COMMAND <SOURCE_DIR>/configure --host=${CMAKE_C_MACHINE} --prefix=<INSTALL_DIR> ${FFI_OPTIONS} | ||
BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} | ||
BINARY_DIR ${CMAKE_BINARY_DIR}/${FFI_FULL_NAME} | ||
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install | ||
LOG_DOWNLOAD ON | ||
LOG_CONFIGURE ON | ||
LOG_BUILD ON | ||
LOG_INSTALL ON) | ||
|
||
ExternalProject_Get_Property(${FFI_FULL_NAME} INSTALL_DIR) | ||
set(FFI_INCLUDE_DIR ${INSTALL_DIR}/include) | ||
set(FFI_ARCHIVE_LIB ${INSTALL_DIR}/lib/${FFI_NAME}.a) | ||
unset(INSTALL_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* _ | ||
* ___ __ _ __ _ _ _(_) | ||
* / __|/ _` |/ _` | | | | | | ||
* \__ \ (_| | (_| | |_| | | | ||
* |___/\__,_|\__, |\__,_|_| | ||
* |___/ | ||
* | ||
* –– cross-platform library which helps to develop web servers or frameworks. | ||
* | ||
* Copyright (c) 2016-2018 Silvio Clecio <[email protected]> | ||
* | ||
* This file is part of Sagui library. | ||
* | ||
* Sagui library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sagui library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Sagui library. If not, see <http:https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
#include <sagui.h> | ||
|
||
/* NOTE: Error checking has been omitted to make it clear. */ | ||
|
||
static char *my_function(bool b, int i, const char *s) { | ||
const char *fmt = "%s|%d|%s"; | ||
const char *tf = (b ? "TRUE" : "FALSE"); | ||
char *str; | ||
size_t len = (size_t) snprintf(NULL, 0, fmt, tf, i, s) + 1; | ||
str = sg_alloc(len); | ||
snprintf(str, len, fmt, tf, i, s); | ||
return str; | ||
} | ||
|
||
int main(void) { | ||
struct sg_ffi *ffi; | ||
void *args[3]; | ||
char *ret = NULL; | ||
bool b = true; | ||
int i = 123; | ||
const char *s = "abc"; | ||
args[0] = &b; | ||
args[1] = &i; | ||
args[2] = &s; | ||
/* bis:s+p | ||
* b = param 1: bool | ||
* i = param 2: int | ||
* p = param 3: pointer | ||
* p = return: pointer | ||
* d = default ABI | ||
*/ | ||
//ffi = sg_ffi_new("bip:p:d"); | ||
ffi = sg_ffi_new("bip:p:d"); | ||
sg_ffi_call(ffi, (sg_ffi_fn) my_function, args, &ret); | ||
printf("my_function: %s\n", ret); | ||
sg_free(ret); | ||
sg_ffi_free(ffi); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.