cpython/Python/getargs.c


/* New getargs implementation */

#define PY_CXX_CONST
#include "Python.h"
#include "pycore_abstract.h"      // _PyNumber_Index()
#include "pycore_dict.h"          // _PyDict_HasOnlyStringKeys()
#include "pycore_modsupport.h"    // export _PyArg_NoKeywords()
#include "pycore_pylifecycle.h"   // _PyArg_Fini
#include "pycore_pystate.h"       // _Py_IsMainInterpreter()
#include "pycore_tuple.h"         // _PyTuple_ITEMS()
#include "pycore_pyerrors.h"      // _Py_CalculateSuggestions()

/* Export Stable ABIs (abi only) */
PyAPI_FUNC(int) _PyArg_Parse_SizeT(PyObject *, const char *, ...);
PyAPI_FUNC(int) _PyArg_ParseTuple_SizeT(PyObject *, const char *, ...);
PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywords_SizeT(PyObject *, PyObject *,
                                                  const char *, const char * const *, ...);
PyAPI_FUNC(int) _PyArg_VaParse_SizeT(PyObject *, const char *, va_list);
PyAPI_FUNC(int) _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *, PyObject *,
                                              const char *, const char * const *, va_list);

#define FLAG_COMPAT

destr_t;


/* Keep track of "objects" that have been allocated or initialized and
   which will need to be deallocated or cleaned up somehow if overall
   parsing fails.
*/
freelistentry_t;

freelist_t;

#define STATIC_FREELIST_ENTRIES

/* Forward */
static int vgetargs1_impl(PyObject *args, PyObject *const *stack, Py_ssize_t nargs,
                          const char *format, va_list *p_va, int flags);
static int vgetargs1(PyObject *, const char *, va_list *, int);
static void seterror(Py_ssize_t, const char *, int *, const char *, const char *);
static const char *convertitem(PyObject *, const char **, va_list *, int, int *,
                               char *, size_t, freelist_t *);
static const char *converttuple(PyObject *, const char **, va_list *, int,
                                int *, char *, size_t, freelist_t *);
static const char *convertsimple(PyObject *, const char **, va_list *, int,
                                 char *, size_t, freelist_t *);
static Py_ssize_t convertbuffer(PyObject *, const void **p, const char **);
static int getbuffer(PyObject *, Py_buffer *, const char**);

static int vgetargskeywords(PyObject *, PyObject *,
                            const char *, const char * const *, va_list *, int);
static int vgetargskeywordsfast(PyObject *, PyObject *,
                            struct _PyArg_Parser *, va_list *, int);
static int vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
                          PyObject *keywords, PyObject *kwnames,
                          struct _PyArg_Parser *parser,
                          va_list *p_va, int flags);
static const char *skipitem(const char **, va_list *, int);

int
PyArg_Parse(PyObject *args, const char *format, ...)
{}

PyAPI_FUNC(int)
_PyArg_Parse_SizeT(PyObject *args, const char *format, ...)
{}


int
PyArg_ParseTuple(PyObject *args, const char *format, ...)
{}

int
_PyArg_ParseTuple_SizeT(PyObject *args, const char *format, ...)
{}


int
_PyArg_ParseStack(PyObject *const *args, Py_ssize_t nargs, const char *format, ...)
{}

int
PyArg_VaParse(PyObject *args, const char *format, va_list va)
{}

int
_PyArg_VaParse_SizeT(PyObject *args, const char *format, va_list va)
{}


/* Handle cleanup of allocated memory in case of exception */

static int
cleanup_ptr(PyObject *self, void *ptr)
{}

static int
cleanup_buffer(PyObject *self, void *ptr)
{}

static int
addcleanup(void *ptr, freelist_t *freelist, destr_t destructor)
{}

static int
cleanreturn(int retval, freelist_t *freelist)
{}


static int
vgetargs1_impl(PyObject *compat_args, PyObject *const *stack, Py_ssize_t nargs, const char *format,
               va_list *p_va, int flags)
{}

static int
vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)
{}


static void
seterror(Py_ssize_t iarg, const char *msg, int *levels, const char *fname,
         const char *message)
{}


/* Convert a tuple argument.
   On entry, *p_format points to the character _after_ the opening '('.
   On successful exit, *p_format points to the closing ')'.
   If successful:
      *p_format and *p_va are updated,
      *levels and *msgbuf are untouched,
      and NULL is returned.
   If the argument is invalid:
      *p_format is unchanged,
      *p_va is undefined,
      *levels is a 0-terminated list of item numbers,
      *msgbuf contains an error message, whose format is:
     "must be <typename1>, not <typename2>", where:
        <typename1> is the name of the expected type, and
        <typename2> is the name of the actual type,
      and msgbuf is returned.
*/

static const char *
converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
             int *levels, char *msgbuf, size_t bufsize,
             freelist_t *freelist)
{}


/* Convert a single item. */

static const char *
convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,
            int *levels, char *msgbuf, size_t bufsize, freelist_t *freelist)
{}



