Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e4616e67
Commit
e4616e67
authored
Oct 23, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fulton, based on code Jim supplied.
parent
4855b025
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
Include/modsupport.h
Include/modsupport.h
+1
-0
Python/getargs.c
Python/getargs.c
+60
-0
No files found.
Include/modsupport.h
View file @
e4616e67
...
...
@@ -13,6 +13,7 @@ extern DL_IMPORT(int) PyArg_Parse(PyObject *, char *, ...);
extern
DL_IMPORT
(
int
)
PyArg_ParseTuple
(
PyObject
*
,
char
*
,
...);
extern
DL_IMPORT
(
int
)
PyArg_ParseTupleAndKeywords
(
PyObject
*
,
PyObject
*
,
char
*
,
char
**
,
...);
extern
DL_IMPORT
(
int
)
PyArg_UnpackTuple
(
PyObject
*
,
char
*
,
int
,
int
,
...);
extern
DL_IMPORT
(
PyObject
*
)
Py_BuildValue
(
char
*
,
...);
extern
DL_IMPORT
(
int
)
PyArg_VaParse
(
PyObject
*
,
char
*
,
va_list
);
...
...
Python/getargs.c
View file @
e4616e67
...
...
@@ -1360,3 +1360,63 @@ skipitem(char **p_format, va_list *p_va)
*
p_format
=
format
;
return
NULL
;
}
int
PyArg_UnpackTuple
(
PyObject
*
args
,
char
*
name
,
int
min
,
int
max
,
...)
{
int
i
,
l
;
PyObject
**
o
;
va_list
vargs
;
#ifdef HAVE_STDARG_PROTOTYPES
va_start
(
vargs
,
max
);
#else
va_start
(
vargs
);
#endif
assert
(
min
>=
0
);
assert
(
min
<=
max
);
if
(
!
PyTuple_Check
(
args
))
{
PyErr_SetString
(
PyExc_SystemError
,
"PyArg_UnpackTuple() argument list is not a tuple"
);
return
0
;
}
l
=
PyTuple_GET_SIZE
(
args
);
if
(
l
<
min
)
{
if
(
name
!=
NULL
)
PyErr_Format
(
PyExc_TypeError
,
"%s expected %s%d arguments, got %d"
,
name
,
(
min
==
max
?
""
:
"at least "
),
min
,
l
);
else
PyErr_Format
(
PyExc_TypeError
,
"unpacked tuple should have %s%d elements,"
" but has %d"
,
(
min
==
max
?
""
:
"at least "
),
min
,
l
);
va_end
(
vargs
);
return
0
;
}
if
(
l
>
max
)
{
if
(
name
!=
NULL
)
PyErr_Format
(
PyExc_TypeError
,
"%s expected %s%d arguments, got %d"
,
name
,
(
min
==
max
?
""
:
"at most "
),
max
,
l
);
else
PyErr_Format
(
PyExc_TypeError
,
"unpacked tuple should have %s%d elements,"
" but has %d"
,
(
min
==
max
?
""
:
"at most "
),
max
,
l
);
va_end
(
vargs
);
return
0
;
}
for
(
i
=
0
;
i
<
l
;
i
++
)
{
o
=
va_arg
(
vargs
,
PyObject
**
);
*
o
=
PyTuple_GET_ITEM
(
args
,
i
);
}
va_end
(
vargs
);
return
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment