mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Make CObjects mutable. Fixes #477441.
This commit is contained in:
parent
95cf84a4f3
commit
01a74b2fa1
4 changed files with 30 additions and 5 deletions
|
@ -2479,34 +2479,40 @@ information on using these objects.
|
||||||
\end{ctypedesc}
|
\end{ctypedesc}
|
||||||
|
|
||||||
\begin{cfuncdesc}{int}{PyCObject_Check}{PyObject *p}
|
\begin{cfuncdesc}{int}{PyCObject_Check}{PyObject *p}
|
||||||
Returns true if its argument is a \ctype{PyCObject}.
|
Return true if its argument is a \ctype{PyCObject}.
|
||||||
\end{cfuncdesc}
|
\end{cfuncdesc}
|
||||||
|
|
||||||
\begin{cfuncdesc}{PyObject*}{PyCObject_FromVoidPtr}{void* cobj,
|
\begin{cfuncdesc}{PyObject*}{PyCObject_FromVoidPtr}{void* cobj,
|
||||||
void (*destr)(void *)}
|
void (*destr)(void *)}
|
||||||
Creates a \ctype{PyCObject} from the \code{void *}\var{cobj}. The
|
Create a \ctype{PyCObject} from the \code{void *}\var{cobj}. The
|
||||||
\var{destr} function will be called when the object is reclaimed,
|
\var{destr} function will be called when the object is reclaimed,
|
||||||
unless it is \NULL.
|
unless it is \NULL.
|
||||||
\end{cfuncdesc}
|
\end{cfuncdesc}
|
||||||
|
|
||||||
\begin{cfuncdesc}{PyObject*}{PyCObject_FromVoidPtrAndDesc}{void* cobj,
|
\begin{cfuncdesc}{PyObject*}{PyCObject_FromVoidPtrAndDesc}{void* cobj,
|
||||||
void* desc, void (*destr)(void *, void *)}
|
void* desc, void (*destr)(void *, void *)}
|
||||||
Creates a \ctype{PyCObject} from the \ctype{void *}\var{cobj}. The
|
Create a \ctype{PyCObject} from the \ctype{void *}\var{cobj}. The
|
||||||
\var{destr} function will be called when the object is reclaimed.
|
\var{destr} function will be called when the object is reclaimed.
|
||||||
The \var{desc} argument can be used to pass extra callback data for
|
The \var{desc} argument can be used to pass extra callback data for
|
||||||
the destructor function.
|
the destructor function.
|
||||||
\end{cfuncdesc}
|
\end{cfuncdesc}
|
||||||
|
|
||||||
\begin{cfuncdesc}{void*}{PyCObject_AsVoidPtr}{PyObject* self}
|
\begin{cfuncdesc}{void*}{PyCObject_AsVoidPtr}{PyObject* self}
|
||||||
Returns the object \ctype{void *} that the \ctype{PyCObject}
|
Return the object \ctype{void *} that the \ctype{PyCObject}
|
||||||
\var{self} was created with.
|
\var{self} was created with.
|
||||||
\end{cfuncdesc}
|
\end{cfuncdesc}
|
||||||
|
|
||||||
\begin{cfuncdesc}{void*}{PyCObject_GetDesc}{PyObject* self}
|
\begin{cfuncdesc}{void*}{PyCObject_GetDesc}{PyObject* self}
|
||||||
Returns the description \ctype{void *} that the \ctype{PyCObject}
|
Return the description \ctype{void *} that the \ctype{PyCObject}
|
||||||
\var{self} was created with.
|
\var{self} was created with.
|
||||||
\end{cfuncdesc}
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
\begin{cfuncdesc}{int}{PyCObject_SetVoidPtr}{PyObject* self, void* cobj}
|
||||||
|
Set the void pointer inside \var{self} to \var{cobj}.
|
||||||
|
The \ctype{PyCObject} must not have an associated destructor.
|
||||||
|
Return true on success, false on failure.
|
||||||
|
\end{cfuncdesc}
|
||||||
|
|
||||||
|
|
||||||
\subsection{Cell Objects \label{cell-objects}}
|
\subsection{Cell Objects \label{cell-objects}}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,9 @@ PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
|
||||||
/* Import a pointer to a C object from a module using a PyCObject. */
|
/* Import a pointer to a C object from a module using a PyCObject. */
|
||||||
PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
|
PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
|
||||||
|
|
||||||
|
/* Modify a C object. Fails (==0) if object has a destructor. */
|
||||||
|
PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,6 +12,8 @@ What's New in Python 2.4 alpha 1?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- CObjects are now mutable (on the C level) through PyCObject_SetVoidPtr.
|
||||||
|
|
||||||
- list.sort() now supports three keyword arguments: cmp, key, and reverse.
|
- list.sort() now supports three keyword arguments: cmp, key, and reverse.
|
||||||
The key argument can be a function of one argument that extracts a
|
The key argument can be a function of one argument that extracts a
|
||||||
comparison key from the original record: mylist.sort(key=str.lower).
|
comparison key from the original record: mylist.sort(key=str.lower).
|
||||||
|
|
|
@ -99,6 +99,20 @@ PyCObject_Import(char *module_name, char *name)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
PyCObject_SetVoidPtr(PyObject *_self, void *cobj)
|
||||||
|
{
|
||||||
|
PyCObject* self = (PyCObject*)_self;
|
||||||
|
if (self == NULL || !PyCObject_Check(self) ||
|
||||||
|
self->destructor != NULL) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"Invalid call to PyCObject_SetVoidPtr");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
self->cobject = cobj;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PyCObject_dealloc(PyCObject *self)
|
PyCObject_dealloc(PyCObject *self)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue