Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(205939)

Delta Between Two Patch Sets: Objects/abstract.c

Issue 27809: _PyObject_FastCall(): add support for keyword arguments
Left Patch Set: Created 3 years, 3 months ago
Right Patch Set: Created 3 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Modules/_sre.c ('k') | Objects/fileobject.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* Abstract Object Interface (many thanks to Jim Fulton) */ 1 /* Abstract Object Interface (many thanks to Jim Fulton) */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include <ctype.h> 4 #include <ctype.h>
5 #include "structmember.h" /* we need the offsetof() macro from there */ 5 #include "structmember.h" /* we need the offsetof() macro from there */
6 #include "longintrepr.h" 6 #include "longintrepr.h"
7 7
8 8
9 9
10 /* Shorthands to return certain errors */ 10 /* Shorthands to return certain errors */
(...skipping 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 PyObject_Call(PyObject *func, PyObject *args, PyObject *kwargs) 2208 PyObject_Call(PyObject *func, PyObject *args, PyObject *kwargs)
2209 { 2209 {
2210 ternaryfunc call; 2210 ternaryfunc call;
2211 PyObject *result; 2211 PyObject *result;
2212 2212
2213 /* PyObject_Call() must not be called with an exception set, 2213 /* PyObject_Call() must not be called with an exception set,
2214 because it may clear it (directly or indirectly) and so the 2214 because it may clear it (directly or indirectly) and so the
2215 caller loses its exception */ 2215 caller loses its exception */
2216 assert(!PyErr_Occurred()); 2216 assert(!PyErr_Occurred());
2217 assert(PyTuple_Check(args)); 2217 assert(PyTuple_Check(args));
2218 assert(args == NULL || PyTuple_Check(args));
2219 assert(kwargs == NULL || PyDict_Check(kwargs)); 2218 assert(kwargs == NULL || PyDict_Check(kwargs));
2220 2219
2221 call = func->ob_type->tp_call; 2220 call = func->ob_type->tp_call;
2222 if (call == NULL) { 2221 if (call == NULL) {
2223 PyErr_Format(PyExc_TypeError, "'%.200s' object is not callable", 2222 PyErr_Format(PyExc_TypeError, "'%.200s' object is not callable",
2224 func->ob_type->tp_name); 2223 func->ob_type->tp_name);
2225 return NULL; 2224 return NULL;
2226 } 2225 }
2227 2226
2228 if (Py_EnterRecursiveCall(" while calling a Python object")) 2227 if (Py_EnterRecursiveCall(" while calling a Python object"))
(...skipping 20 matching lines...) Expand all
2249 for (i=0; i < nargs; i++) { 2248 for (i=0; i < nargs; i++) {
2250 PyObject *item = stack[i]; 2249 PyObject *item = stack[i];
2251 Py_INCREF(item); 2250 Py_INCREF(item);
2252 PyTuple_SET_ITEM(args, i, item); 2251 PyTuple_SET_ITEM(args, i, item);
2253 } 2252 }
2254 2253
2255 return args; 2254 return args;
2256 } 2255 }
2257 2256
2258 PyObject * 2257 PyObject *
2259 _PyObject_FastCall(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) 2258 _PyObject_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwa rgs)
2260 { 2259 {
2261 ternaryfunc call; 2260 ternaryfunc call;
2262 PyObject *result = NULL; 2261 PyObject *result = NULL;
2263 2262
2264 /* _PyObject_FastCall() must not be called with an exception set, 2263 /* _PyObject_FastCallDict() must not be called with an exception set,
2265 because it may clear it (directly or indirectly) and so the 2264 because it may clear it (directly or indirectly) and so the
2266 caller loses its exception */ 2265 caller loses its exception */
2267 assert(!PyErr_Occurred()); 2266 assert(!PyErr_Occurred());
2268 2267
2269 assert(func != NULL); 2268 assert(func != NULL);
2270 assert(nargs >= 0); 2269 assert(nargs >= 0);
2271 assert(nargs == 0 || args != NULL); 2270 assert(nargs == 0 || args != NULL);
2272 assert(kwargs == NULL || PyDict_Check(kwargs)); 2271 /* issue #27128: support for keywords will come later:
2272 _PyFunction_FastCall() doesn't support keyword arguments yet */
2273 assert(kwargs == NULL);
2273 2274
2274 if (Py_EnterRecursiveCall(" while calling a Python object")) { 2275 if (Py_EnterRecursiveCall(" while calling a Python object")) {
2275 return NULL; 2276 return NULL;
2276 } 2277 }
2277 2278
2278 if (PyFunction_Check(func)) { 2279 if (PyFunction_Check(func)) {
2279 result = _PyFunction_FastCall(func, args, nargs, kwargs); 2280 result = _PyFunction_FastCall(func, args, nargs, kwargs);
2280 } 2281 }
2281 else if (PyCFunction_Check(func)) { 2282 else if (PyCFunction_Check(func)) {
2282 result = _PyCFunction_FastCall(func, args, nargs, kwargs); 2283 result = _PyCFunction_FastCall(func, args, nargs, kwargs);
(...skipping 27 matching lines...) Expand all
2310 } 2311 }
2311 2312
2312 static PyObject* 2313 static PyObject*
2313 call_function_tail(PyObject *callable, PyObject *args) 2314 call_function_tail(PyObject *callable, PyObject *args)
2314 { 2315 {
2315 PyObject *result; 2316 PyObject *result;
2316 2317
2317 assert(args != NULL); 2318 assert(args != NULL);
2318 2319
2319 if (!PyTuple_Check(args)) { 2320 if (!PyTuple_Check(args)) {
2320 result = _PyObject_FastCall(callable, &args, 1, NULL); 2321 result = _PyObject_CallArg1(callable, args);
2321 } 2322 }
2322 else { 2323 else {
2323 result = PyObject_Call(callable, args, NULL); 2324 result = PyObject_Call(callable, args, NULL);
2324 } 2325 }
2325 2326
2326 return result; 2327 return result;
2327 } 2328 }
2328 2329
2329 PyObject * 2330 PyObject *
2330 PyObject_CallFunction(PyObject *callable, const char *format, ...) 2331 PyObject_CallFunction(PyObject *callable, const char *format, ...)
2331 { 2332 {
2332 va_list va; 2333 va_list va;
2333 PyObject *args, *result; 2334 PyObject *args, *result;
2334 2335
2335 if (callable == NULL) { 2336 if (callable == NULL) {
2336 return null_error(); 2337 return null_error();
2337 } 2338 }
2338 2339
2339 if (!format || !*format) { 2340 if (!format || !*format) {
2340 return _PyObject_FastCall(callable, NULL, 0, NULL); 2341 return _PyObject_CallNoArg(callable);
2341 } 2342 }
2342 2343
2343 va_start(va, format); 2344 va_start(va, format);
2344 args = Py_VaBuildValue(format, va); 2345 args = Py_VaBuildValue(format, va);
2345 va_end(va); 2346 va_end(va);
2346 if (args == NULL) { 2347 if (args == NULL) {
2347 return NULL; 2348 return NULL;
2348 } 2349 }
2349 2350
2350 result = call_function_tail(callable, args); 2351 result = call_function_tail(callable, args);
2351 Py_DECREF(args); 2352 Py_DECREF(args);
2352 return result; 2353 return result;
2353 } 2354 }
2354 2355
2355 PyObject * 2356 PyObject *
2356 _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...) 2357 _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...)
2357 { 2358 {
2358 va_list va; 2359 va_list va;
2359 PyObject *args, *result; 2360 PyObject *args, *result;
2360 2361
2361 if (callable == NULL) { 2362 if (callable == NULL) {
2362 return null_error(); 2363 return null_error();
2363 } 2364 }
2364 2365
2365 if (!format || !*format) { 2366 if (!format || !*format) {
2366 return _PyObject_FastCall(callable, NULL, 0, NULL); 2367 return _PyObject_CallNoArg(callable);
2367 } 2368 }
2368 2369
2369 va_start(va, format); 2370 va_start(va, format);
2370 args = _Py_VaBuildValue_SizeT(format, va); 2371 args = _Py_VaBuildValue_SizeT(format, va);
2371 va_end(va); 2372 va_end(va);
2372 if (args == NULL) { 2373 if (args == NULL) {
2373 return NULL; 2374 return NULL;
2374 } 2375 }
2375 2376
2376 result = call_function_tail(callable, args); 2377 result = call_function_tail(callable, args);
2377 Py_DECREF(args); 2378 Py_DECREF(args);
2378 return result; 2379 return result;
2379 } 2380 }
2380 2381
2381 static PyObject* 2382 static PyObject*
2382 callmethod(PyObject* func, const char *format, va_list va, int is_size_t) 2383 callmethod(PyObject* func, const char *format, va_list va, int is_size_t)
2383 { 2384 {
2384 PyObject *args, *result; 2385 PyObject *args, *result;
2385 2386
2386 assert(func != NULL); 2387 assert(func != NULL);
2387 2388
2388 if (!PyCallable_Check(func)) { 2389 if (!PyCallable_Check(func)) {
2389 type_error("attribute of type '%.200s' is not callable", func); 2390 type_error("attribute of type '%.200s' is not callable", func);
2390 return NULL; 2391 return NULL;
2391 } 2392 }
2392 2393
2393 if (!format || !*format) { 2394 if (!format || !*format) {
2394 return _PyObject_FastCall(func, NULL, 0, NULL); 2395 return _PyObject_CallNoArg(func);
2395 } 2396 }
2396 2397
2397 if (is_size_t) { 2398 if (is_size_t) {
2398 args = _Py_VaBuildValue_SizeT(format, va); 2399 args = _Py_VaBuildValue_SizeT(format, va);
2399 } 2400 }
2400 else { 2401 else {
2401 args = Py_VaBuildValue(format, va); 2402 args = Py_VaBuildValue(format, va);
2402 } 2403 }
2403 if (args == NULL) { 2404 if (args == NULL) {
2404 return NULL; 2405 return NULL;
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
3007 /* Free's a NULL terminated char** array of C strings. */ 3008 /* Free's a NULL terminated char** array of C strings. */
3008 void 3009 void
3009 _Py_FreeCharPArray(char *const array[]) 3010 _Py_FreeCharPArray(char *const array[])
3010 { 3011 {
3011 Py_ssize_t i; 3012 Py_ssize_t i;
3012 for (i = 0; array[i] != NULL; ++i) { 3013 for (i = 0; array[i] != NULL; ++i) {
3013 PyMem_Free(array[i]); 3014 PyMem_Free(array[i]);
3014 } 3015 }
3015 PyMem_Free((void*)array); 3016 PyMem_Free((void*)array);
3016 } 3017 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+