Skip to content

Commit

Permalink
修复TdxInstance析构bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JaysonAlbert committed Aug 10, 2017
1 parent 06c0395 commit 4ab1aaf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
22 changes: 12 additions & 10 deletions tdx_api/tdx_api.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -22,32 +22,32 @@
<ProjectGuid>{9AD58336-FF02-4C17-8FBF-F1757B47CF32}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>tdx_api</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand All @@ -71,12 +71,14 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetExt>.pyd</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.pyd</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
Expand All @@ -88,12 +90,12 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;BOOST_PYTHON_STATIC_LIB;_DEBUG;_WINDOWS;_USRDLL;TDX_API_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>C:\local\boost_1_61_0_x86;C:\Users\fit\Anaconda2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\local\boost_1_64_0;D:\Users\jayso\Anaconda2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\local\boost_1_61_0_x86\lib32-msvc-14.0;C:\Users\fit\Anaconda2\libs\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>C:\local\boost_1_64_0\lib32-msvc-14.1;D:\Users\jayso\Anaconda2\libs\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -120,14 +122,14 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;BOOST_PYTHON_STATIC_LIB;NDEBUG;_WINDOWS;_USRDLL;TDX_API_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>C:\local\boost_1_61_0_x86;C:\Users\fit\Anaconda2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\local\boost_1_64_0;D:\Users\jayso\Anaconda2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\local\boost_1_61_0_x86\lib32-msvc-14.0;C:\Users\fit\Anaconda2\libs\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>C:\local\boost_1_64_0\lib32-msvc-14.1;D:\Users\jayso\Anaconda2\libs\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down
5 changes: 2 additions & 3 deletions tdx_api/tdx_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using namespace std;

void TdxInstance::Init(string dll_name)
void TdxInstance::Open(string dll_name)
{
module_ = LoadLibrary(dll_name.c_str());
//获取api函数
Expand All @@ -31,8 +31,7 @@ void TdxInstance::Init(string dll_name)
OpenTdx();
}

TdxInstance::~TdxInstance()
{
void TdxInstance::Close() {
CloseTdx();
FreeLibrary(module_);
}
Expand Down
6 changes: 2 additions & 4 deletions tdx_api/tdx_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ using namespace std;
class TdxInstance
{
public:
//constructor private
void Init(string dll_name);
//destructor
~TdxInstance();
void Open(string dll_name);
void Close();
int login(string& ip, short& port, string& version, short& yybId, string& AccountNo, string& TradeAccount, string& jyPassword, string& txPassword) noexcept;
void log_off(const int& client_ID);
//definitions for functions
Expand Down
11 changes: 8 additions & 3 deletions tdx_api/tdx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ boost::python::list format(vector<tdx_data>& datas, vector<tdx_error>& errors) {

struct TdxApi {
TdxInstance instance;
void init(string dll) {
instance.Init(dll);
void Open(string dll) {
instance.Open(dll);
}

void Close() {
instance.Close();
}

boost::python::list login(char* IP, short Port, char* Version, short YybID, char* AccountNo, char* TradeAccount, char* JyPassword, char* TxPassword) {
Expand Down Expand Up @@ -169,7 +173,8 @@ BOOST_PYTHON_MODULE(tdx_api)
{
using namespace boost::python;
class_<TdxApi>("TdxApi").
def("init", &TdxApi::init).
def("Open", &TdxApi::Open).
def("Close", &TdxApi::Close).
def("Logon", &TdxApi::login).
def("Logoff", &TdxApi::logoff).
def("QueryHistoryData", &TdxApi::QueryHistoryData).
Expand Down

0 comments on commit 4ab1aaf

Please sign in to comment.