Skip to content
Snippets Groups Projects
Commit e759e9202ec7 authored by jfp's avatar jfp
Browse files

Allow ile3 retlen to be short or long.

parent a0da7ea8aa30
Branches
No related tags found
No related merge requests found
'vms Extension Series for Python'
"""vms Extension Series for Python"""
__version__ = '0.3'
"""vms Extension Series for Python
......@@ -67,6 +67,23 @@
# Length of ILEA
ILEA_64_C_LENGTH = 24
from ctypes import Structure, c_ushort, c_uint32, c_void_p, c_char, POINTER, cast, sizeof, pointer
from ctypes import (
Structure,
Union,
c_ushort,
c_ulong,
c_uint32,
c_void_p,
c_char,
POINTER,
cast,
sizeof,
pointer,
)
class RETLEN(Union):
_fields_ = [('ushort', POINTER(c_ushort)), ('ulong', POINTER(c_ulong))]
class ILE3(Structure):
......@@ -71,9 +88,10 @@
class ILE3(Structure):
_fields_ = [("ile3_w_length", c_ushort), # Length of buffer in bytes
("ile3_w_code", c_ushort), # Item code value
("ile3_ps_bufaddr", c_void_p), # Buffer address
("ile3_ps_retlen_addr", POINTER(c_uint32)) # Address of word or longword
_fields_ = [
('ile3_w_length', c_ushort), # Length of buffer in bytes
('ile3_w_code', c_ushort), # Item code value
('ile3_ps_bufaddr', c_void_p), # Buffer address
('ile3_ps_retlen_addr', RETLEN) # Address of word or longword
# for returned length
]
......@@ -77,4 +95,5 @@
# for returned length
]
class ILE2(Structure):
......@@ -80,6 +99,7 @@
class ILE2(Structure):
_fields_ = [("ile2_w_length", c_ushort), # Length of buffer in bytes
("ile2_w_code", c_ushort), # Item code value
("ile2_ps_bufaddr", c_void_p) # Buffer address
_fields_ = [
('ile2_w_length', c_ushort), # Length of buffer in bytes
('ile2_w_code', c_ushort), # Item code value
('ile2_ps_bufaddr', c_void_p), # Buffer address
]
......@@ -84,3 +104,4 @@
]
def set_ile3_item(item, length=None, code=0, buffer=None, retlen=None):
......@@ -86,6 +107,9 @@
def set_ile3_item(item, length=None, code=0, buffer=None, retlen=None):
if (length is None and buffer is not None and
isinstance(buffer, c_char*sizeof(buffer))):
if (
length is None
and buffer is not None
and isinstance(buffer, c_char * sizeof(buffer))
):
length = sizeof(buffer) - 1
if length is None:
length = 0
......@@ -95,6 +119,14 @@
buffer = cast(buffer, c_void_p)
item.ile3_ps_bufaddr = buffer
if retlen is not None:
retlen = pointer(retlen)
oretlen = retlen
if isinstance(retlen, c_ushort):
retlen = RETLEN()
retlen.ushort = pointer(oretlen)
elif isinstance(retlen, c_ulong):
retlen = RETLEN()
retlen.ulong = pointer(oretlen)
else:
raise ValueError('retlen should be None or c_ushort or c_ulong')
item.ile3_ps_retlen_addr = retlen
......@@ -99,3 +131,4 @@
item.ile3_ps_retlen_addr = retlen
def set_ile2_item(item, length=None, code=0, buffer=None):
......@@ -101,6 +134,9 @@
def set_ile2_item(item, length=None, code=0, buffer=None):
if (length is None and buffer is not None and
isinstance(buffer, c_char*sizeof(buffer))):
if (
length is None
and buffer is not None
and isinstance(buffer, c_char * sizeof(buffer))
):
length = sizeof(buffer) - 1
if length is None:
length = 0
......@@ -110,7 +146,8 @@
buffer = cast(buffer, c_void_p)
item.ile2_ps_bufaddr = buffer
def get_ile3_string_item(item):
if item.ile3_ps_retlen_addr is None:
retlen = item.ile3_w_length + 1
else:
......@@ -113,10 +150,10 @@
def get_ile3_string_item(item):
if item.ile3_ps_retlen_addr is None:
retlen = item.ile3_w_length + 1
else:
retlen = item.ile3_ps_retlen_addr.contents.value
return cast(item.ile3_ps_bufaddr,
POINTER(c_char*(retlen))).contents
retlen = item.ile3_ps_retlen_addr.ushort.contents.value
return cast(item.ile3_ps_bufaddr, POINTER(c_char * (retlen))).contents
def get_ile2_string_item(item):
retlen = item.ile3_w_length + 1
......@@ -120,5 +157,4 @@
def get_ile2_string_item(item):
retlen = item.ile3_w_length + 1
return cast(item.ile3_ps_bufaddr,
POINTER(c_char*(retlen))).contents
return cast(item.ile3_ps_bufaddr, POINTER(c_char * (retlen))).contents
......@@ -485,7 +485,6 @@
def test_ile3_a():
from ctypes import (
c_ushort,
c_uint32,
create_string_buffer,
CDLL,
sizeof,
......@@ -495,7 +494,7 @@
c_int,
byref,
)
from ovms.iledef import ILE3, set_ile3_item, get_ile3_string_item
from ovms.iledef import ILE3, RETLEN, set_ile3_item, get_ile3_string_item
from ovms.efndef import EFN_C_ENF
from ovms.ssdef import SS__NOMORENODE
from ovms.stsdef import vms_status_success
......@@ -509,5 +508,5 @@
iosb = IOSB_r_get_64()
verlen = c_uint32()
verlen = c_ushort()
verbuf = create_string_buffer(16 + 1)
......@@ -513,3 +512,3 @@
verbuf = create_string_buffer(16 + 1)
nodelen = c_uint32()
nodelen = c_ushort()
nodebuf = create_string_buffer(12 + 1)
......@@ -515,5 +514,5 @@
nodebuf = create_string_buffer(12 + 1)
devlen = c_uint32()
devlen = c_ushort()
devbuf = create_string_buffer(255 + 1)
it = (ILE3 * 4)()
......@@ -521,8 +520,9 @@
it[0].ile3_w_length = sizeof(verbuf) - 1
it[0].ile3_w_code = SYI__VERSION
it[0].ile3_ps_bufaddr = cast(verbuf, c_void_p)
it[0].ile3_ps_retlen_addr = pointer(verlen)
it[0].ile3_ps_retlen_addr = RETLEN()
it[0].ile3_ps_retlen_addr.ushort = pointer(verlen)
set_ile3_item(it[1], sizeof(nodebuf) - 1, SYI__NODENAME, nodebuf, nodelen)
set_ile3_item(it[2], None, SYI__BOOT_DEVICE, devbuf, devlen)
......@@ -525,10 +525,7 @@
set_ile3_item(it[1], sizeof(nodebuf) - 1, SYI__NODENAME, nodebuf, nodelen)
set_ile3_item(it[2], None, SYI__BOOT_DEVICE, devbuf, devlen)
# it[3].ile3_w_length = it[3].ile3_w_code = 0
# it[3].ile3_ps_bufaddr = None
# it[3].ile3_ps_retlen_addr = None
set_ile3_item(it[3])
status = getsyiw(
......@@ -1003,7 +1000,7 @@
nodename = ctypes.create_string_buffer(32 + 1)
pid = ctypes.c_uint32()
retlen = ctypes.c_uint32()
retlen = ctypes.c_ushort()
it = (ILE3 * 3)()
set_ile3_item(
it[0],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment