1 //////////////////// ArgTypeTest.proto ////////////////////
3 static CYTHON_INLINE
int __Pyx_ArgTypeTest(PyObject
*obj
, PyTypeObject
*type
, int none_allowed
,
4 const char *name
, int exact
); /*proto*/
6 //////////////////// ArgTypeTest ////////////////////
8 static void __Pyx_RaiseArgumentTypeInvalid(const char* name
, PyObject
*obj
, PyTypeObject
*type
) {
9 PyErr_Format(PyExc_TypeError
,
10 "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
11 name
, type
->tp_name
, Py_TYPE(obj
)->tp_name
);
14 static CYTHON_INLINE
int __Pyx_ArgTypeTest(PyObject
*obj
, PyTypeObject
*type
, int none_allowed
,
15 const char *name
, int exact
)
17 if (unlikely(!type
)) {
18 PyErr_SetString(PyExc_SystemError
, "Missing type object");
21 if (none_allowed
&& obj
== Py_None
) return 1;
23 if (likely(Py_TYPE(obj
) == type
)) return 1;
24 #if PY_MAJOR_VERSION == 2
25 else if ((type
== &PyBaseString_Type
) && likely(__Pyx_PyBaseString_CheckExact(obj
))) return 1;
29 if (likely(PyObject_TypeCheck(obj
, type
))) return 1;
31 __Pyx_RaiseArgumentTypeInvalid(name
, obj
, type
);
35 //////////////////// RaiseArgTupleInvalid.proto ////////////////////
37 static void __Pyx_RaiseArgtupleInvalid(const char* func_name
, int exact
,
38 Py_ssize_t num_min
, Py_ssize_t num_max
, Py_ssize_t num_found
); /*proto*/
40 //////////////////// RaiseArgTupleInvalid ////////////////////
42 // __Pyx_RaiseArgtupleInvalid raises the correct exception when too
43 // many or too few positional arguments were found. This handles
44 // Py_ssize_t formatting correctly.
46 static void __Pyx_RaiseArgtupleInvalid(
47 const char* func_name
,
53 Py_ssize_t num_expected
;
54 const char *more_or_less
;
56 if (num_found
< num_min
) {
57 num_expected
= num_min
;
58 more_or_less
= "at least";
60 num_expected
= num_max
;
61 more_or_less
= "at most";
64 more_or_less
= "exactly";
66 PyErr_Format(PyExc_TypeError
,
67 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T
"d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T
"d given)",
68 func_name
, more_or_less
, num_expected
,
69 (num_expected
== 1) ? "" : "s", num_found
);
73 //////////////////// RaiseKeywordRequired.proto ////////////////////
75 static CYTHON_INLINE
void __Pyx_RaiseKeywordRequired(const char* func_name
, PyObject
* kw_name
); /*proto*/
77 //////////////////// RaiseKeywordRequired ////////////////////
79 static CYTHON_INLINE
void __Pyx_RaiseKeywordRequired(
80 const char* func_name
,
83 PyErr_Format(PyExc_TypeError
,
84 #if PY_MAJOR_VERSION >= 3
85 "%s() needs keyword-only argument %U", func_name
, kw_name
);
87 "%s() needs keyword-only argument %s", func_name
,
88 PyString_AS_STRING(kw_name
));
93 //////////////////// RaiseDoubleKeywords.proto ////////////////////
95 static void __Pyx_RaiseDoubleKeywordsError(const char* func_name
, PyObject
* kw_name
); /*proto*/
97 //////////////////// RaiseDoubleKeywords ////////////////////
99 static void __Pyx_RaiseDoubleKeywordsError(
100 const char* func_name
,
103 PyErr_Format(PyExc_TypeError
,
104 #if PY_MAJOR_VERSION >= 3
105 "%s() got multiple values for keyword argument '%U'", func_name
, kw_name
);
107 "%s() got multiple values for keyword argument '%s'", func_name
,
108 PyString_AsString(kw_name
));
113 //////////////////// KeywordStringCheck.proto ////////////////////
115 static CYTHON_INLINE
int __Pyx_CheckKeywordStrings(PyObject
*kwdict
, const char* function_name
, int kw_allowed
); /*proto*/
117 //////////////////// KeywordStringCheck ////////////////////
119 // __Pyx_CheckKeywordStrings raises an error if non-string keywords
120 // were passed to a function, or if any keywords were passed to a
121 // function that does not accept them.
123 static CYTHON_INLINE
int __Pyx_CheckKeywordStrings(
125 const char* function_name
,
130 #if CYTHON_COMPILING_IN_PYPY
131 /* PyPy appears to check keywords at call time, not at unpacking time => not much to do here */
132 if (!kw_allowed
&& PyDict_Next(kwdict
, &pos
, &key
, 0))
133 goto invalid_keyword
;
136 while (PyDict_Next(kwdict
, &pos
, &key
, 0)) {
137 #if PY_MAJOR_VERSION < 3
138 if (unlikely(!PyString_CheckExact(key
)) && unlikely(!PyString_Check(key
)))
140 if (unlikely(!PyUnicode_Check(key
)))
141 goto invalid_keyword_type
;
143 if ((!kw_allowed
) && unlikely(key
))
144 goto invalid_keyword
;
146 invalid_keyword_type
:
147 PyErr_Format(PyExc_TypeError
,
148 "%.200s() keywords must be strings", function_name
);
152 PyErr_Format(PyExc_TypeError
,
153 #if PY_MAJOR_VERSION < 3
154 "%.200s() got an unexpected keyword argument '%.200s'",
155 function_name
, PyString_AsString(key
));
157 "%s() got an unexpected keyword argument '%U'",
164 //////////////////// ParseKeywords.proto ////////////////////
166 static int __Pyx_ParseOptionalKeywords(PyObject
*kwds
, PyObject
**argnames
[], \
167 PyObject
*kwds2
, PyObject
*values
[], Py_ssize_t num_pos_args
, \
168 const char* function_name
); /*proto*/
170 //////////////////// ParseKeywords ////////////////////
171 //@requires: RaiseDoubleKeywords
173 // __Pyx_ParseOptionalKeywords copies the optional/unknown keyword
174 // arguments from the kwds dict into kwds2. If kwds2 is NULL, unknown
175 // keywords will raise an invalid keyword error.
177 // Three kinds of errors are checked: 1) non-string keywords, 2)
178 // unexpected keywords and 3) overlap with positional arguments.
180 // If num_posargs is greater 0, it denotes the number of positional
181 // arguments that were passed and that must therefore not appear
182 // amongst the keywords as well.
184 // This method does not check for required keyword arguments.
186 static int __Pyx_ParseOptionalKeywords(
188 PyObject
**argnames
[],
191 Py_ssize_t num_pos_args
,
192 const char* function_name
)
194 PyObject
*key
= 0, *value
= 0;
197 PyObject
*** first_kw_arg
= argnames
+ num_pos_args
;
199 while (PyDict_Next(kwds
, &pos
, &key
, &value
)) {
201 while (*name
&& (**name
!= key
)) name
++;
203 values
[name
-argnames
] = value
;
208 #if PY_MAJOR_VERSION < 3
209 if (likely(PyString_CheckExact(key
)) || likely(PyString_Check(key
))) {
211 if ((CYTHON_COMPILING_IN_PYPY
|| PyString_GET_SIZE(**name
) == PyString_GET_SIZE(key
))
212 && _PyString_Eq(**name
, key
)) {
213 values
[name
-argnames
] = value
;
220 // not found after positional args, check for duplicate
221 PyObject
*** argname
= argnames
;
222 while (argname
!= first_kw_arg
) {
223 if ((**argname
== key
) || (
224 (CYTHON_COMPILING_IN_PYPY
|| PyString_GET_SIZE(**argname
) == PyString_GET_SIZE(key
))
225 && _PyString_Eq(**argname
, key
))) {
226 goto arg_passed_twice
;
233 if (likely(PyUnicode_Check(key
))) {
235 int cmp
= (**name
== key
) ? 0 :
236 #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
237 (PyUnicode_GET_SIZE(**name
) != PyUnicode_GET_SIZE(key
)) ? 1 :
239 // need to convert argument name from bytes to unicode for comparison
240 PyUnicode_Compare(**name
, key
);
241 if (cmp
< 0 && unlikely(PyErr_Occurred())) goto bad
;
243 values
[name
-argnames
] = value
;
250 // not found after positional args, check for duplicate
251 PyObject
*** argname
= argnames
;
252 while (argname
!= first_kw_arg
) {
253 int cmp
= (**argname
== key
) ? 0 :
254 #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
255 (PyUnicode_GET_SIZE(**argname
) != PyUnicode_GET_SIZE(key
)) ? 1 :
257 // need to convert argument name from bytes to unicode for comparison
258 PyUnicode_Compare(**argname
, key
);
259 if (cmp
< 0 && unlikely(PyErr_Occurred())) goto bad
;
260 if (cmp
== 0) goto arg_passed_twice
;
265 goto invalid_keyword_type
;
268 if (unlikely(PyDict_SetItem(kwds2
, key
, value
))) goto bad
;
270 goto invalid_keyword
;
275 __Pyx_RaiseDoubleKeywordsError(function_name
, key
);
277 invalid_keyword_type
:
278 PyErr_Format(PyExc_TypeError
,
279 "%.200s() keywords must be strings", function_name
);
282 PyErr_Format(PyExc_TypeError
,
283 #if PY_MAJOR_VERSION < 3
284 "%.200s() got an unexpected keyword argument '%.200s'",
285 function_name
, PyString_AsString(key
));
287 "%s() got an unexpected keyword argument '%U'",