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 8389
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |