فهرست منبع

rewritten send_word() and sent_int() that work around VS2003 compiler bug


git-svn-id: svn://svn.sphinxsearch.com/sphinx/trunk@2422 406a0c4d-033a-0410-8de8-e80135713968
shodan 15 سال پیش
والد
کامیت
233bee08a9
3فایلهای تغییر یافته به همراه169 افزوده شده و 16 حذف شده
  1. 10 16
      api/libsphinxclient/sphinxclient.c
  2. 21 0
      api/libsphinxclient/test03.sln
  3. 138 0
      api/libsphinxclient/test03.vcproj

+ 10 - 16
api/libsphinxclient/sphinxclient.c

@@ -1000,27 +1000,21 @@ static void send_bytes ( char ** pp, const char * bytes, int len )
 
 static void send_int ( char ** pp, unsigned int value )
 {
-	union
-	{
-		unsigned int n;
-		char c[sizeof(int)];
-	} u;
-
-	u.n = htonl ( value );
-	send_bytes ( pp, u.c, (int)sizeof(int) );
+	unsigned char * b = (unsigned char*) *pp;
+	b[0] = ( value >> 24 ) & 0xff;
+	b[1] = ( value >> 16 ) & 0xff;
+	b[2] = ( value >> 8 ) & 0xff;
+	b[3] = ( value & 0xFF );
+	*pp += 4;
 }
 
 
 static void send_word ( char ** pp, unsigned short value )
 {
-	union
-	{
-		unsigned short n;
-		char c[sizeof(short)];
-	} u;
-
-	u.n = htons ( value );
-	send_bytes ( pp, u.c, (int)sizeof(short) );
+	unsigned char * b = (unsigned char*) *pp;
+	b[0] = ( value >> 8 );
+	b[1] = ( value & 0xFF );
+	*pp += 2;
 }
 
 

+ 21 - 0
api/libsphinxclient/test03.sln

@@ -0,0 +1,21 @@
+Microsoft Visual Studio Solution File, Format Version 8.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test03", "test03.vcproj", "{3F3C7CA8-E864-4FB5-8EB0-A114FAFBE24E}"
+	ProjectSection(ProjectDependencies) = postProject
+	EndProjectSection
+EndProject
+Global
+	GlobalSection(SolutionConfiguration) = preSolution
+		Debug = Debug
+		Release = Release
+	EndGlobalSection
+	GlobalSection(ProjectConfiguration) = postSolution
+		{3F3C7CA8-E864-4FB5-8EB0-A114FAFBE24E}.Debug.ActiveCfg = Debug|Win32
+		{3F3C7CA8-E864-4FB5-8EB0-A114FAFBE24E}.Debug.Build.0 = Debug|Win32
+		{3F3C7CA8-E864-4FB5-8EB0-A114FAFBE24E}.Release.ActiveCfg = Release|Win32
+		{3F3C7CA8-E864-4FB5-8EB0-A114FAFBE24E}.Release.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+	EndGlobalSection
+	GlobalSection(ExtensibilityAddIns) = postSolution
+	EndGlobalSection
+EndGlobal

+ 138 - 0
api/libsphinxclient/test03.vcproj

@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="windows-1251"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="test03"
+	ProjectGUID="{3F3C7CA8-E864-4FB5-8EB0-A114FAFBE24E}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="Debug"
+			IntermediateDirectory="Debug"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="5"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/test03.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/test03.pdb"
+				SubSystem="1"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="Release"
+			IntermediateDirectory="Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				RuntimeLibrary="4"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/test03.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="TRUE"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\sphinxclient.c">
+			</File>
+			<File
+				RelativePath=".\test.c">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath=".\sphinxclient.h">
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>