2001-01-25 16:04:14 -04:00
|
|
|
/* Cell object implementation */
|
|
|
|
|
|
|
|
#include "Python.h"
|
2024-03-29 14:35:43 -03:00
|
|
|
#include "pycore_cell.h" // PyCell_GetRef()
|
2023-10-17 09:30:31 -03:00
|
|
|
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
|
2018-11-21 17:27:47 -04:00
|
|
|
#include "pycore_object.h"
|
2001-01-25 16:04:14 -04:00
|
|
|
|
|
|
|
PyObject *
|
|
|
|
PyCell_New(PyObject *obj)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyCellObject *op;
|
2001-01-25 16:04:14 -04:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
op = (PyCellObject *)PyObject_GC_New(PyCellObject, &PyCell_Type);
|
|
|
|
if (op == NULL)
|
|
|
|
return NULL;
|
2022-11-10 11:27:32 -04:00
|
|
|
op->ob_ref = Py_XNewRef(obj);
|
2001-01-25 16:04:14 -04:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
_PyObject_GC_TRACK(op);
|
|
|
|
return (PyObject *)op;
|
2001-01-25 16:04:14 -04:00
|
|
|
}
|
|
|
|
|
2019-02-07 15:36:48 -04:00
|
|
|
PyDoc_STRVAR(cell_new_doc,
|
|
|
|
"cell([contents])\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Create a new cell object.\n"
|
|
|
|
"\n"
|
|
|
|
" contents\n"
|
|
|
|
" the contents of the cell. If not specified, the cell will be empty,\n"
|
|
|
|
" and \n further attempts to access its cell_contents attribute will\n"
|
|
|
|
" raise a ValueError.");
|
|
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
cell_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
PyObject *obj = NULL;
|
|
|
|
|
|
|
|
if (!_PyArg_NoKeywords("cell", kwargs)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
/* min = 0: we allow the cell to be empty */
|
|
|
|
if (!PyArg_UnpackTuple(args, "cell", 0, 1, &obj)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = PyCell_New(obj);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2001-01-25 16:04:14 -04:00
|
|
|
PyObject *
|
|
|
|
PyCell_Get(PyObject *op)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!PyCell_Check(op)) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return NULL;
|
|
|
|
}
|
2024-03-29 14:35:43 -03:00
|
|
|
return PyCell_GetRef((PyCellObject *)op);
|
2001-01-25 16:04:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-05-11 18:24:48 -03:00
|
|
|
PyCell_Set(PyObject *op, PyObject *value)
|
2001-01-25 16:04:14 -04:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!PyCell_Check(op)) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return -1;
|
|
|
|
}
|
2024-03-29 14:35:43 -03:00
|
|
|
PyCell_SetTakeRef((PyCellObject *)op, Py_XNewRef(value));
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2001-01-25 16:04:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_dealloc(PyCellObject *op)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
_PyObject_GC_UNTRACK(op);
|
|
|
|
Py_XDECREF(op->ob_ref);
|
|
|
|
PyObject_GC_Del(op);
|
2001-01-25 16:04:14 -04:00
|
|
|
}
|
|
|
|
|
2009-02-01 06:28:51 -04:00
|
|
|
static PyObject *
|
|
|
|
cell_richcompare(PyObject *a, PyObject *b, int op)
|
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61538 | steven.bethard | 2008-03-18 20:03:50 +0100 (Di, 18 Mär 2008) | 1 line
cell_compare needs to return -2 instead of NULL.
........
r61539 | steven.bethard | 2008-03-18 20:04:32 +0100 (Di, 18 Mär 2008) | 1 line
_have_soundcard() is a bad check for winsound.Beep, since you can have a soundcard but have the beep driver disabled. This revision basically disables the beep tests by wrapping them in a try/except. The Right Way To Do It is to come up with a _have_enabled_beep_driver() and use that.
........
r61540 | gregory.p.smith | 2008-03-18 20:05:32 +0100 (Di, 18 Mär 2008) | 8 lines
Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
uid and gid input to accept values >=2**31 as valid while still accepting
negative numbers to pass -1 to chown for "no change".
Fixes issue1747858.
This should be backported to release25-maint.
........
r61556 | steven.bethard | 2008-03-18 20:59:14 +0100 (Di, 18 Mär 2008) | 1 line
Fix test_atexit so that it still passes when -3 is supplied. (It was catching the warning messages on stdio from using the reload() function.)
........
r61559 | neal.norwitz | 2008-03-18 21:30:38 +0100 (Di, 18 Mär 2008) | 1 line
Import the test properly. This is especially important for py3k.
........
r61560 | gregory.p.smith | 2008-03-18 21:40:01 +0100 (Di, 18 Mär 2008) | 2 lines
news entry for the chown fix
........
r61563 | brett.cannon | 2008-03-18 22:12:42 +0100 (Di, 18 Mär 2008) | 2 lines
Ignore BIG5HKSCS-2004.TXT which is downloaded as part of a test.
........
r61565 | steven.bethard | 2008-03-18 22:30:13 +0100 (Di, 18 Mär 2008) | 1 line
Have regrtest skip test_py3kwarn when the -3 flag is missing.
........
r61571 | gregory.p.smith | 2008-03-18 23:27:41 +0100 (Di, 18 Mär 2008) | 4 lines
Add a test to make sure zlib.crc32 and binascii.crc32 return the same thing.
Fix a buglet in binascii.crc32, the second optional argument could previously
have a signedness mismatch with the C variable its going into.
........
r61575 | raymond.hettinger | 2008-03-19 00:22:29 +0100 (Mi, 19 Mär 2008) | 1 line
Speed-up isinstance() for one easy case.
........
r61576 | raymond.hettinger | 2008-03-19 00:33:08 +0100 (Mi, 19 Mär 2008) | 1 line
Issue: 2354: Add 3K warning for the cmp argument to list.sort() and sorted().
........
r61580 | andrew.kuchling | 2008-03-19 02:05:35 +0100 (Mi, 19 Mär 2008) | 1 line
Add Jeff Rush
........
r61581 | gregory.p.smith | 2008-03-19 02:38:35 +0100 (Mi, 19 Mär 2008) | 3 lines
Mention that crc32 and adler32 are available in a different module (zlib).
Some people look for them in hashlib.
........
r61582 | gregory.p.smith | 2008-03-19 02:46:10 +0100 (Mi, 19 Mär 2008) | 3 lines
Use zlib's crc32 routine instead of binascii when available. zlib's is faster
when compiled properly optimized and about the same speed otherwise.
........
r61586 | david.wolever | 2008-03-19 03:26:57 +0100 (Mi, 19 Mär 2008) | 1 line
Added my name to ACKS
........
r61591 | gregory.p.smith | 2008-03-19 04:14:41 +0100 (Mi, 19 Mär 2008) | 5 lines
Fix the struct module DeprecationWarnings that zipfile was triggering by
removing all use of signed struct values.
test_zipfile and test_zipfile64 pass. no more warnings.
........
r61593 | raymond.hettinger | 2008-03-19 04:56:59 +0100 (Mi, 19 Mär 2008) | 1 line
Fix compiler warning.
........
r61595 | martin.v.loewis | 2008-03-19 05:39:13 +0100 (Mi, 19 Mär 2008) | 2 lines
Issue #2400: Allow relative imports to "import *".
........
r61605 | martin.v.loewis | 2008-03-19 07:00:28 +0100 (Mi, 19 Mär 2008) | 2 lines
Import relimport using a relative import.
........
r61606 | trent.nelson | 2008-03-19 07:28:24 +0100 (Mi, 19 Mär 2008) | 1 line
Issue2290: Support x64 Windows builds that live in pcbuild/amd64. Without it, sysutils._python_build() returns the wrong directory, which causes the test_get_config_h_filename method in Lib/distutils/tests/test_sysconfig.py to fail.
........
r61613 | trent.nelson | 2008-03-19 08:45:19 +0100 (Mi, 19 Mär 2008) | 3 lines
Refine the Visual Studio 2008 build solution in order to improve how we deal with external components, as well as fixing outstanding issues with Windows x64 build support. Introduce two new .vcproj files, _bsddb44.vcproj and sqlite3.vcproj, which replace the previous pre-link event scripts for _bsddb and _sqlite3 respectively. The new project files inherit from our property files as if they were any other Python module. This has numerous benefits. First, the components get built with exactly the same compiler flags and settings as the rest of Python. Second, it makes it much easier to debug problems in the external components when they're part of the build system. Third, they'll benefit from profile guided optimisation in the release builds, just like the rest of Python core.
I've also introduced a slightly new pattern for managing externals in subversion. New components get checked in as <name>-<version>.x, where <version> matches the exact vendor version string. After the initial import of the external component, the .x is tagged as .0 (i.e. tcl-8.4.18.x -> tcl-8.4.18.0). Some components may not need any tweaking, whereas there are others that might (tcl/tk fall into this bucket). In that case, the relevant modifications are made to the .x branch, which will be subsequently tagged as .1 (and then n+1 going forward) when they build successfully and all tests pass. Buildbots will be converted to rely on these explicit tags only, which makes it easy for us to switch them over to a new version as and when required. (Simple change to external(-amd64).bat: if we've bumped tcl to 8.4.18.1, change the .bat to rmdir 8.4.18.0 if it exists and check out a new .1 copy.)
........
r61614 | trent.nelson | 2008-03-19 08:56:39 +0100 (Mi, 19 Mär 2008) | 1 line
Remove extraneous apostrophe and semi-colon from AdditionalIncludeDirectories.
........
r61615 | georg.brandl | 2008-03-19 08:56:40 +0100 (Mi, 19 Mär 2008) | 2 lines
Remove footnote from versionchanged as it upsets LaTeX.
........
r61616 | georg.brandl | 2008-03-19 08:57:57 +0100 (Mi, 19 Mär 2008) | 2 lines
Another one.
........
r61618 | trent.nelson | 2008-03-19 09:06:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fix the tcl-8.4.18.1 path and make sure we cd into the right directory when building tcl/tk.
........
r61621 | trent.nelson | 2008-03-19 10:23:08 +0100 (Mi, 19 Mär 2008) | 1 line
Lets have another try at getting the Windows buildbots in a consistent state before rebuilding using the new process.
........
r61622 | eric.smith | 2008-03-19 13:09:55 +0100 (Mi, 19 Mär 2008) | 2 lines
Use test.test_support.captured_stdout instead of a custom contextmanager.
Thanks Nick Coghlan.
........
r61623 | eric.smith | 2008-03-19 13:15:10 +0100 (Mi, 19 Mär 2008) | 1 line
Trivial typo.
........
r61625 | thomas.heller | 2008-03-19 17:10:57 +0100 (Mi, 19 Mär 2008) | 2 lines
Checkout sqlite-source when it is not there.
........
r61627 | brett.cannon | 2008-03-19 17:50:13 +0100 (Mi, 19 Mär 2008) | 5 lines
test_nis would fail if test.test_support.verbose was true but NIS was not set
up on the machine.
Closes issue2411. Thanks Michael Bishop.
........
r61631 | brett.cannon | 2008-03-19 18:37:43 +0100 (Mi, 19 Mär 2008) | 2 lines
Use sys.py3kwarning instead of trying to trigger a Py3k-related warning.
........
r61632 | raymond.hettinger | 2008-03-19 18:45:19 +0100 (Mi, 19 Mär 2008) | 1 line
Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
........
r61633 | raymond.hettinger | 2008-03-19 18:58:59 +0100 (Mi, 19 Mär 2008) | 1 line
The filter() function does support a None argument in Py3.0.
........
r61634 | raymond.hettinger | 2008-03-19 19:01:58 +0100 (Mi, 19 Mär 2008) | 1 line
Remove itertools warnings I had added before the 2-to-3 handled the migration.
........
2008-03-19 18:50:51 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
/* neither argument should be NULL, unless something's gone wrong */
|
|
|
|
assert(a != NULL && b != NULL);
|
|
|
|
|
|
|
|
/* both arguments should be instances of PyCellObject */
|
|
|
|
if (!PyCell_Check(a) || !PyCell_Check(b)) {
|
2017-11-02 07:32:54 -03:00
|
|
|
Py_RETURN_NOTIMPLEMENTED;
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compare cells by contents; empty cells come before anything else */
|
|
|
|
a = ((PyCellObject *)a)->ob_ref;
|
|
|
|
b = ((PyCellObject *)b)->ob_ref;
|
|
|
|
if (a != NULL && b != NULL)
|
|
|
|
return PyObject_RichCompare(a, b, op);
|
|
|
|
|
2017-11-02 07:32:54 -03:00
|
|
|
Py_RETURN_RICHCOMPARE(b == NULL, a == NULL, op);
|
Merged revisions 61538-61540,61556,61559-61560,61563,61565,61571,61575-61576,61580-61582,61586,61591,61593,61595,61605-61606,61613-61616,61618,61621-61623,61625,61627,61631-61634 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61538 | steven.bethard | 2008-03-18 20:03:50 +0100 (Di, 18 Mär 2008) | 1 line
cell_compare needs to return -2 instead of NULL.
........
r61539 | steven.bethard | 2008-03-18 20:04:32 +0100 (Di, 18 Mär 2008) | 1 line
_have_soundcard() is a bad check for winsound.Beep, since you can have a soundcard but have the beep driver disabled. This revision basically disables the beep tests by wrapping them in a try/except. The Right Way To Do It is to come up with a _have_enabled_beep_driver() and use that.
........
r61540 | gregory.p.smith | 2008-03-18 20:05:32 +0100 (Di, 18 Mär 2008) | 8 lines
Fix chown on 64-bit linux. It needed to take a long (64-bit on 64bit linux) as
uid and gid input to accept values >=2**31 as valid while still accepting
negative numbers to pass -1 to chown for "no change".
Fixes issue1747858.
This should be backported to release25-maint.
........
r61556 | steven.bethard | 2008-03-18 20:59:14 +0100 (Di, 18 Mär 2008) | 1 line
Fix test_atexit so that it still passes when -3 is supplied. (It was catching the warning messages on stdio from using the reload() function.)
........
r61559 | neal.norwitz | 2008-03-18 21:30:38 +0100 (Di, 18 Mär 2008) | 1 line
Import the test properly. This is especially important for py3k.
........
r61560 | gregory.p.smith | 2008-03-18 21:40:01 +0100 (Di, 18 Mär 2008) | 2 lines
news entry for the chown fix
........
r61563 | brett.cannon | 2008-03-18 22:12:42 +0100 (Di, 18 Mär 2008) | 2 lines
Ignore BIG5HKSCS-2004.TXT which is downloaded as part of a test.
........
r61565 | steven.bethard | 2008-03-18 22:30:13 +0100 (Di, 18 Mär 2008) | 1 line
Have regrtest skip test_py3kwarn when the -3 flag is missing.
........
r61571 | gregory.p.smith | 2008-03-18 23:27:41 +0100 (Di, 18 Mär 2008) | 4 lines
Add a test to make sure zlib.crc32 and binascii.crc32 return the same thing.
Fix a buglet in binascii.crc32, the second optional argument could previously
have a signedness mismatch with the C variable its going into.
........
r61575 | raymond.hettinger | 2008-03-19 00:22:29 +0100 (Mi, 19 Mär 2008) | 1 line
Speed-up isinstance() for one easy case.
........
r61576 | raymond.hettinger | 2008-03-19 00:33:08 +0100 (Mi, 19 Mär 2008) | 1 line
Issue: 2354: Add 3K warning for the cmp argument to list.sort() and sorted().
........
r61580 | andrew.kuchling | 2008-03-19 02:05:35 +0100 (Mi, 19 Mär 2008) | 1 line
Add Jeff Rush
........
r61581 | gregory.p.smith | 2008-03-19 02:38:35 +0100 (Mi, 19 Mär 2008) | 3 lines
Mention that crc32 and adler32 are available in a different module (zlib).
Some people look for them in hashlib.
........
r61582 | gregory.p.smith | 2008-03-19 02:46:10 +0100 (Mi, 19 Mär 2008) | 3 lines
Use zlib's crc32 routine instead of binascii when available. zlib's is faster
when compiled properly optimized and about the same speed otherwise.
........
r61586 | david.wolever | 2008-03-19 03:26:57 +0100 (Mi, 19 Mär 2008) | 1 line
Added my name to ACKS
........
r61591 | gregory.p.smith | 2008-03-19 04:14:41 +0100 (Mi, 19 Mär 2008) | 5 lines
Fix the struct module DeprecationWarnings that zipfile was triggering by
removing all use of signed struct values.
test_zipfile and test_zipfile64 pass. no more warnings.
........
r61593 | raymond.hettinger | 2008-03-19 04:56:59 +0100 (Mi, 19 Mär 2008) | 1 line
Fix compiler warning.
........
r61595 | martin.v.loewis | 2008-03-19 05:39:13 +0100 (Mi, 19 Mär 2008) | 2 lines
Issue #2400: Allow relative imports to "import *".
........
r61605 | martin.v.loewis | 2008-03-19 07:00:28 +0100 (Mi, 19 Mär 2008) | 2 lines
Import relimport using a relative import.
........
r61606 | trent.nelson | 2008-03-19 07:28:24 +0100 (Mi, 19 Mär 2008) | 1 line
Issue2290: Support x64 Windows builds that live in pcbuild/amd64. Without it, sysutils._python_build() returns the wrong directory, which causes the test_get_config_h_filename method in Lib/distutils/tests/test_sysconfig.py to fail.
........
r61613 | trent.nelson | 2008-03-19 08:45:19 +0100 (Mi, 19 Mär 2008) | 3 lines
Refine the Visual Studio 2008 build solution in order to improve how we deal with external components, as well as fixing outstanding issues with Windows x64 build support. Introduce two new .vcproj files, _bsddb44.vcproj and sqlite3.vcproj, which replace the previous pre-link event scripts for _bsddb and _sqlite3 respectively. The new project files inherit from our property files as if they were any other Python module. This has numerous benefits. First, the components get built with exactly the same compiler flags and settings as the rest of Python. Second, it makes it much easier to debug problems in the external components when they're part of the build system. Third, they'll benefit from profile guided optimisation in the release builds, just like the rest of Python core.
I've also introduced a slightly new pattern for managing externals in subversion. New components get checked in as <name>-<version>.x, where <version> matches the exact vendor version string. After the initial import of the external component, the .x is tagged as .0 (i.e. tcl-8.4.18.x -> tcl-8.4.18.0). Some components may not need any tweaking, whereas there are others that might (tcl/tk fall into this bucket). In that case, the relevant modifications are made to the .x branch, which will be subsequently tagged as .1 (and then n+1 going forward) when they build successfully and all tests pass. Buildbots will be converted to rely on these explicit tags only, which makes it easy for us to switch them over to a new version as and when required. (Simple change to external(-amd64).bat: if we've bumped tcl to 8.4.18.1, change the .bat to rmdir 8.4.18.0 if it exists and check out a new .1 copy.)
........
r61614 | trent.nelson | 2008-03-19 08:56:39 +0100 (Mi, 19 Mär 2008) | 1 line
Remove extraneous apostrophe and semi-colon from AdditionalIncludeDirectories.
........
r61615 | georg.brandl | 2008-03-19 08:56:40 +0100 (Mi, 19 Mär 2008) | 2 lines
Remove footnote from versionchanged as it upsets LaTeX.
........
r61616 | georg.brandl | 2008-03-19 08:57:57 +0100 (Mi, 19 Mär 2008) | 2 lines
Another one.
........
r61618 | trent.nelson | 2008-03-19 09:06:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fix the tcl-8.4.18.1 path and make sure we cd into the right directory when building tcl/tk.
........
r61621 | trent.nelson | 2008-03-19 10:23:08 +0100 (Mi, 19 Mär 2008) | 1 line
Lets have another try at getting the Windows buildbots in a consistent state before rebuilding using the new process.
........
r61622 | eric.smith | 2008-03-19 13:09:55 +0100 (Mi, 19 Mär 2008) | 2 lines
Use test.test_support.captured_stdout instead of a custom contextmanager.
Thanks Nick Coghlan.
........
r61623 | eric.smith | 2008-03-19 13:15:10 +0100 (Mi, 19 Mär 2008) | 1 line
Trivial typo.
........
r61625 | thomas.heller | 2008-03-19 17:10:57 +0100 (Mi, 19 Mär 2008) | 2 lines
Checkout sqlite-source when it is not there.
........
r61627 | brett.cannon | 2008-03-19 17:50:13 +0100 (Mi, 19 Mär 2008) | 5 lines
test_nis would fail if test.test_support.verbose was true but NIS was not set
up on the machine.
Closes issue2411. Thanks Michael Bishop.
........
r61631 | brett.cannon | 2008-03-19 18:37:43 +0100 (Mi, 19 Mär 2008) | 2 lines
Use sys.py3kwarning instead of trying to trigger a Py3k-related warning.
........
r61632 | raymond.hettinger | 2008-03-19 18:45:19 +0100 (Mi, 19 Mär 2008) | 1 line
Issue 2354: Fix-up compare warning. Patch contributed by Jeff Balogh.
........
r61633 | raymond.hettinger | 2008-03-19 18:58:59 +0100 (Mi, 19 Mär 2008) | 1 line
The filter() function does support a None argument in Py3.0.
........
r61634 | raymond.hettinger | 2008-03-19 19:01:58 +0100 (Mi, 19 Mär 2008) | 1 line
Remove itertools warnings I had added before the 2-to-3 handled the migration.
........
2008-03-19 18:50:51 -03:00
|
|
|
}
|
|
|
|
|
2001-01-25 16:04:14 -04:00
|
|
|
static PyObject *
|
|
|
|
cell_repr(PyCellObject *op)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (op->ob_ref == NULL)
|
|
|
|
return PyUnicode_FromFormat("<cell at %p: empty>", op);
|
2001-08-24 15:34:26 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>",
|
2020-02-06 22:04:21 -04:00
|
|
|
op, Py_TYPE(op->ob_ref)->tp_name,
|
2010-05-09 12:52:27 -03:00
|
|
|
op->ob_ref);
|
2001-01-25 16:04:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cell_traverse(PyCellObject *op, visitproc visit, void *arg)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_VISIT(op->ob_ref);
|
|
|
|
return 0;
|
2001-01-25 16:04:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cell_clear(PyCellObject *op)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_CLEAR(op->ob_ref);
|
|
|
|
return 0;
|
2001-01-25 16:04:14 -04:00
|
|
|
}
|
|
|
|
|
2006-04-21 07:40:58 -03:00
|
|
|
static PyObject *
|
|
|
|
cell_get_contents(PyCellObject *op, void *closure)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (op->ob_ref == NULL)
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Cell is empty");
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-11-10 11:27:32 -04:00
|
|
|
return Py_NewRef(op->ob_ref);
|
2006-04-21 07:40:58 -03:00
|
|
|
}
|
|
|
|
|
2017-09-20 10:54:13 -03:00
|
|
|
static int
|
2018-11-27 13:34:35 -04:00
|
|
|
cell_set_contents(PyCellObject *op, PyObject *obj, void *Py_UNUSED(ignored))
|
2017-06-08 08:43:26 -03:00
|
|
|
{
|
2022-11-10 11:27:32 -04:00
|
|
|
Py_XSETREF(op->ob_ref, Py_XNewRef(obj));
|
2017-06-08 08:43:26 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-21 07:40:58 -03:00
|
|
|
static PyGetSetDef cell_getsetlist[] = {
|
2017-09-14 03:38:36 -03:00
|
|
|
{"cell_contents", (getter)cell_get_contents,
|
2017-06-08 08:43:26 -03:00
|
|
|
(setter)cell_set_contents, NULL},
|
2010-05-09 12:52:27 -03:00
|
|
|
{NULL} /* sentinel */
|
2006-04-21 07:40:58 -03:00
|
|
|
};
|
|
|
|
|
2001-01-25 16:04:14 -04:00
|
|
|
PyTypeObject PyCell_Type = {
|
2010-05-09 12:52:27 -03:00
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
"cell",
|
|
|
|
sizeof(PyCellObject),
|
|
|
|
0,
|
2016-05-13 03:12:21 -03:00
|
|
|
(destructor)cell_dealloc, /* tp_dealloc */
|
2019-05-30 23:13:39 -03:00
|
|
|
0, /* tp_vectorcall_offset */
|
2010-05-09 12:52:27 -03:00
|
|
|
0, /* tp_getattr */
|
|
|
|
0, /* tp_setattr */
|
2019-05-30 23:13:39 -03:00
|
|
|
0, /* tp_as_async */
|
2010-05-09 12:52:27 -03:00
|
|
|
(reprfunc)cell_repr, /* tp_repr */
|
|
|
|
0, /* tp_as_number */
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
0, /* tp_hash */
|
|
|
|
0, /* tp_call */
|
|
|
|
0, /* tp_str */
|
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
0, /* tp_setattro */
|
|
|
|
0, /* tp_as_buffer */
|
2016-05-13 03:12:21 -03:00
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
|
2019-02-07 15:36:48 -04:00
|
|
|
cell_new_doc, /* tp_doc */
|
2010-05-09 12:52:27 -03:00
|
|
|
(traverseproc)cell_traverse, /* tp_traverse */
|
|
|
|
(inquiry)cell_clear, /* tp_clear */
|
|
|
|
cell_richcompare, /* tp_richcompare */
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
0, /* tp_iter */
|
|
|
|
0, /* tp_iternext */
|
|
|
|
0, /* tp_methods */
|
|
|
|
0, /* tp_members */
|
|
|
|
cell_getsetlist, /* tp_getset */
|
2019-02-07 15:36:48 -04:00
|
|
|
0, /* tp_base */
|
|
|
|
0, /* tp_dict */
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
0, /* tp_init */
|
|
|
|
0, /* tp_alloc */
|
|
|
|
(newfunc)cell_new, /* tp_new */
|
|
|
|
0, /* tp_free */
|
2001-01-25 16:04:14 -04:00
|
|
|
};
|