Przeglądaj źródła

Merge branch 'dl-symbol-exporting'

* dl-symbol-exporting:
  * Don't use git for generating symbols
  * Undefine real headers/symbols and define our own to avoid redeclaration errors
  * Update symbols to match latest API
  * Remove Tcl_AppendResult as its symbol cannot be properly exported without more manual effort
  * Create actual symbols instead of just redefining, so external libraries will link properly
Bryan Drewery 15 lat temu
rodzic
commit
e299a1002f
8 zmienionych plików z 90 dodań i 46 usunięć
  1. 16 13
      src/generate_defs.sh
  2. 41 0
      src/generate_symbol.sh
  3. 1 0
      src/libcrypto.c
  4. 7 4
      src/libcrypto.h
  5. 1 0
      src/libssl.c
  6. 15 13
      src/libssl.h
  7. 1 2
      src/libtcl.c
  8. 8 14
      src/libtcl.h

+ 16 - 13
src/generate_defs.sh

@@ -1,23 +1,26 @@
 #! /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:]')
+for file in $(grep -l DLSYM_GLOBAL src/*.c|grep -v "src/_"); do
+  defsFile_wrappers="src/.defs/$(basename $file .c)_defs.c"
+  defsFile_pre="src/.defs/$(basename $file .c)_pre.h"
+  defsFile_post="src/.defs/$(basename $file .c)_post.h"
+
+  rm -f $defsFile_pre $defsFile_post > /dev/null 2>&1
 
-  cat > $defsFile << EOF
-#ifndef $defsDefine
-#define $defsDefine
+  echo "extern \"C\" {" > $defsFile_wrappers
+  echo "extern \"C\" {" > $defsFile_post
 
-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
-  done >> $defsFile
-  cat >> $defsFile << EOF
+    echo "#define ${symbol} ORIGINAL_SYMBOL_${symbol}" >> $defsFile_pre
+    echo "#undef ${symbol}" >> $defsFile_post
+    grep "^typedef .*(\*${symbol}_t)" $(dirname $file)/$(basename $file .c).h | src/generate_symbol.sh >> $defsFile_wrappers 2>> $defsFile_post
+  done
 
-#endif /* $defsDefine */
-EOF
+  echo "}" >> $defsFile_wrappers
+  echo "}" >> $defsFile_post
 done
 

+ 41 - 0
src/generate_symbol.sh

@@ -0,0 +1,41 @@
+#! /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
+
+  echo "$returntype $name ($params_full);" >&2
+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;

+ 7 - 4
src/libcrypto.h

@@ -1,11 +1,16 @@
 #ifndef _LIBCRYPTO_H
 #define _LIBCRYPTO_H
 
+#include ".defs/libcrypto_pre.h"
+
 #include <openssl/crypto.h>
 #include <openssl/aes.h>
 #include <openssl/blowfish.h>
 #include <openssl/md5.h>
 #include <openssl/sha.h>
+
+#include ".defs/libcrypto_post.h"
+
 #include "src/crypto/aes_util.h"
 #include "src/crypto/bf_util.h"
 #include "src/crypto/dh_util.h"
@@ -14,7 +19,7 @@
 #include "dl.h"
 #include <bdlib/src/String.h>
 
-typedef void (*AES_cbc_encrypt_t)(const unsigned char*, unsigned char*, const unsigned long, const AES_KEY*, unsigned char*, const int);
+typedef void (*AES_cbc_encrypt_t)(const unsigned char*, unsigned char*, const size_t, const AES_KEY*, unsigned char*, const int);
 typedef void (*AES_decrypt_t)(const unsigned char*, unsigned char*, const AES_KEY*);
 typedef void (*AES_encrypt_t)(const unsigned char*, unsigned char*, const AES_KEY*);
 typedef int (*AES_set_decrypt_key_t)(const unsigned char*, const int, AES_KEY*);
@@ -47,7 +52,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 +65,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;

+ 15 - 13
src/libssl.h

@@ -5,6 +5,8 @@
 #include "dl.h"
 #include <bdlib/src/String.h>
 
+#include ".defs/libssl_pre.h"
+
 #ifdef EGG_SSL_EXT
 # ifndef EGG_SSL_INCS
 #  include <openssl/ssl.h>
@@ -14,22 +16,22 @@
 # 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 *);
+#include ".defs/libssl_post.h"
+
+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_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)(const SSL_METHOD*);
 
 int load_ssl();
 int unload_ssl();

+ 1 - 2
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,6 @@ 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_CreateInterp);
   DLSYM_GLOBAL(handle, Tcl_FindExecutable);
   DLSYM_GLOBAL(handle, Tcl_Init);
@@ -102,7 +102,6 @@ int load_libtcl() {
 
 #include "chanprog.h"
 static int cmd_privmsg STDVAR {
-  BADARGS(3, 999, " channel string");
   bd::String str = argv[2];
   for (int i = 3; i < argc; ++i)
     str += " " + bd::String(argv[i]);

+ 8 - 14
src/libtcl.h

@@ -5,29 +5,23 @@
 #include "dl.h"
 #include <bdlib/src/String.h>
 #ifdef HAVE_LIBTCL
+
+#include ".defs/libtcl_pre.h"
+
 #include <tcl.h>
 
+#include ".defs/libtcl_post.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 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 {                               \
-	if ((argc < (nl)) || (argc > (nh))) {                       \
-		Tcl_AppendResult(interp, "wrong # args: should be \"", \
-			argv[0], (example), "\"", NULL);            \
-		return TCL_ERROR;                                   \
-	}                                                           \
-} while (0)
-
 extern Tcl_Interp *global_interp;
 bd::String tcl_eval(const bd::String&);
 #endif