In an earlier post, I was interested in passing a pointer to a structure to
fcntl.ioctl.
This works:
c = create_string_buffer (...)
args = struct.pack("iP", len(c), cast (pointer (c), c_void_p).value)
err = fcntl.ioctl(eos_fd, request, args)
Now to do the same with ctypes, I have one problem.
class eos_dl_args_t (Structure):
_fields_ = [("length", c_ulong),
("data", c_void_p)]
....
args = eos_dl_args_t()
args_p = cast(pointer(args), c_void_ptr).value
fcntl.ioctl(fd, request, args_p) <<< May fail here
That last may fail, because .value creates a long int, and ioctl needs a
string.
How can I convert my ctypes structure to a string? It _cannot_ be a c-style
0-terminate string, because the structure may contain '0' values. 4 8364
Neal Becker napisa³(a):
In an earlier post, I was interested in passing a pointer to a structure to
fcntl.ioctl.
This works:
c = create_string_buffer (...)
args = struct.pack("iP", len(c), cast (pointer (c), c_void_p).value)
err = fcntl.ioctl(eos_fd, request, args)
Now to do the same with ctypes, I have one problem.
class eos_dl_args_t (Structure):
_fields_ = [("length", c_ulong),
("data", c_void_p)]
...
args = eos_dl_args_t()
args_p = cast(pointer(args), c_void_ptr).value
fcntl.ioctl(fd, request, args_p) <<< May fail here
That last may fail, because .value creates a long int, and ioctl needs a
string.
How can I convert my ctypes structure to a string? It _cannot_ be a c-style
0-terminate string, because the structure may contain '0' values.
Hello. I'm not completely sure what your problem is ("may fail" is not
a good description. Does it fail or does it not?). If you want a
pointer to a structure as the third argument to ioctl, this would be
imho the easiest way to do it with ctypes:
class eos_dl_args_t(Structure):
_fields_ = [("length", c_ulong), ("data", c_void_p)]
args = eos_dl_args_t()
fcntl.ioctl(fd, request, byref(args))
Regards,
Marek
Neal Becker schrieb:
In an earlier post, I was interested in passing a pointer to a structure to
fcntl.ioctl.
This works:
c = create_string_buffer (...)
args = struct.pack("iP", len(c), cast (pointer (c), c_void_p).value)
err = fcntl.ioctl(eos_fd, request, args)
Now to do the same with ctypes, I have one problem.
class eos_dl_args_t (Structure):
_fields_ = [("length", c_ulong),
("data", c_void_p)]
...
args = eos_dl_args_t()
args_p = cast(pointer(args), c_void_ptr).value
fcntl.ioctl(fd, request, args_p) <<< May fail here
That last may fail, because .value creates a long int, and ioctl needs a
string.
How can I convert my ctypes structure to a string? It _cannot_ be a c-style
0-terminate string, because the structure may contain '0' values.
ctypes instances support the buffer interface, and you can convert the buffer
contents into a string:
>>from ctypes import * c_int(42)
c_long(42)
>>buffer(c_int(42))
<read-only buffer for 0x00AE7260, size -1, offset 0 at 0x00B06040>
>>buffer(c_int(42))[:]
'*\x00\x00\x00'
>>>
Thomas ma*********@wp.pl wrote:
Neal Becker napisał(a):
>In an earlier post, I was interested in passing a pointer to a structure to fcntl.ioctl.
This works:
c = create_string_buffer (...) args = struct.pack("iP", len(c), cast (pointer (c), c_void_p).value) err = fcntl.ioctl(eos_fd, request, args)
Now to do the same with ctypes, I have one problem.
class eos_dl_args_t (Structure): _fields_ = [("length", c_ulong), ("data", c_void_p)] ... args = eos_dl_args_t() args_p = cast(pointer(args), c_void_ptr).value fcntl.ioctl(fd, request, args_p) <<< May fail here
That last may fail, because .value creates a long int, and ioctl needs a string.
How can I convert my ctypes structure to a string? It _cannot_ be a c-style 0-terminate string, because the structure may contain '0' values.
Hello. I'm not completely sure what your problem is ("may fail" is not
a good description. Does it fail or does it not?).
May fail is exactly what I meant. As written, ioctl will accept a 3rd arg
that is either a string or int. In this case, it is int. If the address
fits in an int it works, but if the address (which is a long) doesn't fit
it fails (gives an overflow error). Seems to be random (as well as
platform dependent). ma*********@wp.pl wrote:
Neal Becker napisał(a):
>In an earlier post, I was interested in passing a pointer to a structure to fcntl.ioctl.
This works:
c = create_string_buffer (...) args = struct.pack("iP", len(c), cast (pointer (c), c_void_p).value) err = fcntl.ioctl(eos_fd, request, args)
Now to do the same with ctypes, I have one problem.
class eos_dl_args_t (Structure): _fields_ = [("length", c_ulong), ("data", c_void_p)] ... args = eos_dl_args_t() args_p = cast(pointer(args), c_void_ptr).value fcntl.ioctl(fd, request, args_p) <<< May fail here
That last may fail, because .value creates a long int, and ioctl needs a string.
How can I convert my ctypes structure to a string? It _cannot_ be a c-style 0-terminate string, because the structure may contain '0' values.
Hello. I'm not completely sure what your problem is ("may fail" is not
a good description. Does it fail or does it not?). If you want a
pointer to a structure as the third argument to ioctl, this would be
imho the easiest way to do it with ctypes:
>class eos_dl_args_t(Structure): _fields_ = [("length", c_ulong), ("data", c_void_p)] args = eos_dl_args_t() fcntl.ioctl(fd, request, byref(args))
Seems to be a problem with that:
---59 err = fcntl.ioctl(eos_fd, request, byref(args))
60
TypeError: an integer is required This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Thomas Heller |
last post by:
ctypes 0.9.1 released - Sept 14, 2004
=====================================
Overview
ctypes is a ffi (Foreign Function Interface) package for Python
2.3 and higher.
ctypes allows to call...
|
by: Lenard Lindstrom |
last post by:
Posted in a previous thread was some Python code for accessing Window's
Simple MAPI api using the ctypes module.
http://groups-beta.google.com/group/comp.lang.python/msg/56fa74cdba9b7be9
This...
|
by: Srijit Kumar Bhadra |
last post by:
Hello,
Here is some sample code with pywin32 build 203 and ctypes 0.9.6.
Best regards,
/Srijit
File: SharedMemCreate_Mutex_win32all.py
# This application should be used with...
|
by: p.lavarre |
last post by:
Q: The C idea of (pv != NULL) is said most directly in Python ctypes
how?
A: We are of course supposed to write something like:
def c_not_null(pv):
return (ctypes.cast(pv,...
|
by: Eric |
last post by:
Hi,
I am currently dealing with ctypes, interfacing with winscard libbrary
(for smart card access).
Several APIs (e.g. SCardListReaderGroupsW ) take a pointer to an
unicode string as a...
|
by: Chris AtLee |
last post by:
Sorry for the repeat post...I'm not sure if my first post (on May
30th) went through or
not.
I've been trying to write a PAM module using ctypes. In the
conversation
function (my_conv in the...
|
by: waldek |
last post by:
Hi,
I'm using C dll with py module and wanna read value (buffer of bytes)
returned in py callback as parameter passed to dll function.
--------------------------------------------------
def ...
|
by: Andrew Lentvorski |
last post by:
Basically, I'd like to use the ctypes module as a much more descriptive
"struct" module.
Is there a way to take a ctypes.Structure-based class and convert it
to/from a binary string?
Thanks,...
|
by: patelss23 |
last post by:
Hello All Experts,
I am quite new to Ctypes. I am using one c library and writing python
bindings for it.
I need to pass a character pointer to one function.
I am reading one mp3 file and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |