@@ -20,18 +20,18 @@ using namespace std;
2020#endif
2121
2222
23- // ! 获取python异常信息
23+ // ! ��ȡpython�쳣��Ϣ
2424struct pyops_t
2525{
2626 static int traceback (string& ret_);
2727};
2828struct cpp_void_t {};
2929
30- // ! 用于抽取类型、类型对应的引用
30+ // ! ���ڳ�ȡ���͡����Ͷ�Ӧ������
3131template <typename T>
3232struct type_ref_traits_t ;
3333
34- // ! 用于python 可选参数
34+ // ! ����python ��ѡ����
3535template <typename T>
3636struct pyoption_t
3737{
@@ -52,15 +52,15 @@ struct pyoption_t
5252 bool m_set_flag;
5353 value_t m_value;
5454};
55- // ! 用于判断是否是可选参数
55+ // ! �����ж��Ƿ��ǿ�ѡ����
5656template <typename T>
5757struct pyoption_traits_t ;
5858
59- // ! pytype_traits_t 封装 PyLong_FromLong 相关的操作,用于为调用python生成参数
59+ // ! pytype_traits_t ��װ PyLong_FromLong ���صIJ���������Ϊ����python���ɲ���
6060template <typename T>
6161struct pytype_traits_t ;
6262
63- // ! 用于调用python函数,生成tuple类型的python函数参数的工具类
63+ // ! ���ڵ���python����������tuple���͵�python���������Ĺ�����
6464struct pycall_arg_t
6565{
6666 pycall_arg_t (int arg_num):
@@ -98,7 +98,7 @@ struct pycall_arg_t
9898 PyObject * pargs_tuple;
9999};
100100
101- // ! 用于调用python函数,获取返回值的工具类
101+ // ! ���ڵ���python��������ȡ����ֵ�Ĺ�����
102102class pytype_tool_t
103103{
104104public:
@@ -107,10 +107,10 @@ class pytype_tool_t
107107 virtual const char * return_type () {return " " ;}
108108};
109109
110- // ! 用于调用python函数,获取返回值的工具泛型类
110+ // ! ���ڵ���python��������ȡ����ֵ�Ĺ��߷�����
111111template <typename T>
112112class pytype_tool_impl_t ;
113- // ! 封装调用python函数的C API
113+ // ! ��װ����python������C API
114114struct pycall_t
115115{
116116 static int call_func (PyObject *pModule, const string& mod_name_, const string& func_name_,
@@ -123,22 +123,22 @@ struct pycall_t
123123 template <typename T>
124124 static const T& call_lambda (PyObject *pFunc, pycall_arg_t & pyarg_, pytype_tool_impl_t <T>& pyret);
125125};
126- // ! 用于扩展python的工具类,用来解析参数
126+ // ! ������չpython�Ĺ����࣬������������
127127struct pyext_tool_t ;
128128
129129
130130template <typename T>
131131struct pyext_return_tool_t ;
132132
133- // ! 用于扩展python,生成pyobject类型的返回值给python
133+ // ! ������չpython������pyobject���͵ķ���ֵ��python
134134template <typename T>
135135struct pyext_func_traits_t ;
136136
137- // ! 用于扩展python,traits出注册给python的函数接口
137+ // ! ������չpython��traits��ע����python�ĺ����ӿ�
138138#ifndef PYCTOR
139139#define PYCTOR int (*)
140140#endif
141- // ! 表示void类型,由于void类型不能return,用void_ignore_t适配
141+ // ! ��ʾvoid���ͣ�����void���Ͳ���return����void_ignore_t����
142142template <typename T>
143143struct void_ignore_t ;
144144
@@ -156,7 +156,7 @@ struct void_ignore_t<void>
156156
157157#define RET_V typename void_ignore_t <RET >::value_t
158158
159- // ! 记录各个基类和子类的相互关系
159+ // ! ��¼�������������������ϵ
160160struct cpp_to_pyclass_reg_info_t
161161{
162162 struct inherit_info_t
@@ -203,7 +203,7 @@ struct cpp_to_pyclass_reg_info_t
203203};
204204
205205
206- // ! 记录C ++ class 对应到python中的名称、参数信息等,全局
206+ // ! ��¼C ++ class ��Ӧ��python�е����ơ�������Ϣ��,ȫ��
207207struct static_pytype_info_t
208208{
209209 string class_name;
@@ -212,7 +212,7 @@ struct static_pytype_info_t
212212 PyTypeObject* pytype_def;
213213};
214214
215- // ! 工具类,用于生成分配python class的接口,包括分配、释放
215+ // ! �����࣬�������ɷ���python class�Ľӿڣ��������䡢�ͷ�
216216template <typename T>
217217struct pyclass_base_info_t
218218{
@@ -259,18 +259,18 @@ struct pyclass_base_info_t
259259template <typename T>
260260static_pytype_info_t pyclass_base_info_t <T>::pytype_info;
261261
262- // ! 方便生成pyclass 初始化函数
262+ // ! ��������pyclass ��ʼ������
263263template <typename CLASS_TYPE , typename CTOR >
264264struct pyclass_ctor_tool_t ;
265265
266266// ! used to gen method of py class
267267template <typename T>
268268struct pyclass_method_gen_t ;
269269
270- // ! 防止出现指针为NULL调用出错
270+ // ! ��ֹ����ָ��ΪNULL���ó���
271271#define NULL_PTR_GUARD (X ) if (NULL == X) {PyErr_SetString (PyExc_TypeError, " obj data ptr NULL" );return NULL ;}
272272
273- // ! 用于生成python 的getter和setter接口,适配于c ++ class的成员变量
273+ // ! ��������python ��getter��setter�ӿڣ�������c ++ class�ij�Ա����
274274template <typename CLASS_TYPE , typename RET >
275275struct pyclass_member_func_gen_t
276276{
@@ -295,7 +295,7 @@ struct pyclass_member_func_gen_t
295295 }
296296};
297297
298- // ! 用于C ++ 注册class的工具类,会记录class对应的名称、成员方法、成员变量
298+ // ! ����C ++ ע��class�Ĺ����࣬����¼class��Ӧ�����ơ���Ա��������Ա����
299299class pyclass_regigster_tool_t
300300{
301301public:
@@ -347,7 +347,7 @@ class pyclass_regigster_tool_t
347347 // ! property
348348 vector<PyGetSetDef> pyproperty_def;
349349
350- // ! 静态类型需要全局记录该类型被注册成神马python 类型
350+ // ! ��̬������Ҫȫ�ּ�¼�����ͱ�ע��������python ����
351351 static_pytype_info_t * static_pytype_info;
352352
353353 template <typename FUNC >
@@ -411,7 +411,7 @@ class ffpython_t
411411 static int run_string (const string& py_);
412412 static int reload (const string& py_);
413413 static int load (const string& py_);
414- // ! 注册static function,
414+ // ! ע��static function��
415415 template <typename T>
416416 ffpython_t & reg (T func_, const string& func_name_, string doc_ = " " )
417417 {
@@ -429,7 +429,7 @@ class ffpython_t
429429 return *this ;
430430 }
431431
432- // ! 注册c ++ class
432+ // ! ע��c ++ class
433433 template <typename T, typename CTOR >
434434 pyclass_regigster_tool_t & reg_class (const string& class_name_, string doc_ = " " , string inherit_name_ = " " )
435435 {
@@ -453,17 +453,17 @@ class ffpython_t
453453 tmp.args_num = pyext_func_traits_t <CTOR >::args_num ();
454454 tmp.option_args_num = pyext_func_traits_t <CTOR >::option_args_num ();
455455 tmp.static_pytype_info = &(pyclass_base_info_t <T>::pytype_info);
456- // ! 注册析构函数,python若不调用析构函数,当对象被gc时自动调用
456+ // ! ע����������,python����������������,��������gcʱ�Զ�����
457457 tmp.delete_func = (PyCFunction)pyclass_base_info_t <T>::release;
458458 m_all_pyclass.push_back (tmp);
459459
460460 return m_all_pyclass.back ();
461461 }
462462
463- // ! 将需要注册的函数、类型注册到python虚拟机
463+ // ! ����Ҫע���ĺ���������ע�ᵽpython������
464464 int init (const string& mod_name_, string doc_ = " " );
465465
466- // ! 调用python函数,最多支持9个参数
466+ // ! ����python����������֧��9������
467467 template <typename RET >
468468 RET_V call (const string& mod_name_, const string& func_)
469469 {
@@ -977,7 +977,7 @@ int ffpython_t::init_pyclass(PyObject* m)
977977 for (size_t i = 0 ; i < m_all_pyclass.size (); ++i)
978978 {
979979 m_all_pyclass[i].static_pytype_info ->mod_name = m_mod_name;
980- if (false == m_all_pyclass[i].inherit_name .empty ())// ! 存在基类
980+ if (false == m_all_pyclass[i].inherit_name .empty ())// ! ���ڻ���
981981 {
982982 pyclass_regigster_tool_t * inherit_class = get_pyclass_info_by_name (m_all_pyclass[i].inherit_name );
983983 assert (inherit_class && " base class must be registed" );
@@ -1104,7 +1104,7 @@ int ffpython_t::init_pyclass(PyObject* m)
11041104 " import %s\n "
11051105 " class %s(object):\n "
11061106 " \t '''%s'''\n "
1107- " \t def __init__(self, %s assign_obj_ = 0):\n " // ! 定义init函数
1107+ " \t def __init__(self, %s assign_obj_ = 0):\n " // ! ����init����
11081108 " \t\t '''%s'''\n "
11091109 " \t\t if True == isinstance(assign_obj_, %s):\n "
11101110 " \t\t\t self.obj = assign_obj_\n "
@@ -1122,12 +1122,12 @@ int ffpython_t::init_pyclass(PyObject* m)
11221122
11231123 string gen_class_str = buff;
11241124 SAFE_SPRINTF (buff, sizeof (buff),
1125- " \t def delete(self):\n " // ! 定义init函数
1125+ " \t def delete(self):\n " // ! ����init����
11261126 " \t\t '''delete obj'''\n "
11271127 " \t\t self.obj.delete()\n " );
11281128 gen_class_str += buff;
1129- // ! 增加析构函数
1130- // ! 增加属性
1129+ // ! ������������
1130+ // ! ��������
11311131 for (size_t c = 0 ; c < m_all_pyclass[i].propertys_info .size (); ++c)
11321132 {
11331133 SAFE_SPRINTF (buff, sizeof (buff),
@@ -1274,7 +1274,7 @@ struct type_ref_traits_t<const T&>
12741274 typedef T& ref_t ;
12751275 value_t value;
12761276};
1277- // ! 用于判断是否是可选参数
1277+ // ! �����ж��Ƿ��ǿ�ѡ����
12781278template <typename T>
12791279struct pyoption_traits_t
12801280{
@@ -1287,7 +1287,7 @@ struct pyoption_traits_t<pyoption_t<T> >
12871287};
12881288
12891289
1290- // ! pytype_traits_t 封装 PyLong_FromLong 相关的操作,用于为调用python生成参数
1290+ // ! pytype_traits_t ��װ PyLong_FromLong ���صIJ���������Ϊ����python���ɲ���
12911291
12921292template <>// typename T>
12931293struct pytype_traits_t <long >
@@ -1539,7 +1539,7 @@ struct pytype_traits_t<string>
15391539{
15401540 static PyObject* pyobj_from_cppobj (const string& val_)
15411541 {
1542- return PyString_FromString (val_.c_str ());
1542+ return PyString_FromStringAndSize (val_.c_str (), val_. size ());
15431543 }
15441544 static int pyobj_to_cppobj (PyObject *pvalue_, string& m_ret)
15451545 {
@@ -1786,7 +1786,7 @@ struct pytype_traits_t<map<T, R> >
17861786 static const char * get_typename () { return " map" ;}
17871787};
17881788
1789- // ! 获取python函数的返回值,工具类
1789+ // ! ��ȡpython�����ķ���ֵ,������
17901790template <typename T>
17911791class pytype_tool_impl_t : public pytype_tool_t
17921792{
@@ -1844,14 +1844,14 @@ class pytype_tool_impl_t<const T*>: public pytype_tool_t
18441844 T* m_ret;
18451845};
18461846
1847- // ! 封装调用python函数
1847+ // ! ��װ����python����
18481848int pycall_t::call_func (PyObject *pModule, const string& mod_name_, const string& func_name_, pycall_arg_t & pyarg_, pytype_tool_t & pyret_, string& err_)
18491849{
18501850 PyObject *pFunc = PyObject_GetAttrString (pModule, func_name_.c_str ());
18511851 if (pFunc && PyCallable_Check (pFunc)) {
18521852 PyObject *pArgs = pyarg_.get_args ();
18531853 PyObject *pValue = PyObject_CallObject (pFunc, pArgs);
1854- pyarg_.release ();// ! 等价于Py_DECREF (pArgs);
1854+ pyarg_.release ();// ! �ȼ���Py_DECREF (pArgs);
18551855
18561856 if (pValue != NULL ) {
18571857 if (pyret_.parse_value (pValue))
@@ -1883,7 +1883,7 @@ int pycall_t::call_func_obj(PyObject *pFunc, pycall_arg_t& pyarg_, pytype_tool_t
18831883 if (pFunc && PyCallable_Check (pFunc)) {
18841884 PyObject *pArgs = pyarg_.get_args ();
18851885 PyObject *pValue = PyObject_CallObject (pFunc, pArgs);
1886- pyarg_.release ();// ! 等价于Py_DECREF (pArgs);
1886+ pyarg_.release ();// ! �ȼ���Py_DECREF (pArgs);
18871887
18881888 if (pValue != NULL ) {
18891889 if (pyret_.parse_value (pValue))
@@ -1974,7 +1974,7 @@ const T& pycall_t::call_lambda(PyObject *pFunc, pycall_arg_t& pyarg_, pytype_too
19741974}
19751975
19761976
1977- // ! 用于扩展python的工具类,用来解析参数
1977+ // ! ������չpython�Ĺ����࣬������������
19781978struct pyext_tool_t
19791979{
19801980 pyext_tool_t (PyObject* args_):
@@ -2041,16 +2041,16 @@ struct pyext_tool_t
20412041 PyObject* m_arg_tuple;
20422042 int m_index;
20432043 int m_size;
2044- bool m_err;// ! 是否异常
2044+ bool m_err;// ! �Ƿ��쳣
20452045 long m_func_addr;
20462046};
20472047
20482048
2049- // ! 用于扩展python,生成pyobject类型的返回值给python
2049+ // ! ������չpython������pyobject���͵ķ���ֵ��python
20502050template <typename T>
20512051struct pyext_return_tool_t
20522052{
2053- // ! 用于静态方法
2053+ // ! ���ھ�̬����
20542054 template <typename F>
20552055 static PyObject* route_call (F f)
20562056 {
@@ -2107,7 +2107,7 @@ struct pyext_return_tool_t
21072107 return pytype_traits_t <T>::pyobj_from_cppobj (f (a1.value , a2.value , a3.value , a4.value , a5.value , a6.value ,
21082108 a7.value , a8.value , a9.value ));
21092109 }
2110- // ! 用于成员方法
2110+ // ! ���ڳ�Ա����
21112111 template <typename O, typename F>
21122112 static PyObject* route_method_call (O o, F f)
21132113 {
@@ -2307,7 +2307,7 @@ struct pyext_return_tool_t<void>
23072307};
23082308
23092309
2310- // ! 用于扩展python,traits出注册给python的函数接口
2310+ // ! ������չpython��traits��ע����python�ĺ����ӿ�
23112311template <typename RET >
23122312struct pyext_func_traits_t <RET (*)()>
23132313{
@@ -2683,7 +2683,7 @@ struct pyext_func_traits_t<RET (*)(ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG
26832683 }
26842684};
26852685
2686- // ! 方便生成pyclass 初始化函数
2686+ // ! ��������pyclass ��ʼ������
26872687template <typename CLASS_TYPE >
26882688struct pyclass_ctor_tool_t <CLASS_TYPE , int (*)()>
26892689{
@@ -3322,7 +3322,7 @@ struct pyclass_method_gen_t<RET (CLASS_TYPE::*)(ARG1, ARG2, ARG3, ARG4, ARG5, AR
33223322 }
33233323};
33243324
3325- // ! const类型成员函数 ---------------------------------------------------------------------------------------------
3325+ // ! const���ͳ�Ա���� ---------------------------------------------------------------------------------------------
33263326
33273327template <typename RET , typename CLASS_TYPE >
33283328struct pyclass_method_gen_t <RET (CLASS_TYPE ::*)() const >
@@ -3707,7 +3707,7 @@ struct pyclass_method_gen_t<RET (CLASS_TYPE::*)(ARG1, ARG2, ARG3, ARG4, ARG5, AR
37073707 }
37083708};
37093709
3710- // ! 获取python异常信息
3710+ // ! ��ȡpython�쳣��Ϣ
37113711int pyops_t::traceback (string& ret_)
37123712{
37133713 PyObject* err = PyErr_Occurred ();
0 commit comments