|
|
|
|
 一个SWIG问题. - raisesail [ 2004-03-20 21:44 | 1,694 byte(s)]
 Re: 一个SWIG问题. - raise_sail [ 2004-03-21 21:07 | 14 byte(s)]
|
|
|
|
[Original]
[Print]
[Top]
|
我在maillist上问过了.
我用SWIG封装了一个结构的成员, 那是一个指针. 实际使用时是一个数组.
当然要封装list, 表面上它已经工作了. 但是还有一些问题. 详细如下:
typedef struct /**** Files ****/
{
....
int num_emulations; /* Number of emulations supported */
ppd_emul_t *emulations; /* Emulations and the code to invoke them */
....
} ppd_file_t;
import pyPPD as ppd # pyPPD is my module name
f = ppd.file_t() # file_t same as ppd_file_t in C.
e = ppd.emul_t() # emul_t same as ppd_emul_t in C.
print f.emulations # Now it is [].
f.emulations = [e] # OK.
f.emulations.append(e)
asssert len(f.emulations) == 2 # too bad , it is failed at here!
del f.emulations[0] # if we bypass above assert statement.
asssert len(f.emulations) == 0 # too bad , it is failed at here!
del f.emulations[0] # if we bypass too.
asssert len(f.emulations) == 0 # too bad , it is failed at here!
f.emulations+=e # if we bypass above assert statement.
asssert len(f.emulations) == 2 # It OK!
发现:
li = f.emulations = []
li.append(e)
assert len(li) == 1 # it OK!!
有点怪的问题, 不是吗? 谁熟悉SWIG, 指点一下.
PS. 其实这里的emulations成员应该是只读的, 但某个功能不全, 非常不爽.
|
|
|
[Original]
[Print]
[Top]
|
|
|