/* Format an error message generated by convertsimple().
   displayname must be UTF-8 encoded.
*/

void
_PyArg_BadArgument(const char *fname, const char *displayname,
                   const char *expected, PyObject *arg)
{}

static const char *
converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
{}

static const char *
convertcharerr(const char *expected, const char *what, Py_ssize_t size,
               char *msgbuf, size_t bufsize)
{}

#define CONV_UNICODE

/* Convert a non-tuple argument.  Return NULL if conversion went OK,
   or a string with a message describing the failure.  The message is
   formatted as "must be <desired type>, not <actual type>".
   When failing, an exception may or may not have been raised.
   Don't call if a tuple is expected.

   When you add new format codes, please don't forget poor skipitem() below.
*/

static const char *
convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
              char *msgbuf, size_t bufsize, freelist_t *freelist)
{}

static Py_ssize_t
convertbuffer(PyObject *arg, const void **p, const char **errmsg)
{}

static int
getbuffer(PyObject *arg, Py_buffer *view, const char **errmsg)
{}

/* Support for keyword arguments donated by
   Geoff Philbrick <[email protected]> */

/* Return false (0) for error, else true. */
int
PyArg_ParseTupleAndKeywords(PyObject *args,
                            PyObject *keywords,
                            const char *format,
                            const char * const *kwlist, ...)
{}

int
_PyArg_ParseTupleAndKeywords_SizeT(PyObject *args,
                                  PyObject *keywords,
                                  const char *format,
                                  const char * const *kwlist, ...)
{}


int
PyArg_VaParseTupleAndKeywords(PyObject *args,
                              PyObject *keywords,
                              const char *format,
                              const char * const *kwlist, va_list va)
{}

int
_PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
                                    PyObject *keywords,
                                    const char *format,
                                    const char * const *kwlist, va_list va)
{}

PyAPI_FUNC(int)
_PyArg_ParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords,
                            struct _PyArg_Parser *parser, ...)
{}

int
_PyArg_ParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords,
                            struct _PyArg_Parser *parser, ...)
{}

int
_PyArg_ParseStackAndKeywords(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames,
                  struct _PyArg_Parser *parser, ...)
{}

int
_PyArg_ParseStackAndKeywords_SizeT(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames,
                        struct _PyArg_Parser *parser, ...)
{}


static void
error_unexpected_keyword_arg(PyObject *kwargs, PyObject *kwnames, PyObject *kwtuple, const char *fname)
{}

int
PyArg_ValidateKeywordArguments(PyObject *kwargs)
{}

static PyObject *
new_kwtuple(const char * const *keywords, int total, int pos);

#define IS_END_OF_FORMAT(c)

static int
vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
                 const char * const *kwlist, va_list *p_va, int flags)
{}


static int
scan_keywords(const char * const *keywords, int *ptotal, int *pposonly)
{}

static int
parse_format(const char *format, int total, int npos,
             const char **pfname, const char **pcustommsg,
             int *pmin, int *pmax)
{}

static PyObject *
new_kwtuple(const char * const *keywords, int total, int pos)
{}

static int
_parser_init(void *arg)
{}

static int
parser_init(struct _PyArg_Parser *parser)
{}

static void
parser_clear(struct _PyArg_Parser *parser)
{}

static PyObject*
find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
{}

static int
vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
                          PyObject *kwargs, PyObject *kwnames,
                          struct _PyArg_Parser *parser,
                          va_list *p_va, int flags)
{}

static int
vgetargskeywordsfast(PyObject *args, PyObject *keywords,
                     struct _PyArg_Parser *parser, va_list *p_va, int flags)
{}


#undef _PyArg_UnpackKeywords

PyObject * const *
_PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs,
                      PyObject *kwargs, PyObject *kwnames,
                      struct _PyArg_Parser *parser,
                      int minpos, int maxpos, int minkw, int varpos,
                      PyObject **buf)
{}

static const char *
skipitem(const char **p_format, va_list *p_va, int flags)
{}


#undef _PyArg_CheckPositional

int
_PyArg_CheckPositional(const char *name, Py_ssize_t nargs,
                       Py_ssize_t min, Py_ssize_t max)
{}

static int
unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
             Py_ssize_t min, Py_ssize_t max, va_list vargs)
{}

int
PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...)
{}

int
_PyArg_UnpackStack(PyObject *const *args, Py_ssize_t nargs, const char *name,
                   Py_ssize_t min, Py_ssize_t max, ...)
{}


#undef _PyArg_NoKeywords
#undef _PyArg_NoKwnames
#undef _PyArg_NoPositional

/* For type constructors that don't take keyword args
 *
 * Sets a TypeError and returns 0 if the args/kwargs is
 * not empty, returns 1 otherwise
 */
int
_PyArg_NoKeywords(const char *funcname, PyObject *kwargs)
{}

int
_PyArg_NoPositional(const char *funcname, PyObject *args)
{}

int
_PyArg_NoKwnames(const char *funcname, PyObject *kwnames)
{}

void
_PyArg_Fini(void)
{}