Bonjour,
Je souhaite utiliser une librairie c :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
....
typedef struct __pmlist_t PM_LIST;
typedef struct __pmdb_t PM_DB;
..
int pacman_parse_config(char *file, pacman_cb_db_register callback, const char *this_section);
/* Database registration callback */
typedef void (*pacman_cb_db_register)(const char *, PM_DB *);
....
J'ai donc écris :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 
#!/usr/bin/env python
 
import os, tempfile, shutil, sys
from ctypes import *
import ctypes
 
#GLOBAL
pacman=cdll.LoadLibrary("libpacman.so")
CFG_FILE = '/etc/pacman-g2.conf'
 
#for print debug messages
debug=1
 
 
#some class for pacman-g2
class PM_LIST(Structure):
  pass
PM_LIST._fields_ = [
        ("data", ctypes.c_void_p),
        ("prev", POINTER(PM_LIST)),
        ("next", POINTER(PM_LIST)),
        ("last", POINTER(PM_LIST))]
class PM_DB(Structure):
  pass
PM_DB._fields_ = [
        ("path", ctypes.c_char),
        ("treename", ctypes.c_char),
        ("handle", ctypes.c_void_p),
        ("pkgcache", POINTER(PM_LIST)),
        ("grpcache", POINTER(PM_LIST)),
        ("handle", POINTER(PM_LIST)),
        ("servers", ctypes.c_char)]
 
def _db_cb (section,db):
  print_debug(db)
  return
 
def pacman_init():
  pacman.pacman_release()
  if pacman.pacman_initialize("/") == -1:
    print "Can't initialise pacman-g2"
    sys.exit(0) 
 
def pacman_init_database():
  print_debug("init database")
  pacman_cb_db_register = CFUNCTYPE(POINTER(ctypes.c_void_p), POINTER(ctypes.c_char_p), PM_DB)
  print_debug("pacman_parse_config")
  pacman.pacman_parse_config.argtypes = [POINTER(ctypes.c_char_p),POINTER(pacman_cb_db_register),POINTER(ctypes.c_char_p)]
  pacman.pacman_parse_config(CFG_FILE,pacman_cb_db_register(_db_cb),'')
 
def main():
  pacman_init()
  pacman_init_database()
 
 
def help():
  print "help :"
  print "--search Package"
  sys.exit(0)
 
 
def print_debug(textConsole):
  if debug <> 1:
    return
  print "DEBUG : "+textConsole
 
def _db_cb(section , db):
  print db
 
#start main program
main()
Mais quand je lance le script :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
 DEBUG : init database
DEBUG : pacman_parse_config
Traceback (most recent call last):
  File "py-pacman.py", line 73, in <module>
    main()
  File "py-pacman.py", line 55, in main
    pacman_init_database()
  File "py-pacman.py", line 51, in pacman_init_database
    pacman.pacman_parse_config(CFG_FILE,pacman_cb_db_register(_db_cb),'')
TypeError: invalid result type for callback function
Je me doute que j'ai du me tromper mais je vois pas si quelqu'un à une idée je suis preneur