Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-78878: Fix crash when creating an instance of_ctypes.CField#14837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kumaraditya303 merged 9 commits intopython:mainfromshihai1991:bpo_34697
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletionsLib/ctypes/test/test_struct_fields.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,12 @@ class Y(X):
Y._fields_ = []
self.assertRaises(AttributeError, setattr, X, "_fields_", [])

def test_5(self):
class X(Structure):
_fields_ = [("x", c_int)]
CField = type(X.x)
self.assertRaises(TypeError, CField)

# __set__ and __get__ should raise a TypeError in case their self
# argument is not a ctype instance.
def test___set__(self):
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Remove the ``PyCField_new`` which user cannot call it directly.
11 changes: 2 additions & 9 deletionsModules/_ctypes/cfield.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,13 +22,6 @@ static void pymem_destructor(PyObject *ptr)
/*
PyCField_Type
*/
static PyObject *
PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
CFieldObject *obj;
obj = (CFieldObject *)type->tp_alloc(type, 0);
return (PyObject *)obj;
}

/*
* Expects the size, index and offset for the current field in *psize and
Expand DownExpand Up@@ -60,7 +53,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
#define CONT_BITFIELD 2
#define EXPAND_BITFIELD 3

self = (CFieldObject *)_PyObject_CallNoArg((PyObject *)&PyCField_Type);
self = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0);
if (self == NULL)
return NULL;
dict = PyType_stgdict(desc);
Expand DownExpand Up@@ -336,7 +329,7 @@ PyTypeObject PyCField_Type = {
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyCField_new, /* tp_new */
0, /* tp_new */
0, /* tp_free */
};

Expand Down
2 changes: 1 addition & 1 deletionModules/_ctypes/stgdict.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -248,7 +248,7 @@ MakeFields(PyObject *type, CFieldObject *descr,
}
continue;
}
new_descr = (CFieldObject *)_PyObject_CallNoArg((PyObject *)&PyCField_Type);
new_descr = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0);
if (new_descr == NULL) {
Py_DECREF(fdescr);
Py_DECREF(fieldlist);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp