mirror of https://github.com/python/cpython.git
Fixed a bit (still no warranties).
This commit is contained in:
parent
59b3590711
commit
320a5ccbdc
|
@ -1,5 +1,17 @@
|
||||||
|
/* Use this file as a template to start implementing a new object type.
|
||||||
|
If your objects will be called foobar, start by copying this file to
|
||||||
|
foobarobject.c, changing all occurrences of xx to foobar and all
|
||||||
|
occurrences of Xx by Foobar. You will probably want to delete all
|
||||||
|
references to 'x_attr' and add your own types of attributes
|
||||||
|
instead. Maybe you want to name your local variables other than
|
||||||
|
'xp'. If your object type is needed in other files, you'll have to
|
||||||
|
create a file "foobarobject.h"; see intobject.h for an example. */
|
||||||
|
|
||||||
|
|
||||||
/* Xx objects */
|
/* Xx objects */
|
||||||
|
|
||||||
|
#include "allobjects.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OB_HEAD
|
OB_HEAD
|
||||||
object *x_attr; /* Attributes dictionary */
|
object *x_attr; /* Attributes dictionary */
|
||||||
|
@ -7,6 +19,8 @@ typedef struct {
|
||||||
|
|
||||||
extern typeobject Xxtype; /* Really static, forward */
|
extern typeobject Xxtype; /* Really static, forward */
|
||||||
|
|
||||||
|
#define is_xxobject(v) ((v)->ob_type == &Xxtype)
|
||||||
|
|
||||||
static xxobject *
|
static xxobject *
|
||||||
newxxobject(arg)
|
newxxobject(arg)
|
||||||
object *arg;
|
object *arg;
|
||||||
|
@ -25,8 +39,7 @@ static void
|
||||||
xx_dealloc(xp)
|
xx_dealloc(xp)
|
||||||
xxobject *xp;
|
xxobject *xp;
|
||||||
{
|
{
|
||||||
if (xp->x_attr != NULL)
|
XDECREF(xp->x_attr);
|
||||||
DECREF(xp->x_attr);
|
|
||||||
DEL(xp);
|
DEL(xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +83,7 @@ xx_setattr(xp, name, v)
|
||||||
if (xp->x_attr == NULL) {
|
if (xp->x_attr == NULL) {
|
||||||
xp->x_attr = newdictobject();
|
xp->x_attr = newdictobject();
|
||||||
if (xp->x_attr == NULL)
|
if (xp->x_attr == NULL)
|
||||||
return errno;
|
return -1;
|
||||||
}
|
}
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return dictremove(xp->x_attr, name);
|
return dictremove(xp->x_attr, name);
|
||||||
|
|
Loading…
Reference in New Issue