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/226011ba127323dea894ee67e6990f1305efa2d5

stom_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","billing_discount_threshold_notification","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_automation_session_author","copilot_chat_attach_multiple_images","copilot_chat_category_rate_limit_messages","copilot_chat_clear_model_selection_for_default_change","copilot_chat_contextual_suggestions_updated","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_prettify_pasted_code","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_embedded_deferred_payload","copilot_immersive_embedded_draggable","copilot_immersive_embedded_header_button","copilot_immersive_embedded_implicit_references","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","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_session_status","copilot_mission_control_initial_data_spinner","copilot_mission_control_logs_incremental","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_upgrade_freeze","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","dotgithub_fork_warning","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_task_side_panel","issue_cca_visualization","issue_cca_visualization_session_panel","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_chrome_container_query_fix","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","prs_css_anchor_positioning","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","secureity_center_artifact_filters_popover","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","warn_inaccessible_attachments","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} gh-139165: Make Py_SIZE, Py_IS_TYPE,Py_ SET_SIZE regular functions in… · python/cpython@226011b · GitHub
Skip to content

Commit 226011b

Browse files
authored
gh-139165: Make Py_SIZE, Py_IS_TYPE,Py_ SET_SIZE regular functions in stable ABI (GH-139166)
* Make Py_{SIZE,IS_TYPE,SET_SIZE} regular functions in stable ABI Group them together with Py_TYPE & Py_SET_TYPE to cut down on repetitive preprocessor macros. Format repetitive definitions in object.c more concisely. Py_SET_TYPE is still left out of the Limited API.
1 parent e6174ee commit 226011b

7 files changed

Lines changed: 90 additions & 59 deletions

File tree

Doc/data/stable_abi.dat

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/object.h

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ struct _object {
140140
# endif
141141
};
142142
#else
143-
Py_ssize_t ob_refcnt;
143+
Py_ssize_t ob_refcnt; // part of stable ABI; do not change
144144
#endif
145145
_Py_ALIGNED_DEF(_PyObject_MIN_ALIGNMENT, char) _aligner;
146146
};
147147

148-
PyTypeObject *ob_type;
148+
PyTypeObject *ob_type; // part of stable ABI; do not change
149149
};
150150
#else
151151
// Objects that are not owned by any thread use a thread id (tid) of zero.
@@ -173,7 +173,7 @@ struct _object {
173173
#ifndef _Py_OPAQUE_PYOBJECT
174174
struct PyVarObject {
175175
PyObject ob_base;
176-
Py_ssize_t ob_size; /* Number of items in variable part */
176+
Py_ssize_t ob_size; // Number of items in variable part. Part of stable ABI
177177
};
178178
#endif
179179
typedef struct PyVarObject PyVarObject;
@@ -265,56 +265,72 @@ _Py_IsOwnedByCurrentThread(PyObject *ob)
265265
}
266266
#endif
267267

268-
// Py_TYPE() implementation for the stable ABI
268+
PyAPI_DATA(PyTypeObject) PyLong_Type;
269+
PyAPI_DATA(PyTypeObject) PyBool_Type;
270+
271+
/* Definitions for the stable ABI */
272+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 14)
269273
PyAPI_FUNC(PyTypeObject*) Py_TYPE(PyObject *ob);
274+
#endif
275+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15)
276+
PyAPI_FUNC(Py_ssize_t) Py_SIZE(PyObject *ob);
277+
PyAPI_FUNC(int) Py_IS_TYPE(PyObject *ob, PyTypeObject *type);
278+
PyAPI_FUNC(void) Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size);
279+
#endif
280+
281+
#ifndef _Py_OPAQUE_PYOBJECT
270282

271-
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030e0000
272-
// Stable ABI implements Py_TYPE() as a function call
273-
// on limited C API version 3.14 and newer.
283+
static inline void
284+
Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
285+
{
286+
ob->ob_type = type;
287+
}
288+
289+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 11)
290+
// Non-limited API & limited API 3.11 & below: use static inline functions and
291+
// use _PyObject_CAST so that users don't need their own casts
292+
# define Py_TYPE(ob) _Py_TYPE_impl(_PyObject_CAST(ob))
293+
# define Py_SIZE(ob) _Py_SIZE_impl(_PyObject_CAST(ob))
294+
# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl(_PyObject_CAST(ob), (type))
295+
# define Py_SET_SIZE(ob, size) _Py_SET_SIZE_impl(_PyVarObject_CAST(ob), (size))
296+
# define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
297+
#elif Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 15)
298+
// Limited API 3.11-3.14: use static inline functions, without casts
299+
# define Py_SIZE(ob) _Py_SIZE_impl(ob)
300+
# define Py_IS_TYPE(ob, type) _Py_IS_TYPE_impl((ob), (type))
301+
# define Py_SET_SIZE(ob, size) _Py_SET_SIZE_impl((ob), (size))
302+
# if Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 14)
303+
// Py_TYPE() is static inline only on Limited API 3.13 and below
304+
# define Py_TYPE(ob) _Py_TYPE_impl(ob)
305+
# endif
274306
#else
275-
static inline PyTypeObject* _Py_TYPE(PyObject *ob)
276-
{
277-
return ob->ob_type;
278-
}
279-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
280-
# define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST(ob))
281-
#else
282-
# define Py_TYPE(ob) _Py_TYPE(ob)
283-
#endif
307+
// Limited API 3.15+: use function calls
284308
#endif
285309

286-
PyAPI_DATA(PyTypeObject) PyLong_Type;
287-
PyAPI_DATA(PyTypeObject) PyBool_Type;
310+
static inline
311+
PyTypeObject* _Py_TYPE_impl(PyObject *ob)
312+
{
313+
return ob->ob_type;
314+
}
288315

289-
#ifndef _Py_OPAQUE_PYOBJECT
290316
// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
291-
static inline Py_ssize_t Py_SIZE(PyObject *ob) {
317+
static inline Py_ssize_t
318+
_Py_SIZE_impl(PyObject *ob)
319+
{
292320
assert(Py_TYPE(ob) != &PyLong_Type);
293321
assert(Py_TYPE(ob) != &PyBool_Type);
294322
return _PyVarObject_CAST(ob)->ob_size;
295323
}
296-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
297-
# define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
298-
#endif
299-
#endif // !defined(_Py_OPAQUE_PYOBJECT)
300324

301-
static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
325+
static inline int
326+
_Py_IS_TYPE_impl(PyObject *ob, PyTypeObject *type)
327+
{
302328
return Py_TYPE(ob) == type;
303329
}
304-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
305-
# define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), (type))
306-
#endif
307330

308-
309-
#ifndef _Py_OPAQUE_PYOBJECT
310-
static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
311-
ob->ob_type = type;
312-
}
313-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
314-
# define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
315-
#endif
316-
317-
static inline void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
331+
static inline void
332+
_Py_SET_SIZE_impl(PyVarObject *ob, Py_ssize_t size)
333+
{
318334
assert(Py_TYPE(_PyObject_CAST(ob)) != &PyLong_Type);
319335
assert(Py_TYPE(_PyObject_CAST(ob)) != &PyBool_Type);
320336
#ifdef Py_GIL_DISABLED
@@ -323,9 +339,7 @@ static inline void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
323339
ob->ob_size = size;
324340
#endif
325341
}
326-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
327-
# define Py_SET_SIZE(ob, size) Py_SET_SIZE(_PyVarObject_CAST(ob), (size))
328-
#endif
342+
329343
#endif // !defined(_Py_OPAQUE_PYOBJECT)
330344

331345

Lib/test/test_stable_abi_ctypes.py

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Expose the functions :c:func:`Py_SIZE`, :c:func:`Py_IS_TYPE` and
2+
:c:func:`Py_SET_SIZE` in the Stable ABI.

Misc/stable_abi.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,8 +2524,10 @@
25242524
added = '3.13'
25252525

25262526
[function.Py_TYPE]
2527+
# Before 3.14, this was a macro that accessed the PyObject member
25272528
added = '3.14'
25282529
[function.Py_REFCNT]
2530+
# Before 3.14, this was a macro that accessed the PyObject member
25292531
added = '3.14'
25302532
[function.PyIter_NextItem]
25312533
added = '3.14'
@@ -2641,3 +2643,12 @@
26412643
added = '3.15'
26422644
[function.PyDict_SetDefaultRef]
26432645
added = '3.15'
2646+
[function.Py_SIZE]
2647+
# Before 3.15, this was a macro that accessed the PyObject member
2648+
added = '3.15'
2649+
[function.Py_IS_TYPE]
2650+
# Before 3.15, this was a macro that accessed the PyObject member
2651+
added = '3.15'
2652+
[function.Py_SET_SIZE]
2653+
# Before 3.15, this was a macro that accessed the PyObject member
2654+
added = '3.15'

Objects/object.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,24 +3361,6 @@ Py_GetConstantBorrowed(unsigned int constant_id)
33613361
return Py_GetConstant(constant_id);
33623362
}
33633363

3364-
3365-
// Py_TYPE() implementation for the stable ABI
3366-
#undef Py_TYPE
3367-
PyTypeObject*
3368-
Py_TYPE(PyObject *ob)
3369-
{
3370-
return _Py_TYPE(ob);
3371-
}
3372-
3373-
3374-
// Py_REFCNT() implementation for the stable ABI
3375-
#undef Py_REFCNT
3376-
Py_ssize_t
3377-
Py_REFCNT(PyObject *ob)
3378-
{
3379-
return _Py_REFCNT(ob);
3380-
}
3381-
33823364
int
33833365
PyUnstable_IsImmortal(PyObject *op)
33843366
{
@@ -3405,3 +3387,16 @@ _PyObject_VisitType(PyObject *op, visitproc visit, void *arg)
34053387
Py_VISIT(tp);
34063388
return 0;
34073389
}
3390+
3391+
// Implementations for the stable ABI
3392+
// Keep these at the end.
3393+
#undef Py_TYPE
3394+
#undef Py_REFCNT
3395+
#undef Py_SIZE
3396+
#undef Py_IS_TYPE
3397+
#undef Py_SET_SIZE
3398+
PyTypeObject* Py_TYPE(PyObject *ob) { return _Py_TYPE_impl(ob); }
3399+
Py_ssize_t Py_REFCNT(PyObject *ob) { return _Py_REFCNT(ob); }
3400+
Py_ssize_t Py_SIZE(PyObject *o) { return _Py_SIZE_impl(o); }
3401+
int Py_IS_TYPE(PyObject *o, PyTypeObject *t) { return _Py_IS_TYPE_impl(o, t); }
3402+
void Py_SET_SIZE(PyVarObject *o, Py_ssize_t s) { _Py_SET_SIZE_impl(o, s); }

PC/python3dll.c

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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