Просмотр исходного кода

* Create actual symbols instead of just redefining, so external libraries will link properly

Bryan Drewery 15 лет назад
Родитель
Сommit
fe5e2c3042
8 измененных файлов с 68 добавлено и 34 удалено
  1. 8 10
      src/generate_defs.sh
  2. 39 0
      src/generate_symbol.sh
  3. 1 0
      src/libcrypto.c
  4. 1 3
      src/libcrypto.h
  5. 1 0
      src/libssl.c
  6. 12 14
      src/libssl.h
  7. 2 1
      src/libtcl.c
  8. 4 6
      src/libtcl.h

+ 8 - 10
src/generate_defs.sh

@@ -1,23 +1,21 @@
 #! /bin/bash
 
+echo "Generating lib symbols"
+
 mkdir -p src/.defs > /dev/null 2>&1
 
 for file in $(git grep -l DLSYM_GLOBAL|grep "\.c$"); do
-  defsFile="src/.defs/$(basename $file .c)_defs.h"
-  defsDefine=$(echo "_$(basename $file .c)_defs_h"| tr '[:lower:]' '[:upper:]')
-
+  defsFile="src/.defs/$(basename $file .c)_defs.c"
   cat > $defsFile << EOF
-#ifndef $defsDefine
-#define $defsDefine
-
+extern "C" {
 EOF
+
   for symbol in $(sed -n -e 's/.*DLSYM_GLOBAL(.*, \([^)]*\).*/\1/p' $file|sort -u); do
-    key="_DLST_IDX_${symbol}"
-    printf "#define %-25s DLSYM_VAR(%s)\n" $symbol $symbol
+    grep "^typedef .*(\*${symbol}_t)" $(dirname $file)/$(basename $file .c).h | src/generate_symbol.sh
   done >> $defsFile
-  cat >> $defsFile << EOF
 
-#endif /* $defsDefine */
+  cat >> $defsFile << EOF
+}
 EOF
 done
 

+ 39 - 0
src/generate_symbol.sh

@@ -0,0 +1,39 @@
+#! /bin/bash
+
+# X="typedef int (*Tcl_Eval_t)(Tcl_Interp*, const char*);"
+
+while read line; do
+  returntype=$(echo "$line" | sed -e 's/typedef \([^(]*\) (\*\([^ ]*\)_t)(\(.*\));/\1/')
+  name=$(echo "$line" | sed -e 's/typedef \([^(]*\) (\*\([^ ]*\)_t)(\(.*\));/\2/')
+  params=$(echo "$line" | sed -e 's/typedef \([^(]*\) (\*\([^ ]*\)_t)(\(.*\));/\3/')
+
+  IFS=,
+
+  params_full=""
+  param_names=""
+
+  set $params
+  paramCount=$#
+
+  for (( i=0; i < $paramCount; i++)); do
+    x="x${i}"
+    if [ $1 = "void" ]; then
+      params_full="void"
+      param_names=""
+    else
+      params_full="${params_full}${1} ${x}"
+      param_names="${param_names}${x}"
+      if ! [[ $i = $(expr $paramCount - 1) ]]; then
+        params_full="${params_full},"
+        param_names="${param_names}, "
+      fi
+    fi
+    shift
+  done
+
+  cat << EOF
+$returntype $name ($params_full) {
+  return DLSYM_VAR($name)($param_names);
+}
+EOF
+done

+ 1 - 0
src/libcrypto.c

@@ -32,6 +32,7 @@
 #include <bdlib/src/Array.h>
 
 #include "libcrypto.h"
+#include ".defs/libcrypto_defs.c"
 
 void *libcrypto_handle = NULL;
 static bd::Array<bd::String> my_symbols;

+ 1 - 3
src/libcrypto.h

@@ -47,7 +47,7 @@ typedef int (*SHA256_Update_t)(SHA256_CTX*, const void*, size_t);
 
 typedef BIGNUM* (*BN_bin2bn_t)(const unsigned char*, int, BIGNUM*);
 typedef BIGNUM* (*BN_dup_t)(const BIGNUM*);
-typedef int (*BN_bn2bin_t)(BIGNUM*, unsigned char*);
+typedef int (*BN_bn2bin_t)(const BIGNUM*, unsigned char*);
 typedef int (*BN_dec2bn_t)(BIGNUM**, const char*);
 typedef int (*BN_hex2bn_t)(BIGNUM**, const char*);
 typedef int (*BN_num_bits_t)(const BIGNUM*);
@@ -60,8 +60,6 @@ typedef DH* (*DH_new_t)(void);
 typedef int (*DH_size_t)(const DH*);
 
 
-#include ".defs/libcrypto_defs.h"
-
 int load_libcrypto();
 int unload_libcrypto();
 

+ 1 - 0
src/libssl.c

