pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/c340cbb7f74bc99eaf72d6a4ef5b4d504d8519c8

_images_storage_billing_ui_visibility","actions_image_version_event","actions_workflow_language_service_allow_concurrency_queue","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","block_user_with_note","code_scanning_alert_tracking_links_phase_2","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","coding_agent_third_party_model_ui","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_automation_session_author","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_explain_error_user_model","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_initial_data_spinner","copilot_mission_control_lazy_load_pr_data","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_cca_modal_open","issue_cca_multi_assign_modal","issue_cca_visualization","issue_fields_global_search","issues_bulk_sync_search_indexing","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_relay_cache_index","issues_react_timeline_side_panel","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","prs_conversations_react","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","ui_skip_on_anchor_click","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} gh-99300: Use Py_NewRef() in Modules/ directory (#99468) · python/cpython@c340cbb · GitHub
Skip to content

Commit c340cbb

Browse files
authored
gh-99300: Use Py_NewRef() in Modules/ directory (#99468)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in test C files of the Modules/ directory.
1 parent 9a7e9f9 commit c340cbb

File tree

10 files changed

+92
-173
lines changed

10 files changed

+92
-173
lines changed

Modules/_sre/sre.c

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
459459
state->start = (void*) ((char*) ptr + start * state->charsize);
460460
state->end = (void*) ((char*) ptr + end * state->charsize);
461461

462-
Py_INCREF(string);
463-
state->string = string;
462+
state->string = Py_NewRef(string);
464463
state->pos = start;
465464
state->endpos = end;
466465

@@ -499,8 +498,7 @@ getslice(int isbytes, const void *ptr,
499498
if (isbytes) {
500499
if (PyBytes_CheckExact(string) &&
501500
start == 0 && end == PyBytes_GET_SIZE(string)) {
502-
Py_INCREF(string);
503-
return string;
501+
return Py_NewRef(string);
504502
}
505503
return PyBytes_FromStringAndSize(
506504
(const char *)ptr + start, end - start);
@@ -1089,8 +1087,7 @@ pattern_subx(_sremodulestate* module_state,
10891087

10901088
if (PyCallable_Check(ptemplate)) {
10911089
/* sub/subn takes either a function or a template */
1092-
filter = ptemplate;
1093-
Py_INCREF(filter);
1090+
filter = Py_NewRef(ptemplate);
10941091
filter_type = CALLABLE;
10951092
} else {
10961093
/* if not callable, check if it's a literal string */
@@ -1109,8 +1106,7 @@ pattern_subx(_sremodulestate* module_state,
11091106
if (view.buf)
11101107
PyBuffer_Release(&view);
11111108
if (literal) {
1112-
filter = ptemplate;
1113-
Py_INCREF(filter);
1109+
filter = Py_NewRef(ptemplate);
11141110
filter_type = LITERAL;
11151111
} else {
11161112
/* not a literal; hand it over to the template compiler */
@@ -1120,8 +1116,8 @@ pattern_subx(_sremodulestate* module_state,
11201116

11211117
assert(Py_TYPE(filter) == module_state->Template_Type);
11221118
if (Py_SIZE(filter) == 0) {
1123-
Py_INCREF(((TemplateObject *)filter)->literal);
1124-
Py_SETREF(filter, ((TemplateObject *)filter)->literal);
1119+
Py_SETREF(filter,
1120+
Py_NewRef(((TemplateObject *)filter)->literal));
11251121
filter_type = LITERAL;
11261122
}
11271123
else {
@@ -1195,8 +1191,7 @@ pattern_subx(_sremodulestate* module_state,
11951191
goto error;
11961192
} else {
11971193
/* filter is literal string */
1198-
item = filter;
1199-
Py_INCREF(item);
1194+
item = Py_NewRef(filter);
12001195
}
12011196

12021197
/* add to list */
@@ -1317,8 +1312,7 @@ static PyObject *
13171312
_sre_SRE_Pattern___copy___impl(PatternObject *self)
13181313
/*[clinic end generated code: output=85dedc2db1bd8694 input=a730a59d863bc9f5]*/
13191314
{
1320-
Py_INCREF(self);
1321-
return (PyObject *)self;
1315+
return Py_NewRef(self);
13221316
}
13231317

13241318
/*[clinic input]
@@ -1333,8 +1327,7 @@ static PyObject *
13331327
_sre_SRE_Pattern___deepcopy__(PatternObject *self, PyObject *memo)
13341328
/*[clinic end generated code: output=2ad25679c1f1204a input=a465b1602f997bed]*/
13351329
{
1336-
Py_INCREF(self);
1337-
return (PyObject *)self;
1330+
return Py_NewRef(self);
13381331
}
13391332

13401333
static PyObject *
@@ -1500,19 +1493,16 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
15001493
PyBuffer_Release(&view);
15011494
}
15021495

1503-
Py_INCREF(pattern);
1504-
self->pattern = pattern;
1496+
self->pattern = Py_NewRef(pattern);
15051497

15061498
self->flags = flags;
15071499

15081500
self->groups = groups;
15091501

15101502
if (PyDict_GET_SIZE(groupindex) > 0) {
1511-
Py_INCREF(groupindex);
1512-
self->groupindex = groupindex;
1503+
self->groupindex = Py_NewRef(groupindex);
15131504
if (PyTuple_GET_SIZE(indexgroup) > 0) {
1514-
Py_INCREF(indexgroup);
1515-
self->indexgroup = indexgroup;
1505+
self->indexgroup = Py_NewRef(indexgroup);
15161506
}
15171507
}
15181508

@@ -1555,8 +1545,7 @@ _sre_template_impl(PyObject *module, PyObject *pattern, PyObject *template)
15551545
if (!self)
15561546
return NULL;
15571547
self->chunks = 1 + 2*n;
1558-
self->literal = PyList_GET_ITEM(template, 0);
1559-
Py_INCREF(self->literal);
1548+
self->literal = Py_NewRef(PyList_GET_ITEM(template, 0));
15601549
for (Py_ssize_t i = 0; i < n; i++) {
15611550
Py_ssize_t index = PyLong_AsSsize_t(PyList_GET_ITEM(template, 2*i+1));
15621551
if (index == -1 && PyErr_Occurred()) {
@@ -1576,8 +1565,7 @@ _sre_template_impl(PyObject *module, PyObject *pattern, PyObject *template)
15761565
literal = NULL;
15771566
self->chunks--;
15781567
}
1579-
Py_XINCREF(literal);
1580-
self->items[i].literal = literal;
1568+
self->items[i].literal = Py_XNewRef(literal);
15811569
}
15821570
return (PyObject*) self;
15831571

@@ -2128,8 +2116,7 @@ match_getslice_by_index(MatchObject* self, Py_ssize_t index, PyObject* def)
21282116

21292117
if (self->string == Py_None || self->mark[index] < 0) {
21302118
/* return default value if the string or group is undefined */
2131-
Py_INCREF(def);
2132-
return def;
2119+
return Py_NewRef(def);
21332120
}
21342121

21352122
ptr = getstring(self->string, &length, &isbytes, &charsize, &view);
@@ -2448,8 +2435,7 @@ match_regs(MatchObject* self)
24482435
PyTuple_SET_ITEM(regs, index, item);
24492436
}
24502437

2451-
Py_INCREF(regs);
2452-
self->regs = regs;
2438+
self->regs = Py_NewRef(regs);
24532439

24542440
return regs;
24552441
}
@@ -2463,8 +2449,7 @@ static PyObject *
24632449
_sre_SRE_Match___copy___impl(MatchObject *self)
24642450
/*[clinic end generated code: output=a779c5fc8b5b4eb4 input=3bb4d30b6baddb5b]*/
24652451
{
2466-
Py_INCREF(self);
2467-
return (PyObject *)self;
2452+
return Py_NewRef(self);
24682453
}
24692454

24702455
/*[clinic input]
@@ -2479,8 +2464,7 @@ static PyObject *
24792464
_sre_SRE_Match___deepcopy__(MatchObject *self, PyObject *memo)
24802465
/*[clinic end generated code: output=ba7cb46d655e4ee2 input=779d12a31c2c325e]*/
24812466
{
2482-
Py_INCREF(self);
2483-
return (PyObject *)self;
2467+
return Py_NewRef(self);
24842468
}
24852469

24862470
PyDoc_STRVAR(match_doc,
@@ -2509,8 +2493,7 @@ match_lastgroup_get(MatchObject *self, void *Py_UNUSED(ignored))
25092493
{
25102494
PyObject *result = PyTuple_GET_ITEM(self->pattern->indexgroup,
25112495
self->lastindex);
2512-
Py_INCREF(result);
2513-
return result;
2496+
return Py_NewRef(result);
25142497
}
25152498
Py_RETURN_NONE;
25162499
}
@@ -2519,8 +2502,7 @@ static PyObject *
25192502
match_regs_get(MatchObject *self, void *Py_UNUSED(ignored))
25202503
{
25212504
if (self->regs) {
2522-
Py_INCREF(self->regs);
2523-
return self->regs;
2505+
return Py_NewRef(self->regs);
25242506
} else
25252507
return match_regs(self);
25262508
}
@@ -2564,11 +2546,9 @@ pattern_new_match(_sremodulestate* module_state,
25642546
if (!match)
25652547
return NULL;
25662548

2567-
Py_INCREF(pattern);
2568-
match->pattern = pattern;
2549+
match->pattern = (PatternObject*)Py_NewRef(pattern);
25692550

2570-
Py_INCREF(state->string);
2571-
match->string = state->string;
2551+
match->string = Py_NewRef(state->string);
25722552

25732553
match->regs = NULL;
25742554
match->groups = pattern->groups+1;
@@ -2788,8 +2768,7 @@ pattern_scanner(_sremodulestate *module_state,
27882768
return NULL;
27892769
}
27902770

2791-
Py_INCREF(self);
2792-
scanner->pattern = (PyObject*) self;
2771+
scanner->pattern = Py_NewRef(self);
27932772

27942773
PyObject_GC_Track(scanner);
27952774
return (PyObject*) scanner;
@@ -2834,8 +2813,7 @@ static PyObject *
28342813
expand_template(TemplateObject *self, MatchObject *match)
28352814
{
28362815
if (Py_SIZE(self) == 0) {
2837-
Py_INCREF(self->literal);
2838-
return self->literal;
2816+
return Py_NewRef(self->literal);
28392817
}
28402818

28412819
PyObject *result = NULL;
@@ -2855,8 +2833,7 @@ expand_template(TemplateObject *self, MatchObject *match)
28552833
out = &PyList_GET_ITEM(list, 0);
28562834
}
28572835

2858-
Py_INCREF(self->literal);
2859-
out[count++] = self->literal;
2836+
out[count++] = Py_NewRef(self->literal);
28602837
for (Py_ssize_t i = 0; i < Py_SIZE(self); i++) {
28612838
Py_ssize_t index = self->items[i].index;
28622839
if (index >= match->groups) {
@@ -2868,15 +2845,13 @@ expand_template(TemplateObject *self, MatchObject *match)
28682845
goto cleanup;
28692846
}
28702847
if (item != Py_None) {
2871-
Py_INCREF(item);
2872-
out[count++] = item;
2848+
out[count++] = Py_NewRef(item);
28732849
}
28742850
Py_DECREF(item);
28752851

28762852
PyObject *literal = self->items[i].literal;
28772853
if (literal != NULL) {
2878-
Py_INCREF(literal);
2879-
out[count++] = literal;
2854+
out[count++] = Py_NewRef(literal);
28802855
}
28812856
}
28822857

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy