| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -453,7 +453,7 @@ def generate_bin_op_reverse_dunder_call(fn: FuncIR, emitter: Emitter, rmethod: s | |||
| 453 | 453 | # Ternary pow() will never call the reverse dunder. | |
| 454 | 454 | emitter.emit_line("if (obj_mod == Py_None) {") | |
| 455 | 455 | emitter.emit_line( | |
| 456 | - 'return CPy_CallReverseOpMethod(obj_left, obj_right, "{}", "{}");'.format( | ||
| 456 | + 'return CPy_CallReverseOpMethod(obj_left, obj_right, "{}", &_Py_ID({}));'.format( | ||
| 457 | 457 | op_methods_to_symbols[fn.name], rmethod | |
| 458 | 458 | ) | |
| 459 | 459 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -938,7 +938,7 @@ int CPyStatics_Initialize(PyObject **statics, | |||
| 938 | 938 | const int *frozensets); | |
| 939 | 939 | PyObject *CPy_Super(PyObject *builtins, PyObject *self); | |
| 940 | 940 | PyObject *CPy_CallReverseOpMethod(PyObject *left, PyObject *right, const char *op, | |
| 941 | - const char *method); | ||
| 941 | + PyObject *method); | ||
| 942 | 942 | ||
| 943 | 943 | bool CPyImport_ImportMany(PyObject *modules, CPyModule **statics[], PyObject *globals, | |
| 944 | 944 | PyObject *tb_path, PyObject *tb_function, Py_ssize_t *tb_lines); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,11 +41,5 @@ PyObject *CPyBytes_Translate(PyObject *bytes, PyObject *table) { | |||
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | 43 | // Fallback to Python method call for non-exact types or non-standard tables | |
| 44 | - PyObject *name = PyUnicode_FromString("translate"); | ||
| 45 | - if (name == NULL) { | ||
| 46 | - return NULL; | ||
| 47 | - } | ||
| 48 | - PyObject *res = PyObject_CallMethodOneArg(bytes, name, table); | ||
| 49 | - Py_DECREF(name); | ||
| 50 | - return res; | ||
| 44 | + return PyObject_CallMethodOneArg(bytes, &_Py_ID(translate), table); | ||
| 51 | 45 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,13 +101,7 @@ PyObject *CPyBytes_Join(PyObject *sep, PyObject *iter) { | |||
| 101 | 101 | if (PyBytes_CheckExact(sep)) { | |
| 102 | 102 | return PyBytes_Join(sep, iter); | |
| 103 | 103 | } else { | |
| 104 | - PyObject *name = PyUnicode_FromString("join"); | ||
| 105 | - if (name == NULL) { | ||
| 106 | - return NULL; | ||
| 107 | - } | ||
| 108 | - PyObject *res = PyObject_CallMethodOneArg(sep, name, iter); | ||
| 109 | - Py_DECREF(name); | ||
| 110 | - return res; | ||
| 104 | + return PyObject_CallMethodOneArg(sep, &_Py_ID(join), iter); | ||
| 111 | 105 | } | |
| 112 | 106 | } | |
| 113 | 107 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -170,7 +170,7 @@ int CPyDict_Update(PyObject *dict, PyObject *stuff) { | |||
| 170 | 170 | int CPyDict_UpdateFromAny(PyObject *dict, PyObject *stuff) { | |
| 171 | 171 | if (PyDict_CheckExact(dict)) { | |
| 172 | 172 | // Argh this sucks | |
| 173 | - if (PyDict_Check(stuff) || _CPyObject_HasAttrId(stuff, "keys")) { | ||
| 173 | + if (PyDict_Check(stuff) || _CPyObject_HasAttrId(stuff, &_Py_ID(keys))) { | ||
| 174 | 174 | return PyDict_Update(dict, stuff); | |
| 175 | 175 | } else { | |
| 176 | 176 | return PyDict_MergeFromSeq2(dict, stuff, 1); | |
@@ -189,7 +189,7 @@ PyObject *CPyDict_FromAny(PyObject *obj) { | |||
| 189 | 189 | if (!dict) { | |
| 190 | 190 | return NULL; | |
| 191 | 191 | } | |
| 192 | - if (_CPyObject_HasAttrId(obj, "keys")) { | ||
| 192 | + if (_CPyObject_HasAttrId(obj, &_Py_ID(keys))) { | ||
| 193 | 193 | res = PyDict_Update(dict, obj); | |
| 194 | 194 | } else { | |
| 195 | 195 | res = PyDict_MergeFromSeq2(dict, obj, 1); | |
@@ -206,39 +206,21 @@ PyObject *CPyDict_KeysView(PyObject *dict) { | |||
| 206 | 206 | if (PyDict_CheckExact(dict)){ | |
| 207 | 207 | return _CPyDictView_New(dict, &PyDictKeys_Type); | |
| 208 | 208 | } | |
| 209 | - PyObject *name = PyUnicode_FromString("keys"); | ||
| 210 | - if (name == NULL) { | ||
| 211 | - return NULL; | ||
| 212 | - } | ||
| 213 | - PyObject *res = PyObject_CallMethodNoArgs(dict, name); | ||
| 214 | - Py_DECREF(name); | ||
| 215 | - return res; | ||
| 209 | + return PyObject_CallMethodNoArgs(dict, &_Py_ID(keys)); | ||
| 216 | 210 | } | |
| 217 | 211 | ||
| 218 | 212 | PyObject *CPyDict_ValuesView(PyObject *dict) { | |
| 219 | 213 | if (PyDict_CheckExact(dict)){ | |
| 220 | 214 | return _CPyDictView_New(dict, &PyDictValues_Type); | |
| 221 | 215 | } | |
| 222 | - PyObject *name = PyUnicode_FromString("values"); | ||
| 223 | - if (name == NULL) { | ||
| 224 | - return NULL; | ||
| 225 | - } | ||
| 226 | - PyObject *res = PyObject_CallMethodNoArgs(dict, name); | ||
| 227 | - Py_DECREF(name); | ||
| 228 | - return res; | ||
| 216 | + return PyObject_CallMethodNoArgs(dict, &_Py_ID(values)); | ||
| 229 | 217 | } | |
| 230 | 218 | ||
| 231 | 219 | PyObject *CPyDict_ItemsView(PyObject *dict) { | |
| 232 | 220 | if (PyDict_CheckExact(dict)){ | |
| 233 | 221 | return _CPyDictView_New(dict, &PyDictItems_Type); | |
| 234 | 222 | } | |
| 235 | - PyObject *name = PyUnicode_FromString("items"); | ||
| 236 | - if (name == NULL) { | ||
| 237 | - return NULL; | ||
| 238 | - } | ||
| 239 | - PyObject *res = PyObject_CallMethodNoArgs(dict, name); | ||
| 240 | - Py_DECREF(name); | ||
| 241 | - return res; | ||
| 223 | + return PyObject_CallMethodNoArgs(dict, &_Py_ID(items)); | ||
| 242 | 224 | } | |
| 243 | 225 | ||
| 244 | 226 | PyObject *CPyDict_Keys(PyObject *dict) { | |
@@ -247,12 +229,7 @@ PyObject *CPyDict_Keys(PyObject *dict) { | |||
| 247 | 229 | } | |
| 248 | 230 | // Inline generic fallback logic to also return a list. | |
| 249 | 231 | PyObject *list = PyList_New(0); | |
| 250 | - PyObject *name = PyUnicode_FromString("keys"); | ||
| 251 | - if (name == NULL) { | ||
| 252 | - return NULL; | ||
| 253 | - } | ||
| 254 | - PyObject *view = PyObject_CallMethodNoArgs(dict, name); | ||
| 255 | - Py_DECREF(name); | ||
| 232 | + PyObject *view = PyObject_CallMethodNoArgs(dict, &_Py_ID(keys)); | ||
| 256 | 233 | if (view == NULL) { | |
| 257 | 234 | return NULL; | |
| 258 | 235 | } | |
@@ -270,12 +247,7 @@ PyObject *CPyDict_Values(PyObject *dict) { | |||
| 270 | 247 | } | |
| 271 | 248 | // Inline generic fallback logic to also return a list. | |
| 272 | 249 | PyObject *list = PyList_New(0); | |
| 273 | - PyObject *name = PyUnicode_FromString("values"); | ||
| 274 | - if (name == NULL) { | ||
| 275 | - return NULL; | ||
| 276 | - } | ||
| 277 | - PyObject *view = PyObject_CallMethodNoArgs(dict, name); | ||
| 278 | - Py_DECREF(name); | ||
| 250 | + PyObject *view = PyObject_CallMethodNoArgs(dict, &_Py_ID(values)); | ||
| 279 | 251 | if (view == NULL) { | |
| 280 | 252 | return NULL; | |
| 281 | 253 | } | |
@@ -293,12 +265,7 @@ PyObject *CPyDict_Items(PyObject *dict) { | |||
| 293 | 265 | } | |
| 294 | 266 | // Inline generic fallback logic to also return a list. | |
| 295 | 267 | PyObject *list = PyList_New(0); | |
| 296 | - PyObject *name = PyUnicode_FromString("items"); | ||
| 297 | - if (name == NULL) { | ||
| 298 | - return NULL; | ||
| 299 | - } | ||
| 300 | - PyObject *view = PyObject_CallMethodNoArgs(dict, name); | ||
| 301 | - Py_DECREF(name); | ||
| 268 | + PyObject *view = PyObject_CallMethodNoArgs(dict, &_Py_ID(items)); | ||
| 302 | 269 | if (view == NULL) { | |
| 303 | 270 | return NULL; | |
| 304 | 271 | } | |
@@ -314,12 +281,7 @@ char CPyDict_Clear(PyObject *dict) { | |||
| 314 | 281 | if (PyDict_CheckExact(dict)) { | |
| 315 | 282 | PyDict_Clear(dict); | |
| 316 | 283 | } else { | |
| 317 | - PyObject *name = PyUnicode_FromString("clear"); | ||
| 318 | - if (name == NULL) { | ||
| 319 | - return 0; | ||
| 320 | - } | ||
| 321 | - PyObject *res = PyObject_CallMethodNoArgs(dict, name); | ||
| 322 | - Py_DECREF(name); | ||
| 284 | + PyObject *res = PyObject_CallMethodNoArgs(dict, &_Py_ID(clear)); | ||
| 323 | 285 | if (res == NULL) { | |
| 324 | 286 | return 0; | |
| 325 | 287 | } | |
@@ -331,12 +293,7 @@ PyObject *CPyDict_Copy(PyObject *dict) { | |||
| 331 | 293 | if (PyDict_CheckExact(dict)) { | |
| 332 | 294 | return PyDict_Copy(dict); | |
| 333 | 295 | } | |
| 334 | - PyObject *name = PyUnicode_FromString("copy"); | ||
| 335 | - if (name == NULL) { | ||
| 336 | - return NULL; | ||
| 337 | - } | ||
| 338 | - PyObject *res = PyObject_CallMethodNoArgs(dict, name); | ||
| 339 | - Py_DECREF(name); | ||
| 296 | + PyObject *res = PyObject_CallMethodNoArgs(dict, &_Py_ID(copy)); | ||
| 340 | 297 | return res; | |
| 341 | 298 | } | |
| 342 | 299 | ||
@@ -355,12 +312,7 @@ PyObject *CPyDict_GetItemsIter(PyObject *dict) { | |||
| 355 | 312 | Py_INCREF(dict); | |
| 356 | 313 | return dict; | |
| 357 | 314 | } | |
| 358 | - PyObject *name = PyUnicode_FromString("items"); | ||
| 359 | - if (name == NULL) { | ||
| 360 | - return NULL; | ||
| 361 | - } | ||
| 362 | - PyObject *view = PyObject_CallMethodNoArgs(dict, name); | ||
| 363 | - Py_DECREF(name); | ||
| 315 | + PyObject *view = PyObject_CallMethodNoArgs(dict, &_Py_ID(items)); | ||
| 364 | 316 | if (view == NULL) { | |
| 365 | 317 | return NULL; | |
| 366 | 318 | } | |
@@ -375,12 +327,7 @@ PyObject *CPyDict_GetValuesIter(PyObject *dict) { | |||
| 375 | 327 | Py_INCREF(dict); | |
| 376 | 328 | return dict; | |
| 377 | 329 | } | |
| 378 | - PyObject *name = PyUnicode_FromString("values"); | ||
| 379 | - if (name == NULL) { | ||
| 380 | - return NULL; | ||
| 381 | - } | ||
| 382 | - PyObject *view = PyObject_CallMethodNoArgs(dict, name); | ||
| 383 | - Py_DECREF(name); | ||
| 330 | + PyObject *view = PyObject_CallMethodNoArgs(dict, &_Py_ID(values)); | ||
| 384 | 331 | if (view == NULL) { | |
| 385 | 332 | return NULL; | |
| 386 | 333 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,12 +33,7 @@ char CPyList_Clear(PyObject *list) { | |||
| 33 | 33 | if (PyList_CheckExact(list)) { | |
| 34 | 34 | PyList_Clear(list); | |
| 35 | 35 | } else { | |
| 36 | - PyObject *name = PyUnicode_FromString("clear"); | ||
| 37 | - if (name == NULL) { | ||
| 38 | - return 0; | ||
| 39 | - } | ||
| 40 | - PyObject *res = PyObject_CallMethodNoArgs(list, name); | ||
| 41 | - Py_DECREF(name); | ||
| 36 | + PyObject *res = PyObject_CallMethodNoArgs(list, &_Py_ID(clear)); | ||
| 42 | 37 | if (res == NULL) { | |
| 43 | 38 | return 0; | |
| 44 | 39 | } | |
@@ -51,13 +46,7 @@ PyObject *CPyList_Copy(PyObject *list) { | |||
| 51 | 46 | return PyList_GetSlice(list, 0, PyList_GET_SIZE(list)); | |
| 52 | 47 | } | |
| 53 | 48 | ||
| 54 | - PyObject *name = PyUnicode_FromString("copy"); | ||
| 55 | - if (name == NULL) { | ||
| 56 | - return NULL; | ||
| 57 | - } | ||
| 58 | - PyObject *res = PyObject_CallMethodNoArgs(list, name); | ||
| 59 | - Py_DECREF(res); | ||
| 60 | - return res; | ||
| 49 | + return PyObject_CallMethodNoArgs(list, &_Py_ID(copy)); | ||
| 61 | 50 | } | |
| 62 | 51 | ||
| 63 | 52 | PyObject *CPyList_GetItemShort(PyObject *list, CPyTagged index) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,13 +29,7 @@ PyObject *CPyIter_Send(PyObject *iter, PyObject *val) | |||
| 29 | 29 | if (Py_IsNone(val)) { | |
| 30 | 30 | return CPyIter_Next(iter); | |
| 31 | 31 | } else { | |
| 32 | - PyObject *name = PyUnicode_FromString("send"); | ||
| 33 | - if (name == NULL) { | ||
| 34 | - return NULL; | ||
| 35 | - } | ||
| 36 | - PyObject *res = PyObject_CallMethodOneArg(iter, name, val); | ||
| 37 | - Py_DECREF(name); | ||
| 38 | - return res; | ||
| 32 | + return PyObject_CallMethodOneArg(iter, &_Py_ID(send), val); | ||
| 39 | 33 | } | |
| 40 | 34 | } | |
| 41 | 35 | ||
@@ -876,9 +870,9 @@ PyObject * | |||
| 876 | 870 | CPy_CallReverseOpMethod(PyObject *left, | |
| 877 | 871 | PyObject *right, | |
| 878 | 872 | const char *op, | |
| 879 | - const char *method) { | ||
| 873 | + PyObject *method) { | ||
| 880 | 874 | // Look up reverse method | |
| 881 | - PyObject *m = PyObject_GetAttrString(right, method); | ||
| 875 | + PyObject *m = PyObject_GetAttr(right, method); | ||
| 882 | 876 | if (m == NULL) { | |
| 883 | 877 | // If reverse method not defined, generate TypeError instead AttributeError | |
| 884 | 878 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) { | |
@@ -1064,10 +1058,7 @@ PyObject *CPy_GetName(PyObject *obj) { | |||
| 1064 | 1058 | if (PyType_Check(obj)) { | |
| 1065 | 1059 | return PyType_GetName((PyTypeObject *)obj); | |
| 1066 | 1060 | } | |
| 1067 | - PyObject *name = PyUnicode_FromString("__name__"); | ||
| 1068 | - PyObject *res = PyObject_GetAttr(obj, name); | ||
| 1069 | - Py_DECREF(name); | ||
| 1070 | - return res; | ||
| 1061 | + return PyObject_GetAttr(obj, &_Py_ID(__name__)); | ||
| 1071 | 1062 | } | |
| 1072 | 1063 | ||
| 1073 | 1064 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,10 +20,14 @@ | |||
| 20 | 20 | #include "internal/pycore_genobject.h" // _PyGen_FetchStopIterationValue | |
| 21 | 21 | #include "internal/pycore_pyerrors.h" // _PyErr_FormatFromCause, _PyErr_SetKeyError | |
| 22 | 22 | #include "internal/pycore_setobject.h" // _PySet_Update | |
| 23 | + #include "internal/pycore_runtime.h" | ||
| 24 | + #include "internal/pycore_global_strings.h" | ||
| 23 | 25 | #endif | |
| 24 | 26 | ||
| 25 | 27 | #if CPY_3_12_FEATURES | |
| 26 | 28 | #include "internal/pycore_frame.h" | |
| 29 | + #include "internal/pycore_runtime.h" | ||
| 30 | + #include "internal/pycore_global_strings.h" | ||
| 27 | 31 | #endif | |
| 28 | 32 | ||
| 29 | 33 | #ifdef __cplusplus | |
@@ -377,9 +381,9 @@ _CPyDictView_New(PyObject *dict, PyTypeObject *type) | |||
| 377 | 381 | ||
| 378 | 382 | #if PY_VERSION_HEX >= 0x030A0000 // 3.10 | |
| 379 | 383 | static int | |
| 380 | - _CPyObject_HasAttrId(PyObject *v, const char *name) { | ||
| 384 | + _CPyObject_HasAttrId(PyObject *v, PyObject *name) { | ||
| 381 | 385 | PyObject *tmp = NULL; | |
| 382 | - int result = PyObject_GetOptionalAttrString(v, name, &tmp); | ||
| 386 | + int result = PyObject_GetOptionalAttr(v, name, &tmp); | ||
| 383 | 387 | if (tmp) { | |
| 384 | 388 | Py_DECREF(tmp); | |
| 385 | 389 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments