From f4f6d6742c3a3cbbdb179d6b84d711884813315e Mon Sep 17 00:00:00 2001 From: nanoric Date: Wed, 25 Jul 2018 05:28:38 -0400 Subject: [PATCH] =?UTF-8?q?[Fix]=20=E4=BC=98=E5=8C=96=E4=BA=86ctp=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3py=E8=BD=AC=E6=8D=A2=E5=B1=82=E7=9A=84=E6=80=A7?= =?UTF-8?q?=E8=83=BD=20=20=20=20=20=20=201.=E4=BD=BF=E7=94=A8=E7=89=B9?= =?UTF-8?q?=E5=8C=96=E7=89=88=E7=9A=84strcpy=5Fs=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E6=8B=B7=E8=B4=9D=E6=80=A7=E8=83=BD=20=20=20=20=20=20?= =?UTF-8?q?=202.=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=E7=9A=84string?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp b/vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp index df689fb2..231a6520 100644 --- a/vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp +++ b/vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp @@ -7,7 +7,7 @@ ///从Python对象到C++类型转换用的函数 ///------------------------------------------------------------------------------------- -void getInt(dict d, string key, int *value) +void getInt(dict d, const string &key, int *value) { if (d.has_key(key)) //检查字典中是否存在该键值 { @@ -20,7 +20,7 @@ void getInt(dict d, string key, int *value) } }; -void getDouble(dict d, string key, double *value) +void getDouble(dict d, const string &key, double *value) { if (d.has_key(key)) { @@ -33,7 +33,9 @@ void getDouble(dict d, string key, double *value) } }; -void getStr(dict d, string key, char *value) +// 使用特化的strcpy_s,能提升性能 +template +void getStr(dict d, const string &key, const CharType(&value)[size]) { if (d.has_key(key)) { @@ -43,18 +45,18 @@ void getStr(dict d, string key, char *value) { string s = x(); const char *buffer = s.c_str(); - //对字符串指针赋值必须使用strcpy_s, vs2013使用strcpy编译通不过 - //+1应该是因为C++字符串的结尾符号?不是特别确定,不加这个1会出错 #ifdef _MSC_VER //WIN32 - strcpy_s(value, strlen(buffer) + 1, buffer); + strcpy_s(value, buffer); #elif __GNUC__ strncpy(value, buffer, strlen(buffer) + 1); +#else +#pragma error("unsupported compiler") #endif } } -}; +} -void getChar(dict d, string key, char *value) +void getChar(dict d, const string &key, char *value) { if (d.has_key(key)) {