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

Side by Side Diff: Objects/abstract.c

Issue 27809: _PyObject_FastCall(): add support for keyword arguments
Patch Set: Created 3 years 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:
View unified diff | Download patch
« no previous file with comments | « Modules/_sre.c ('k') | Objects/fileobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2237 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 for (i=0; i < nargs; i++) { 2248 for (i=0; i < nargs; i++) {
2249 PyObject *item = stack[i]; 2249 PyObject *item = stack[i];
2250 Py_INCREF(item); 2250 Py_INCREF(item);
2251 PyTuple_SET_ITEM(args, i, item); 2251 PyTuple_SET_ITEM(args, i, item);
2252 } 2252 }
2253 2253
2254 return args; 2254 return args;
2255 } 2255 }
2256 2256
2257 PyObject * 2257 PyObject *
2258 _PyObject_FastCall(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) 2258 _PyObject_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwa rgs)
2259 { 2259 {
2260 ternaryfunc call; 2260 ternaryfunc call;
2261 PyObject *result = NULL; 2261 PyObject *result = NULL;
2262 2262
2263 /* _PyObject_FastCall() must not be called with an exception set, 2263 /* _PyObject_FastCallDict() must not be called with an exception set,
2264 because it may clear it (directly or indirectly) and so the 2264 because it may clear it (directly or indirectly) and so the
2265 caller loses its exception */ 2265 caller loses its exception */
2266 assert(!PyErr_Occurred()); 2266 assert(!PyErr_Occurred());
2267 2267
2268 assert(func != NULL); 2268 assert(func != NULL);
2269 assert(nargs >= 0); 2269 assert(nargs >= 0);
2270 assert(nargs == 0 || args != NULL); 2270 assert(nargs == 0 || args != NULL);
2271 /* issue #27128: support for keywords will come later: 2271 /* issue #27128: support for keywords will come later:
2272 _PyFunction_FastCall() doesn't support keyword arguments yet */ 2272 _PyFunction_FastCall() doesn't support keyword arguments yet */
2273 assert(kwargs == NULL); 2273 assert(kwargs == NULL);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 } 2311 }
2312 2312
2313 static PyObject* 2313 static PyObject*
2314 call_function_tail(PyObject *callable, PyObject *args) 2314 call_function_tail(PyObject *callable, PyObject *args)
2315 { 2315 {
2316 PyObject *result; 2316 PyObject *result;
2317 2317
2318 assert(args != NULL); 2318 assert(args != NULL);
2319 2319
2320 if (!PyTuple_Check(args)) { 2320 if (!PyTuple_Check(args)) {
2321 result = _PyObject_FastCall(callable, &args, 1, NULL); 2321 result = _PyObject_CallArg1(callable, args);
2322 } 2322 }
2323 else { 2323 else {
2324 result = PyObject_Call(callable, args, NULL); 2324 result = PyObject_Call(callable, args, NULL);
2325 } 2325 }
2326 2326
2327 return result; 2327 return result;
2328 } 2328 }
2329 2329
2330 PyObject * 2330 PyObject *
2331 PyObject_CallFunction(PyObject *callable, const char *format, ...) 2331 PyObject_CallFunction(PyObject *callable, const char *format, ...)
2332 { 2332 {
2333 va_list va; 2333 va_list va;
2334 PyObject *args, *result; 2334 PyObject *args, *result;
2335 2335
2336 if (callable == NULL) { 2336 if (callable == NULL) {
2337 return null_error(); 2337 return null_error();
2338 } 2338 }
2339 2339
2340 if (!format || !*format) { 2340 if (!format || !*format) {
2341 return _PyObject_FastCall(callable, NULL, 0, NULL); 2341 return _PyObject_CallNoArg(callable);
2342 } 2342 }
2343 2343
2344 va_start(va, format); 2344 va_start(va, format);
2345 args = Py_VaBuildValue(format, va); 2345 args = Py_VaBuildValue(format, va);
2346 va_end(va); 2346 va_end(va);
2347 if (args == NULL) { 2347 if (args == NULL) {
2348 return NULL; 2348 return NULL;
2349 } 2349 }
2350 2350
2351 result = call_function_tail(callable, args); 2351 result = call_function_tail(callable, args);
2352 Py_DECREF(args); 2352 Py_DECREF(args);
2353 return result; 2353 return result;
2354 } 2354 }
2355 2355
2356 PyObject * 2356 PyObject *
2357 _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...) 2357 _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...)
2358 { 2358 {
2359 va_list va; 2359 va_list va;
2360 PyObject *args, *result; 2360 PyObject *args, *result;
2361 2361
2362 if (callable == NULL) { 2362 if (callable == NULL) {
2363 return null_error(); 2363 return null_error();
2364 } 2364 }
2365 2365
2366 if (!format || !*format) { 2366 if (!format || !*format) {
2367 return _PyObject_FastCall(callable, NULL, 0, NULL); 2367 return _PyObject_CallNoArg(callable);
2368 } 2368 }
2369 2369
2370 va_start(va, format); 2370 va_start(va, format);
2371 args = _Py_VaBuildValue_SizeT(format, va); 2371 args = _Py_VaBuildValue_SizeT(format, va);
2372 va_end(va); 2372 va_end(va);
2373 if (args == NULL) { 2373 if (args == NULL) {
2374 return NULL; 2374 return NULL;
2375 } 2375 }
2376 2376
2377 result = call_function_tail(callable, args); 2377 result = call_function_tail(callable, args);
2378 Py_DECREF(args); 2378 Py_DECREF(args);
2379 return result; 2379 return result;
2380 } 2380 }
2381 2381
2382 static PyObject* 2382 static PyObject*
2383 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)
2384 { 2384 {
2385 PyObject *args, *result; 2385 PyObject *args, *result;
2386 2386
2387 assert(func != NULL); 2387 assert(func != NULL);
2388 2388
2389 if (!PyCallable_Check(func)) { 2389 if (!PyCallable_Check(func)) {
2390 type_error("attribute of type '%.200s' is not callable", func); 2390 type_error("attribute of type '%.200s' is not callable", func);
2391 return NULL; 2391 return NULL;
2392 } 2392 }
2393 2393
2394 if (!format || !*format) { 2394 if (!format || !*format) {
2395 return _PyObject_FastCall(func, NULL, 0, NULL); 2395 return _PyObject_CallNoArg(func);
2396 } 2396 }
2397 2397
2398 if (is_size_t) { 2398 if (is_size_t) {
2399 args = _Py_VaBuildValue_SizeT(format, va); 2399 args = _Py_VaBuildValue_SizeT(format, va);
2400 } 2400 }
2401 else { 2401 else {
2402 args = Py_VaBuildValue(format, va); 2402 args = Py_VaBuildValue(format, va);
2403 } 2403 }
2404 if (args == NULL) { 2404 if (args == NULL) {
2405 return NULL; 2405 return NULL;
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
3008 /* Free's a NULL terminated char** array of C strings. */ 3008 /* Free's a NULL terminated char** array of C strings. */
3009 void 3009 void
3010 _Py_FreeCharPArray(char *const array[]) 3010 _Py_FreeCharPArray(char *const array[])
3011 { 3011 {
3012 Py_ssize_t i; 3012 Py_ssize_t i;
3013 for (i = 0; array[i] != NULL; ++i) { 3013 for (i = 0; array[i] != NULL; ++i) {
3014 PyMem_Free(array[i]); 3014 PyMem_Free(array[i]);
3015 } 3015 }
3016 PyMem_Free((void*)array); 3016 PyMem_Free((void*)array);
3017 } 3017 }
OLDNEW
« no previous file with comments | « Modules/_sre.c ('k') | Objects/fileobject.c » ('j') | no next file with comments »

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