1991-02-19 08:39:46 -04:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/* Method object implementation */
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
#include "Python.h"
|
2017-09-08 02:51:28 -03:00
|
|
|
#include "internal/mem.h"
|
|
|
|
#include "internal/pystate.h"
|
2003-01-31 14:33:18 -04:00
|
|
|
#include "structmember.h"
|
1990-10-14 09:07:46 -03:00
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60568-60598,60600-60616 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60568 | christian.heimes | 2008-02-04 19:48:38 +0100 (Mon, 04 Feb 2008) | 1 line
Increase debugging to investige failing tests on some build bots
........
r60570 | christian.heimes | 2008-02-04 20:30:05 +0100 (Mon, 04 Feb 2008) | 1 line
Small adjustments for test compact freelist test. It's no passing on Windows as well.
........
r60573 | amaury.forgeotdarc | 2008-02-04 21:53:14 +0100 (Mon, 04 Feb 2008) | 2 lines
Correct quotes in NEWS file
........
r60575 | amaury.forgeotdarc | 2008-02-04 22:45:05 +0100 (Mon, 04 Feb 2008) | 13 lines
#1750076: Debugger did not step on every iteration of a while statement.
The mapping between bytecode offsets and source lines (lnotab) did not contain
an entry for the beginning of the loop.
Now it does, and the lnotab can be a bit larger:
in particular, several statements on the same line generate several entries.
However, this does not bother the settrace function, which will trigger only
one 'line' event.
The lnotab seems to be exactly the same as with python2.4.
........
r60584 | amaury.forgeotdarc | 2008-02-05 01:26:21 +0100 (Tue, 05 Feb 2008) | 3 lines
Change r60575 broke test_compile:
there is no need to emit co_lnotab item when both offsets are zeros.
........
r60587 | skip.montanaro | 2008-02-05 03:32:16 +0100 (Tue, 05 Feb 2008) | 1 line
sync with most recent version from python-mode sf project
........
r60588 | lars.gustaebel | 2008-02-05 12:51:40 +0100 (Tue, 05 Feb 2008) | 5 lines
Issue #2004: Use mode 0700 for temporary directories and default
permissions for missing directories.
(will backport to 2.5)
........
r60590 | georg.brandl | 2008-02-05 13:01:24 +0100 (Tue, 05 Feb 2008) | 2 lines
Convert external links to internal links. Fixes #2010.
........
r60592 | marc-andre.lemburg | 2008-02-05 15:50:40 +0100 (Tue, 05 Feb 2008) | 3 lines
Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
........
r60593 | andrew.kuchling | 2008-02-05 17:06:57 +0100 (Tue, 05 Feb 2008) | 5 lines
Update PEP URL.
(This code is duplicated between pydoc and DocXMLRPCServer; maybe it
should be refactored as a GHOP project.)
2.5.2 backport candidate.
........
r60596 | guido.van.rossum | 2008-02-05 18:32:15 +0100 (Tue, 05 Feb 2008) | 2 lines
In the experimental 'Scanner' feature, the group count was set wrong.
........
r60602 | facundo.batista | 2008-02-05 20:03:32 +0100 (Tue, 05 Feb 2008) | 3 lines
Issue 1951. Converts wave test cases to unittest.
........
r60603 | georg.brandl | 2008-02-05 20:07:10 +0100 (Tue, 05 Feb 2008) | 2 lines
Actually run the test.
........
r60604 | skip.montanaro | 2008-02-05 20:24:30 +0100 (Tue, 05 Feb 2008) | 2 lines
correct object name
........
r60605 | georg.brandl | 2008-02-05 20:58:17 +0100 (Tue, 05 Feb 2008) | 7 lines
* Use the same code to profile for test_profile and test_cprofile.
* Convert both to unittest.
* Use the same unit testing code.
* Include the expected output in both test files.
* Make it possible to regenerate the expected output by running
the file as a script with an '-r' argument.
........
r60613 | raymond.hettinger | 2008-02-06 02:49:00 +0100 (Wed, 06 Feb 2008) | 1 line
Sync-up with Py3k work.
........
r60614 | christian.heimes | 2008-02-06 13:44:34 +0100 (Wed, 06 Feb 2008) | 1 line
Limit free list of method and builtin function objects to 256 entries each.
........
r60616 | christian.heimes | 2008-02-06 14:33:44 +0100 (Wed, 06 Feb 2008) | 7 lines
Unified naming convention for free lists and their limits. All free lists
in Object/ are named ``free_list``, the counter ``numfree`` and the upper
limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block.
The chances should make it easier to adjust Python for platforms with
less memory, e.g. mobile phones.
........
2008-02-06 10:31:34 -04:00
|
|
|
/* Free list for method objects to safe malloc/free overhead
|
|
|
|
* The m_self element is used to chain the objects.
|
|
|
|
*/
|
1997-08-04 23:11:41 -03:00
|
|
|
static PyCFunctionObject *free_list = NULL;
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60568-60598,60600-60616 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60568 | christian.heimes | 2008-02-04 19:48:38 +0100 (Mon, 04 Feb 2008) | 1 line
Increase debugging to investige failing tests on some build bots
........
r60570 | christian.heimes | 2008-02-04 20:30:05 +0100 (Mon, 04 Feb 2008) | 1 line
Small adjustments for test compact freelist test. It's no passing on Windows as well.
........
r60573 | amaury.forgeotdarc | 2008-02-04 21:53:14 +0100 (Mon, 04 Feb 2008) | 2 lines
Correct quotes in NEWS file
........
r60575 | amaury.forgeotdarc | 2008-02-04 22:45:05 +0100 (Mon, 04 Feb 2008) | 13 lines
#1750076: Debugger did not step on every iteration of a while statement.
The mapping between bytecode offsets and source lines (lnotab) did not contain
an entry for the beginning of the loop.
Now it does, and the lnotab can be a bit larger:
in particular, several statements on the same line generate several entries.
However, this does not bother the settrace function, which will trigger only
one 'line' event.
The lnotab seems to be exactly the same as with python2.4.
........
r60584 | amaury.forgeotdarc | 2008-02-05 01:26:21 +0100 (Tue, 05 Feb 2008) | 3 lines
Change r60575 broke test_compile:
there is no need to emit co_lnotab item when both offsets are zeros.
........
r60587 | skip.montanaro | 2008-02-05 03:32:16 +0100 (Tue, 05 Feb 2008) | 1 line
sync with most recent version from python-mode sf project
........
r60588 | lars.gustaebel | 2008-02-05 12:51:40 +0100 (Tue, 05 Feb 2008) | 5 lines
Issue #2004: Use mode 0700 for temporary directories and default
permissions for missing directories.
(will backport to 2.5)
........
r60590 | georg.brandl | 2008-02-05 13:01:24 +0100 (Tue, 05 Feb 2008) | 2 lines
Convert external links to internal links. Fixes #2010.
........
r60592 | marc-andre.lemburg | 2008-02-05 15:50:40 +0100 (Tue, 05 Feb 2008) | 3 lines
Keep distutils Python 2.1 compatible (or even Python 2.4 in this case).
........
r60593 | andrew.kuchling | 2008-02-05 17:06:57 +0100 (Tue, 05 Feb 2008) | 5 lines
Update PEP URL.
(This code is duplicated between pydoc and DocXMLRPCServer; maybe it
should be refactored as a GHOP project.)
2.5.2 backport candidate.
........
r60596 | guido.van.rossum | 2008-02-05 18:32:15 +0100 (Tue, 05 Feb 2008) | 2 lines
In the experimental 'Scanner' feature, the group count was set wrong.
........
r60602 | facundo.batista | 2008-02-05 20:03:32 +0100 (Tue, 05 Feb 2008) | 3 lines
Issue 1951. Converts wave test cases to unittest.
........
r60603 | georg.brandl | 2008-02-05 20:07:10 +0100 (Tue, 05 Feb 2008) | 2 lines
Actually run the test.
........
r60604 | skip.montanaro | 2008-02-05 20:24:30 +0100 (Tue, 05 Feb 2008) | 2 lines
correct object name
........
r60605 | georg.brandl | 2008-02-05 20:58:17 +0100 (Tue, 05 Feb 2008) | 7 lines
* Use the same code to profile for test_profile and test_cprofile.
* Convert both to unittest.
* Use the same unit testing code.
* Include the expected output in both test files.
* Make it possible to regenerate the expected output by running
the file as a script with an '-r' argument.
........
r60613 | raymond.hettinger | 2008-02-06 02:49:00 +0100 (Wed, 06 Feb 2008) | 1 line
Sync-up with Py3k work.
........
r60614 | christian.heimes | 2008-02-06 13:44:34 +0100 (Wed, 06 Feb 2008) | 1 line
Limit free list of method and builtin function objects to 256 entries each.
........
r60616 | christian.heimes | 2008-02-06 14:33:44 +0100 (Wed, 06 Feb 2008) | 7 lines
Unified naming convention for free lists and their limits. All free lists
in Object/ are named ``free_list``, the counter ``numfree`` and the upper
limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block.
The chances should make it easier to adjust Python for platforms with
less memory, e.g. mobile phones.
........
2008-02-06 10:31:34 -04:00
|
|
|
static int numfree = 0;
|
|
|
|
#ifndef PyCFunction_MAXFREELIST
|
|
|
|
#define PyCFunction_MAXFREELIST 256
|
|
|
|
#endif
|
1997-08-04 23:11:41 -03:00
|
|
|
|
2012-12-26 17:08:54 -04:00
|
|
|
/* undefine macro trampoline to PyCFunction_NewEx */
|
|
|
|
#undef PyCFunction_New
|
|
|
|
|
2015-04-27 11:48:50 -03:00
|
|
|
PyAPI_FUNC(PyObject *)
|
2012-12-25 07:32:35 -04:00
|
|
|
PyCFunction_New(PyMethodDef *ml, PyObject *self)
|
|
|
|
{
|
|
|
|
return PyCFunction_NewEx(ml, self, NULL);
|
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
PyObject *
|
2003-01-31 14:33:18 -04:00
|
|
|
PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyCFunctionObject *op;
|
|
|
|
op = free_list;
|
|
|
|
if (op != NULL) {
|
|
|
|
free_list = (PyCFunctionObject *)(op->m_self);
|
2013-12-04 04:27:47 -04:00
|
|
|
(void)PyObject_INIT(op, &PyCFunction_Type);
|
2010-05-09 12:52:27 -03:00
|
|
|
numfree--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
op = PyObject_GC_New(PyCFunctionObject, &PyCFunction_Type);
|
|
|
|
if (op == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-06 20:31:40 -03:00
|
|
|
op->m_weakreflist = NULL;
|
2010-05-09 12:52:27 -03:00
|
|
|
op->m_ml = ml;
|
|
|
|
Py_XINCREF(self);
|
|
|
|
op->m_self = self;
|
|
|
|
Py_XINCREF(module);
|
|
|
|
op->m_module = module;
|
|
|
|
_PyObject_GC_TRACK(op);
|
|
|
|
return (PyObject *)op;
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
PyCFunction
|
2000-07-09 03:03:25 -03:00
|
|
|
PyCFunction_GetFunction(PyObject *op)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!PyCFunction_Check(op)) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-23 07:40:16 -04:00
|
|
|
return PyCFunction_GET_FUNCTION(op);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
PyObject *
|
2000-07-09 03:03:25 -03:00
|
|
|
PyCFunction_GetSelf(PyObject *op)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!PyCFunction_Check(op)) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-23 07:40:16 -04:00
|
|
|
return PyCFunction_GET_SELF(op);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1991-12-16 09:07:24 -04:00
|
|
|
int
|
2000-07-09 03:03:25 -03:00
|
|
|
PyCFunction_GetFlags(PyObject *op)
|
1991-12-16 09:07:24 -04:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!PyCFunction_Check(op)) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return -1;
|
|
|
|
}
|
2011-12-23 07:40:16 -04:00
|
|
|
return PyCFunction_GET_FLAGS(op);
|
1991-12-16 09:07:24 -04:00
|
|
|
}
|
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/* Methods (the standard built-in methods, that is) */
|
|
|
|
|
|
|
|
static void
|
2000-07-09 03:03:25 -03:00
|
|
|
meth_dealloc(PyCFunctionObject *m)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
_PyObject_GC_UNTRACK(m);
|
2014-08-06 20:31:40 -03:00
|
|
|
if (m->m_weakreflist != NULL) {
|
|
|
|
PyObject_ClearWeakRefs((PyObject*) m);
|
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_XDECREF(m->m_self);
|
|
|
|
Py_XDECREF(m->m_module);
|
|
|
|
if (numfree < PyCFunction_MAXFREELIST) {
|
|
|
|
m->m_self = (PyObject *)free_list;
|
|
|
|
free_list = m;
|
|
|
|
numfree++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyObject_GC_Del(m);
|
|
|
|
}
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
2013-11-24 06:41:05 -04:00
|
|
|
static PyObject *
|
|
|
|
meth_reduce(PyCFunctionObject *m)
|
|
|
|
{
|
|
|
|
_Py_IDENTIFIER(getattr);
|
|
|
|
|
|
|
|
if (m->m_self == NULL || PyModule_Check(m->m_self))
|
|
|
|
return PyUnicode_FromString(m->m_ml->ml_name);
|
|
|
|
|
2018-12-11 04:51:27 -04:00
|
|
|
return Py_BuildValue("N(Os)", _PyEval_GetBuiltinId(&PyId_getattr),
|
|
|
|
m->m_self, m->m_ml->ml_name);
|
2013-11-24 06:41:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef meth_methods[] = {
|
|
|
|
{"__reduce__", (PyCFunction)meth_reduce, METH_NOARGS, NULL},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2013-11-23 19:37:55 -04:00
|
|
|
static PyObject *
|
|
|
|
meth_get__text_signature__(PyCFunctionObject *m, void *closure)
|
|
|
|
{
|
2014-02-09 02:15:29 -04:00
|
|
|
return _PyType_GetTextSignatureFromInternalDoc(m->m_ml->ml_name, m->m_ml->ml_doc);
|
2013-11-23 19:37:55 -04:00
|
|
|
}
|
|
|
|
|
2001-08-02 01:15:00 -03:00
|
|
|
static PyObject *
|
|
|
|
meth_get__doc__(PyCFunctionObject *m, void *closure)
|
|
|
|
{
|
2014-02-09 02:15:29 -04:00
|
|
|
return _PyType_GetDocFromInternalDoc(m->m_ml->ml_name, m->m_ml->ml_doc);
|
2001-08-02 01:15:00 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
meth_get__name__(PyCFunctionObject *m, void *closure)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return PyUnicode_FromString(m->m_ml->ml_name);
|
2001-08-02 01:15:00 -03:00
|
|
|
}
|
|
|
|
|
2011-12-23 07:40:16 -04:00
|
|
|
static PyObject *
|
|
|
|
meth_get__qualname__(PyCFunctionObject *m, void *closure)
|
|
|
|
{
|
|
|
|
/* If __self__ is a module or NULL, return m.__name__
|
|
|
|
(e.g. len.__qualname__ == 'len')
|
|
|
|
|
|
|
|
If __self__ is a type, return m.__self__.__qualname__ + '.' + m.__name__
|
|
|
|
(e.g. dict.fromkeys.__qualname__ == 'dict.fromkeys')
|
|
|
|
|
|
|
|
Otherwise return type(m.__self__).__qualname__ + '.' + m.__name__
|
|
|
|
(e.g. [].append.__qualname__ == 'list.append') */
|
|
|
|
PyObject *type, *type_qualname, *res;
|
|
|
|
_Py_IDENTIFIER(__qualname__);
|
|
|
|
|
|
|
|
if (m->m_self == NULL || PyModule_Check(m->m_self))
|
|
|
|
return PyUnicode_FromString(m->m_ml->ml_name);
|
|
|
|
|
|
|
|
type = PyType_Check(m->m_self) ? m->m_self : (PyObject*)Py_TYPE(m->m_self);
|
|
|
|
|
|
|
|
type_qualname = _PyObject_GetAttrId(type, &PyId___qualname__);
|
|
|
|
if (type_qualname == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!PyUnicode_Check(type_qualname)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "<method>.__class__."
|
|
|
|
"__qualname__ is not a unicode object");
|
|
|
|
Py_XDECREF(type_qualname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = PyUnicode_FromFormat("%S.%s", type_qualname, m->m_ml->ml_name);
|
|
|
|
Py_DECREF(type_qualname);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-07-12 10:27:35 -03:00
|
|
|
static int
|
|
|
|
meth_traverse(PyCFunctionObject *m, visitproc visit, void *arg)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_VISIT(m->m_self);
|
|
|
|
Py_VISIT(m->m_module);
|
|
|
|
return 0;
|
2001-07-12 10:27:35 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2001-08-02 01:15:00 -03:00
|
|
|
meth_get__self__(PyCFunctionObject *m, void *closure)
|
1995-01-07 08:34:58 -04:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject *self;
|
Merged revisions 55270-55324 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
r55271 | fred.drake | 2007-05-11 10:14:47 -0700 (Fri, 11 May 2007) | 3 lines
remove jpeg, panel libraries for SGI; there is more IRIX stuff left over,
I guess that should be removed too, but will leave for someone who is sure
........
r55280 | fred.drake | 2007-05-11 19:11:37 -0700 (Fri, 11 May 2007) | 1 line
remove mention of file that has been removed
........
r55301 | brett.cannon | 2007-05-13 17:38:05 -0700 (Sun, 13 May 2007) | 4 lines
Remove rexec and Bastion from the stdlib. This also eliminates the need for
f_restricted on frames. This in turn negates the need for
PyEval_GetRestricted() and PyFrame_IsRestricted().
........
r55303 | brett.cannon | 2007-05-13 19:22:22 -0700 (Sun, 13 May 2007) | 2 lines
Remove the md5 and sha modules.
........
r55305 | george.yoshida | 2007-05-13 19:45:55 -0700 (Sun, 13 May 2007) | 2 lines
fix markup
........
r55306 | neal.norwitz | 2007-05-13 19:47:57 -0700 (Sun, 13 May 2007) | 1 line
Get the doc building again after some removals.
........
r55307 | neal.norwitz | 2007-05-13 19:50:45 -0700 (Sun, 13 May 2007) | 1 line
Get test_pyclbr passing again after getstatus was removed from commands. This "test case" was weird since it was just importing a seemingly random module. Remove the import
........
r55322 | brett.cannon | 2007-05-14 14:09:20 -0700 (Mon, 14 May 2007) | 3 lines
Remove the compiler package. Will eventually need a mechanism to byte compile
an AST.
........
2007-05-14 19:03:55 -03:00
|
|
|
|
2011-12-23 07:40:16 -04:00
|
|
|
self = PyCFunction_GET_SELF(m);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (self == NULL)
|
|
|
|
self = Py_None;
|
|
|
|
Py_INCREF(self);
|
|
|
|
return self;
|
1995-01-07 08:34:58 -04:00
|
|
|
}
|
|
|
|
|
2001-09-20 18:45:26 -03:00
|
|
|
static PyGetSetDef meth_getsets [] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
{"__doc__", (getter)meth_get__doc__, NULL, NULL},
|
|
|
|
{"__name__", (getter)meth_get__name__, NULL, NULL},
|
2011-12-23 07:40:16 -04:00
|
|
|
{"__qualname__", (getter)meth_get__qualname__, NULL, NULL},
|
2010-05-09 12:52:27 -03:00
|
|
|
{"__self__", (getter)meth_get__self__, NULL, NULL},
|
2013-11-23 19:37:55 -04:00
|
|
|
{"__text_signature__", (getter)meth_get__text_signature__, NULL, NULL},
|
2010-05-09 12:52:27 -03:00
|
|
|
{0}
|
2001-08-02 01:15:00 -03:00
|
|
|
};
|
|
|
|
|
2003-01-31 14:33:18 -04:00
|
|
|
#define OFF(x) offsetof(PyCFunctionObject, x)
|
|
|
|
|
|
|
|
static PyMemberDef meth_members[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
{"__module__", T_OBJECT, OFF(m_module), PY_WRITE_RESTRICTED},
|
|
|
|
{NULL}
|
2003-01-31 14:33:18 -04:00
|
|
|
};
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 03:03:25 -03:00
|
|
|
meth_repr(PyCFunctionObject *m)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (m->m_self == NULL || PyModule_Check(m->m_self))
|
|
|
|
return PyUnicode_FromFormat("<built-in function %s>",
|
|
|
|
m->m_ml->ml_name);
|
|
|
|
return PyUnicode_FromFormat("<built-in method %s of %s object at %p>",
|
|
|
|
m->m_ml->ml_name,
|
|
|
|
m->m_self->ob_type->tp_name,
|
|
|
|
m->m_self);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
2006-08-23 21:41:19 -03:00
|
|
|
static PyObject *
|
|
|
|
meth_richcompare(PyObject *self, PyObject *other, int op)
|
1993-03-29 06:43:31 -04:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyCFunctionObject *a, *b;
|
|
|
|
PyObject *res;
|
|
|
|
int eq;
|
|
|
|
|
|
|
|
if ((op != Py_EQ && op != Py_NE) ||
|
|
|
|
!PyCFunction_Check(self) ||
|
|
|
|
!PyCFunction_Check(other))
|
|
|
|
{
|
2011-08-10 22:28:54 -03:00
|
|
|
Py_RETURN_NOTIMPLEMENTED;
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
a = (PyCFunctionObject *)self;
|
|
|
|
b = (PyCFunctionObject *)other;
|
|
|
|
eq = a->m_self == b->m_self;
|
|
|
|
if (eq)
|
|
|
|
eq = a->m_ml->ml_meth == b->m_ml->ml_meth;
|
|
|
|
if (op == Py_EQ)
|
|
|
|
res = eq ? Py_True : Py_False;
|
|
|
|
else
|
|
|
|
res = eq ? Py_False : Py_True;
|
|
|
|
Py_INCREF(res);
|
|
|
|
return res;
|
1993-03-29 06:43:31 -04:00
|
|
|
}
|
|
|
|
|
2010-10-17 17:54:53 -03:00
|
|
|
static Py_hash_t
|
2000-07-09 03:03:25 -03:00
|
|
|
meth_hash(PyCFunctionObject *a)
|
1993-03-29 06:43:31 -04:00
|
|
|
{
|
2010-10-17 17:54:53 -03:00
|
|
|
Py_hash_t x, y;
|
2010-05-09 12:52:27 -03:00
|
|
|
if (a->m_self == NULL)
|
|
|
|
x = 0;
|
|
|
|
else {
|
|
|
|
x = PyObject_Hash(a->m_self);
|
|
|
|
if (x == -1)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
y = _Py_HashPointer((void*)(a->m_ml->ml_meth));
|
|
|
|
if (y == -1)
|
|
|
|
return -1;
|
|
|
|
x ^= y;
|
|
|
|
if (x == -1)
|
|
|
|
x = -2;
|
|
|
|
return x;
|
1993-03-29 06:43:31 -04:00
|
|
|
}
|
|
|
|
|
2001-08-02 01:15:00 -03:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
PyTypeObject PyCFunction_Type = {
|
2010-05-09 12:52:27 -03:00
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
"builtin_function_or_method",
|
|
|
|
sizeof(PyCFunctionObject),
|
|
|
|
0,
|
|
|
|
(destructor)meth_dealloc, /* tp_dealloc */
|
|
|
|
0, /* tp_print */
|
|
|
|
0, /* tp_getattr */
|
|
|
|
0, /* tp_setattr */
|
|
|
|
0, /* tp_reserved */
|
|
|
|
(reprfunc)meth_repr, /* tp_repr */
|
|
|
|
0, /* tp_as_number */
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
(hashfunc)meth_hash, /* tp_hash */
|
|
|
|
PyCFunction_Call, /* tp_call */
|
|
|
|
0, /* tp_str */
|
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
0, /* tp_setattro */
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
|
|
|
0, /* tp_doc */
|
|
|
|
(traverseproc)meth_traverse, /* tp_traverse */
|
|
|
|
0, /* tp_clear */
|
|
|
|
meth_richcompare, /* tp_richcompare */
|
2014-08-06 20:31:40 -03:00
|
|
|
offsetof(PyCFunctionObject, m_weakreflist), /* tp_weaklistoffset */
|
2010-05-09 12:52:27 -03:00
|
|
|
0, /* tp_iter */
|
|
|
|
0, /* tp_iternext */
|
2013-11-24 06:41:05 -04:00
|
|
|
meth_methods, /* tp_methods */
|
2010-05-09 12:52:27 -03:00
|
|
|
meth_members, /* tp_members */
|
|
|
|
meth_getsets, /* tp_getset */
|
|
|
|
0, /* tp_base */
|
|
|
|
0, /* tp_dict */
|
1990-10-14 09:07:46 -03:00
|
|
|
};
|
1990-12-20 11:06:42 -04:00
|
|
|
|
1997-08-04 23:11:41 -03:00
|
|
|
/* Clear out the free list */
|
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60790 | raymond.hettinger | 2008-02-14 10:32:45 +0100 (Thu, 14 Feb 2008) | 4 lines
Add diagnostic message to help figure-out why SocketServer tests occasionally crash
when trying to remove a pid that in not in the activechildren list.
........
r60791 | raymond.hettinger | 2008-02-14 11:46:57 +0100 (Thu, 14 Feb 2008) | 1 line
Add fixed-point examples to the decimal FAQ
........
r60792 | raymond.hettinger | 2008-02-14 12:01:10 +0100 (Thu, 14 Feb 2008) | 1 line
Improve rst markup
........
r60794 | raymond.hettinger | 2008-02-14 12:57:25 +0100 (Thu, 14 Feb 2008) | 1 line
Show how to remove exponents.
........
r60795 | raymond.hettinger | 2008-02-14 13:05:42 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup.
........
r60797 | christian.heimes | 2008-02-14 13:47:33 +0100 (Thu, 14 Feb 2008) | 1 line
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
........
r60798 | raymond.hettinger | 2008-02-14 13:49:37 +0100 (Thu, 14 Feb 2008) | 1 line
Simplify moneyfmt() recipe.
........
r60810 | raymond.hettinger | 2008-02-14 20:02:39 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup
........
r60811 | raymond.hettinger | 2008-02-14 20:30:30 +0100 (Thu, 14 Feb 2008) | 1 line
No need to register subclass of ABCs.
........
r60814 | thomas.heller | 2008-02-14 22:00:28 +0100 (Thu, 14 Feb 2008) | 1 line
Try to correct a markup error that does hide the following paragraph.
........
r60822 | christian.heimes | 2008-02-14 23:40:11 +0100 (Thu, 14 Feb 2008) | 1 line
Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in #2115
........
r60827 | christian.heimes | 2008-02-15 07:57:08 +0100 (Fri, 15 Feb 2008) | 1 line
Fixed repr() and str() of complex numbers. Complex suffered from the same problem as floats but I forgot to test and fix them.
........
r60830 | christian.heimes | 2008-02-15 09:20:11 +0100 (Fri, 15 Feb 2008) | 2 lines
Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
Thanks to Thomas Herve for the fix.
........
r60835 | eric.smith | 2008-02-15 13:14:32 +0100 (Fri, 15 Feb 2008) | 1 line
In PyNumber_ToBase, changed from an assert to returning an error when PyObject_Index() returns something other than an int or long. It should never be possible to trigger this, as PyObject_Index checks to make sure it returns an int or long.
........
r60837 | skip.montanaro | 2008-02-15 20:03:59 +0100 (Fri, 15 Feb 2008) | 8 lines
Two new functions:
* place_summary_first copies the regrtest summary to the front of the file
making it easier to scan quickly for problems.
* count_failures gets the actual count of the number of failing tests, not
just a 1 (some failures) or 0 (no failures).
........
r60840 | raymond.hettinger | 2008-02-15 22:21:25 +0100 (Fri, 15 Feb 2008) | 1 line
Update example to match the current syntax.
........
r60841 | amaury.forgeotdarc | 2008-02-15 22:22:45 +0100 (Fri, 15 Feb 2008) | 8 lines
Issue #2115: __slot__ attributes setting was 10x slower.
Also correct a possible crash using ABCs.
This change is exactly the same as an optimisation
done 5 years ago, but on slot *access*:
http://svn.python.org/view?view=rev&rev=28297
........
r60842 | amaury.forgeotdarc | 2008-02-15 22:27:44 +0100 (Fri, 15 Feb 2008) | 2 lines
Temporarily let these tests pass
........
r60843 | kurt.kaiser | 2008-02-15 22:56:36 +0100 (Fri, 15 Feb 2008) | 2 lines
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
........
r60844 | kurt.kaiser | 2008-02-15 23:25:09 +0100 (Fri, 15 Feb 2008) | 4 lines
Configured selection highlighting colors were ignored; updating highlighting
in the config dialog would cause non-Python files to be colored as if they
were Python source; improve use of ColorDelagator. Patch 1334. Tal Einat.
........
r60845 | amaury.forgeotdarc | 2008-02-15 23:44:20 +0100 (Fri, 15 Feb 2008) | 9 lines
Re-enable tests, they were failing since gc.collect() clears the various freelists.
They still remain fragile.
For example, a call to assertEqual currently does not make any allocation
(which surprised me at first).
But this can change when gc.collect also deletes the numerous "zombie frames"
attached to each function.
........
2008-02-16 03:38:31 -04:00
|
|
|
int
|
|
|
|
PyCFunction_ClearFreeList(void)
|
1997-08-04 23:11:41 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
int freelist_size = numfree;
|
|
|
|
|
|
|
|
while (free_list) {
|
|
|
|
PyCFunctionObject *v = free_list;
|
|
|
|
free_list = (PyCFunctionObject *)(v->m_self);
|
|
|
|
PyObject_GC_Del(v);
|
|
|
|
numfree--;
|
|
|
|
}
|
|
|
|
assert(numfree == 0);
|
|
|
|
return freelist_size;
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60790 | raymond.hettinger | 2008-02-14 10:32:45 +0100 (Thu, 14 Feb 2008) | 4 lines
Add diagnostic message to help figure-out why SocketServer tests occasionally crash
when trying to remove a pid that in not in the activechildren list.
........
r60791 | raymond.hettinger | 2008-02-14 11:46:57 +0100 (Thu, 14 Feb 2008) | 1 line
Add fixed-point examples to the decimal FAQ
........
r60792 | raymond.hettinger | 2008-02-14 12:01:10 +0100 (Thu, 14 Feb 2008) | 1 line
Improve rst markup
........
r60794 | raymond.hettinger | 2008-02-14 12:57:25 +0100 (Thu, 14 Feb 2008) | 1 line
Show how to remove exponents.
........
r60795 | raymond.hettinger | 2008-02-14 13:05:42 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup.
........
r60797 | christian.heimes | 2008-02-14 13:47:33 +0100 (Thu, 14 Feb 2008) | 1 line
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
........
r60798 | raymond.hettinger | 2008-02-14 13:49:37 +0100 (Thu, 14 Feb 2008) | 1 line
Simplify moneyfmt() recipe.
........
r60810 | raymond.hettinger | 2008-02-14 20:02:39 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup
........
r60811 | raymond.hettinger | 2008-02-14 20:30:30 +0100 (Thu, 14 Feb 2008) | 1 line
No need to register subclass of ABCs.
........
r60814 | thomas.heller | 2008-02-14 22:00:28 +0100 (Thu, 14 Feb 2008) | 1 line
Try to correct a markup error that does hide the following paragraph.
........
r60822 | christian.heimes | 2008-02-14 23:40:11 +0100 (Thu, 14 Feb 2008) | 1 line
Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in #2115
........
r60827 | christian.heimes | 2008-02-15 07:57:08 +0100 (Fri, 15 Feb 2008) | 1 line
Fixed repr() and str() of complex numbers. Complex suffered from the same problem as floats but I forgot to test and fix them.
........
r60830 | christian.heimes | 2008-02-15 09:20:11 +0100 (Fri, 15 Feb 2008) | 2 lines
Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
Thanks to Thomas Herve for the fix.
........
r60835 | eric.smith | 2008-02-15 13:14:32 +0100 (Fri, 15 Feb 2008) | 1 line
In PyNumber_ToBase, changed from an assert to returning an error when PyObject_Index() returns something other than an int or long. It should never be possible to trigger this, as PyObject_Index checks to make sure it returns an int or long.
........
r60837 | skip.montanaro | 2008-02-15 20:03:59 +0100 (Fri, 15 Feb 2008) | 8 lines
Two new functions:
* place_summary_first copies the regrtest summary to the front of the file
making it easier to scan quickly for problems.
* count_failures gets the actual count of the number of failing tests, not
just a 1 (some failures) or 0 (no failures).
........
r60840 | raymond.hettinger | 2008-02-15 22:21:25 +0100 (Fri, 15 Feb 2008) | 1 line
Update example to match the current syntax.
........
r60841 | amaury.forgeotdarc | 2008-02-15 22:22:45 +0100 (Fri, 15 Feb 2008) | 8 lines
Issue #2115: __slot__ attributes setting was 10x slower.
Also correct a possible crash using ABCs.
This change is exactly the same as an optimisation
done 5 years ago, but on slot *access*:
http://svn.python.org/view?view=rev&rev=28297
........
r60842 | amaury.forgeotdarc | 2008-02-15 22:27:44 +0100 (Fri, 15 Feb 2008) | 2 lines
Temporarily let these tests pass
........
r60843 | kurt.kaiser | 2008-02-15 22:56:36 +0100 (Fri, 15 Feb 2008) | 2 lines
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
........
r60844 | kurt.kaiser | 2008-02-15 23:25:09 +0100 (Fri, 15 Feb 2008) | 4 lines
Configured selection highlighting colors were ignored; updating highlighting
in the config dialog would cause non-Python files to be colored as if they
were Python source; improve use of ColorDelagator. Patch 1334. Tal Einat.
........
r60845 | amaury.forgeotdarc | 2008-02-15 23:44:20 +0100 (Fri, 15 Feb 2008) | 9 lines
Re-enable tests, they were failing since gc.collect() clears the various freelists.
They still remain fragile.
For example, a call to assertEqual currently does not make any allocation
(which surprised me at first).
But this can change when gc.collect also deletes the numerous "zombie frames"
attached to each function.
........
2008-02-16 03:38:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PyCFunction_Fini(void)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
(void)PyCFunction_ClearFreeList();
|
1997-08-04 23:11:41 -03:00
|
|
|
}
|
2003-01-31 14:33:18 -04:00
|
|
|
|
2012-06-22 15:55:41 -03:00
|
|
|
/* Print summary info about the state of the optimized allocator */
|
|
|
|
void
|
|
|
|
_PyCFunction_DebugMallocStats(FILE *out)
|
|
|
|
{
|
|
|
|
_PyDebugAllocatorStats(out,
|
2013-04-11 16:01:40 -03:00
|
|
|
"free PyCFunctionObject",
|
2012-12-30 17:46:04 -04:00
|
|
|
numfree, sizeof(PyCFunctionObject));
|
2012-06-22 15:55:41 -03:00
|
|
|
}
|