We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2896 - Visual Studio 2005 compatibility
Summary: Visual Studio 2005 compatibility
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: All Windows (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-01 17:45 UTC by Ozkan Sezer
Modified: 2015-06-08 00:00 UTC (History)
0 users

See Also:


Attachments
SDL2 patch for better VS2005 compatibility (1.74 KB, patch)
2015-03-01 17:45 UTC, Ozkan Sezer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ozkan Sezer 2015-03-01 17:45:11 UTC
Created attachment 2056 [details]
SDL2 patch for better VS2005 compatibility

The following trivial changes make SDL2 tree (mostly) compatible with Visual
Studio 2005:

* SDL_stdlib.c: Similar to VS2010 and newer, VS2005 also generates memcpy(),
  (it also generates memset(), see below), so propagate the #if condition to
  cover VS2005.

* SDL_pixels.c (SDL_CalculateGammaRamp): VS2005 generates a memset() call for
  gamma==0 case, so replace the if loop with SDL_memset().

* SDL_windowsvideo.h: Include msctf.h only with VS2008 and newer, otherwise
  include SDL_msctf.h

* SDL_windowskeyboard.c: Adjust the #ifdefs so that SDL_msctf.h inclusion is
  always recognized correctly.

These would make people's lives rather easier.  As for project files, anyone
can hand-edit them for using with VS2005 (see down below for an example.)

The changes are inlined below, and also attached as a patch file.

--- SDL2/src/stdlib/SDL_stdlib.c
+++ SDL2src/src/stdlib/SDL_stdlib.c
@@ -279,7 +279,8 @@ __declspec(selectany) int _fltused = 1;
 #endif
 
 /* The optimizer on Visual Studio 2010/2012 generates memcpy() calls */
-#if _MSC_VER >= 1600 && defined(_WIN64) && !defined(_DEBUG)
+/* Visual Studio 2005 does it too, and it also generates memset() calls */
+#if (_MSC_VER == 1400 || _MSC_VER >= 1600) && defined(_WIN64) && !defined(_DEBUG)
 #include <intrin.h>
 
 #pragma function(memcpy)
--- SDL2/src/video/SDL_pixels.c
+++ SDL2src/src/video/SDL_pixels.c
@@ -1101,9 +1101,7 @@ SDL_CalculateGammaRamp(float gamma, Uint
 
     /* 0.0 gamma is all black */
     if (gamma == 0.0f) {
-        for (i = 0; i < 256; ++i) {
-            ramp[i] = 0;
-        }
+        SDL_memset(ramp, 0, 256 * sizeof(Uint16));
         return;
     } else if (gamma == 1.0f) {
         /* 1.0 gamma is identity */
--- SDL2/src/video/windows/SDL_windowsvideo.h
+++ SDL2src/src/video/windows/SDL_windowsvideo.h
@@ -27,7 +27,7 @@
 
 #include "../SDL_sysvideo.h"
 
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) && (_MSC_VER >= 1500)
 #include <msctf.h>
 #else
 #include "SDL_msctf.h"
--- SDL2/src/video/windows/SDL_windowskeyboard.c
+++ SDL2src/src/video/windows/SDL_windowskeyboard.c
@@ -211,7 +211,12 @@ void IME_Present(SDL_VideoData *videodat
 
 #else
 
-#ifdef __GNUC__
+#ifdef _SDL_msctf_h
+#define USE_INIT_GUID
+#elif defined(__GNUC__)
+#define USE_INIT_GUID
+#endif
+#ifdef USE_INIT_GUID
 #undef DEFINE_GUID
 #define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) static const GUID n = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
 DEFINE_GUID(IID_ITfInputProcessorProfileActivationSink,        0x71C6E74E,0x0F28,0x11D8,0xA8,0x2A,0x00,0x06,0x5B,0x84,0x43,0x5C);



Example for changing VS2008 project files into VS2005 project files:

--- SDL2/VisualC/SDL_VS2008.sln
+++ SDL2src/VisualC/SDL_VS2008.sln
@@ -1,5 +1,5 @@
-Microsoft Visual Studio Solution File, Format Version 10.00

-# Visual Studio 2008

+Microsoft Visual Studio Solution File, Format Version 9.00

+# Visual Studio 2005

 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2", "SDL\SDL_VS2008.vcproj", "{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}"

 EndProject

 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2main", "SDLmain\SDLmain_VS2008.vcproj", "{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}"

--- SDL2/VisualC/SDL/SDL_VS2008.vcproj
+++ SDL2src/VisualC/SDL/SDL_VS2008.vcproj
@@ -1,11 +1,10 @@
 <?xml version="1.0" encoding="Windows-1252"?>

 <VisualStudioProject

 	ProjectType="Visual C++"

-	Version="9.00"

+	Version="8,00"

 	Name="SDL2"

 	ProjectGUID="{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}"

 	RootNamespace="SDL"

-	TargetFrameworkVersion="131072"

 	>

 	<Platforms>

 		<Platform
Comment 1 Ryan C. Gordon 2015-06-08 00:00:59 UTC
This patch is now https://hg.libsdl.org/SDL/rev/8945c203a54b, thanks!

--ryan.