-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import unittest | ||
from test.support import import_helper | ||
|
||
_testcapi = import_helper.import_module('_testcapi') | ||
|
||
|
||
class TestCAPI(unittest.TestCase): | ||
def test_immortal_builtins(self): | ||
_testcapi.test_immortal_builtins() | ||
|
||
def test_immortal_small_ints(self): | ||
_testcapi.test_immortal_small_ints() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "parts.h" | ||
|
||
int verify_immortality(PyObject *object) | ||
{ | ||
assert(_Py_IsImmortal(object)); | ||
Py_ssize_t old_count = Py_REFCNT(object); | ||
for (int j = 0; j < 10000; j++) { | ||
Py_DECREF(object); | ||
} | ||
Py_ssize_t current_count = Py_REFCNT(object); | ||
return old_count == current_count; | ||
} | ||
|
||
static PyObject * | ||
test_immortal_builtins(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||
{ | ||
PyObject *objects[] = {Py_True, Py_False, Py_None, Py_Ellipsis}; | ||
Py_ssize_t n = Py_ARRAY_LENGTH(objects); | ||
for (Py_ssize_t i = 0; i < n; i++) { | ||
assert(verify_immortality(objects[i])); | ||
} | ||
Py_RETURN_NONE; | ||
} | ||
|
||
static PyObject * | ||
test_immortal_small_ints(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||
{ | ||
for (int i = -5; i <= 256; i++) { | ||
assert(verify_immortality(PyLong_FromLong(i))); | ||
} | ||
Py_RETURN_NONE; | ||
} | ||
|
||
static PyMethodDef test_methods[] = { | ||
{"test_immortal_builtins", test_immortal_builtins, METH_NOARGS}, | ||
{"test_immortal_small_ints", test_immortal_small_ints, METH_NOARGS}, | ||
{NULL}, | ||
}; | ||
|
||
int | ||
_PyTestCapi_Init_Immortal(PyObject *mod) | ||
{ | ||
if (PyModule_AddFunctions(mod, test_methods) < 0) { | ||
return -1; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters