Skip to content

Commit fb8595d

Browse files
committed
Patch #661760: Cygwin auto-import module patch
The attached patch enables shared extension modules to build cleanly under Cygwin without moving the static initialization of certain function pointers (i.e., ones exported from the Python DLL core) to a module initialization function. Additionally, this patch fixes the modules that have been changed in the past to accommodate Cygwin.
1 parent f2128b0 commit fb8595d

8 files changed

Lines changed: 33 additions & 60 deletions

File tree

Include/pyport.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,11 @@ and both these use __declspec()
429429
# else /* Py_BUILD_CORE */
430430
/* Building an extension module, or an embedded situation */
431431
/* public Python functions and data are imported */
432-
# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
432+
/* Under Cygwin, auto-import functions to prevent compilation */
433+
/* failures similar to http://python.org/doc/FAQ.html#3.24 */
434+
# if !defined(__CYGWIN__)
435+
# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
436+
# endif /* !__CYGWIN__ */
433437
# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
434438
/* module init functions outside the core must be exported */
435439
# if defined(__cplusplus)

Modules/_hotshot.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ static PyTypeObject ProfilerType = {
12581258
0, /* tp_hash */
12591259
0, /* tp_call */
12601260
0, /* tp_str */
1261-
0, /* tp_getattro */
1261+
PyObject_GenericGetAttr, /* tp_getattro */
12621262
0, /* tp_setattro */
12631263
0, /* tp_as_buffer */
12641264
Py_TPFLAGS_DEFAULT, /* tp_flags */
@@ -1343,7 +1343,7 @@ static PyTypeObject LogReaderType = {
13431343
0, /* tp_hash */
13441344
0, /* tp_call */
13451345
0, /* tp_str */
1346-
0, /* tp_getattro */
1346+
PyObject_GenericGetAttr, /* tp_getattro */
13471347
0, /* tp_setattro */
13481348
0, /* tp_as_buffer */
13491349
Py_TPFLAGS_DEFAULT, /* tp_flags */
@@ -1634,9 +1634,7 @@ init_hotshot(void)
16341634
PyObject *module;
16351635

16361636
LogReaderType.ob_type = &PyType_Type;
1637-
LogReaderType.tp_getattro = PyObject_GenericGetAttr;
16381637
ProfilerType.ob_type = &PyType_Type;
1639-
ProfilerType.tp_getattro = PyObject_GenericGetAttr;
16401638
module = Py_InitModule("_hotshot", functions);
16411639
if (module != NULL) {
16421640
char *s = get_version_string();

Modules/_randommodule.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static PyTypeObject Random_Type = {
486486
0, /*tp_hash*/
487487
0, /*tp_call*/
488488
0, /*tp_str*/
489-
0, /*tp_getattro*/
489+
PyObject_GenericGetAttr, /*tp_getattro*/
490490
0, /*tp_setattro*/
491491
0, /*tp_as_buffer*/
492492
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
@@ -506,9 +506,9 @@ static PyTypeObject Random_Type = {
506506
0, /*tp_descr_set*/
507507
0, /*tp_dictoffset*/
508508
0, /*tp_init*/
509-
0, /*tp_alloc*/
509+
PyType_GenericAlloc, /*tp_alloc*/
510510
random_new, /*tp_new*/
511-
0, /*tp_free*/
511+
_PyObject_Del, /*tp_free*/
512512
0, /*tp_is_gc*/
513513
};
514514

@@ -520,9 +520,6 @@ init_random(void)
520520
{
521521
PyObject *m;
522522

523-
Random_Type.tp_getattro = PyObject_GenericGetAttr;
524-
Random_Type.tp_alloc = PyType_GenericAlloc;
525-
Random_Type.tp_free = _PyObject_Del;
526523
if (PyType_Ready(&Random_Type) < 0)
527524
return;
528525
m = Py_InitModule3("_random", NULL, module_doc);

Modules/_tkinter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ statichere PyTypeObject PyTclObject_Type = {
834834
0, /*tp_hash*/
835835
0, /*tp_call*/
836836
(reprfunc)PyTclObject_str, /*tp_str*/
837-
0, /*tp_getattro*/
837+
PyObject_GenericGetAttr,/*tp_getattro*/
838838
0, /*tp_setattro*/
839839
0, /*tp_as_buffer*/
840840
Py_TPFLAGS_DEFAULT, /*tp_flags*/
@@ -2931,7 +2931,6 @@ init_tkinter(void)
29312931
PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
29322932

29332933
PyTclObject_Type.ob_type = &PyType_Type;
2934-
PyTclObject_Type.tp_getattro = &PyObject_GenericGetAttr;
29352934
PyDict_SetItemString(d, "Tcl_Obj", (PyObject *)&PyTclObject_Type);
29362935

29372936
#ifdef TK_AQUA

Modules/arraymodule.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#endif /* DONT_HAVE_SYS_TYPES_H */
1414
#endif /* !STDC_HEADERS */
1515

16-
#define DELAYED(X) 0
17-
1816
struct arrayobject; /* Forward */
1917

2018
/* All possible arraydescr values are defined in the vector "descriptors"
@@ -1842,7 +1840,7 @@ static PyTypeObject Arraytype = {
18421840
0, /* tp_hash */
18431841
0, /* tp_call */
18441842
0, /* tp_str */
1845-
DELAYED(PyObject_GenericGetAttr), /* tp_getattro */
1843+
PyObject_GenericGetAttr, /* tp_getattro */
18461844
0, /* tp_setattro */
18471845
&array_as_buffer, /* tp_as_buffer*/
18481846
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
@@ -1862,9 +1860,9 @@ static PyTypeObject Arraytype = {
18621860
0, /* tp_descr_set */
18631861
0, /* tp_dictoffset */
18641862
0, /* tp_init */
1865-
DELAYED(PyType_GenericAlloc), /* tp_alloc */
1863+
PyType_GenericAlloc, /* tp_alloc */
18661864
array_new, /* tp_new */
1867-
DELAYED(PyObject_Del), /* tp_free */
1865+
PyObject_Del, /* tp_free */
18681866
};
18691867

18701868
/* No functions in array module. */
@@ -1879,9 +1877,6 @@ initarray(void)
18791877
PyObject *m;
18801878

18811879
Arraytype.ob_type = &PyType_Type;
1882-
Arraytype.tp_getattro = PyObject_GenericGetAttr;
1883-
Arraytype.tp_alloc = PyType_GenericAlloc;
1884-
Arraytype.tp_free = PyObject_Del;
18851880
m = Py_InitModule3("array", a_methods, module_doc);
18861881

18871882
Py_INCREF((PyObject *)&Arraytype);

Modules/bz2module.c

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,8 @@ static PyTypeObject BZ2File_Type = {
13871387
0, /*tp_hash*/
13881388
0, /*tp_call*/
13891389
0, /*tp_str*/
1390-
0, /*tp_getattro*/
1391-
0, /*tp_setattro*/
1390+
PyObject_GenericGetAttr,/*tp_getattro*/
1391+
PyObject_GenericSetAttr,/*tp_setattro*/
13921392
0, /*tp_as_buffer*/
13931393
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
13941394
BZ2File__doc__, /*tp_doc*/
@@ -1407,9 +1407,9 @@ static PyTypeObject BZ2File_Type = {
14071407
0, /*tp_descr_set*/
14081408
0, /*tp_dictoffset*/
14091409
(initproc)BZ2File_init, /*tp_init*/
1410-
0, /*tp_alloc*/
1410+
PyType_GenericAlloc, /*tp_alloc*/
14111411
0, /*tp_new*/
1412-
0, /*tp_free*/
1412+
_PyObject_Del, /*tp_free*/
14131413
0, /*tp_is_gc*/
14141414
};
14151415

@@ -1652,8 +1652,8 @@ static PyTypeObject BZ2Comp_Type = {
16521652
0, /*tp_hash*/
16531653
0, /*tp_call*/
16541654
0, /*tp_str*/
1655-
0, /*tp_getattro*/
1656-
0, /*tp_setattro*/
1655+
PyObject_GenericGetAttr,/*tp_getattro*/
1656+
PyObject_GenericSetAttr,/*tp_setattro*/
16571657
0, /*tp_as_buffer*/
16581658
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
16591659
BZ2Comp__doc__, /*tp_doc*/
@@ -1672,9 +1672,9 @@ static PyTypeObject BZ2Comp_Type = {
16721672
0, /*tp_descr_set*/
16731673
0, /*tp_dictoffset*/
16741674
(initproc)BZ2Comp_init, /*tp_init*/
1675-
0, /*tp_alloc*/
1676-
0, /*tp_new*/
1677-
0, /*tp_free*/
1675+
PyType_GenericAlloc, /*tp_alloc*/
1676+
PyType_GenericNew, /*tp_new*/
1677+
_PyObject_Del, /*tp_free*/
16781678
0, /*tp_is_gc*/
16791679
};
16801680

@@ -1869,8 +1869,8 @@ static PyTypeObject BZ2Decomp_Type = {
18691869
0, /*tp_hash*/
18701870
0, /*tp_call*/
18711871
0, /*tp_str*/
1872-
0, /*tp_getattro*/
1873-
0, /*tp_setattro*/
1872+
PyObject_GenericGetAttr,/*tp_getattro*/
1873+
PyObject_GenericSetAttr,/*tp_setattro*/
18741874
0, /*tp_as_buffer*/
18751875
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
18761876
BZ2Decomp__doc__, /*tp_doc*/
@@ -1889,9 +1889,9 @@ static PyTypeObject BZ2Decomp_Type = {
18891889
0, /*tp_descr_set*/
18901890
0, /*tp_dictoffset*/
18911891
(initproc)BZ2Decomp_init, /*tp_init*/
1892-
0, /*tp_alloc*/
1893-
0, /*tp_new*/
1894-
0, /*tp_free*/
1892+
PyType_GenericAlloc, /*tp_alloc*/
1893+
PyType_GenericNew, /*tp_new*/
1894+
_PyObject_Del, /*tp_free*/
18951895
0, /*tp_is_gc*/
18961896
};
18971897

@@ -2089,24 +2089,9 @@ initbz2(void)
20892089
BZ2File_Type.ob_type = &PyType_Type;
20902090
BZ2File_Type.tp_base = &PyFile_Type;
20912091
BZ2File_Type.tp_new = PyFile_Type.tp_new;
2092-
BZ2File_Type.tp_getattro = PyObject_GenericGetAttr;
2093-
BZ2File_Type.tp_setattro = PyObject_GenericSetAttr;
2094-
BZ2File_Type.tp_alloc = PyType_GenericAlloc;
2095-
BZ2File_Type.tp_free = _PyObject_Del;
20962092

20972093
BZ2Comp_Type.ob_type = &PyType_Type;
2098-
BZ2Comp_Type.tp_getattro = PyObject_GenericGetAttr;
2099-
BZ2Comp_Type.tp_setattro = PyObject_GenericSetAttr;
2100-
BZ2Comp_Type.tp_alloc = PyType_GenericAlloc;
2101-
BZ2Comp_Type.tp_new = PyType_GenericNew;
2102-
BZ2Comp_Type.tp_free = _PyObject_Del;
2103-
21042094
BZ2Decomp_Type.ob_type = &PyType_Type;
2105-
BZ2Decomp_Type.tp_getattro = PyObject_GenericGetAttr;
2106-
BZ2Decomp_Type.tp_setattro = PyObject_GenericSetAttr;
2107-
BZ2Decomp_Type.tp_alloc = PyType_GenericAlloc;
2108-
BZ2Decomp_Type.tp_new = PyType_GenericNew;
2109-
BZ2Decomp_Type.tp_free = _PyObject_Del;
21102095

21112096
m = Py_InitModule3("bz2", bz2_methods, bz2__doc__);
21122097

Modules/cPickle.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,8 +2543,8 @@ static PyTypeObject Picklertype = {
25432543
0, /* tp_hash */
25442544
0, /* tp_call */
25452545
0, /* tp_str */
2546-
0, /* set below */ /* tp_getattro */
2547-
0, /* set below */ /* tp_setattro */
2546+
PyObject_GenericGetAttr, /* tp_getattro */
2547+
PyObject_GenericSetAttr, /* tp_setattro */
25482548
0, /* tp_as_buffer */
25492549
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
25502550
Picklertype__doc__, /* tp_doc */
@@ -4808,8 +4808,6 @@ initcPickle(void)
48084808
PyObject *compatible_formats;
48094809

48104810
Picklertype.ob_type = &PyType_Type;
4811-
Picklertype.tp_getattro = PyObject_GenericGetAttr;
4812-
Picklertype.tp_setattro = PyObject_GenericSetAttr;
48134811
Unpicklertype.ob_type = &PyType_Type;
48144812
PdataType.ob_type = &PyType_Type;
48154813

Modules/socketmodule.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ static PyTypeObject sock_type = {
21152115
0, /* tp_hash */
21162116
0, /* tp_call */
21172117
0, /* tp_str */
2118-
0, /* set below */ /* tp_getattro */
2118+
PyObject_GenericGetAttr, /* tp_getattro */
21192119
0, /* tp_setattro */
21202120
0, /* tp_as_buffer */
21212121
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
@@ -2135,9 +2135,9 @@ static PyTypeObject sock_type = {
21352135
0, /* tp_descr_set */
21362136
0, /* tp_dictoffset */
21372137
sock_initobj, /* tp_init */
2138-
0, /* set below */ /* tp_alloc */
2138+
PyType_GenericAlloc, /* tp_alloc */
21392139
sock_new, /* tp_new */
2140-
0, /* set below */ /* tp_free */
2140+
PyObject_Del, /* tp_free */
21412141
};
21422142

21432143

@@ -3147,9 +3147,6 @@ init_socket(void)
31473147
return;
31483148

31493149
sock_type.ob_type = &PyType_Type;
3150-
sock_type.tp_getattro = PyObject_GenericGetAttr;
3151-
sock_type.tp_alloc = PyType_GenericAlloc;
3152-
sock_type.tp_free = PyObject_Del;
31533150
m = Py_InitModule3(PySocket_MODULE_NAME,
31543151
socket_methods,
31553152
socket_doc);

0 commit comments

Comments
 (0)