Skip to content

Commit 55f97c9

Browse files
committed
[GR-23753] Implement more dummy classes in ctypes module.
PullRequest: graalpython/989
2 parents 05b0c88 + 3e19116 commit 55f97c9

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

graalpython/lib-graalpython/ctypes.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -55,10 +55,37 @@ class CDLL(object):
5555
pass
5656

5757

58-
class _SimpleCData:
58+
# Dummy classes:
59+
60+
61+
class _CData:
62+
pass
63+
64+
65+
class _Array(_CData):
66+
pass
67+
68+
69+
70+
class _SimpleCDataMetaCls(type):
71+
"""
72+
Dummy implementation of the operators on _SimpleCDatan subclasses.
73+
74+
For example: ctypes.c_int * 3 gives dynamically created class representing
75+
the type of the array.
76+
"""
77+
78+
def __mul__(self, other):
79+
return type(self.__name__ + '_Array_' + str(other), (_Array, object,), {})
80+
81+
def __rmul__(self, other):
82+
return type(self.__name__ + '_Array_' + str(other), (_Array, object,), {})
83+
84+
85+
class _SimpleCData(_CData, metaclass=_SimpleCDataMetaCls):
5986
pass
6087

61-
# dummies
88+
6289
class c_void_p(_SimpleCData):
6390
_type_ = "P"
6491

@@ -71,6 +98,30 @@ class c_int(_SimpleCData):
7198
_type_ = "i"
7299

73100

101+
class c_int32(c_int):
102+
pass
103+
104+
105+
class c_uint(_SimpleCData):
106+
_type_ = "I"
107+
108+
109+
class c_uint32(c_uint):
110+
pass
111+
112+
113+
class c_ulong(_SimpleCData):
114+
_type_ = "L"
115+
116+
117+
class c_uint64(c_ulong):
118+
pass
119+
120+
121+
class c_char(_SimpleCData):
122+
_type_ = "c"
123+
124+
74125
class py_object(_SimpleCData):
75126
_type_ = "O"
76127
def __repr__(self):

0 commit comments

Comments
 (0)