Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(17)

Side by Side Diff: Python/import.c

Issue 20152: Derby: Convert the _imp module to use Argument Clinic
Patch Set: Created 6 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* Module definition and import implementation */ 2 /* Module definition and import implementation */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 5
6 #include "Python-ast.h" 6 #include "Python-ast.h"
7 #undef Yield /* undefine macro conflicting with winbase.h */ 7 #undef Yield /* undefine macro conflicting with winbase.h */
8 #include "errcode.h" 8 #include "errcode.h"
9 #include "marshal.h" 9 #include "marshal.h"
10 #include "code.h" 10 #include "code.h"
(...skipping 12 matching lines...) Expand all
23 23
24 /* See _PyImport_FixupExtensionObject() below */ 24 /* See _PyImport_FixupExtensionObject() below */
25 static PyObject *extensions = NULL; 25 static PyObject *extensions = NULL;
26 26
27 /* This table is defined in config.c: */ 27 /* This table is defined in config.c: */
28 extern struct _inittab _PyImport_Inittab[]; 28 extern struct _inittab _PyImport_Inittab[];
29 29
30 struct _inittab *PyImport_Inittab = _PyImport_Inittab; 30 struct _inittab *PyImport_Inittab = _PyImport_Inittab;
31 31
32 static PyObject *initstr = NULL; 32 static PyObject *initstr = NULL;
33
34 /*[clinic input]
35 module _imp
36 [clinic start generated code]*/
37 /*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709] */
38
39 /*[python input]
40 class fs_unicode_converter(CConverter):
41 type = 'PyObject *'
42 format_unit = 'O&'
larry 2014/01/08 19:10:35 'O&' is the default format unit for CConverter, ve
brett.cannon 2014/01/10 01:01:38 Hold-over from when I tried to subclass object_con
43 converter = 'PyUnicode_FSDecoder'
44
45 [python start generated code]*/
46 /*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709] */
33 47
34 /* Initialize things */ 48 /* Initialize things */
35 49
36 void 50 void
37 _PyImport_Init(void) 51 _PyImport_Init(void)
38 { 52 {
39 initstr = PyUnicode_InternFromString("__init__"); 53 initstr = PyUnicode_InternFromString("__init__");
40 if (initstr == NULL) 54 if (initstr == NULL)
41 Py_FatalError("Can't initialize import variables"); 55 Py_FatalError("Can't initialize import variables");
42 } 56 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 import_lock_thread = me; 217 import_lock_thread = me;
204 import_lock_level--; 218 import_lock_level--;
205 } else { 219 } else {
206 import_lock_thread = -1; 220 import_lock_thread = -1;
207 import_lock_level = 0; 221 import_lock_level = 0;
208 } 222 }
209 } 223 }
210 224
211 #endif 225 #endif
212 226
227 /*[clinic input]
228 _imp.lock_held
229
230 Return True if the import lock is currently held, else False.
231
232 On platforms without threads, return False.
233 [clinic start generated code]*/
234
235 PyDoc_STRVAR(_imp_lock_held__doc__,
236 "lock_held()\n"
237 "Return True if the import lock is currently held, else False.\n"
238 "\n"
239 "On platforms without threads, return False.");
240
241 #define _IMP_LOCK_HELD_METHODDEF \
242 {"lock_held", (PyCFunction)_imp_lock_held, METH_NOARGS, _imp_lock_held__doc_ _},
243
213 static PyObject * 244 static PyObject *
214 imp_lock_held(PyObject *self, PyObject *noargs) 245 _imp_lock_held_impl(PyModuleDef *module);
246
247 static PyObject *
248 _imp_lock_held(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
249 {
250 PyObject *return_value = NULL;
251
252 return_value = _imp_lock_held_impl(module);
253
254 return return_value;
255 }
256
257 static PyObject *
258 _imp_lock_held_impl(PyModuleDef *module)
259 /*[clinic end generated code: checksum=c5858b257881f94dee95526229a8d1a57ccff158] */
215 { 260 {
216 #ifdef WITH_THREAD 261 #ifdef WITH_THREAD
217 return PyBool_FromLong(import_lock_thread != -1); 262 return PyBool_FromLong(import_lock_thread != -1);
218 #else 263 #else
219 return PyBool_FromLong(0); 264 return PyBool_FromLong(0);
220 #endif 265 #endif
221 } 266 }
222 267
268 /*[clinic input]
269 _imp.acquire_lock
270
271 Acquires the interpreter's import lock for the current thread.
272
273 This lock should be used by import hooks to ensure thread-safety when importing
274 modules. On platforms without threads, this function does nothing.
275 [clinic start generated code]*/
276
277 PyDoc_STRVAR(_imp_acquire_lock__doc__,
278 "acquire_lock()\n"
279 "Acquires the interpreter\'s import lock for the current thread.\n"
280 "\n"
281 "This lock should be used by import hooks to ensure thread-safety when importing \n"
282 "modules. On platforms without threads, this function does nothing.");
283
284 #define _IMP_ACQUIRE_LOCK_METHODDEF \
285 {"acquire_lock", (PyCFunction)_imp_acquire_lock, METH_NOARGS, _imp_acquire_l ock__doc__},
286
223 static PyObject * 287 static PyObject *
224 imp_acquire_lock(PyObject *self, PyObject *noargs) 288 _imp_acquire_lock_impl(PyModuleDef *module);
289
290 static PyObject *
291 _imp_acquire_lock(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
292 {
293 PyObject *return_value = NULL;
294
295 return_value = _imp_acquire_lock_impl(module);
296
297 return return_value;
298 }
299
300 static PyObject *
301 _imp_acquire_lock_impl(PyModuleDef *module)
302 /*[clinic end generated code: checksum=badb56ed0079a6b902c9616fe068d572765b1863] */
225 { 303 {
226 #ifdef WITH_THREAD 304 #ifdef WITH_THREAD
227 _PyImport_AcquireLock(); 305 _PyImport_AcquireLock();
228 #endif 306 #endif
229 Py_INCREF(Py_None); 307 Py_INCREF(Py_None);
230 return Py_None; 308 return Py_None;
231 } 309 }
232 310
311 /*[clinic input]
312 _imp.release_lock
313
314 Release the interpreter's import lock.
315
316 On platforms without threads, this function does nothing.
317 [clinic start generated code]*/
318
319 PyDoc_STRVAR(_imp_release_lock__doc__,
320 "release_lock()\n"
321 "Release the interpreter\'s import lock.\n"
322 "\n"
323 "On platforms without threads, this function does nothing.");
324
325 #define _IMP_RELEASE_LOCK_METHODDEF \
326 {"release_lock", (PyCFunction)_imp_release_lock, METH_NOARGS, _imp_release_l ock__doc__},
327
233 static PyObject * 328 static PyObject *
234 imp_release_lock(PyObject *self, PyObject *noargs) 329 _imp_release_lock_impl(PyModuleDef *module);
330
331 static PyObject *
332 _imp_release_lock(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
333 {
334 PyObject *return_value = NULL;
335
336 return_value = _imp_release_lock_impl(module);
337
338 return return_value;
339 }
340
341 static PyObject *
342 _imp_release_lock_impl(PyModuleDef *module)
343 /*[clinic end generated code: checksum=f1c2a75e3136a113184e0af2a676d5f0b5b685b4] */
235 { 344 {
236 #ifdef WITH_THREAD 345 #ifdef WITH_THREAD
237 if (_PyImport_ReleaseLock() < 0) { 346 if (_PyImport_ReleaseLock() < 0) {
238 PyErr_SetString(PyExc_RuntimeError, 347 PyErr_SetString(PyExc_RuntimeError,
239 "not holding the import lock"); 348 "not holding the import lock");
240 return NULL; 349 return NULL;
241 } 350 }
242 #endif 351 #endif
243 Py_INCREF(Py_None); 352 Py_INCREF(Py_None);
244 return Py_None; 353 return Py_None;
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 919
811 if (PyUnicode_Compare(co->co_filename, newname) == 0) 920 if (PyUnicode_Compare(co->co_filename, newname) == 0)
812 return; 921 return;
813 922
814 oldname = co->co_filename; 923 oldname = co->co_filename;
815 Py_INCREF(oldname); 924 Py_INCREF(oldname);
816 update_code_filenames(co, oldname, newname); 925 update_code_filenames(co, oldname, newname);
817 Py_DECREF(oldname); 926 Py_DECREF(oldname);
818 } 927 }
819 928
929 /*[clinic input]
930 _imp._fix_co_filename
931
932 code: object
larry 2014/01/08 19:10:35 If you change this to code: object(type="PyCodeOb
brett.cannon 2014/01/10 01:01:38 Done.
933 Code object to change.
934
935 path: unicode
936 File path to use.
937 /
938
939 Changes code.co_filename to specify the passed-in file path.
940 [clinic start generated code]*/
941
942 PyDoc_STRVAR(_imp__fix_co_filename__doc__,
943 "_fix_co_filename(code, path)\n"
944 "Changes code.co_filename to specify the passed-in file path.\n"
945 "\n"
946 " code\n"
947 " Code object to change.\n"
948 " path\n"
949 " File path to use.");
950
951 #define _IMP__FIX_CO_FILENAME_METHODDEF \
952 {"_fix_co_filename", (PyCFunction)_imp__fix_co_filename, METH_VARARGS, _imp_ _fix_co_filename__doc__},
953
820 static PyObject * 954 static PyObject *
821 imp_fix_co_filename(PyObject *self, PyObject *args) 955 _imp__fix_co_filename_impl(PyModuleDef *module, PyObject *code, PyObject *path);
956
957 static PyObject *
958 _imp__fix_co_filename(PyModuleDef *module, PyObject *args)
822 { 959 {
823 PyObject *co; 960 PyObject *return_value = NULL;
824 PyObject *file_path; 961 PyObject *code;
962 PyObject *path;
825 963
826 if (!PyArg_ParseTuple(args, "OO:_fix_co_filename", &co, &file_path)) 964 if (!PyArg_ParseTuple(args,
827 return NULL; 965 "OU:_fix_co_filename",
larry 2014/01/08 19:10:35 You panicked me: the original format string is "OO
966 &code, &path))
967 goto exit;
968 return_value = _imp__fix_co_filename_impl(module, code, path);
828 969
829 if (!PyCode_Check(co)) { 970 exit:
971 return return_value;
972 }
973
974 static PyObject *
975 _imp__fix_co_filename_impl(PyModuleDef *module, PyObject *code, PyObject *path)
976 /*[clinic end generated code: checksum=88822f90df4664448a927862ebae39bae86514e0] */
977
978 {
979 if (!PyCode_Check(code)) {
830 PyErr_SetString(PyExc_TypeError, 980 PyErr_SetString(PyExc_TypeError,
831 "first argument must be a code object"); 981 "first argument must be a code object");
832 return NULL; 982 return NULL;
833 } 983 }
834 984
835 if (!PyUnicode_Check(file_path)) { 985 update_compiled_module((PyCodeObject*)code, path);
836 PyErr_SetString(PyExc_TypeError,
837 "second argument must be a string");
838 return NULL;
839 }
840
841 update_compiled_module((PyCodeObject*)co, file_path);
842 986
843 Py_RETURN_NONE; 987 Py_RETURN_NONE;
844 } 988 }
845 989
846 990
847 /* Forward */ 991 /* Forward */
848 static const struct _frozen * find_frozen(PyObject *); 992 static const struct _frozen * find_frozen(PyObject *);
849 993
850 994
851 /* Helper to test for built-in module */ 995 /* Helper to test for built-in module */
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 Py_INCREF(r); 1828 Py_INCREF(r);
1685 1829
1686 err: 1830 err:
1687 Py_XDECREF(globals); 1831 Py_XDECREF(globals);
1688 Py_XDECREF(builtins); 1832 Py_XDECREF(builtins);
1689 Py_XDECREF(import); 1833 Py_XDECREF(import);
1690 1834
1691 return r; 1835 return r;
1692 } 1836 }
1693 1837
1838 /*[clinic input]
1839 _imp.extension_suffixes
1840
1841 Returns the list of file suffixes used to identify extension modules.
1842 [clinic start generated code]*/
1843
1844 PyDoc_STRVAR(_imp_extension_suffixes__doc__,
1845 "extension_suffixes()\n"
1846 "Returns the list of file suffixes used to identify extension modules.");
1847
1848 #define _IMP_EXTENSION_SUFFIXES_METHODDEF \
1849 {"extension_suffixes", (PyCFunction)_imp_extension_suffixes, METH_NOARGS, _i mp_extension_suffixes__doc__},
1850
1694 static PyObject * 1851 static PyObject *
1695 imp_extension_suffixes(PyObject *self, PyObject *noargs) 1852 _imp_extension_suffixes_impl(PyModuleDef *module);
1853
1854 static PyObject *
1855 _imp_extension_suffixes(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
1856 {
1857 PyObject *return_value = NULL;
1858
1859 return_value = _imp_extension_suffixes_impl(module);
1860
1861 return return_value;
1862 }
1863
1864 static PyObject *
1865 _imp_extension_suffixes_impl(PyModuleDef *module)
1866 /*[clinic end generated code: checksum=835921e67fd698e22e101eea64839d1ad62b6451] */
1696 { 1867 {
1697 PyObject *list; 1868 PyObject *list;
1698 const char *suffix; 1869 const char *suffix;
1699 unsigned int index = 0; 1870 unsigned int index = 0;
1700 1871
1701 list = PyList_New(0); 1872 list = PyList_New(0);
1702 if (list == NULL) 1873 if (list == NULL)
1703 return NULL; 1874 return NULL;
1704 #ifdef HAVE_DYNAMIC_LOADING 1875 #ifdef HAVE_DYNAMIC_LOADING
1705 while ((suffix = _PyImport_DynLoadFiletab[index])) { 1876 while ((suffix = _PyImport_DynLoadFiletab[index])) {
1706 PyObject *item = PyUnicode_FromString(suffix); 1877 PyObject *item = PyUnicode_FromString(suffix);
1707 if (item == NULL) { 1878 if (item == NULL) {
1708 Py_DECREF(list); 1879 Py_DECREF(list);
1709 return NULL; 1880 return NULL;
1710 } 1881 }
1711 if (PyList_Append(list, item) < 0) { 1882 if (PyList_Append(list, item) < 0) {
1712 Py_DECREF(list); 1883 Py_DECREF(list);
1713 Py_DECREF(item); 1884 Py_DECREF(item);
1714 return NULL; 1885 return NULL;
1715 } 1886 }
1716 Py_DECREF(item); 1887 Py_DECREF(item);
1717 index += 1; 1888 index += 1;
1718 } 1889 }
1719 #endif 1890 #endif
1720 return list; 1891 return list;
1721 } 1892 }
1722 1893
1894 /*[clinic input]
1895 _imp.init_builtin
1896
1897 name: unicode
1898 /
1899
1900 Initializes a built-in module.
1901 [clinic start generated code]*/
1902
1903 PyDoc_STRVAR(_imp_init_builtin__doc__,
1904 "init_builtin(name)\n"
1905 "Initializes a built-in module.");
1906
1907 #define _IMP_INIT_BUILTIN_METHODDEF \
1908 {"init_builtin", (PyCFunction)_imp_init_builtin, METH_VARARGS, _imp_init_bui ltin__doc__},
1909
1723 static PyObject * 1910 static PyObject *
1724 imp_init_builtin(PyObject *self, PyObject *args) 1911 _imp_init_builtin_impl(PyModuleDef *module, PyObject *name);
1912
1913 static PyObject *
1914 _imp_init_builtin(PyModuleDef *module, PyObject *args)
1725 { 1915 {
1916 PyObject *return_value = NULL;
1726 PyObject *name; 1917 PyObject *name;
1918
1919 if (!PyArg_ParseTuple(args,
1920 "U:init_builtin",
1921 &name))
1922 goto exit;
1923 return_value = _imp_init_builtin_impl(module, name);
1924
1925 exit:
1926 return return_value;
1927 }
1928
1929 static PyObject *
1930 _imp_init_builtin_impl(PyModuleDef *module, PyObject *name)
1931 /*[clinic end generated code: checksum=59239206e5b2fb59358066e72fd0e72e55a7baf5] */
1932 {
1727 int ret; 1933 int ret;
1728 PyObject *m; 1934 PyObject *m;
1729 if (!PyArg_ParseTuple(args, "U:init_builtin", &name)) 1935
1730 return NULL;
1731 ret = init_builtin(name); 1936 ret = init_builtin(name);
1732 if (ret < 0) 1937 if (ret < 0)
1733 return NULL; 1938 return NULL;
1734 if (ret == 0) { 1939 if (ret == 0) {
1735 Py_INCREF(Py_None); 1940 Py_INCREF(Py_None);
1736 return Py_None; 1941 return Py_None;
1737 } 1942 }
1738 m = PyImport_AddModuleObject(name); 1943 m = PyImport_AddModuleObject(name);
1739 Py_XINCREF(m); 1944 Py_XINCREF(m);
1740 return m; 1945 return m;
1741 } 1946 }
1742 1947
1948 /*[clinic input]
1949 _imp.init_frozen
1950
1951 name: unicode
1952 /
1953
1954 Initializes a frozen module.
1955 [clinic start generated code]*/
1956
1957 PyDoc_STRVAR(_imp_init_frozen__doc__,
1958 "init_frozen(name)\n"
1959 "Initializes a frozen module.");
1960
1961 #define _IMP_INIT_FROZEN_METHODDEF \
1962 {"init_frozen", (PyCFunction)_imp_init_frozen, METH_VARARGS, _imp_init_froze n__doc__},
1963
1743 static PyObject * 1964 static PyObject *
1744 imp_init_frozen(PyObject *self, PyObject *args) 1965 _imp_init_frozen_impl(PyModuleDef *module, PyObject *name);
1966
1967 static PyObject *
1968 _imp_init_frozen(PyModuleDef *module, PyObject *args)
1745 { 1969 {
1970 PyObject *return_value = NULL;
1746 PyObject *name; 1971 PyObject *name;
1972
1973 if (!PyArg_ParseTuple(args,
1974 "U:init_frozen",
1975 &name))
1976 goto exit;
1977 return_value = _imp_init_frozen_impl(module, name);
1978
1979 exit:
1980 return return_value;
1981 }
1982
1983 static PyObject *
1984 _imp_init_frozen_impl(PyModuleDef *module, PyObject *name)
1985 /*[clinic end generated code: checksum=503fcc3de9961263e4d9484259af357a7d287a0b] */
1986 {
1747 int ret; 1987 int ret;
1748 PyObject *m; 1988 PyObject *m;
1749 if (!PyArg_ParseTuple(args, "U:init_frozen", &name)) 1989
1750 return NULL;
1751 ret = PyImport_ImportFrozenModuleObject(name); 1990 ret = PyImport_ImportFrozenModuleObject(name);
1752 if (ret < 0) 1991 if (ret < 0)
1753 return NULL; 1992 return NULL;
1754 if (ret == 0) { 1993 if (ret == 0) {
1755 Py_INCREF(Py_None); 1994 Py_INCREF(Py_None);
1756 return Py_None; 1995 return Py_None;
1757 } 1996 }
1758 m = PyImport_AddModuleObject(name); 1997 m = PyImport_AddModuleObject(name);
1759 Py_XINCREF(m); 1998 Py_XINCREF(m);
1760 return m; 1999 return m;
1761 } 2000 }
1762 2001
1763 static PyObject * 2002 /*[clinic input]
1764 imp_get_frozen_object(PyObject *self, PyObject *args) 2003 _imp.get_frozen_object
1765 { 2004
1766 PyObject *name; 2005 name: unicode
1767 2006 /
1768 if (!PyArg_ParseTuple(args, "U:get_frozen_object", &name)) 2007
1769 return NULL; 2008 Create a code object for a frozen module.
2009 [clinic start generated code]*/
2010
2011 PyDoc_STRVAR(_imp_get_frozen_object__doc__,
2012 "get_frozen_object(name)\n"
2013 "Create a code object for a frozen module.");
2014
2015 #define _IMP_GET_FROZEN_OBJECT_METHODDEF \
2016 {"get_frozen_object", (PyCFunction)_imp_get_frozen_object, METH_VARARGS, _im p_get_frozen_object__doc__},
2017
2018 static PyObject *
2019 _imp_get_frozen_object_impl(PyModuleDef *module, PyObject *name);
2020
2021 static PyObject *
2022 _imp_get_frozen_object(PyModuleDef *module, PyObject *args)
2023 {
2024 PyObject *return_value = NULL;
2025 PyObject *name;
2026
2027 if (!PyArg_ParseTuple(args,
2028 "U:get_frozen_object",
2029 &name))
2030 goto exit;
2031 return_value = _imp_get_frozen_object_impl(module, name);
2032
2033 exit:
2034 return return_value;
2035 }
2036
2037 static PyObject *
2038 _imp_get_frozen_object_impl(PyModuleDef *module, PyObject *name)
2039 /*[clinic end generated code: checksum=7a6423a4daf139496b9a394ff3ac6130089d1cba] */
2040 {
1770 return get_frozen_object(name); 2041 return get_frozen_object(name);
1771 } 2042 }
1772 2043
1773 static PyObject * 2044 /*[clinic input]
1774 imp_is_frozen_package(PyObject *self, PyObject *args) 2045 _imp.is_frozen_package
1775 { 2046
1776 PyObject *name; 2047 name: unicode
1777 2048 /
1778 if (!PyArg_ParseTuple(args, "U:is_frozen_package", &name)) 2049
1779 return NULL; 2050 Returns True if the module name is of a frozen package.
2051 [clinic start generated code]*/
2052
2053 PyDoc_STRVAR(_imp_is_frozen_package__doc__,
2054 "is_frozen_package(name)\n"
2055 "Returns True if the module name is of a frozen package.");
2056
2057 #define _IMP_IS_FROZEN_PACKAGE_METHODDEF \
2058 {"is_frozen_package", (PyCFunction)_imp_is_frozen_package, METH_VARARGS, _im p_is_frozen_package__doc__},
2059
2060 static PyObject *
2061 _imp_is_frozen_package_impl(PyModuleDef *module, PyObject *name);
2062
2063 static PyObject *
2064 _imp_is_frozen_package(PyModuleDef *module, PyObject *args)
2065 {
2066 PyObject *return_value = NULL;
2067 PyObject *name;
2068
2069 if (!PyArg_ParseTuple(args,
2070 "U:is_frozen_package",
2071 &name))
2072 goto exit;
2073 return_value = _imp_is_frozen_package_impl(module, name);
2074
2075 exit:
2076 return return_value;
2077 }
2078
2079 static PyObject *
2080 _imp_is_frozen_package_impl(PyModuleDef *module, PyObject *name)
2081 /*[clinic end generated code: checksum=dc7e361ea30b6945b8bbe7266d7b9a5ea433b510] */
2082 {
1780 return is_frozen_package(name); 2083 return is_frozen_package(name);
1781 } 2084 }
1782 2085
1783 static PyObject * 2086 /*[clinic input]
1784 imp_is_builtin(PyObject *self, PyObject *args) 2087 _imp.is_builtin
1785 { 2088
1786 PyObject *name; 2089 name: unicode
1787 if (!PyArg_ParseTuple(args, "U:is_builtin", &name)) 2090 /
1788 return NULL; 2091
2092 Returns True if the module name corresponds to a built-in module.
2093 [clinic start generated code]*/
2094
2095 PyDoc_STRVAR(_imp_is_builtin__doc__,
2096 "is_builtin(name)\n"
2097 "Returns True if the module name corresponds to a built-in module.");
2098
2099 #define _IMP_IS_BUILTIN_METHODDEF \
2100 {"is_builtin", (PyCFunction)_imp_is_builtin, METH_VARARGS, _imp_is_builtin__ doc__},
2101
2102 static PyObject *
2103 _imp_is_builtin_impl(PyModuleDef *module, PyObject *name);
2104
2105 static PyObject *
2106 _imp_is_builtin(PyModuleDef *module, PyObject *args)
2107 {
2108 PyObject *return_value = NULL;
2109 PyObject *name;
2110
2111 if (!PyArg_ParseTuple(args,
2112 "U:is_builtin",
2113 &name))
2114 goto exit;
2115 return_value = _imp_is_builtin_impl(module, name);
2116
2117 exit:
2118 return return_value;
2119 }
2120
2121 static PyObject *
2122 _imp_is_builtin_impl(PyModuleDef *module, PyObject *name)
2123 /*[clinic end generated code: checksum=353938c1d55210a1e3850d3ccba7539d02165cac] */
2124 {
1789 return PyLong_FromLong(is_builtin(name)); 2125 return PyLong_FromLong(is_builtin(name));
1790 } 2126 }
1791 2127
1792 static PyObject * 2128 /*[clinic input]
1793 imp_is_frozen(PyObject *self, PyObject *args) 2129 _imp.is_frozen
1794 { 2130
1795 PyObject *name; 2131 name: unicode
2132 /
2133
2134 Returns True if the module name corresponds to a frozen module.
2135 [clinic start generated code]*/
2136
2137 PyDoc_STRVAR(_imp_is_frozen__doc__,
2138 "is_frozen(name)\n"
2139 "Returns True if the module name corresponds to a frozen module.");
2140
2141 #define _IMP_IS_FROZEN_METHODDEF \
2142 {"is_frozen", (PyCFunction)_imp_is_frozen, METH_VARARGS, _imp_is_frozen__doc __},
2143
2144 static PyObject *
2145 _imp_is_frozen_impl(PyModuleDef *module, PyObject *name);
2146
2147 static PyObject *
2148 _imp_is_frozen(PyModuleDef *module, PyObject *args)
2149 {
2150 PyObject *return_value = NULL;
2151 PyObject *name;
2152
2153 if (!PyArg_ParseTuple(args,
2154 "U:is_frozen",
2155 &name))
2156 goto exit;
2157 return_value = _imp_is_frozen_impl(module, name);
2158
2159 exit:
2160 return return_value;
2161 }
2162
2163 static PyObject *
2164 _imp_is_frozen_impl(PyModuleDef *module, PyObject *name)
2165 /*[clinic end generated code: checksum=978b547ddcb76fa6c4a181ad53569c9acf382c7b] */
2166 {
1796 const struct _frozen *p; 2167 const struct _frozen *p;
1797 if (!PyArg_ParseTuple(args, "U:is_frozen", &name)) 2168
1798 return NULL;
1799 p = find_frozen(name); 2169 p = find_frozen(name);
1800 return PyBool_FromLong((long) (p == NULL ? 0 : p->size)); 2170 return PyBool_FromLong((long) (p == NULL ? 0 : p->size));
1801 } 2171 }
1802 2172
1803 #ifdef HAVE_DYNAMIC_LOADING 2173 #ifdef HAVE_DYNAMIC_LOADING
1804 2174
1805 static PyObject * 2175 /*[clinic input]
1806 imp_load_dynamic(PyObject *self, PyObject *args) 2176 _imp.load_dynamic
1807 { 2177
1808 PyObject *name, *pathname, *fob = NULL, *mod; 2178 name: unicode
2179 path: fs_unicode
2180 file: object = NULL
2181 /
2182
2183 Loads an extension module.
2184 [clinic start generated code]*/
2185
2186 PyDoc_STRVAR(_imp_load_dynamic__doc__,
2187 "load_dynamic(name, path, file=None)\n"
2188 "Loads an extension module.");
2189
2190 #define _IMP_LOAD_DYNAMIC_METHODDEF \
2191 {"load_dynamic", (PyCFunction)_imp_load_dynamic, METH_VARARGS, _imp_load_dyn amic__doc__},
2192
2193 static PyObject *
2194 _imp_load_dynamic_impl(PyModuleDef *module, PyObject *name, PyObject *path, PyOb ject *file);
2195
2196 static PyObject *
2197 _imp_load_dynamic(PyModuleDef *module, PyObject *args)
2198 {
2199 PyObject *return_value = NULL;
2200 PyObject *name;
2201 PyObject *path;
2202 PyObject *file = NULL;
2203
2204 if (!PyArg_ParseTuple(args,
2205 "UO&|O:load_dynamic",
2206 &name, PyUnicode_FSDecoder, &path, &file))
2207 goto exit;
2208 return_value = _imp_load_dynamic_impl(module, name, path, file);
2209
2210 exit:
2211 return return_value;
2212 }
2213
2214 static PyObject *
2215 _imp_load_dynamic_impl(PyModuleDef *module, PyObject *name, PyObject *path, PyOb ject *file)
2216 /*[clinic end generated code: checksum=6795f65d9ce003ccaf08e4e8eef484dc52e262d0] */
2217 {
2218 PyObject *mod;
1809 FILE *fp; 2219 FILE *fp;
1810 2220
1811 if (!PyArg_ParseTuple(args, "UO&|O:load_dynamic", 2221 if (file != NULL) {
1812 &name, PyUnicode_FSDecoder, &pathname, &fob)) 2222 fp = _Py_fopen_obj(path, "r");
1813 return NULL;
1814 if (fob != NULL) {
1815 fp = _Py_fopen_obj(pathname, "r");
1816 if (fp == NULL) { 2223 if (fp == NULL) {
1817 Py_DECREF(pathname); 2224 Py_DECREF(path);
1818 if (!PyErr_Occurred()) 2225 if (!PyErr_Occurred())
1819 PyErr_SetFromErrno(PyExc_IOError); 2226 PyErr_SetFromErrno(PyExc_IOError);
1820 return NULL; 2227 return NULL;
1821 } 2228 }
1822 } 2229 }
1823 else 2230 else
1824 fp = NULL; 2231 fp = NULL;
1825 mod = _PyImport_LoadDynamicModule(name, pathname, fp); 2232 mod = _PyImport_LoadDynamicModule(name, path, fp);
1826 Py_DECREF(pathname); 2233 Py_DECREF(path);
1827 if (fp) 2234 if (fp)
1828 fclose(fp); 2235 fclose(fp);
1829 return mod; 2236 return mod;
1830 } 2237 }
1831 2238
1832 #endif /* HAVE_DYNAMIC_LOADING */ 2239 #endif /* HAVE_DYNAMIC_LOADING */
1833 2240
1834
1835 /* Doc strings */
1836 2241
1837 PyDoc_STRVAR(doc_imp, 2242 PyDoc_STRVAR(doc_imp,
1838 "(Extremely) low-level import machinery bits as used by importlib and imp."); 2243 "(Extremely) low-level import machinery bits as used by importlib and imp.");
1839 2244
1840 PyDoc_STRVAR(doc_extension_suffixes,
1841 "extension_suffixes() -> list of strings\n\
1842 Returns the list of file suffixes used to identify extension modules.");
1843
1844 PyDoc_STRVAR(doc_lock_held,
1845 "lock_held() -> boolean\n\
1846 Return True if the import lock is currently held, else False.\n\
1847 On platforms without threads, return False.");
1848
1849 PyDoc_STRVAR(doc_acquire_lock,
1850 "acquire_lock() -> None\n\
1851 Acquires the interpreter's import lock for the current thread.\n\
1852 This lock should be used by import hooks to ensure thread-safety\n\
1853 when importing modules.\n\
1854 On platforms without threads, this function does nothing.");
1855
1856 PyDoc_STRVAR(doc_release_lock,
1857 "release_lock() -> None\n\
1858 Release the interpreter's import lock.\n\
1859 On platforms without threads, this function does nothing.");
1860
1861 static PyMethodDef imp_methods[] = { 2245 static PyMethodDef imp_methods[] = {
1862 {"extension_suffixes", imp_extension_suffixes, METH_NOARGS, 2246 _IMP_EXTENSION_SUFFIXES_METHODDEF
1863 doc_extension_suffixes}, 2247 _IMP_LOCK_HELD_METHODDEF
1864 {"lock_held", imp_lock_held, METH_NOARGS, doc_lock_held}, 2248 _IMP_ACQUIRE_LOCK_METHODDEF
1865 {"acquire_lock", imp_acquire_lock, METH_NOARGS, doc_acquire_lock}, 2249 _IMP_RELEASE_LOCK_METHODDEF
1866 {"release_lock", imp_release_lock, METH_NOARGS, doc_release_lock}, 2250 _IMP_GET_FROZEN_OBJECT_METHODDEF
1867 {"get_frozen_object", imp_get_frozen_object, METH_VARARGS}, 2251 _IMP_IS_FROZEN_PACKAGE_METHODDEF
1868 {"is_frozen_package", imp_is_frozen_package, METH_VARARGS}, 2252 _IMP_INIT_BUILTIN_METHODDEF
1869 {"init_builtin", imp_init_builtin, METH_VARARGS}, 2253 _IMP_INIT_FROZEN_METHODDEF
1870 {"init_frozen", imp_init_frozen, METH_VARARGS}, 2254 _IMP_IS_BUILTIN_METHODDEF
1871 {"is_builtin", imp_is_builtin, METH_VARARGS}, 2255 _IMP_IS_FROZEN_METHODDEF
1872 {"is_frozen", imp_is_frozen, METH_VARARGS},
1873 #ifdef HAVE_DYNAMIC_LOADING 2256 #ifdef HAVE_DYNAMIC_LOADING
1874 {"load_dynamic", imp_load_dynamic, METH_VARARGS}, 2257 _IMP_LOAD_DYNAMIC_METHODDEF
1875 #endif 2258 #endif
1876 {"_fix_co_filename", imp_fix_co_filename, METH_VARARGS}, 2259 _IMP__FIX_CO_FILENAME_METHODDEF
1877 {NULL, NULL} /* sentinel */ 2260 {NULL, NULL} /* sentinel */
1878 }; 2261 };
1879 2262
1880 2263
1881 static struct PyModuleDef impmodule = { 2264 static struct PyModuleDef impmodule = {
1882 PyModuleDef_HEAD_INIT, 2265 PyModuleDef_HEAD_INIT,
1883 "_imp", 2266 "_imp",
1884 doc_imp, 2267 doc_imp,
1885 0, 2268 0,
1886 imp_methods, 2269 imp_methods,
1887 NULL, 2270 NULL,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1957 2340
1958 newtab[0].name = (char *)name; 2341 newtab[0].name = (char *)name;
1959 newtab[0].initfunc = initfunc; 2342 newtab[0].initfunc = initfunc;
1960 2343
1961 return PyImport_ExtendInittab(newtab); 2344 return PyImport_ExtendInittab(newtab);
1962 } 2345 }
1963 2346
1964 #ifdef __cplusplus 2347 #ifdef __cplusplus
1965 } 2348 }
1966 #endif 2349 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+