mirror of
https://github.com/python/cpython.git
synced 2025-09-19 15:10:58 +00:00
Add "varargs" attribute.
This commit is contained in:
parent
3ddee714d1
commit
c06022966f
3 changed files with 26 additions and 9 deletions
|
@ -30,13 +30,15 @@ extern typeobject Methodtype;
|
||||||
|
|
||||||
typedef object *(*method) FPROTO((object *, object *));
|
typedef object *(*method) FPROTO((object *, object *));
|
||||||
|
|
||||||
extern object *newmethodobject PROTO((char *, method, object *));
|
extern object *newmethodobject PROTO((char *, method, object *, int));
|
||||||
extern method getmethod PROTO((object *));
|
extern method getmethod PROTO((object *));
|
||||||
extern object *getself PROTO((object *));
|
extern object *getself PROTO((object *));
|
||||||
|
extern int getvarargs PROTO((object *));
|
||||||
|
|
||||||
struct methodlist {
|
struct methodlist {
|
||||||
char *ml_name;
|
char *ml_name;
|
||||||
method ml_meth;
|
method ml_meth;
|
||||||
|
int ml_varargs;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern object *findmethod PROTO((struct methodlist *, object *, char *));
|
extern object *findmethod PROTO((struct methodlist *, object *, char *));
|
||||||
|
|
|
@ -33,13 +33,15 @@ typedef struct {
|
||||||
char *m_name;
|
char *m_name;
|
||||||
method m_meth;
|
method m_meth;
|
||||||
object *m_self;
|
object *m_self;
|
||||||
|
int m_varargs;
|
||||||
} methodobject;
|
} methodobject;
|
||||||
|
|
||||||
object *
|
object *
|
||||||
newmethodobject(name, meth, self)
|
newmethodobject(name, meth, self, varargs)
|
||||||
char *name; /* static string */
|
char *name; /* static string */
|
||||||
method meth;
|
method meth;
|
||||||
object *self;
|
object *self;
|
||||||
|
int varargs;
|
||||||
{
|
{
|
||||||
methodobject *op = NEWOBJ(methodobject, &Methodtype);
|
methodobject *op = NEWOBJ(methodobject, &Methodtype);
|
||||||
if (op != NULL) {
|
if (op != NULL) {
|
||||||
|
@ -48,6 +50,7 @@ newmethodobject(name, meth, self)
|
||||||
if (self != NULL)
|
if (self != NULL)
|
||||||
INCREF(self);
|
INCREF(self);
|
||||||
op->m_self = self;
|
op->m_self = self;
|
||||||
|
op->m_varargs = varargs;
|
||||||
}
|
}
|
||||||
return (object *)op;
|
return (object *)op;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +77,17 @@ getself(op)
|
||||||
return ((methodobject *)op) -> m_self;
|
return ((methodobject *)op) -> m_self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
getvarargs(op)
|
||||||
|
object *op;
|
||||||
|
{
|
||||||
|
if (!is_methodobject(op)) {
|
||||||
|
err_badcall();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return ((methodobject *)op) -> m_varargs;
|
||||||
|
}
|
||||||
|
|
||||||
/* Methods (the standard built-in methods, that is) */
|
/* Methods (the standard built-in methods, that is) */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -168,7 +182,8 @@ findmethod(ml, op, name)
|
||||||
return listmethods(ml);
|
return listmethods(ml);
|
||||||
for (; ml->ml_name != NULL; ml++) {
|
for (; ml->ml_name != NULL; ml++) {
|
||||||
if (strcmp(name, ml->ml_name) == 0)
|
if (strcmp(name, ml->ml_name) == 0)
|
||||||
return newmethodobject(ml->ml_name, ml->ml_meth, op);
|
return newmethodobject(ml->ml_name, ml->ml_meth,
|
||||||
|
op, ml->ml_varargs);
|
||||||
}
|
}
|
||||||
err_setstr(AttributeError, name);
|
err_setstr(AttributeError, name);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -45,7 +45,7 @@ initmodule(name, methods)
|
||||||
for (ml = methods; ml->ml_name != NULL; ml++) {
|
for (ml = methods; ml->ml_name != NULL; ml++) {
|
||||||
sprintf(namebuf, "%s.%s", name, ml->ml_name);
|
sprintf(namebuf, "%s.%s", name, ml->ml_name);
|
||||||
v = newmethodobject(strdup(namebuf), ml->ml_meth,
|
v = newmethodobject(strdup(namebuf), ml->ml_meth,
|
||||||
(object *)NULL);
|
(object *)NULL, ml->ml_varargs);
|
||||||
/* XXX The strdup'ed memory is never freed */
|
/* XXX The strdup'ed memory is never freed */
|
||||||
if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) {
|
if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) {
|
||||||
fprintf(stderr, "initializing module: %s\n", name);
|
fprintf(stderr, "initializing module: %s\n", name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue