码迷,mamicode.com
首页 > 编程语言 > 详细

项目记录 -- python调用回调函数

时间:2014-07-09 00:17:54      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   文件   os   for   

C源文件:

 1 static int
 2 get_callback(zpool_handle_t *zhp, void *data)
 3 {
 4     zprop_get_cbdata_t *cbp = (zprop_get_cbdata_t *)data;
 5     char value[MAXNAMELEN];
 6     zprop_source_t srctype;
 7     zprop_list_t *pl;
 8 
 9     for (pl = cbp->cb_proplist; pl != NULL; pl = pl->pl_next) {
10 
11         /*
12          * Skip the special fake placeholder. This will also skip
13          * over the name property when ‘all‘ is specified.
14          */
15         if (pl->pl_prop == ZPOOL_PROP_NAME &&
16             pl == cbp->cb_proplist)
17             continue;
18 
19         if (pl->pl_prop == ZPROP_INVAL &&
20             (zpool_prop_feature(pl->pl_user_prop) ||
21             zpool_prop_unsupported(pl->pl_user_prop))) {
22             srctype = ZPROP_SRC_LOCAL;
23 
24             if (zpool_prop_get_feature(zhp, pl->pl_user_prop,
25                 value, sizeof (value)) == 0) {
26                 zprop_print_one_property(zpool_get_name(zhp),
27                     cbp, pl->pl_user_prop, value, srctype,
28                     NULL, NULL);
29             }
30         } else {
31             if (zpool_get_prop(zhp, pl->pl_prop, value,
32                 sizeof (value), &srctype) != 0)
33                 continue;
34 
35             zprop_print_one_property(zpool_get_name(zhp), cbp,
36                 zpool_prop_to_name(pl->pl_prop), value, srctype,
37                 NULL, NULL);
38         }
39     }
40     return (0);
41 }
42 来源 -- illumos/usr/src/cmd/zpool/zpool_main.c

上面代码中:value定义的是数组char value[MAXNAMELEN];,我采用的方法如下:

1 value = c_char * 256
2 
3 libzfs.zpool_get_prop(zhp, prop, value, 256, byref(srctype))

采用上述方法时,当运行到libzfs.zpool_get_prop时,直接显示为None

 

正确的方法为:

1 value = create_string_buffer(256)
2 
3 ret = libzfs.zpool_get_prop(zhp, prop, value, 256, byref(srctype))

采用create_string_buffer才能正确显示

执行命令:print(type(value))
              print(dir(value))

显示如下:

<class ‘ctypes.c_char_Array_256‘>
[‘__class__‘, ‘__ctypes_from_outparam__‘, ‘__delattr__‘, ‘__delitem__‘, ‘__dict__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getitem__‘, ‘__gt__‘, ‘__hash__‘, ‘__init__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__module__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__setattr__‘, ‘__setitem__‘, ‘__setstate__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘__weakref__‘, ‘_b_base_‘, ‘_b_needsfree_‘, ‘_length_‘, ‘_objects‘, ‘_type_‘, ‘raw‘, ‘value‘]

项目记录 -- python调用回调函数,布布扣,bubuko.com

项目记录 -- python调用回调函数

标签:style   blog   color   文件   os   for   

原文地址:http://www.cnblogs.com/fendou-999/p/3830240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!