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-105927: Avoid calling PyWeakref_GET_OBJECT()#105997

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
vstinner merged 1 commit intopython:mainfromvstinner:getref_obj
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
13 changes: 10 additions & 3 deletionsModules/_sqlite/blob.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif

#include "blob.h"
#include "util.h"
#include "pycore_weakref.h" // _PyWeakref_GET_REF()

#define clinic_state() (pysqlite_get_state_by_type(Py_TYPE(self)))
#include "clinic/blob.c.h"
Expand DownExpand Up@@ -97,10 +102,12 @@ pysqlite_close_all_blobs(pysqlite_Connection *self)
{
for (int i = 0; i < PyList_GET_SIZE(self->blobs); i++) {
PyObject *weakref = PyList_GET_ITEM(self->blobs, i);
PyObject *blob =PyWeakref_GetObject(weakref);
if (!Py_IsNone(blob)) {
close_blob((pysqlite_Blob *)blob);
PyObject *blob =_PyWeakref_GET_REF(weakref);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ideally, we should use public API only in the sqlite3 extension module.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I hesitated to use PyWeakref_GetRef() but pysqlite_close_all_blobs() cannot report errors (return type is void), and I hesitated to use PyErr_WriteUnraisable().

erlend-aasland reacted with thumbs up emoji
if (blob == NULL) {
continue;
}
close_blob((pysqlite_Blob *)blob);
Py_DECREF(blob);
}
}

Expand Down
6 changes: 5 additions & 1 deletionObjects/weakrefobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -140,7 +140,11 @@ weakref_vectorcall(PyObject *self, PyObject *const *args,
if (!_PyArg_CheckPositional("weakref", nargs, 0, 0)) {
return NULL;
}
return Py_NewRef(PyWeakref_GET_OBJECT(self));
PyObject *obj = _PyWeakref_GET_REF(self);
if (obj == NULL) {
Py_RETURN_NONE;
}
return obj;
}

static Py_hash_t
Expand Down
9 changes: 6 additions & 3 deletionsPython/pystate.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,8 @@
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
#include "pycore_pystate.h"
#include "pycore_runtime_init.h" // _PyRuntimeState_INIT
#include "pycore_sysmodule.h"
#include "pycore_sysmodule.h" // _PySys_Audit()
#include "pycore_weakref.h" // _PyWeakref_GET_REF()

/* --------------------------------------------------------------------------
CAUTION
Expand DownExpand Up@@ -2589,16 +2590,18 @@ _xidregistry_find_type(struct _xidregistry *xidregistry, PyTypeObject *cls)
{
struct _xidregitem *cur = xidregistry->head;
while (cur != NULL) {
PyObject *registered =PyWeakref_GetObject(cur->cls);
if (registered ==Py_None) {
PyObject *registered =_PyWeakref_GET_REF(cur->cls);
if (registered ==NULL) {
// The weakly ref'ed object was freed.
cur = _xidregistry_remove_entry(xidregistry, cur);
}
else {
assert(PyType_Check(registered));
if (registered == (PyObject *)cls) {
Py_DECREF(registered);
return cur;
}
Py_DECREF(registered);
cur = cur->next;
}
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp