Ctypes

Un article de Haypo.

(Différences entre les versions)
Version du 19 février 2008 à 22:33 (modifier)
Haypo (Discuter | Contributions)
(Pour définir une structure)
← Différence précédente
Version actuelle (16 avril 2009 à 16:44) (modifier) (défaire)
Haypo (Discuter | Contributions)
(Résumé automatique : contenu remplacé par 'Article déplacé à l'adresse '''http://wikipython.flibuste.net/Ctypes'''')
 
(16 révisions intermédiaires masquées)
Ligne 1 : Ligne 1 :
-[[Catégorie:Langage de programmation]]+Article déplacé à l'adresse '''http://wikipython.flibuste.net/Ctypes'''
-{{Retour|Langages de programmation|Retour aux langages de programmation}}+
- +
-'''ctypes''' est une bibliothèque [[Python]] permettant d'accéder aux fonctions et symboles d'une bibliothèque externe (en particulier, codée en C).+
- +
-== Hello World! ==+
- +
- $ python+
- >>> libc=cdll.LoadLibrary('libc.so.6')+
- >>> libc.printf("Hello World!\n")+
- Hello World!+
- 13+
- +
-== Pour définir une structure ==+
- +
- from ctypes import Structure, Union+
- +
- class user_regs_struct(Structure):+
- _fields_ = (+
- ("ebx", c_ulong),+
- ("ecx", c_ulong),+
- ("edx", c_ulong),+
- ("esi", c_ulong),+
- ...+
- )+
- +
- _sifields_t = (...)+
- class siginfo(Structure):+
- _fields_ = (+
- ("si_signo", c_int),+
- ("si_errno", c_int),+
- ("si_code", c_int),+
- ("_sifields", _sifields_t)+
- )+
- _anonymous_ = ("_sifields",)+
- +
-== Tableau d'octet ==+
- +
- from ctypes import create_string_buffer+
- python_string = "string with \0 byte"+
- c_string = create_string_buffer(python_string)+
- assert c_string.value == 'string with'+
- assert c_string.raw == python_string+
- +
-== Modules ==+
- +
-* '''[http://fusil.hachoir.org/trac/browser/ptrace/trunk/ptrace/ctypes_errno.py ctypes_errno.py]''' : lire la variable errno, code d'erreur C+
-* '''[http://fusil.hachoir.org/trac/browser/ptrace/trunk/ptrace/ctypes_libc.py ctypes_libc.py]''' : accéder à la libc de manière portable+
-* '''[http://fusil.hachoir.org/trac/browser/ptrace/trunk/ptrace/ctypes_stdint.py ctypes_stdint.py]''' : types uint8_t, int32_t, ..., uint64_t+
-* '''[http://fusil.hachoir.org/trac/browser/ptrace/trunk/ptrace/ctypes_tools.py ctypes_tools.py]''' : outils divers+
- +
-Outils connexes :+
-* [http://fusil.hachoir.org/trac/browser/ptrace/trunk/ptrace/cpu_info.py cpu_info.py] : informations sur le processeur+
-* [http://fusil.hachoir.org/trac/browser/ptrace/trunk/ptrace/os_tools.py os_tools.py] : informations sur le système d'exploitation+
- +
-== Articles connexes ==+
- +
-* [[Python]]+

Version actuelle

Article déplacé à l'adresse http://wikipython.flibuste.net/Ctypes