summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c261
1 files changed, 108 insertions, 153 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index c0b3624..abe0887 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -1401,6 +1401,7 @@ _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
return retval;
}
+#define IS_END_OF_FORMAT(c) (c == '\0' || c == ';' || c == ':')
static int
vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
@@ -1408,13 +1409,10 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
{
char msgbuf[512];
int levels[32];
- const char *fname, *message;
- int min, max;
- const char *formatsave;
+ const char *fname, *msg, *custom_msg, *keyword;
+ int min = INT_MAX;
int i, len, nargs, nkeywords;
- const char *msg;
- char **p;
- PyObject *freelist = NULL;
+ PyObject *freelist = NULL, *current_arg;
assert(args != NULL && PyTuple_Check(args));
assert(keywords == NULL || PyDict_Check(keywords));
@@ -1422,168 +1420,108 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
assert(kwlist != NULL);
assert(p_va != NULL);
- /* Search the format:
- message <- error msg, if any (else NULL).
- fname <- routine name, if any (else NULL).
- min <- # of required arguments, or -1 if all are required.
- max <- most arguments (required + optional).
- Check that kwlist has a non-NULL entry for each arg.
- Raise error if a tuple arg spec is found.
- */
- fname = message = NULL;
- formatsave = format;
- p = kwlist;
- min = -1;
- max = 0;
- while ((i = *format++) != '\0') {
- if (isalpha(Py_CHARMASK(i)) && i != 'e') {
- max++;
- if (*p == NULL) {
- PyErr_SetString(PyExc_RuntimeError,
- "more argument specifiers than "
- "keyword list entries");
- return 0;
- }
- p++;
- }
- else if (i == '|')
- min = max;
- else if (i == ':') {
- fname = format;
- break;
- }
- else if (i == ';') {
- message = format;
- break;
- }
- else if (i == '(') {
- PyErr_SetString(PyExc_RuntimeError,
- "tuple found in format when using keyword "
- "arguments");
- return 0;
- }
- }
- format = formatsave;
- if (*p != NULL) {
- PyErr_SetString(PyExc_RuntimeError,
- "more keyword list entries than "
- "argument specifiers");
- return 0;
- }
- if (min < 0) {
- /* All arguments are required. */
- min = max;
+ /* grab the function name or custom error msg first (mutually exclusive) */
+ fname = strchr(format, ':');
+ if (fname) {
+ fname++;
+ custom_msg = NULL;
}
-
- nargs = PyTuple_GET_SIZE(args);
- nkeywords = keywords == NULL ? 0 : PyDict_Size(keywords);
-
- /* make sure there are no duplicate values for an argument;
- its not clear when to use the term "keyword argument vs.
- keyword parameter in messages */
- if (nkeywords > 0) {
- for (i = 0; i < nargs; i++) {
- const char *thiskw = kwlist[i];
- if (thiskw == NULL)
- break;
- if (PyDict_GetItemString(keywords, thiskw)) {
- PyErr_Format(PyExc_TypeError,
- "keyword parameter '%s' was given "
- "by position and by name",
- thiskw);
- return 0;
- }
- else if (PyErr_Occurred())
- return 0;
- }
+ else {
+ custom_msg = strchr(format,';');
+ if (custom_msg)
+ custom_msg++;
}
- /* required arguments missing from args can be supplied by keyword
- arguments; set len to the number of positional arguments, and,
- if that's less than the minimum required, add in the number of
- required arguments that are supplied by keywords */
- len = nargs;
- if (nkeywords > 0 && nargs < min) {
- for (i = nargs; i < min; i++) {
- if (PyDict_GetItemString(keywords, kwlist[i]))
- len++;
- else if (PyErr_Occurred())
- return 0;
- }
- }
+ /* scan kwlist and get greatest possible nbr of args */
+ for (len=0; kwlist[len]; len++)
+ continue;
- /* make sure we got an acceptable number of arguments; the message
- is a little confusing with keywords since keyword arguments
- which are supplied, but don't match the required arguments
- are not included in the "%d given" part of the message
- XXX and this isn't a bug!? */
- if (len < min || max < len) {
- if (message == NULL) {
- PyOS_snprintf(msgbuf, sizeof(msgbuf),
- "%.200s%s takes %s %d argument%s "
- "(%d given)",
- fname==NULL ? "function" : fname,
- fname==NULL ? "" : "()",
- min==max ? "exactly"
- : len < min ? "at least" : "at most",
- len < min ? min : max,
- (len < min ? min : max) == 1 ? "" : "s",
- len);
- message = msgbuf;
- }
- PyErr_SetString(PyExc_TypeError, message);
+ nargs = PyTuple_GET_SIZE(args);
+ nkeywords = (keywords == NULL) ? 0 : PyDict_Size(keywords);
+ if (nargs + nkeywords > len) {
+ PyErr_Format(PyExc_TypeError, "%s%s takes at most %d "
+ "argument%s (%d given)",
+ (fname == NULL) ? "function" : fname,
+ (fname == NULL) ? "" : "()",
+ len,
+ (len == 1) ? "" : "s",
+ nargs + nkeywords);
return 0;
}
- /* convert the positional arguments */
- for (i = 0; i < nargs; i++) {
- if (*format == '|')
+ /* convert tuple args and keyword args in same loop, using kwlist to drive process */
+ for (i = 0; i < len; i++) {
+ keyword = kwlist[i];
+ if (*format == '|') {
+ min = i;
format++;
- msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va,
- flags, levels, msgbuf, sizeof(msgbuf),
- &freelist);
- if (msg) {
- seterror(i+1, msg, levels, fname, message);
+ }
+ if (IS_END_OF_FORMAT(*format)) {
+ PyErr_Format(PyExc_RuntimeError,
+ "More keyword list entries (%d) than "
+ "format specifiers (%d)", len, i);
return cleanreturn(0, freelist);
}
- }
-
- /* handle no keyword parameters in call */
- if (nkeywords == 0)
- return cleanreturn(1, freelist);
-
- /* convert the keyword arguments; this uses the format
- string where it was left after processing args */
- for (i = nargs; i < max; i++) {
- PyObject *item;
- if (*format == '|')
- format++;
- item = PyDict_GetItemString(keywords, kwlist[i]);
- if (item != NULL) {
- Py_INCREF(item);
- msg = convertitem(item, &format, p_va, flags, levels,
- msgbuf, sizeof(msgbuf), &freelist);
- Py_DECREF(item);
- if (msg) {
- seterror(i+1, msg, levels, fname, message);
+ current_arg = NULL;
+ if (nkeywords) {
+ current_arg = PyDict_GetItemString(keywords, keyword);
+ }
+ if (current_arg) {
+ --nkeywords;
+ if (i < nargs) {
+ /* arg present in tuple and in dict */
+ PyErr_Format(PyExc_TypeError,
+ "Argument given by name ('%s') "
+ "and position (%d)",
+ keyword, i+1);
return cleanreturn(0, freelist);
}
- --nkeywords;
- if (nkeywords == 0)
- break;
}
- else if (PyErr_Occurred())
+ else if (nkeywords && PyErr_Occurred())
return cleanreturn(0, freelist);
- else {
- msg = skipitem(&format, p_va, flags);
+ else if (i < nargs)
+ current_arg = PyTuple_GET_ITEM(args, i);
+
+ if (current_arg) {
+ msg = convertitem(current_arg, &format, p_va, flags,
+ levels, msgbuf, sizeof(msgbuf), &freelist);
if (msg) {
- levels[0] = 0;
- seterror(i+1, msg, levels, fname, message);
+ seterror(i+1, msg, levels, fname, custom_msg);
return cleanreturn(0, freelist);
}
+ continue;
+ }
+
+ if (i < min) {
+ PyErr_Format(PyExc_TypeError, "Required argument "
+ "'%s' (pos %d) not found",
+ keyword, i+1);
+ return cleanreturn(0, freelist);
+ }
+ /* current code reports success when all required args
+ * fulfilled and no keyword args left, with no further
+ * validation. XXX Maybe skip this in debug build ?
+ */
+ if (!nkeywords)
+ return cleanreturn(1, freelist);
+
+ /* We are into optional args, skip thru to any remaining
+ * keyword args */
+ msg = skipitem(&format, p_va, flags);
+ if (msg) {
+ PyErr_Format(PyExc_RuntimeError, "%s: '%s'", msg,
+ format);
+ return cleanreturn(0, freelist);
}
}
+ if (!IS_END_OF_FORMAT(*format)) {
+ PyErr_Format(PyExc_RuntimeError,
+ "more argument specifiers than keyword list entries "
+ "(remaining format:'%s')", format);
+ return cleanreturn(0, freelist);
+ }
+
/* make sure there are no extraneous keyword arguments */
if (nkeywords > 0) {
PyObject *key, *value;
@@ -1597,7 +1535,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
return cleanreturn(0, freelist);
}
ks = PyUnicode_AsString(key);
- for (i = 0; i < max; i++) {
+ for (i = 0; i < len; i++) {
if (!strcmp(ks, kwlist[i])) {
match = 1;
break;
@@ -1620,7 +1558,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
static char *
skipitem(const char **p_format, va_list *p_va, int flags)
{
- const char *format = *p_format;
+ const char *format = *p_format;
char c = *format++;
switch (c) {
@@ -1726,15 +1664,32 @@ skipitem(const char **p_format, va_list *p_va, int flags)
break;
}
+ case '(': /* bypass tuple, not handled at all previously */
+ {
+ char *msg;
+ for (;;) {
+ if (*format==')')
+ break;
+ if (IS_END_OF_FORMAT(*format))
+ return "Unmatched left paren in format "
+ "string";
+ msg = skipitem(&format, p_va, flags);
+ if (msg)
+ return msg;
+ }
+ format++;
+ break;
+ }
+
+ case ')':
+ return "Unmatched right paren in format string";
+
default:
err:
return "impossible<bad format char>";
}
- /* The "(...)" format code for tuples is not handled here because
- * it is not allowed with keyword args. */
-
*p_format = format;
return NULL;
}
n value='experiment'>experiment Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
path: root/libtommath
diff options
context:
space:
mode:
Diffstat (limited to 'libtommath')
-rw-r--r--libtommath/README.md4
-rw-r--r--libtommath/TODO16
-rw-r--r--libtommath/bn_error.c6
-rw-r--r--libtommath/bn_fast_mp_invmod.c6
-rw-r--r--libtommath/bn_fast_mp_montgomery_reduce.c6
-rw-r--r--libtommath/bn_fast_s_mp_mul_digs.c6
-rw-r--r--libtommath/bn_fast_s_mp_mul_high_digs.c6
-rw-r--r--libtommath/bn_fast_s_mp_sqr.c6
-rw-r--r--libtommath/bn_mp_2expt.c6
-rw-r--r--libtommath/bn_mp_abs.c6
-rw-r--r--libtommath/bn_mp_add.c6
-rw-r--r--libtommath/bn_mp_add_d.c6
-rw-r--r--libtommath/bn_mp_addmod.c6
-rw-r--r--libtommath/bn_mp_and.c6
-rw-r--r--libtommath/bn_mp_clamp.c6
-rw-r--r--libtommath/bn_mp_clear.c6
-rw-r--r--libtommath/bn_mp_clear_multi.c6
-rw-r--r--libtommath/bn_mp_cmp.c6
-rw-r--r--libtommath/bn_mp_cmp_d.c6
-rw-r--r--libtommath/bn_mp_cmp_mag.c6
-rw-r--r--libtommath/bn_mp_cnt_lsb.c6
-rw-r--r--libtommath/bn_mp_copy.c6
-rw-r--r--libtommath/bn_mp_count_bits.c6
-rw-r--r--libtommath/bn_mp_div.c6
-rw-r--r--libtommath/bn_mp_div_2.c6
-rw-r--r--libtommath/bn_mp_div_2d.c6
-rw-r--r--libtommath/bn_mp_div_3.c6
-rw-r--r--libtommath/bn_mp_div_d.c6
-rw-r--r--libtommath/bn_mp_dr_is_modulus.c6
-rw-r--r--libtommath/bn_mp_dr_reduce.c6
-rw-r--r--libtommath/bn_mp_dr_setup.c6
-rw-r--r--libtommath/bn_mp_exch.c6
-rw-r--r--libtommath/bn_mp_export.c6
-rw-r--r--libtommath/bn_mp_expt_d.c6
-rw-r--r--libtommath/bn_mp_expt_d_ex.c6
-rw-r--r--libtommath/bn_mp_exptmod.c6
-rw-r--r--libtommath/bn_mp_exptmod_fast.c6
-rw-r--r--libtommath/bn_mp_exteuclid.c6
-rw-r--r--libtommath/bn_mp_fread.c6
-rw-r--r--libtommath/bn_mp_fwrite.c6
-rw-r--r--libtommath/bn_mp_gcd.c6
-rw-r--r--libtommath/bn_mp_get_int.c6
-rw-r--r--libtommath/bn_mp_grow.c6
-rw-r--r--libtommath/bn_mp_import.c6
-rw-r--r--libtommath/bn_mp_init.c6
-rw-r--r--libtommath/bn_mp_init_copy.c6
-rw-r--r--libtommath/bn_mp_init_multi.c6
-rw-r--r--libtommath/bn_mp_init_set.c6
-rw-r--r--libtommath/bn_mp_init_set_int.c6
-rw-r--r--libtommath/bn_mp_init_size.c6
-rw-r--r--libtommath/bn_mp_invmod.c6
-rw-r--r--libtommath/bn_mp_invmod_slow.c6
-rw-r--r--libtommath/bn_mp_is_square.c6
-rw-r--r--libtommath/bn_mp_jacobi.c6
-rw-r--r--libtommath/bn_mp_karatsuba_mul.c6
-rw-r--r--libtommath/bn_mp_karatsuba_sqr.c6
-rw-r--r--libtommath/bn_mp_lcm.c6
-rw-r--r--libtommath/bn_mp_lshd.c6
-rw-r--r--libtommath/bn_mp_mod.c6
-rw-r--r--libtommath/bn_mp_mod_2d.c6
-rw-r--r--libtommath/bn_mp_mod_d.c6
-rw-r--r--libtommath/bn_mp_montgomery_calc_normalization.c6
-rw-r--r--libtommath/bn_mp_montgomery_reduce.c6
-rw-r--r--libtommath/bn_mp_montgomery_setup.c6
-rw-r--r--libtommath/bn_mp_mul.c6
-rw-r--r--libtommath/bn_mp_mul_2.c6
-rw-r--r--libtommath/bn_mp_mul_2d.c6
-rw-r--r--libtommath/bn_mp_mul_d.c6
-rw-r--r--libtommath/bn_mp_mulmod.c6
-rw-r--r--libtommath/bn_mp_n_root.c6
-rw-r--r--libtommath/bn_mp_n_root_ex.c6
-rw-r--r--libtommath/bn_mp_neg.c6
-rw-r--r--libtommath/bn_mp_or.c6
-rw-r--r--libtommath/bn_mp_prime_fermat.c6
-rw-r--r--libtommath/bn_mp_prime_is_divisible.c6
-rw-r--r--libtommath/bn_mp_prime_is_prime.c6
-rw-r--r--libtommath/bn_mp_prime_miller_rabin.c6
-rw-r--r--libtommath/bn_mp_prime_next_prime.c6
-rw-r--r--libtommath/bn_mp_prime_rabin_miller_trials.c6
-rw-r--r--libtommath/bn_mp_prime_random_ex.c6
-rw-r--r--libtommath/bn_mp_radix_size.c6
-rw-r--r--libtommath/bn_mp_radix_smap.c6
-rw-r--r--libtommath/bn_mp_rand.c6
-rw-r--r--libtommath/bn_mp_read_radix.c6
-rw-r--r--libtommath/bn_mp_read_signed_bin.c6
-rw-r--r--libtommath/bn_mp_read_unsigned_bin.c6
-rw-r--r--libtommath/bn_mp_reduce.c6
-rw-r--r--libtommath/bn_mp_reduce_2k.c6
-rw-r--r--libtommath/bn_mp_reduce_2k_l.c6
-rw-r--r--libtommath/bn_mp_reduce_2k_setup.c6
-rw-r--r--libtommath/bn_mp_reduce_2k_setup_l.c6
-rw-r--r--libtommath/bn_mp_reduce_is_2k.c6
-rw-r--r--libtommath/bn_mp_reduce_is_2k_l.c6
-rw-r--r--libtommath/bn_mp_reduce_setup.c6
-rw-r--r--libtommath/bn_mp_rshd.c6
-rw-r--r--libtommath/bn_mp_set.c6
-rw-r--r--libtommath/bn_mp_set_int.c6
-rw-r--r--libtommath/bn_mp_set_long.c6
-rw-r--r--libtommath/bn_mp_set_long_long.c6
-rw-r--r--libtommath/bn_mp_shrink.c6
-rw-r--r--libtommath/bn_mp_signed_bin_size.c6
-rw-r--r--libtommath/bn_mp_sqr.c6
-rw-r--r--libtommath/bn_mp_sqrmod.c6
-rw-r--r--libtommath/bn_mp_sqrt.c6
-rw-r--r--libtommath/bn_mp_sub.c6
-rw-r--r--libtommath/bn_mp_sub_d.c6
-rw-r--r--libtommath/bn_mp_submod.c6
-rw-r--r--libtommath/bn_mp_to_signed_bin.c6
-rw-r--r--libtommath/bn_mp_to_signed_bin_n.c6
-rw-r--r--libtommath/bn_mp_to_unsigned_bin.c6
-rw-r--r--libtommath/bn_mp_to_unsigned_bin_n.c6
-rw-r--r--libtommath/bn_mp_toom_mul.c6
-rw-r--r--libtommath/bn_mp_toom_sqr.c6
-rw-r--r--libtommath/bn_mp_toradix.c6
-rw-r--r--libtommath/bn_mp_toradix_n.c6
-rw-r--r--libtommath/bn_mp_unsigned_bin_size.c6
-rw-r--r--libtommath/bn_mp_xor.c6
-rw-r--r--libtommath/bn_mp_zero.c6
-rw-r--r--libtommath/bn_prime_tab.c6
-rw-r--r--libtommath/bn_reverse.c6
-rw-r--r--libtommath/bn_s_mp_add.c6
-rw-r--r--libtommath/bn_s_mp_exptmod.c6
-rw-r--r--libtommath/bn_s_mp_mul_digs.c6
-rw-r--r--libtommath/bn_s_mp_mul_high_digs.c6
-rw-r--r--libtommath/bn_s_mp_sqr.c6
-rw-r--r--libtommath/bn_s_mp_sub.c6
-rw-r--r--libtommath/bncore.c6
-rw-r--r--libtommath/makefile.include105
-rw-r--r--libtommath/tommath.h6
-rw-r--r--libtommath/tommath_private.h6
-rw-r--r--libtommath/tommath_superclass.h6
131 files changed, 387 insertions, 506 deletions
diff --git a/libtommath/README.md b/libtommath/README.md
index 866f024..4c5da71 100644
--- a/libtommath/README.md
+++ b/libtommath/README.md
@@ -1,4 +1,6 @@
-[![Build Status](https://travis-ci.org/libtom/libtommath.png?branch=develop)](https://travis-ci.org/libtom/libtommath)
+[![Build Status - master](https://travis-ci.org/libtom/libtommath.png?branch=master)](https://travis-ci.org/libtom/libtommath)
+
+[![Build Status - develop](https://travis-ci.org/libtom/libtommath.png?branch=develop)](https://travis-ci.org/libtom/libtommath)
This is the git repository for [LibTomMath](http://www.libtom.org/), a free open source portable number theoretic multiple-precision integer (MPI) library written entirely in C.
diff --git a/libtommath/TODO b/libtommath/TODO
deleted file mode 100644
index deffba1..0000000
--- a/libtommath/TODO
+++ /dev/null
@@ -1,16 +0,0 @@
-things for book in order of importance...
-
-- Fix up pseudo-code [only] for combas that are not consistent with source
-- Start in chapter 3 [basics] and work up...
- - re-write to prose [less abrupt]
- - clean up pseudo code [spacing]
- - more examples where appropriate and figures
-
-Goal:
- - Get sync done by mid January [roughly 8-12 hours work]
- - Finish ch3-6 by end of January [roughly 12-16 hours of work]
- - Finish ch7-end by mid Feb [roughly 20-24 hours of work].
-
-Goal isn't "first edition" but merely cleaner to read.
-
-
diff --git a/libtommath/bn_error.c b/libtommath/bn_error.c
index 380f46a..0d77411 100644
--- a/libtommath/bn_error.c
+++ b/libtommath/bn_error.c
@@ -42,6 +42,6 @@ const char *mp_error_to_string(int code)
#endif
-/* ref: tag: v1.0.1, master */
-/* git commit: 5953f62e42b24af93748b1ee5e1d062e242c2546 */
-/* commit time: 2017-08-29 22:27:36 +0200 */
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/libtommath/bn_fast_mp_invmod.c b/libtommath/bn_fast_mp_invmod.c