@@ -32,6 +32,7 @@
 #include <bdlib/src/Array.h>
 
 #include "libssl.h"
+#include ".defs/libssl_defs.c"
 
 void *libssl_handle = NULL;
 static bd::Array<bd::String> my_symbols;

+ 12 - 14
src/libssl.h

@@ -14,22 +14,20 @@
 # endif
 #endif
 
-typedef int (*SSL_get_error_t)(const SSL *, int);
-typedef void (*SSL_free_t)(SSL *);
-typedef int (*SSL_connect_t)(SSL *);
-typedef int (*SSL_read_t)(SSL *, void*, int);
-typedef int (*SSL_write_t)(SSL *, const void*, int);
-typedef SSL* (*SSL_new_t)(SSL_CTX *);
-typedef const SSL_METHOD* (*SSLv23_client_method_t)(void);
-typedef int (*SSL_shutdown_t)(SSL *);
-typedef int (*SSL_set_fd_t)(SSL *, int);
-typedef int (*SSL_pending_t)(const SSL *);
+typedef int (*SSL_get_error_t)(const SSL*, int);
+typedef void (*SSL_free_t)(SSL*);
+typedef int (*SSL_connect_t)(SSL*);
+typedef int (*SSL_read_t)(SSL*, void*, int);
+typedef int (*SSL_write_t)(SSL*, const void*, int);
+typedef SSL* (*SSL_new_t)(SSL_CTX*);
+typedef SSL_METHOD* (*SSLv23_client_method_t)(void);
+typedef int (*SSL_shutdown_t)(SSL*);
+typedef int (*SSL_set_fd_t)(SSL*, int);
+typedef int (*SSL_pending_t)(const SSL*);
 typedef void (*SSL_load_error_strings_t)(void);
 typedef int (*SSL_library_init_t)(void);
-typedef void (*SSL_CTX_free_t)(SSL_CTX *);
-typedef SSL_CTX* (*SSL_CTX_new_t)(const SSL_METHOD *);
-
-#include ".defs/libssl_defs.h"
+typedef void (*SSL_CTX_free_t)(SSL_CTX*);
+typedef SSL_CTX* (*SSL_CTX_new_t)(SSL_METHOD*);
 
 int load_ssl();
 int unload_ssl();

+ 2 - 1
src/libtcl.c

@@ -32,6 +32,7 @@
 #include <bdlib/src/Array.h>
 
 #include "libtcl.h"
+#include ".defs/libtcl_defs.c"
 
 #ifdef HAVE_LIBTCL
 Tcl_Interp *global_interp = NULL;
@@ -50,7 +51,7 @@ static int load_symbols(void *handle) {
   DLSYM_GLOBAL(handle, Tcl_GetStringResult);
   DLSYM_GLOBAL(handle, Tcl_DeleteInterp);
   DLSYM_GLOBAL(handle, Tcl_CreateCommand);
-  DLSYM_GLOBAL(handle, Tcl_AppendResult);
+//  DLSYM_GLOBAL(handle, Tcl_AppendResult);
   DLSYM_GLOBAL(handle, Tcl_CreateInterp);
   DLSYM_GLOBAL(handle, Tcl_FindExecutable);
   DLSYM_GLOBAL(handle, Tcl_Init);

+ 4 - 6
src/libtcl.h

@@ -8,16 +8,14 @@
 #include <tcl.h>
 
 typedef int (*Tcl_Eval_t)(Tcl_Interp*, const char*);
-typedef void (*Tcl_AppendResult_t)(Tcl_Interp*, ...);
-typedef void (*Tcl_CreateCommand_t)(Tcl_Interp*, const char*, Tcl_CmdProc*, ClientData, Tcl_CmdDeleteProc*);
+//typedef void (*Tcl_AppendResult_t)(Tcl_Interp*, ...);
+typedef Tcl_Command (*Tcl_CreateCommand_t)(Tcl_Interp*, const char*, Tcl_CmdProc*, ClientData, Tcl_CmdDeleteProc*);
 typedef const char* (*Tcl_GetStringResult_t)(Tcl_Interp*);
-typedef int (*Tcl_DeleteInterp_t)(Tcl_Interp*);
-typedef Tcl_Interp* (*Tcl_CreateInterp_t)();
+typedef void (*Tcl_DeleteInterp_t)(Tcl_Interp*);
+typedef Tcl_Interp* (*Tcl_CreateInterp_t)(void);
 typedef void (*Tcl_FindExecutable_t)(const char*);
 typedef int (*Tcl_Init_t)(Tcl_Interp*);
 
-#include ".defs/libtcl_defs.h"
-
 #define STDVAR (ClientData cd, Tcl_Interp *interp, int argc, const char *argv[])
 
 #define BADARGS(nl, nh, example) do {                               \