Skip to content

Commit 3f34237

Browse files
author
Erlend E. Aasland
committed
Move _PyType_DisabledNew to Include/internal and build affected extension modules with Py_BUILD_CORE_*
1 parent d41b799 commit 3f34237

File tree

16 files changed

+36
-13
lines changed

16 files changed

+36
-13
lines changed

Include/cpython/object.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
PyAPI_FUNC(void) _Py_NewReference(PyObject *op);
66

7-
PyAPI_FUNC(PyObject *) _PyType_DisabledNew(PyTypeObject *, PyObject *,
8-
PyObject *);
9-
107
#ifdef Py_TRACE_REFS
118
/* Py_TRACE_REFS is such major surgery that we call external routines. */
129
PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);

Include/internal/pycore_object.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ _PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
2929

3030
extern void _PyType_InitCache(PyInterpreterState *interp);
3131

32+
PyAPI_FUNC(PyObject *) _PyType_DisabledNew(PyTypeObject *type, PyObject *args,
33+
PyObject *kwds);
34+
3235

3336
/* Inline functions trading binary compatibility for speed:
3437
_PyObject_Init() is the fast version of PyObject_Init(), and

Modules/Setup

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ _symtable symtablemodule.c
166166

167167
# Modules that should always be present (non UNIX dependent):
168168

169-
#array -DPy_BUILD_CORE_MODULE arraymodule.c # array objects
169+
#array -DPy_BUILD_CORE_BUILTIN arraymodule.c # array objects
170170
#cmath cmathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # complex math library functions
171171
#math mathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # math library functions, e.g. sin()
172172
#_contextvars _contextvarsmodule.c # Context Variables
@@ -279,7 +279,7 @@ _symtable symtablemodule.c
279279
# every system.
280280

281281
# *** Always uncomment this (leave the leading underscore in!):
282-
# _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \
282+
# _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT -DPy_BUILD_CORE_BUILTIN \
283283
# *** Uncomment and edit to reflect where your Tcl/Tk libraries are:
284284
# -L/usr/local/lib \
285285
# *** Uncomment and edit to reflect where your Tcl/Tk headers are:
@@ -320,7 +320,7 @@ _symtable symtablemodule.c
320320

321321
#_curses _cursesmodule.c -lcurses -ltermcap -DPy_BUILD_CORE_MODULE
322322
# Wrapper for the panel library that's part of ncurses and SYSV curses.
323-
#_curses_panel _curses_panel.c -lpanel -lncurses
323+
#_curses_panel _curses_panel.c -lpanel -lncurses -DPy_BUILD_CORE_BUILTIN
324324

325325

326326
# Modules that provide persistent dictionary-like semantics. You will
@@ -330,11 +330,11 @@ _symtable symtablemodule.c
330330
# implementation independent wrapper for these; dbm/dumb.py provides
331331
# similar functionality (but slower of course) implemented in Python.
332332

333-
#_dbm _dbmmodule.c # dbm(3) may require -lndbm or similar
333+
#_dbm _dbmmodule.c -DPy_BUILD_CORE_BUILTIN # dbm(3) may require -lndbm or similar
334334

335335
# Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
336336

337-
#_gdbm _gdbmmodule.c -I/usr/local/include -L/usr/local/lib -lgdbm
337+
#_gdbm _gdbmmodule.c -I/usr/local/include -L/usr/local/lib -lgdbm -DPy_BUILD_CORE_BUILTIN
338338

339339

340340
# Helper module for various ascii-encoders
@@ -343,17 +343,17 @@ _symtable symtablemodule.c
343343
# Andrew Kuchling's zlib module.
344344
# This require zlib 1.1.3 (or later).
345345
# See http://www.gzip.org/zlib/
346-
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
346+
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz -DPy_BUILD_CORE_BUILTIN
347347

348348
# Interface to the Expat XML parser
349349
# More information on Expat can be found at www.libexpat.org.
350350
#
351-
#pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DXML_POOR_ENTROPY -DUSE_PYEXPAT_CAPI
351+
#pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DXML_POOR_ENTROPY -DUSE_PYEXPAT_CAPI -DPy_BUILD_CORE_BUILTIN
352352

353353
# Hye-Shik Chang's CJKCodecs
354354

355355
# multibytecodec is required for all the other CJK codec modules
356-
#_multibytecodec cjkcodecs/multibytecodec.c
356+
#_multibytecodec cjkcodecs/multibytecodec.c -DPy_BUILD_CORE_BUILTIN
357357

358358
#_codecs_cn cjkcodecs/_codecs_cn.c
359359
#_codecs_hk cjkcodecs/_codecs_hk.c

Modules/_curses_panel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static const char PyCursesVersion[] = "2.1";
1313
#include "Python.h"
1414

1515
#include "py_curses.h"
16+
#include "pycore_object.h" // _PyType_DisabledNew()
1617

1718
#include <panel.h>
1819

Modules/_dbmmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#define PY_SSIZE_T_CLEAN
66
#include "Python.h"
7+
#include "pycore_object.h" // _PyType_DisabledNew()
78

89
#include <sys/types.h>
910
#include <sys/stat.h>

Modules/_gdbmmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#define PY_SSIZE_T_CLEAN
77
#include "Python.h"
8+
#include "pycore_object.h" // _PyType_DisabledNew()
89

910
#include <sys/types.h>
1011
#include <sys/stat.h>

Modules/_sre.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static const char copyright[] =
4343
#include "Python.h"
4444
#include "pycore_long.h" // _PyLong_GetZero()
4545
#include "pycore_moduleobject.h" // _PyModule_GetState()
46+
#include "pycore_object.h" // _PyType_DisabledNew()
4647
#include "structmember.h" // PyMemberDef
4748

4849
#include "sre.h"

Modules/_threadmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Python.h"
66
#include "pycore_interp.h" // _PyInterpreterState.num_threads
77
#include "pycore_moduleobject.h" // _PyModule_GetState()
8+
#include "pycore_object.h" // _PyType_DisabledNew()
89
#include "pycore_pylifecycle.h"
910
#include "pycore_pystate.h" // _PyThreadState_Init()
1011
#include <stddef.h> // offsetof()

Modules/_tkinter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Copyright (C) 1994 Steen Lumholt.
2424
#define PY_SSIZE_T_CLEAN
2525

2626
#include "Python.h"
27+
#include "pycore_object.h" // _PyType_DisabledNew()
2728
#include <ctype.h>
2829

2930
#ifdef MS_WINDOWS

Modules/arraymodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define PY_SSIZE_T_CLEAN
77
#include "Python.h"
88
#include "pycore_moduleobject.h" // _PyModule_GetState()
9+
#include "pycore_object.h" // _PyType_DisabledNew()
910
#include "structmember.h" // PyMemberDef
1011
#include <stddef.h> // offsetof()
1112

Modules/cjkcodecs/multibytecodec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#define PY_SSIZE_T_CLEAN
88
#include "Python.h"
9+
#include "pycore_object.h" // _PyType_DisabledNew()
910
#include "structmember.h" // PyMemberDef
1011
#include "multibytecodec.h"
1112
#include "clinic/multibytecodec.c.h"

Modules/posixmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "pycore_ceval.h" // _PyEval_ReInitThreads()
3030
#include "pycore_import.h" // _PyImport_ReInitLock()
3131
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
32+
#include "pycore_object.h" // _PyType_DisabledNew()
3233
#include "pycore_pystate.h" // _PyInterpreterState_GET()
3334
#include "structmember.h" // PyMemberDef
3435
#ifndef MS_WINDOWS

Modules/pyexpat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Python.h"
22
#include <ctype.h>
33

4+
#include "pycore_object.h" // _PyType_DisabledNew()
45
#include "structmember.h" // PyMemberDef
56
#include "frameobject.h"
67
#include "expat.h"

Modules/unicodedata.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define PY_SSIZE_T_CLEAN
1717

1818
#include "Python.h"
19+
#include "pycore_object.h" // _PyType_DisabledNew()
1920
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
2021
#include "structmember.h" // PyMemberDef
2122

Modules/zlibmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define PY_SSIZE_T_CLEAN
77

88
#include "Python.h"
9+
#include "pycore_object.h" // _PyType_DisabledNew()
910
#include "structmember.h" // PyMemberDef
1011
#include "zlib.h"
1112

setup.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ def detect_readline_curses(self):
11901190
self.add(Extension('_curses_panel', ['_curses_panel.c'],
11911191
include_dirs=curses_includes,
11921192
define_macros=curses_defines,
1193+
extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
11931194
libraries=[panel_library, *curses_libs]))
11941195
elif not skip_curses_panel:
11951196
self.missing.append('_curses_panel')
@@ -1440,6 +1441,7 @@ class db_found(Exception): pass
14401441
else:
14411442
dbm_order = "ndbm:gdbm:bdb".split(":")
14421443
dbmext = None
1444+
dbm_compile_args = ['-DPy_BUILD_CORE_MODULE']
14431445
for cand in dbm_order:
14441446
if cand == "ndbm":
14451447
if find_file("ndbm.h", self.inc_dirs, []) is not None:
@@ -1458,6 +1460,7 @@ class db_found(Exception): pass
14581460
define_macros=[
14591461
('HAVE_NDBM_H',None),
14601462
],
1463+
extra_compile_args=dbm_compile_args,
14611464
libraries=ndbm_libs)
14621465
break
14631466

@@ -1474,6 +1477,7 @@ class db_found(Exception): pass
14741477
define_macros=[
14751478
('HAVE_GDBM_NDBM_H', None),
14761479
],
1480+
extra_compile_args=dbm_compile_args,
14771481
libraries = gdbm_libs)
14781482
break
14791483
if find_file("gdbm-ndbm.h", self.inc_dirs, []) is not None:
@@ -1483,6 +1487,7 @@ class db_found(Exception): pass
14831487
define_macros=[
14841488
('HAVE_GDBM_DASH_NDBM_H', None),
14851489
],
1490+
extra_compile_args=dbm_compile_args,
14861491
libraries = gdbm_libs)
14871492
break
14881493
elif cand == "bdb":
@@ -1496,6 +1501,7 @@ class db_found(Exception): pass
14961501
('HAVE_BERKDB_H', None),
14971502
('DB_DBM_HSEARCH', None),
14981503
],
1504+
extra_compile_args=dbm_compile_args,
14991505
libraries=dblibs)
15001506
break
15011507
if dbmext is not None:
@@ -1507,6 +1513,7 @@ class db_found(Exception): pass
15071513
if ('gdbm' in dbm_order and
15081514
self.compiler.find_library_file(self.lib_dirs, 'gdbm')):
15091515
self.add(Extension('_gdbm', ['_gdbmmodule.c'],
1516+
extra_compile_args=dbm_compile_args,
15101517
libraries=['gdbm']))
15111518
else:
15121519
self.missing.append('_gdbm')
@@ -1682,6 +1689,7 @@ def detect_compress_exts(self):
16821689
zlib_extra_link_args = ()
16831690
self.add(Extension('zlib', ['zlibmodule.c'],
16841691
libraries=['z'],
1692+
extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
16851693
extra_link_args=zlib_extra_link_args))
16861694
have_zlib = True
16871695
else:
@@ -1752,7 +1760,7 @@ def detect_expat_elementtree(self):
17521760
# call XML_SetHashSalt(), expat entropy sources are not needed
17531761
('XML_POOR_ENTROPY', '1'),
17541762
]
1755-
extra_compile_args = []
1763+
extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
17561764
expat_lib = []
17571765
expat_sources = ['expat/xmlparse.c',
17581766
'expat/xmlrole.c',
@@ -1802,7 +1810,8 @@ def detect_expat_elementtree(self):
18021810
def detect_multibytecodecs(self):
18031811
# Hye-Shik Chang's CJKCodecs modules.
18041812
self.add(Extension('_multibytecodec',
1805-
['cjkcodecs/multibytecodec.c']))
1813+
['cjkcodecs/multibytecodec.c'],
1814+
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
18061815
for loc in ('kr', 'jp', 'cn', 'tw', 'hk', 'iso2022'):
18071816
self.add(Extension('_codecs_%s' % loc,
18081817
['cjkcodecs/_codecs_%s.c' % loc]))
@@ -1925,6 +1934,7 @@ def detect_tkinter_fromenv(self):
19251934
return False
19261935

19271936
extra_compile_args = tcltk_includes.split()
1937+
extra_compile_args.append('-DPy_BUILD_CORE_MODULE')
19281938
extra_link_args = tcltk_libs.split()
19291939
self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
19301940
define_macros=[('WITH_APPINIT', 1)],
@@ -2056,6 +2066,7 @@ def detect_tkinter_darwin(self):
20562066
if '-Wstrict-prototypes' in cflags.split():
20572067
compile_args.append('-Wno-strict-prototypes')
20582068

2069+
compile_args.append('-DPy_BUILD_CORE_MODULE')
20592070
self.add(Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
20602071
define_macros=[('WITH_APPINIT', 1)],
20612072
include_dirs=include_dirs,

0 commit comments

Comments
 (0)