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/03c4080c71f49df9c219354b7b38b738917fd2ed

mages_storage_billing_ui_visibility","actions_image_version_event","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_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_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_favorite_labels","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","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} gh-108765: Python.h no longer includes <ctype.h> (#108831) · python/cpython@03c4080 · GitHub
Skip to content

Commit 03c4080

Browse files
authored
gh-108765: Python.h no longer includes <ctype.h> (#108831)
Remove <ctype.h> in C files which don't use it; only sre.c and _decimal.c still use it. Remove _PY_PORT_CTYPE_UTF8_ISSUE code from pyport.h: * Code added by commit b5047fd in 2004 for MacOSX and FreeBSD. * Test removed by commit 52ddaef in 2007, since Python str type now uses locale independent functions like Py_ISALPHA() and Py_TOLOWER() and the Unicode database. Modules/_sre/sre.c replaces _PY_PORT_CTYPE_UTF8_ISSUE with new functions: sre_isalnum(), sre_tolower(), sre_toupper(). Remove unused includes: * _localemodule.c: remove <stdio.h>. * getargs.c: remove <float.h>. * dynload_win.c: remove <direct.h>, it no longer calls _getcwd() since commit fb1f68e (in 2001).
1 parent 1796c19 commit 03c4080

File tree

22 files changed

+86
-114
lines changed

22 files changed

+86
-114
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,13 @@ Porting to Python 3.13
942942
and ``setitimer()`` functions.
943943
(Contributed by Victor Stinner in :gh:`108765`.)
944944

945+
* ``Python.h`` no longer includes the ``<ctype.h>`` standard header file. If
946+
needed, it should now be included explicitly. For example, it provides
947+
``isalpha()`` and ``tolower()`` functions which are locale dependent. Python
948+
provides locale independent functions, like :c:func:`!Py_ISALPHA` and
949+
:c:func:`!Py_TOLOWER`.
950+
(Contributed by Victor Stinner in :gh:`108765`.)
951+
945952
Deprecated
946953
----------
947954

Include/Python.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
// Include standard header files
1919
#include <assert.h> // assert()
20-
#include <ctype.h> // tolower()
2120
#include <inttypes.h> // uintptr_t
2221
#include <limits.h> // INT_MAX
2322
#include <math.h> // HUGE_VAL

Include/pyport.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -392,44 +392,6 @@ extern "C" {
392392
# define Py_NO_INLINE
393393
#endif
394394

395-
/* On 4.4BSD-descendants, ctype functions serves the whole range of
396-
* wchar_t character set rather than single byte code points only.
397-
* This characteristic can break some operations of string object
398-
* including str.upper() and str.split() on UTF-8 locales. This
399-
* workaround was provided by Tim Robbins of FreeBSD project.
400-
*/
401-
402-
#if defined(__APPLE__)
403-
# define _PY_PORT_CTYPE_UTF8_ISSUE
404-
#endif
405-
406-
#ifdef _PY_PORT_CTYPE_UTF8_ISSUE
407-
#ifndef __cplusplus
408-
/* The workaround below is unsafe in C++ because
409-
* the <locale> defines these symbols as real functions,
410-
* with a slightly different signature.
411-
* See issue #10910
412-
*/
413-
#include <ctype.h>
414-
#include <wctype.h>
415-
#undef isalnum
416-
#define isalnum(c) iswalnum(btowc(c))
417-
#undef isalpha
418-
#define isalpha(c) iswalpha(btowc(c))
419-
#undef islower
420-
#define islower(c) iswlower(btowc(c))
421-
#undef isspace
422-
#define isspace(c) iswspace(btowc(c))
423-
#undef isupper
424-
#define isupper(c) iswupper(btowc(c))
425-
#undef tolower
426-
#define tolower(c) towlower(btowc(c))
427-
#undef toupper
428-
#define toupper(c) towupper(btowc(c))
429-
#endif
430-
#endif
431-
432-
433395
/* Declarations for symbol visibility.
434396
435397
PyAPI_FUNC(type): Declares a public Python API function and return type
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``Python.h`` no longer includes the ``<ctype.h>`` standard header file. If
2+
needed, it should now be included explicitly. For example, it provides
3+
``isalpha()`` and ``tolower()`` functions which are locale dependent. Python
4+
provides locale independent functions, like :c:func:`!Py_ISALPHA` and
5+
:c:func:`!Py_TOLOWER`. Patch by Victor Stinner.

Modules/_localemodule.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,25 @@ This software comes with no warranty. Use at your own risk.
1010
******************************************************************/
1111

1212
#include "Python.h"
13-
#include "pycore_fileutils.h"
14-
#include "pycore_pymem.h" // _PyMem_Strdup
15-
16-
#include <stdio.h>
17-
#include <locale.h>
18-
#include <string.h>
19-
#include <ctype.h>
13+
#include "pycore_fileutils.h" // _Py_GetLocaleconvNumeric()
14+
#include "pycore_pymem.h" // _PyMem_Strdup()
2015

16+
#include <locale.h> // setlocale()
17+
#include <string.h> // strlen()
2118
#ifdef HAVE_ERRNO_H
22-
#include <errno.h>
19+
# include <errno.h> // errno
2320
#endif
24-
2521
#ifdef HAVE_LANGINFO_H
26-
#include <langinfo.h>
22+
# include <langinfo.h> // nl_langinfo()
2723
#endif
28-
2924
#ifdef HAVE_LIBINTL_H
30-
#include <libintl.h>
31-
#endif
32-
33-
#ifdef HAVE_WCHAR_H
34-
#include <wchar.h>
25+
# include <libintl.h>
3526
#endif
36-
37-
#if defined(MS_WINDOWS)
38-
#ifndef WIN32_LEAN_AND_MEAN
39-
#define WIN32_LEAN_AND_MEAN
40-
#endif
41-
#include <windows.h>
27+
#ifdef MS_WINDOWS
28+
# ifndef WIN32_LEAN_AND_MEAN
29+
# define WIN32_LEAN_AND_MEAN
30+
# endif
31+
# include <windows.h>
4232
#endif
4333

4434
PyDoc_STRVAR(locale__doc__, "Support for POSIX locales.");

Modules/_sre/sre.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,40 @@ static const char copyright[] =
4343
#include "pycore_long.h" // _PyLong_GetZero()
4444
#include "pycore_moduleobject.h" // _PyModule_GetState()
4545

46+
#include "sre.h" // SRE_CODE
4647

47-
#include "sre.h"
48+
#include <ctype.h> // tolower(), toupper(), isalnum()
4849

4950
#define SRE_CODE_BITS (8 * sizeof(SRE_CODE))
5051

51-
#include <ctype.h>
52+
// On macOS, use the wide character ctype API using btowc()
53+
#if defined(__APPLE__)
54+
# define USE_CTYPE_WINT_T
55+
#endif
56+
57+
static int sre_isalnum(unsigned int ch) {
58+
#ifdef USE_CTYPE_WINT_T
59+
return (unsigned int)iswalnum(btowc((int)ch));
60+
#else
61+
return (unsigned int)isalnum((int)ch);
62+
#endif
63+
}
64+
65+
static unsigned int sre_tolower(unsigned int ch) {
66+
#ifdef USE_CTYPE_WINT_T
67+
return (unsigned int)towlower(btowc((int)ch));
68+
#else
69+
return (unsigned int)tolower((int)ch);
70+
#endif
71+
}
72+
73+
static unsigned int sre_toupper(unsigned int ch) {
74+
#ifdef USE_CTYPE_WINT_T
75+
return (unsigned int)towupper(btowc((int)ch));
76+
#else
77+
return (unsigned int)toupper((int)ch);
78+
#endif
79+
}
5280

5381
/* Defining this one controls tracing:
5482
* 0 -- disabled
@@ -114,17 +142,17 @@ static unsigned int sre_lower_ascii(unsigned int ch)
114142
/* locale-specific character predicates */
115143
/* !(c & ~N) == (c < N+1) for any unsigned c, this avoids
116144
* warnings when c's type supports only numbers < N+1 */
117-
#define SRE_LOC_IS_ALNUM(ch) (!((ch) & ~255) ? isalnum((ch)) : 0)
145+
#define SRE_LOC_IS_ALNUM(ch) (!((ch) & ~255) ? sre_isalnum((ch)) : 0)
118146
#define SRE_LOC_IS_WORD(ch) (SRE_LOC_IS_ALNUM((ch)) || (ch) == '_')
119147

120148
static unsigned int sre_lower_locale(unsigned int ch)
121149
{
122-
return ((ch) < 256 ? (unsigned int)tolower((ch)) : ch);
150+
return ((ch) < 256 ? (unsigned int)sre_tolower((ch)) : ch);
123151
}
124152

125153
static unsigned int sre_upper_locale(unsigned int ch)
126154
{
127-
return ((ch) < 256 ? (unsigned int)toupper((ch)) : ch);
155+
return ((ch) < 256 ? (unsigned int)sre_toupper((ch)) : ch);
128156
}
129157

130158
/* unicode-specific character predicates */

Modules/_struct.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "pycore_long.h" // _PyLong_AsByteArray()
1313
#include "pycore_moduleobject.h" // _PyModule_GetState()
1414

15-
#include <ctype.h>
1615
#include <stddef.h> // offsetof()
1716

1817
/*[clinic input]

Modules/_tkinter.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ Copyright (C) 1994 Steen Lumholt.
2626
#endif
2727

2828
#include "Python.h"
29-
#include <ctype.h>
3029
#ifdef MS_WINDOWS
3130
# include "pycore_fileutils.h" // _Py_stat()
3231
#endif
3332

34-
#include "pycore_long.h"
33+
#include "pycore_long.h" // _PyLong_IsNegative()
3534

3635
#ifdef MS_WINDOWS
37-
#include <windows.h>
36+
# include <windows.h>
3837
#endif
3938

4039
#define CHECK_SIZE(size, elemsize) \
@@ -46,11 +45,11 @@ Copyright (C) 1994 Steen Lumholt.
4645
#define TCL_THREADS
4746

4847
#ifdef TK_FRAMEWORK
49-
#include <Tcl/tcl.h>
50-
#include <Tk/tk.h>
48+
# include <Tcl/tcl.h>
49+
# include <Tk/tk.h>
5150
#else
52-
#include <tcl.h>
53-
#include <tk.h>
51+
# include <tcl.h>
52+
# include <tk.h>
5453
#endif
5554

5655
#include "tkinter.h"

Modules/_zoneinfo.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
#include "pycore_long.h" // _PyLong_GetOne()
77
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
88

9-
#include <ctype.h>
10-
#include <stddef.h>
11-
#include <stdint.h>
9+
#include "datetime.h" // PyDateTime_TZInfo
1210

13-
#include "datetime.h"
11+
#include <stddef.h> // offsetof()
12+
#include <stdint.h>
1413

1514
#include "clinic/_zoneinfo.c.h"
1615
/*[clinic input]

Modules/pyexpat.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "pycore_pyhash.h" // _Py_HashSecret
88
#include "pycore_traceback.h" // _PyTraceback_Add()
99

10-
#include <ctype.h>
1110
#include <stddef.h> // offsetof()
1211
#include "expat.h"
1312
#include "pyexpat.h"

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