Issue 12476: ctypes: need example how to pass raw data from Python (original) (raw)

Created on 2011-07-03 08:02 by techtonik, last changed 2022-04-11 14:57 by admin.

Messages (3)
msg139675 - (view) Author: anatoly techtonik (techtonik) Date: 2011-07-03 08:02
ctypes documentation lacks an example, how to pass a raw data block from Python to a C function. For example, how to pass this chunk: data = open('somefile', 'rb').read() to this function: int checkBuffer(LPSTR lpData, DWORD dwBufferLength); ?
msg139676 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-07-03 08:52
Can you suggest a patch?
msg139686 - (view) Author: anatoly techtonik (techtonik) Date: 2011-07-03 12:24
ISTM that this code works ok. data = open('data.raw', 'rb').read() ret = checkBuffer(data, len(data)) You need to make sure that checkBuffer doesn't try to modify memory though. For mutable memory blocks use create_string_buffer().
History
Date User Action Args
2022-04-11 14:57:19 admin set github: 56685
2011-07-03 12:24:43 techtonik set messages: +
2011-07-03 08:52:25 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2011-07-03 08:02:36 techtonik create