Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kirill Smelkov
cpython
Commits
1928773e
Commit
1928773e
authored
17 years ago
by
Georg Brandl
Browse files
Options
Download
Email Patches
Plain Diff
Patch #1720595: add T_BOOL to the range of structmember types.
Patch by Angelo Mottola, reviewed by MvL, tests by me.
parent
12c49c6e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
3 deletions
+32
-3
Include/structmember.h
Include/structmember.h
+3
-0
Lib/test/test_structmembers.py
Lib/test/test_structmembers.py
+7
-1
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+5
-2
Python/structmember.c
Python/structmember.c
+15
-0
No files found.
Include/structmember.h
View file @
1928773e
...
...
@@ -62,6 +62,9 @@ typedef struct PyMemberDef {
/* Added by Jack: strings contained in the structure */
#define T_STRING_INPLACE 13
/* Added by Lillo: bools contained in the structure (assumed char) */
#define T_BOOL 14
#define T_OBJECT_EX 16
/* Like T_OBJECT, but raises AttributeError
when the value is NULL, instead of
converting to None. */
...
...
This diff is collapsed.
Click to expand it.
Lib/test/test_structmembers.py
View file @
1928773e
...
...
@@ -8,10 +8,16 @@ from _testcapi import test_structmembersType, \
import
warnings
,
exceptions
,
unittest
,
sys
from
test
import
test_support
ts
=
test_structmembersType
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9.99999
,
10.1010101010
)
ts
=
test_structmembersType
(
False
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9.99999
,
10.1010101010
)
class
ReadWriteTests
(
unittest
.
TestCase
):
def
test_types
(
self
):
ts
.
T_BOOL
=
True
self
.
assertEquals
(
ts
.
T_BOOL
,
True
)
ts
.
T_BOOL
=
False
self
.
assertEquals
(
ts
.
T_BOOL
,
False
)
self
.
assertRaises
(
TypeError
,
setattr
,
ts
,
'T_BOOL'
,
1
)
ts
.
T_BYTE
=
CHAR_MAX
self
.
assertEquals
(
ts
.
T_BYTE
,
CHAR_MAX
)
ts
.
T_BYTE
=
CHAR_MIN
...
...
This diff is collapsed.
Click to expand it.
Misc/NEWS
View file @
1928773e
...
...
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 1?
Core and builtins
-----------------
- Patch #1720595: add T_BOOL to the range of structmember types.
- Issue #1882: when compiling code from a string, encoding cookies in the
second line of code were not always recognized correctly.
...
...
This diff is collapsed.
Click to expand it.
Modules/_testcapimodule.c
View file @
1928773e
...
...
@@ -762,6 +762,7 @@ static PyMethodDef TestMethods[] = {
#define AddSym(d, n, f, v) {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);}
typedef
struct
{
char
bool_member
;
char
byte_member
;
unsigned
char
ubyte_member
;
short
short_member
;
...
...
@@ -784,6 +785,7 @@ typedef struct {
}
test_structmembers
;
static
struct
PyMemberDef
test_members
[]
=
{
{
"T_BOOL"
,
T_BOOL
,
offsetof
(
test_structmembers
,
structmembers
.
bool_member
),
0
,
NULL
},
{
"T_BYTE"
,
T_BYTE
,
offsetof
(
test_structmembers
,
structmembers
.
byte_member
),
0
,
NULL
},
{
"T_UBYTE"
,
T_UBYTE
,
offsetof
(
test_structmembers
,
structmembers
.
ubyte_member
),
0
,
NULL
},
{
"T_SHORT"
,
T_SHORT
,
offsetof
(
test_structmembers
,
structmembers
.
short_member
),
0
,
NULL
},
...
...
@@ -803,13 +805,13 @@ static struct PyMemberDef test_members[] = {
static
PyObject
*
test_structmembers_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwargs
){
static
char
*
keywords
[]
=
{
"T_BYTE"
,
"T_UBYTE"
,
"T_SHORT"
,
"T_USHORT"
,
"T_INT"
,
"T_UINT"
,
static
char
*
keywords
[]
=
{
"T_BOOL"
,
"T_BYTE"
,
"T_UBYTE"
,
"T_SHORT"
,
"T_USHORT"
,
"T_INT"
,
"T_UINT"
,
"T_LONG"
,
"T_ULONG"
,
"T_FLOAT"
,
"T_DOUBLE"
,
#ifdef HAVE_LONG_LONG
"T_LONGLONG"
,
"T_ULONGLONG"
,
#endif
NULL
};
static
char
*
fmt
=
"|bBhHiIlkfd"
static
char
*
fmt
=
"|
b
bBhHiIlkfd"
#ifdef HAVE_LONG_LONG
"LK"
#endif
...
...
@@ -819,6 +821,7 @@ static PyObject *test_structmembers_new(PyTypeObject *type, PyObject *args, PyOb
return
NULL
;
memset
(
&
ob
->
structmembers
,
0
,
sizeof
(
all_structmembers
));
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
fmt
,
keywords
,
&
ob
->
structmembers
.
bool_member
,
&
ob
->
structmembers
.
byte_member
,
&
ob
->
structmembers
.
ubyte_member
,
&
ob
->
structmembers
.
short_member
,
&
ob
->
structmembers
.
ushort_member
,
&
ob
->
structmembers
.
int_member
,
&
ob
->
structmembers
.
uint_member
,
...
...
This diff is collapsed.
Click to expand it.
Python/structmember.c
View file @
1928773e
...
...
@@ -61,6 +61,9 @@ PyMember_GetOne(const char *addr, PyMemberDef *l)
}
addr
+=
l
->
offset
;
switch
(
l
->
type
)
{
case
T_BOOL
:
v
=
PyBool_FromLong
(
*
(
char
*
)
addr
);
break
;
case
T_BYTE
:
v
=
PyInt_FromLong
(
*
(
char
*
)
addr
);
break
;
...
...
@@ -183,6 +186,18 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
}
addr
+=
l
->
offset
;
switch
(
l
->
type
)
{
case
T_BOOL
:{
if
(
!
PyBool_Check
(
v
))
{
PyErr_SetString
(
PyExc_TypeError
,
"attribute value type must be bool"
);
return
-
1
;
}
if
(
v
==
Py_True
)
*
(
char
*
)
addr
=
(
char
)
1
;
else
*
(
char
*
)
addr
=
(
char
)
0
;
break
;
}
case
T_BYTE
:{
long
long_val
=
PyInt_AsLong
(
v
);
if
((
long_val
==
-
1
)
&&
PyErr_Occurred
())
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment