Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7029c1a

Browse files
authored
gh-85283: Build _scproxy extension with limited C API (#111008)
* Replace Py_SETREF(v, NULL) with Py_CLEAR(v).* Reformat the code.
1 parenta53d7cb commit7029c1a

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

‎Doc/whatsnew/3.13.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,8 @@ Build Changes
933933
library, GCC built-in atomic functions, or MSVC interlocked intrinsics.
934934

935935
* The ``errno``, ``md5``, ``resource``, ``winsound``, ``_ctypes_test``,
936-
``_stat`` and ``_testimportmultiple`` C extensions are now built with the
937-
:ref:`limited C API<limited-c-api>`.
936+
``_scproxy``, ``_stat`` and ``_testimportmultiple`` C extensions are now
937+
built with the:ref:`limited C API<limited-c-api>`.
938938
(Contributed by Victor Stinner in:gh:`85283`.)
939939

940940

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The ``errno``, ``md5``, ``resource``, ``winsound``, ``_ctypes_test``, ``_stat``
2-
and ``_testimportmultiple`` C extensions are now built with the:ref:`limited C
3-
API <limited-c-api>`.
1+
The ``errno``, ``md5``, ``resource``, ``winsound``, ``_ctypes_test``,
2+
``_scproxy``, ``_stat``and ``_testimportmultiple`` C extensions are now built
3+
with the:ref:`limited CAPI<limited-c-api>`.
44
Patch by Victor Stinner.

‎Modules/_scproxy.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
* Helper method for urllib to fetch the proxy configuration settings
33
* using the SystemConfiguration framework.
44
*/
5+
6+
// Need limited C API version 3.13 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
7+
#definePy_LIMITED_API 0x030d0000
8+
59
#include<Python.h>
610
#include<SystemConfiguration/SystemConfiguration.h>
711

@@ -21,8 +25,7 @@ cfstring_to_pystring(CFStringRef ref)
2125

2226
s=CFStringGetCStringPtr(ref,kCFStringEncodingUTF8);
2327
if (s) {
24-
returnPyUnicode_DecodeUTF8(
25-
s,strlen(s),NULL);
28+
returnPyUnicode_DecodeUTF8(s,strlen(s),NULL);
2629

2730
}else {
2831
CFIndexlen=CFStringGetLength(ref);
@@ -43,8 +46,7 @@ cfstring_to_pystring(CFStringRef ref)
4346
PyMem_Free(buf);
4447
returnNULL;
4548
}else {
46-
result=PyUnicode_DecodeUTF8(
47-
buf,strlen(buf),NULL);
49+
result=PyUnicode_DecodeUTF8(buf,strlen(buf),NULL);
4850
PyMem_Free(buf);
4951
}
5052
returnresult;
@@ -84,7 +86,7 @@ get_proxy_settings(PyObject* Py_UNUSED(mod), PyObject *Py_UNUSED(ignored))
8486
if (v==NULL) gotoerror;
8587

8688
r=PyDict_SetItemString(result,"exclude_simple",v);
87-
Py_SETREF(v,NULL);
89+
Py_CLEAR(v);
8890
if (r==-1) gotoerror;
8991

9092
anArray=CFDictionaryGetValue(proxyDict,
@@ -104,13 +106,11 @@ get_proxy_settings(PyObject* Py_UNUSED(mod), PyObject *Py_UNUSED(ignored))
104106

105107
aString=CFArrayGetValueAtIndex(anArray,i);
106108
if (aString==NULL) {
107-
PyTuple_SetItem(v,i,Py_None);
108-
Py_INCREF(Py_None);
109+
PyTuple_SetItem(v,i,Py_NewRef(Py_None));
109110
}else {
110111
PyObject*t=cfstring_to_pystring(aString);
111112
if (!t) {
112-
PyTuple_SetItem(v,i,Py_None);
113-
Py_INCREF(Py_None);
113+
PyTuple_SetItem(v,i,Py_NewRef(Py_None));
114114
}else {
115115
PyTuple_SetItem(v,i,t);
116116
}
@@ -148,15 +148,13 @@ set_proxy(PyObject* proxies, const char* proto, CFDictionaryRef proxyDict,
148148
if (h) {
149149
if (aNum) {
150150
int32_tport=cfnum_to_int32(aNum);
151-
v=PyUnicode_FromFormat("http://%U:%ld",
152-
h, (long)port);
151+
v=PyUnicode_FromFormat("http://%U:%ld",h, (long)port);
153152
}else {
154153
v=PyUnicode_FromFormat("http://%U",h);
155154
}
156155
Py_DECREF(h);
157156
if (!v)return-1;
158-
r=PyDict_SetItemString(proxies,proto,
159-
v);
157+
r=PyDict_SetItemString(proxies,proto,v);
160158
Py_DECREF(v);
161159
returnr;
162160
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp