[patch] XSTools and Visual C++ Compatibility

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

UltimaWeapon
Human
Human
Posts: 37
Joined: 04 Apr 2008, 22:55
Noob?: Yes
Location: Thailand

[patch] XSTools and Visual C++ Compatibility

#1 Post by UltimaWeapon »

This patch for making Visual C++ .NET (2002, 2003, 2005, 2008, 2010) able to make XSTools. It should not affected to other compiler, Such as GCC. But, If you unsure, Please testing it before commit. Thank you. :mrgreen:

Code: Select all

Index: src/auto/XSTools/misc/fastutils.xs
===================================================================
--- src/auto/XSTools/misc/fastutils.xs	(revision 7099)
+++ src/auto/XSTools/misc/fastutils.xs	(working copy)
@@ -1,10 +1,10 @@
 /* Utility functions rewritten in C for speed */
+#include <stdio.h>
+#include <string.h>
+#include <string>
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
-#include <stdio.h>
-#include <string.h>
-#include <string>
 
 typedef double (*NVtime_t) ();
 static void *NVtime = NULL;
Index: src/auto/XSTools/utils/perl/Rijndael.xs
===================================================================
--- src/auto/XSTools/utils/perl/Rijndael.xs	(revision 7099)
+++ src/auto/XSTools/utils/perl/Rijndael.xs	(working copy)
@@ -30,10 +30,11 @@
 SV *
 CRijndael::Encrypt(char* in, char* not_used, size_t n, int iMode)
 INIT:
-	char result[n];
+	char *result = new char [n];
 CODE:
 	THIS->Encrypt(in, result, n, iMode);
 	RETVAL = newSVpv(result, n);
+	delete[] result;
 OUTPUT:
 	RETVAL
 
@@ -41,9 +42,10 @@
 SV *
 CRijndael::Decrypt(char* in, char* not_used, size_t n, int iMode)
 INIT:
-	char result[n];
+	char *result = new char [n];
 CODE:
 	THIS->Decrypt(in, result, n, iMode);
 	RETVAL = newSVpv(result, n);
+	delete[] result;
 OUTPUT:
 	RETVAL
\ No newline at end of file
Index: src/auto/XSTools/utils/sparseconfig.h
===================================================================
--- src/auto/XSTools/utils/sparseconfig.h	(revision 7099)
+++ src/auto/XSTools/utils/sparseconfig.h	(working copy)
@@ -51,14 +51,16 @@
 /* Puts following code inside the Google namespace */
 #define _START_GOOGLE_NAMESPACE_ namespace google {
 
-#ifndef GCC_VERSION
-#define GCC_VERSION (__GNUC__ * 10000 \
-                   	 + __GNUC_MINOR__ * 100 \
-                   	 + __GNUC_PATCHLEVEL__)
-#endif
-/* the location of <hash_fun.h>/<stl_hash_fun.h> */
-#if GCC_VERSION < 40300
-	#define HASH_FUN_H <ext/hash_fun.h>
-#else
-	#define HASH_FUN_H <backward/hash_fun.h>
-#endif
+#ifndef _MSC_VER
+	#ifndef GCC_VERSION
+	#define GCC_VERSION (__GNUC__ * 10000 \
+						 + __GNUC_MINOR__ * 100 \
+						 + __GNUC_PATCHLEVEL__)
+	#endif
+	/* the location of <hash_fun.h>/<stl_hash_fun.h> */
+	#if GCC_VERSION < 40300
+		#define HASH_FUN_H <ext/hash_fun.h>
+	#else
+		#define HASH_FUN_H <backward/hash_fun.h>
+	#endif
+#endif /* _MSC_VER */
Index: src/auto/XSTools/utils/win32/http-reader.cpp
===================================================================
--- src/auto/XSTools/utils/win32/http-reader.cpp	(revision 7099)
+++ src/auto/XSTools/utils/win32/http-reader.cpp	(working copy)
@@ -16,6 +16,10 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifdef _MSC_VER
+	#define snprintf _snprintf
+#endif /* _MSC_VER */
+
 class WinHttpReader: public StdHttpReader {
 private:
 	HINTERNET inetHandle;
Index: src/auto/XSTools/win32/utils.cpp
===================================================================
--- src/auto/XSTools/win32/utils.cpp	(revision 7099)
+++ src/auto/XSTools/win32/utils.cpp	(working copy)
@@ -111,7 +111,7 @@
 		HMODULE lib;
 		int i;
 		HWND hwnd;
-		typedef int WINAPI __declspec(dllexport) (*injectSelfFunc) (HWND hwnd);
+		typedef int (WINAPI *injectSelfFunc) (HWND hwnd);
 		injectSelfFunc injectSelf;
 
 		// The window may not appear immediately so we try for at least 5 seconds
You do not have the required permissions to view the files attached to this post.
I may make you misunderstand. Because my English isn't good enough. So Sorry.
Image