Mercurial > cpython-lru_cache-weakref
annotate Modules/arraymodule.c @ 41554:06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53954 | jeremy.hylton | 2007-02-26 10:41:18 -0800 (Mon, 26 Feb 2007) | 10 lines
Do not copy free variables to locals in class namespaces.
Fixes bug 1569356, but at the cost of a minor incompatibility in
locals(). Add test that verifies that the class namespace is not
polluted. Also clarify the behavior in the library docs.
Along the way, cleaned up the dict_to_map and map_to_dict
implementations and added some comments that explain what they do.
........
r53955 | jeremy.hylton | 2007-02-26 11:00:20 -0800 (Mon, 26 Feb 2007) | 2 lines
Fix assertion.
........
r53969 | neal.norwitz | 2007-02-26 14:41:45 -0800 (Mon, 26 Feb 2007) | 3 lines
When printing an unraisable error, don't print exceptions. before the name.
This duplicates the behavior whening normally printing exceptions.
........
r53970 | andrew.kuchling | 2007-02-26 15:02:47 -0800 (Mon, 26 Feb 2007) | 1 line
Markup fix
........
r53975 | neal.norwitz | 2007-02-26 15:48:27 -0800 (Mon, 26 Feb 2007) | 3 lines
SF #1669182, 2.5 was already fixed. Just assert in 2.6 since string exceptions
are gone.
........
r53976 | andrew.kuchling | 2007-02-26 15:54:17 -0800 (Mon, 26 Feb 2007) | 1 line
Add some items
........
r53981 | jeremy.hylton | 2007-02-26 17:01:59 -0800 (Mon, 26 Feb 2007) | 4 lines
Fix long-standing bug in name mangling for package imports
Reported by Mike Verdone.
........
r53993 | jeremy.hylton | 2007-02-27 08:00:06 -0800 (Tue, 27 Feb 2007) | 2 lines
tabify
........
r53994 | jeremy.hylton | 2007-02-27 08:13:23 -0800 (Tue, 27 Feb 2007) | 5 lines
tabify
Note that ast.c still has a mix of tabs and spaces, because it
attempts to use four-space indents for more of the new code.
........
r53996 | jeremy.hylton | 2007-02-27 09:24:48 -0800 (Tue, 27 Feb 2007) | 2 lines
whitespace normalization
........
r53997 | jeremy.hylton | 2007-02-27 10:29:45 -0800 (Tue, 27 Feb 2007) | 24 lines
Add checking for a number of metaclass error conditions.
We add some new rules that are required for preserving internal
invariants of types.
1. If type (or a subclass of type) appears in bases, it must appear
before any non-type bases. If a non-type base (like a regular
new-style class) occurred first, it could trick type into
allocating the new class an __dict__ which must be impossible.
2. There are several checks that are made of bases when creating a
type. Those checks are now repeated when assigning to __bases__.
We also add the restriction that assignment to __bases__ may not
change the metaclass of the type.
Add new tests for these cases and for a few other oddball errors that
were no previously tested. Remove a crasher test that was fixed.
Also some internal refactoring: Extract the code to find the most
derived metaclass of a type and its bases. It is now needed in two
places. Rewrite the TypeError checks in test_descr to use doctest.
The tests now clearly show what exception they expect to see.
........
r53998 | jeremy.hylton | 2007-02-27 10:33:31 -0800 (Tue, 27 Feb 2007) | 2 lines
Add news about changes to metaclasses and __bases__ error checking.
........
r54016 | armin.rigo | 2007-02-28 01:25:29 -0800 (Wed, 28 Feb 2007) | 3 lines
Modify the segfaulting example to show why r53997 is not a solution to
it.
........
r54022 | brett.cannon | 2007-02-28 10:15:00 -0800 (Wed, 28 Feb 2007) | 2 lines
Add a test for instantiating SyntaxError with no arguments.
........
r54026 | raymond.hettinger | 2007-02-28 10:27:41 -0800 (Wed, 28 Feb 2007) | 1 line
Docstring nit.
........
r54033 | raymond.hettinger | 2007-02-28 10:37:52 -0800 (Wed, 28 Feb 2007) | 1 line
Prepare collections module for pure python code entries.
........
r54053 | raymond.hettinger | 2007-02-28 22:16:43 -0800 (Wed, 28 Feb 2007) | 1 line
Add collections.NamedTuple
........
r54054 | neal.norwitz | 2007-02-28 23:04:41 -0800 (Wed, 28 Feb 2007) | 1 line
Add Pat and Eric for work on PEP 3101 in the sandbox
........
r54061 | andrew.kuchling | 2007-03-01 06:36:12 -0800 (Thu, 01 Mar 2007) | 1 line
Add NamedTuple
........
r54080 | georg.brandl | 2007-03-02 06:37:12 -0800 (Fri, 02 Mar 2007) | 2 lines
Bug #1628895: some better tries to find HTML documentation in pydoc.
........
r54086 | raymond.hettinger | 2007-03-02 11:20:46 -0800 (Fri, 02 Mar 2007) | 1 line
Fix embarrassing typo and fix constantification of None
........
r54088 | georg.brandl | 2007-03-02 12:30:14 -0800 (Fri, 02 Mar 2007) | 2 lines
Bugs #1668032, #1668036, #1669304: clarify behavior of PyMem_Realloc and _Resize.
........
r54114 | georg.brandl | 2007-03-04 09:18:54 -0800 (Sun, 04 Mar 2007) | 2 lines
Fix a bug in test_dict and test_userdict, found at the PyPy sprint.
........
r54124 | skip.montanaro | 2007-03-04 12:52:28 -0800 (Sun, 04 Mar 2007) | 2 lines
Teach setup.py how to find Berkeley DB on Macs using MacPorts.
........
r54125 | skip.montanaro | 2007-03-04 12:54:12 -0800 (Sun, 04 Mar 2007) | 1 line
note MacPorts/BerkDB change in setup.py
........
r54136 | neal.norwitz | 2007-03-04 23:52:01 -0800 (Sun, 04 Mar 2007) | 1 line
Added Pete for 3101 too
........
r54138 | facundo.batista | 2007-03-05 08:31:54 -0800 (Mon, 05 Mar 2007) | 1 line
Minor corrections to docs, and an explanation comentary
........
r54139 | georg.brandl | 2007-03-05 14:28:08 -0800 (Mon, 05 Mar 2007) | 3 lines
Patch #1674228: when assigning a slice (old-style), check for the
sq_ass_slice instead of the sq_slice slot.
........
r54149 | georg.brandl | 2007-03-06 01:33:01 -0800 (Tue, 06 Mar 2007) | 3 lines
Nit: a struct field is set to GenericAlloc, not GenericAlloc().
........
r54150 | georg.brandl | 2007-03-06 02:02:47 -0800 (Tue, 06 Mar 2007) | 3 lines
Patch #1671450: add a section about subclassing builtin types to the
"extending and embedding" tutorial.
........
r54152 | martin.v.loewis | 2007-03-06 02:41:24 -0800 (Tue, 06 Mar 2007) | 2 lines
Patch #1121142: Implement ZipFile.open.
........
r54154 | georg.brandl | 2007-03-06 03:51:14 -0800 (Tue, 06 Mar 2007) | 2 lines
A test case for the fix in #1674228.
........
r54156 | georg.brandl | 2007-03-06 03:52:24 -0800 (Tue, 06 Mar 2007) | 2 lines
Patch #1672481: fix bug in idlelib.MultiCall.
........
r54159 | georg.brandl | 2007-03-06 04:17:50 -0800 (Tue, 06 Mar 2007) | 1 line
Bug #1674503: close the file opened by execfile() in an error condition.
........
r54160 | georg.brandl | 2007-03-06 05:32:52 -0800 (Tue, 06 Mar 2007) | 3 lines
Fix another reincarnation of bug #1576657 in defaultdict.
........
r54162 | georg.brandl | 2007-03-06 05:35:00 -0800 (Tue, 06 Mar 2007) | 2 lines
A test case for the defaultdict KeyError bug.
........
r54164 | georg.brandl | 2007-03-06 05:37:45 -0800 (Tue, 06 Mar 2007) | 3 lines
Patch #1663234: you can now run doctest on test files and modules
using "python -m doctest [-v] filename ...".
........
r54165 | martin.v.loewis | 2007-03-06 06:43:00 -0800 (Tue, 06 Mar 2007) | 3 lines
Patch #912410: Replace HTML entity references for attribute values
in HTMLParser.
........
r54166 | skip.montanaro | 2007-03-06 07:41:38 -0800 (Tue, 06 Mar 2007) | 1 line
patch 1673619 - identify extension modules which cannot be built
........
r54167 | guido.van.rossum | 2007-03-06 07:50:01 -0800 (Tue, 06 Mar 2007) | 5 lines
Patch #1646728: datetime.fromtimestamp fails with negative
fractional times. With unittest.
Somebody please backport to 2.5.
........
r54169 | georg.brandl | 2007-03-06 09:49:14 -0800 (Tue, 06 Mar 2007) | 2 lines
Fix cmp vs. key argument for list.sort.
........
r54170 | georg.brandl | 2007-03-06 10:21:32 -0800 (Tue, 06 Mar 2007) | 2 lines
Small nit, found by Neal.
........
r54171 | georg.brandl | 2007-03-06 10:29:58 -0800 (Tue, 06 Mar 2007) | 3 lines
Patch #1602128: clarify that richcmp methods can return NotImplemented
and should return True or False otherwise.
........
r54173 | georg.brandl | 2007-03-06 10:41:12 -0800 (Tue, 06 Mar 2007) | 2 lines
Patch #1638879: don't accept strings with embedded NUL bytes in long().
........
r54175 | georg.brandl | 2007-03-06 10:47:31 -0800 (Tue, 06 Mar 2007) | 2 lines
Patch #1673121: update README wrt. OSX default shell.
........
r54177 | georg.brandl | 2007-03-06 10:59:11 -0800 (Tue, 06 Mar 2007) | 3 lines
Patch #1654417: make operator.{get,set,del}slice use the full range
of Py_ssize_t.
........
r54180 | walter.doerwald | 2007-03-06 12:38:57 -0800 (Tue, 06 Mar 2007) | 4 lines
Patch for bug #1633621: if curses.resizeterm() or
curses.resize_term() is called, update _curses.LINES,
_curses.COLS, curses.LINES and curses.COLS.
........
r54182 | walter.doerwald | 2007-03-06 13:15:24 -0800 (Tue, 06 Mar 2007) | 2 lines
Document change to curses.
........
r54188 | georg.brandl | 2007-03-06 16:34:46 -0800 (Tue, 06 Mar 2007) | 5 lines
Variant of patch #697613: don't exit the interpreter on a SystemExit
exception if the -i command line option or PYTHONINSPECT environment
variable is given, but break into the interactive interpreter just like
on other exceptions or normal program exit.
(backport)
........
r54189 | georg.brandl | 2007-03-06 16:40:28 -0800 (Tue, 06 Mar 2007) | 4 lines
Patch #703779: unset __file__ in __main__ after running a file. This
makes the filenames the warning module prints much more sensible when
a PYTHONSTARTUP file is used.
........
r54192 | george.yoshida | 2007-03-06 20:21:18 -0800 (Tue, 06 Mar 2007) | 2 lines
add versionadded info
........
r54195 | georg.brandl | 2007-03-06 23:39:06 -0800 (Tue, 06 Mar 2007) | 2 lines
Patch #812285: allow multiple auth schemes in AbstractBasicAuthHandler.
........
r54197 | georg.brandl | 2007-03-07 00:31:51 -0800 (Wed, 07 Mar 2007) | 3 lines
Patch #1001604: glob.glob() now returns unicode filenames if it was
given a unicode argument and os.listdir() returns unicode filenames.
........
r54199 | georg.brandl | 2007-03-07 01:09:40 -0800 (Wed, 07 Mar 2007) | 3 lines
Patches #1550273, #1550272: fix a few bugs in unittest and add a
comprehensive test suite for the module.
........
r54201 | georg.brandl | 2007-03-07 01:21:06 -0800 (Wed, 07 Mar 2007) | 3 lines
Patch #787789: allow to pass custom TestRunner instances to unittest's
main() function.
........
r54202 | georg.brandl | 2007-03-07 01:34:45 -0800 (Wed, 07 Mar 2007) | 2 lines
Patch #1669331: clarify shutil.copyfileobj() behavior wrt. file position.
........
r54204 | martin.v.loewis | 2007-03-07 03:04:33 -0800 (Wed, 07 Mar 2007) | 2 lines
Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', '').
........
r54206 | georg.brandl | 2007-03-07 03:37:42 -0800 (Wed, 07 Mar 2007) | 2 lines
Patch #1675471: convert test_pty to unittest.
........
r54207 | georg.brandl | 2007-03-07 03:54:49 -0800 (Wed, 07 Mar 2007) | 4 lines
Add some sanity checks to unittest.TestSuite's addTest(s) methods.
Fixes #878275.
........
r54209 | guido.van.rossum | 2007-03-07 07:16:29 -0800 (Wed, 07 Mar 2007) | 3 lines
Windows doesn't support negative timestamps. Skip the tests involving them
if os.name == "nt".
........
r54219 | martin.v.loewis | 2007-03-08 05:42:43 -0800 (Thu, 08 Mar 2007) | 2 lines
Add missing ) in parenthical remark.
........
r54220 | georg.brandl | 2007-03-08 09:49:06 -0800 (Thu, 08 Mar 2007) | 2 lines
Fix #1676656: \em is different from \emph...
........
r54222 | georg.brandl | 2007-03-08 10:37:31 -0800 (Thu, 08 Mar 2007) | 2 lines
Add a NEWS entry for rev. 54207,8.
........
r54225 | raymond.hettinger | 2007-03-08 11:24:27 -0800 (Thu, 08 Mar 2007) | 1 line
SF 1676321: empty() returned wrong result
........
r54227 | collin.winter | 2007-03-08 11:58:14 -0800 (Thu, 08 Mar 2007) | 1 line
Backported r54226 from p3yk: Move test_unittest, test_doctest and test_doctest2 higher up in the testing order.
........
r54230 | raymond.hettinger | 2007-03-08 13:33:47 -0800 (Thu, 08 Mar 2007) | 1 line
SF #1637850: make_table in difflib did not work with unicode
........
r54232 | collin.winter | 2007-03-08 14:16:25 -0800 (Thu, 08 Mar 2007) | 1 line
Patch #1668482: don't use '-' in mkstemp
........
r54233 | brett.cannon | 2007-03-08 15:58:11 -0800 (Thu, 08 Mar 2007) | 10 lines
Introduce test.test_support.TransientResource. It's a context manager to
surround calls to resources that may or may not be available. Specifying the
expected exception and attributes to be raised if the resource is not available
prevents overly broad catching of exceptions.
This is meant to help suppress spurious failures by raising
test.test_support.ResourceDenied if the exception matches. It would probably
be good to go through the various network tests and surround the calls to catch
connection timeouts (as done with test_socket_ssl in this commit).
........
r54234 | collin.winter | 2007-03-08 19:15:56 -0800 (Thu, 08 Mar 2007) | 1 line
Patch #1481079: Support of HTTP_REFERER in CGIHTTPServer.py
........
r54235 | collin.winter | 2007-03-08 19:26:32 -0800 (Thu, 08 Mar 2007) | 1 line
Add NEWS item for patch #1481079 (r54234).
........
r54237 | neal.norwitz | 2007-03-08 21:59:01 -0800 (Thu, 08 Mar 2007) | 1 line
Fix SF #1676971, Complex OverflowError has a typo
........
r54239 | georg.brandl | 2007-03-09 04:58:41 -0800 (Fri, 09 Mar 2007) | 2 lines
Typo.
........
r54240 | martin.v.loewis | 2007-03-09 07:35:55 -0800 (Fri, 09 Mar 2007) | 2 lines
Patch #957003: Implement smtplib.LMTP.
........
r54243 | collin.winter | 2007-03-09 10:09:10 -0800 (Fri, 09 Mar 2007) | 2 lines
Bug #1629566: clarify the docs on the return values of parsedate() and parsedate_tz() in email.utils and rfc822.
........
r54244 | thomas.heller | 2007-03-09 11:21:28 -0800 (Fri, 09 Mar 2007) | 3 lines
Fix bug #1646630: ctypes.string_at(buf, 0) and ctypes.wstring_at(buf, 0)
returned string up to the first NUL character.
........
r54245 | martin.v.loewis | 2007-03-09 11:36:01 -0800 (Fri, 09 Mar 2007) | 2 lines
Add Ziga Seilnacht.
........
r54247 | collin.winter | 2007-03-09 12:33:07 -0800 (Fri, 09 Mar 2007) | 2 lines
Patch #1491866: change the complex() constructor to allow parthensized forms. This means complex(repr(x)) now works instead of raising a ValueError.
........
r54248 | thomas.heller | 2007-03-09 12:39:22 -0800 (Fri, 09 Mar 2007) | 7 lines
Bug #1651235: When a tuple was passed to a ctypes function call,
Python would crash instead of raising an error.
The crash was caused by a section of code that should have been
removed long ago, at that time ctypes had other ways to pass
parameters to function calls.
........
r54250 | collin.winter | 2007-03-09 15:30:39 -0800 (Fri, 09 Mar 2007) | 1 line
Hashing simplification pointed out by Thomas Wouters.
........
r54252 | collin.winter | 2007-03-09 18:23:40 -0800 (Fri, 09 Mar 2007) | 5 lines
* Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink.
* Drop safe_remove() in favor of test_support.unlink().
* Fix the indentation of test_samefile so that it runs.
........
r54253 | collin.winter | 2007-03-09 18:51:26 -0800 (Fri, 09 Mar 2007) | 3 lines
Bug #1531963: Make SocketServer.TCPServer's server_address always be equal to calling getsockname() on the server's socket.
Will backport.
........
r54254 | neal.norwitz | 2007-03-09 19:19:18 -0800 (Fri, 09 Mar 2007) | 4 lines
Simplify a little by handling the TCP case first.
Update to use predominant style of spaces around = in args list
and print to stderr if debugging.
........
r54256 | collin.winter | 2007-03-09 19:35:34 -0800 (Fri, 09 Mar 2007) | 1 line
Add proper attribution for a bug fix.
........
r54257 | georg.brandl | 2007-03-09 23:38:14 -0800 (Fri, 09 Mar 2007) | 2 lines
Typos.
........
r54260 | collin.winter | 2007-03-10 06:33:32 -0800 (Sat, 10 Mar 2007) | 1 line
Convert an assert to a raise so it works even in the presence of -O.
........
r54262 | collin.winter | 2007-03-10 06:41:48 -0800 (Sat, 10 Mar 2007) | 2 lines
Patch #1599845: Add an option to disable the implicit calls to server_bind() and server_activate() in the constructors for TCPServer, SimpleXMLRPCServer and DocXMLRPCServer.
........
r54268 | georg.brandl | 2007-03-11 00:28:46 -0800 (Sun, 11 Mar 2007) | 2 lines
Add missing "return" statements in exception handler.
........
r54270 | ziga.seilnacht | 2007-03-11 08:54:54 -0700 (Sun, 11 Mar 2007) | 3 lines
Patch #1675981: remove unreachable code from type.__new__() method.
__dict__ and __weakref__ are removed from the slots tuple earlier
in the code, in the loop that mangles slot names. Will backport.
........
r54271 | collin.winter | 2007-03-11 09:00:20 -0700 (Sun, 11 Mar 2007) | 3 lines
Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Will backport.
........
r54274 | vinay.sajip | 2007-03-11 11:32:07 -0700 (Sun, 11 Mar 2007) | 1 line
Fix resource leak reported in SF #1516995.
........
r54278 | collin.winter | 2007-03-11 18:55:54 -0700 (Sun, 11 Mar 2007) | 4 lines
Patch #1678662: ftp.python.org does not exist. So the testcode in urllib.py must use a more
stable FTP.
Will backport.
........
r54280 | barry.warsaw | 2007-03-11 20:20:01 -0700 (Sun, 11 Mar 2007) | 8 lines
Tokio Kikuchi's fix for SF bug #1629369; folding whitespace allowed in the
display name of an email address, e.g.
Foo
\tBar <foo@example.com>
Test case added by Barry.
........
r54282 | skip.montanaro | 2007-03-11 20:30:50 -0700 (Sun, 11 Mar 2007) | 4 lines
Sane humans would call these invalid tests, but Andrew McNamara pointed out
that given the inputs in these tests Excel does indeed produce the output
these tests expect. Document that for future confused folks.
........
r54283 | martin.v.loewis | 2007-03-12 03:50:39 -0700 (Mon, 12 Mar 2007) | 2 lines
Bug #1675511: Use -Kpic instead of -xcode=pic32 on Solaris/x86.
........
r54285 | martin.v.loewis | 2007-03-12 04:01:10 -0700 (Mon, 12 Mar 2007) | 2 lines
Patch #1677862: Require a space or tab after import in .pth files.
........
r54287 | georg.brandl | 2007-03-12 06:17:36 -0700 (Mon, 12 Mar 2007) | 8 lines
Backport from Py3k branch:
Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir.
Had to change a few bits of the patch because classobjs and __methods__ are still
in Py2.6.
........
r54288 | georg.brandl | 2007-03-12 07:30:05 -0700 (Mon, 12 Mar 2007) | 3 lines
Bug #1678647: write a newline after printing an exception in any
case, even when converting the value to a string failed.
........
r54290 | collin.winter | 2007-03-12 08:57:19 -0700 (Mon, 12 Mar 2007) | 1 line
Patch #1678088: convert test_operations to use unittest, fold the result into test_dict.
........
r54291 | collin.winter | 2007-03-12 09:11:39 -0700 (Mon, 12 Mar 2007) | 3 lines
Bug #742342: make Python stop segfaulting on infinitely-recursive reload()s. Fixed by patch #922167.
Will backport.
........
r54292 | georg.brandl | 2007-03-12 09:15:09 -0700 (Mon, 12 Mar 2007) | 2 lines
Typo fix.
........
r54295 | collin.winter | 2007-03-12 10:24:07 -0700 (Mon, 12 Mar 2007) | 1 line
Patch #1670993: Refactor test_threadedtempfile.py to use unittest.
........
r54296 | tim.peters | 2007-03-12 11:07:52 -0700 (Mon, 12 Mar 2007) | 2 lines
Whitespace normalization.
........
r54297 | tim.peters | 2007-03-12 11:09:22 -0700 (Mon, 12 Mar 2007) | 2 lines
Set missing svn:eol-style property on text files.
........
r54315 | brett.cannon | 2007-03-12 19:34:09 -0700 (Mon, 12 Mar 2007) | 8 lines
Add test.test_support.transient_internet . Returns a context manager that
nests test.test_support.TransientResource context managers that capture
exceptions raised when the Internet connection is flaky.
Initially using in test_socket_ssl but should probably be expanded to cover any
test that should not raise the captured exceptions if the Internet connection
works.
........
r54316 | brett.cannon | 2007-03-12 20:05:40 -0700 (Mon, 12 Mar 2007) | 2 lines
Fix a typo where the variable name was not updated.
........
r54318 | neal.norwitz | 2007-03-12 21:59:58 -0700 (Mon, 12 Mar 2007) | 1 line
Add Jerry Seutter for a bunch of his recent patches refactoring tests
........
r54319 | neal.norwitz | 2007-03-12 22:07:14 -0700 (Mon, 12 Mar 2007) | 7 lines
Add some other acks for recent checkins:
Brian Leair - 922167
Tomer Filiba - 1591665
Jeremy Jones - 1192590
........
r54321 | neal.norwitz | 2007-03-12 22:31:38 -0700 (Mon, 12 Mar 2007) | 9 lines
Fix some style nits:
* lines too long
* wrong indentation
* space after a function name
* wrong function name in error string
* simplifying some logic
Also add an error check to PyDict_SetItemString.
........
r54322 | georg.brandl | 2007-03-13 00:23:16 -0700 (Tue, 13 Mar 2007) | 2 lines
Typo and grammar fixes.
........
r54323 | georg.brandl | 2007-03-13 00:50:57 -0700 (Tue, 13 Mar 2007) | 2 lines
Patch #1679379: add documentation for fnmatch.translate().
........
r54325 | georg.brandl | 2007-03-13 00:57:51 -0700 (Tue, 13 Mar 2007) | 2 lines
Patch #1642844: comments to clarify the complexobject constructor.
........
r54326 | georg.brandl | 2007-03-13 01:14:27 -0700 (Tue, 13 Mar 2007) | 3 lines
Patch #1668100: urllib2 now correctly raises URLError instead of
OSError if accessing a local file via the file:// protocol fails.
........
r54327 | georg.brandl | 2007-03-13 02:32:11 -0700 (Tue, 13 Mar 2007) | 4 lines
Patch #1635454: the csv.DictWriter class now includes the offending
field names in its exception message if you try to write a record with
a dictionary containing fields not in the CSV field names list.
........
r54328 | georg.brandl | 2007-03-13 02:41:31 -0700 (Tue, 13 Mar 2007) | 3 lines
Patch #1555098: use str.join() instead of repeated string
concatenation in robotparser.
........
r54329 | georg.brandl | 2007-03-13 03:06:48 -0700 (Tue, 13 Mar 2007) | 3 lines
Patch #1542681: add entries for "with", "as" and "CONTEXTMANAGERS" to
pydoc's help keywords.
........
r54331 | georg.brandl | 2007-03-13 03:19:22 -0700 (Tue, 13 Mar 2007) | 3 lines
Patch #1569798: fix a bug in distutils when building Python from a
directory within sys.exec_prefix.
........
r54333 | martin.v.loewis | 2007-03-13 03:24:00 -0700 (Tue, 13 Mar 2007) | 4 lines
Patch #1449244: Support Unicode strings in
email.message.Message.{set_charset,get_content_charset}.
Will backport.
........
r54335 | lars.gustaebel | 2007-03-13 03:47:19 -0700 (Tue, 13 Mar 2007) | 34 lines
This is the implementation of POSIX.1-2001 (pax) format read/write
support.
The TarInfo class now contains all necessary logic to process and
create tar header data which has been moved there from the TarFile
class. The fromtarfile() method was added. The new path and linkpath
properties are aliases for the name and linkname attributes in
correspondence to the pax naming scheme.
The TarFile constructor and classmethods now accept a number of
keyword arguments which could only be set as attributes before (e.g.
dereference, ignore_zeros). The encoding and pax_headers arguments
were added for pax support. There is a new tarinfo keyword argument
that allows using subclassed TarInfo objects in TarFile.
The boolean TarFile.posix attribute is deprecated, because now three
tar formats are supported. Instead, the desired format for writing is
specified using the constants USTAR_FORMAT, GNU_FORMAT and PAX_FORMAT
as the format keyword argument. This change affects TarInfo.tobuf()
as well.
The test suite has been heavily reorganized and partially rewritten.
A new testtar.tar was added that contains sample data in many formats
from 4 different tar programs.
Some bugs and quirks that also have been fixed:
Directory names do no longer have a trailing slash in TarInfo.name or
TarFile.getnames().
Adding the same file twice does not create a hardlink file member.
The TarFile constructor does no longer need a name argument.
The TarFile._mode attribute was renamed to mode and contains either
'r', 'w' or 'a'.
........
r54336 | georg.brandl | 2007-03-13 05:34:25 -0700 (Tue, 13 Mar 2007) | 3 lines
Bug #1622896: fix a rare corner case where the bz2 module raised an
error in spite of a succesful compression.
........
r54338 | lars.gustaebel | 2007-03-13 08:47:07 -0700 (Tue, 13 Mar 2007) | 3 lines
Quick fix for tests that fail on systems with an encoding other
than 'iso8859-1'.
........
r54339 | georg.brandl | 2007-03-13 10:43:32 -0700 (Tue, 13 Mar 2007) | 4 lines
Patch #1603688: ConfigParser.SafeConfigParser now checks values that
are set for invalid interpolation sequences that would lead to errors
on reading back those values.
........
r54341 | georg.brandl | 2007-03-13 11:15:41 -0700 (Tue, 13 Mar 2007) | 3 lines
Patch #1581073: add a flag to textwrap that prevents the dropping of
whitespace while wrapping.
........
r54343 | georg.brandl | 2007-03-13 11:24:40 -0700 (Tue, 13 Mar 2007) | 2 lines
Patch #1605192: list allowed states in error messages for imaplib.
........
r54344 | georg.brandl | 2007-03-13 11:31:49 -0700 (Tue, 13 Mar 2007) | 4 lines
Patch #1537850: tempfile.NamedTemporaryFile now has a "delete" parameter
which can be set to False to prevent the default delete-on-close
behavior.
........
r54345 | collin.winter | 2007-03-13 11:53:04 -0700 (Tue, 13 Mar 2007) | 9 lines
Add acks for recent patch checkins:
Arvin Schnell - 1668482
S?\195?\169bastien Martini - 1481079
Heiko Wundram - 1491866
Damon Kohler - 1545011
Peter Parente - 1599845
Bjorn Lindqvist - 1678662
........
r54346 | georg.brandl | 2007-03-13 12:00:36 -0700 (Tue, 13 Mar 2007) | 2 lines
Acks for recent patches.
........
r54347 | georg.brandl | 2007-03-13 12:18:18 -0700 (Tue, 13 Mar 2007) | 3 lines
Fix a tab.
........
r54348 | georg.brandl | 2007-03-13 12:32:21 -0700 (Tue, 13 Mar 2007) | 4 lines
Patch #1533909: the timeit module now accepts callables in addition to
strings for the code to time and the setup code. Also added two
convenience functions for instantiating a Timer and calling its methods.
........
r54352 | georg.brandl | 2007-03-13 13:02:57 -0700 (Tue, 13 Mar 2007) | 3 lines
Patch #1530482: add pydoc.render_doc() which returns the documentation
for a thing instead of paging it to stdout, which pydoc.doc() does.
........
r54357 | thomas.heller | 2007-03-13 13:42:52 -0700 (Tue, 13 Mar 2007) | 1 line
Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl.
........
r54358 | georg.brandl | 2007-03-13 13:46:32 -0700 (Tue, 13 Mar 2007) | 2 lines
Patch #1444529: the builtin compile() now accepts keyword arguments.
(backport)
........
r54359 | thomas.heller | 2007-03-13 14:01:39 -0700 (Tue, 13 Mar 2007) | 1 line
Add versionadded marker for ctypes.c_bool.
........
r54360 | georg.brandl | 2007-03-13 14:08:15 -0700 (Tue, 13 Mar 2007) | 3 lines
Patch #1393667: pdb now has a "run" command which restarts the debugged
Python program, optionally with different arguments.
........
r54361 | georg.brandl | 2007-03-13 14:32:01 -0700 (Tue, 13 Mar 2007) | 3 lines
Deprecate commands.getstatus().
........
r54362 | georg.brandl | 2007-03-13 14:32:56 -0700 (Tue, 13 Mar 2007) | 2 lines
NEWS entry for getstatus() deprecation.
........
r54363 | georg.brandl | 2007-03-13 14:58:44 -0700 (Tue, 13 Mar 2007) | 4 lines
Patch #1429539: pdb now correctly initializes the __main__ module for
the debugged script, which means that imports from __main__ work
correctly now.
........
r54364 | georg.brandl | 2007-03-13 15:07:36 -0700 (Tue, 13 Mar 2007) | 4 lines
Patch #957650: "%var%" environment variable references are now properly
expanded in ntpath.expandvars(), also "~user" home directory references
are recognized and handled on Windows.
........
r54365 | georg.brandl | 2007-03-13 15:16:30 -0700 (Tue, 13 Mar 2007) | 2 lines
Patch #1194449: correctly detect unbound methods in pydoc.
........
r54367 | georg.brandl | 2007-03-13 15:49:43 -0700 (Tue, 13 Mar 2007) | 5 lines
Patch #1185447: binascii.b2a_qp() now correctly quotes binary characters
with ASCII value less than 32. Also, it correctly quotes dots only if
they occur on a single line, as opposed to the previous behavior of
quoting dots if they are the second character of any line.
........
r54368 | collin.winter | 2007-03-13 16:02:15 -0700 (Tue, 13 Mar 2007) | 1 line
Inline PyImport_GetModulesReloading().
........
r54371 | barry.warsaw | 2007-03-13 21:59:50 -0700 (Tue, 13 Mar 2007) | 6 lines
SF bug #1582282; decode_header() incorrectly splits not-conformant RFC
2047-like headers where there is no whitespace between encoded words. This
fix changes the matching regexp to include a trailing lookahead assertion that
the closing ?= must be followed by whitespace, newline, or end-of-string.
This also changes the regexp to add the MULTILINE flag.
........
r54372 | gregory.p.smith | 2007-03-14 00:17:40 -0700 (Wed, 14 Mar 2007) | 2 lines
correct order and names of the less often used keyword parameters.
........
r54373 | gregory.p.smith | 2007-03-14 00:19:50 -0700 (Wed, 14 Mar 2007) | 5 lines
Its time to stop listing (Unix, Windows) when we really mean "everything but Mac OS 9"
now that nobody is likely to use Python on Mac OS 9 and most of the (Mac) platform
items are all OS X special API specific since OS X is unixy enough for these modules
to be available out of the box.
........
r54376 | georg.brandl | 2007-03-14 01:27:52 -0700 (Wed, 14 Mar 2007) | 4 lines
Bug #767111: fix long-standing bug in urllib which caused an
AttributeError instead of an IOError when the server's response didn't
contain a valid HTTP status line.
........
r54378 | ziga.seilnacht | 2007-03-14 05:24:09 -0700 (Wed, 14 Mar 2007) | 4 lines
Patch #1680015: Don't modify __slots__ tuple if it contains an unicode
name. Remove a reference leak that happened if the name could not be
converted to string. Will backport.
........
r54386 | martin.v.loewis | 2007-03-14 13:02:31 -0700 (Wed, 14 Mar 2007) | 3 lines
Patch #1559413: Fix test_cmd_line if sys.executable contains a space.
Will backport.
........
r54389 | brett.cannon | 2007-03-14 14:40:13 -0700 (Wed, 14 Mar 2007) | 3 lines
Note how test_socket_ssl has various exceptions that deal with a flaky Net
connection are silenced.
........
r54390 | brett.cannon | 2007-03-14 14:44:15 -0700 (Wed, 14 Mar 2007) | 2 lines
Raise ResourceDenied in test_urllib2net when the Net connection goes bad.
........
r54391 | neal.norwitz | 2007-03-14 21:41:20 -0700 (Wed, 14 Mar 2007) | 1 line
Wrap a long line and fix a typo (is -> if)
........
r54392 | georg.brandl | 2007-03-15 00:38:14 -0700 (Thu, 15 Mar 2007) | 3 lines
Patch #1680978: consistently use "alive" instead of "active" in the
thread lib doc.
........
r54394 | georg.brandl | 2007-03-15 00:41:30 -0700 (Thu, 15 Mar 2007) | 3 lines
Patch #1681153: the wave module now closes a file object it opened if
initialization failed.
........
r54397 | ziga.seilnacht | 2007-03-15 04:44:55 -0700 (Thu, 15 Mar 2007) | 3 lines
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
the implementation for __reduce__ and __reduce_ex__ into two separate
functions. Fixes bug #931877. Will backport.
........
r54404 | collin.winter | 2007-03-15 21:11:30 -0700 (Thu, 15 Mar 2007) | 3 lines
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Will backport.
........
r54406 | georg.brandl | 2007-03-16 00:55:09 -0700 (Fri, 16 Mar 2007) | 5 lines
Bug #1681228: the webbrowser module now correctly uses the default
GNOME or KDE browser, depending on whether there is a session of one
of those present. Also, it tries the Windows default browser before
trying Mozilla variants.
(backport)
........
r54407 | georg.brandl | 2007-03-16 01:22:40 -0700 (Fri, 16 Mar 2007) | 4 lines
Patch #1273829: os.walk() now has a "followlinks" parameter. If set to
True (which is not the default), it visits symlinks pointing to
directories.
........
r54408 | georg.brandl | 2007-03-16 01:24:21 -0700 (Fri, 16 Mar 2007) | 2 lines
Add \versionadded tag.
........
r54409 | georg.brandl | 2007-03-16 01:33:47 -0700 (Fri, 16 Mar 2007) | 2 lines
RFE #1670167: fix in isinstance() docs.
........
r54412 | ziga.seilnacht | 2007-03-16 04:59:38 -0700 (Fri, 16 Mar 2007) | 3 lines
Patch #1623563: allow __class__ assignment for classes with __slots__.
The old and the new class are still required to have the same slot
names, but the order in which they are specified is not relevant.
........
r54413 | ziga.seilnacht | 2007-03-16 05:11:11 -0700 (Fri, 16 Mar 2007) | 2 lines
Whitespace cleanup. Also remove the empty lines
from the previous check in.
........
r54414 | jeremy.hylton | 2007-03-16 07:49:11 -0700 (Fri, 16 Mar 2007) | 2 lines
Remove warning: funcion declaration isn't a prototype
........
r54415 | jeremy.hylton | 2007-03-16 08:59:47 -0700 (Fri, 16 Mar 2007) | 11 lines
Clean up formatting of this file.
The file should now follow PEP 7, except that it uses 4 space indents
(in the style of Py3k). This particular code would be really hard to
read with the regular tab idents.
Other changes:
- reflow long lines
- change multi-line conditionals to have test at end of line
........
r54417 | collin.winter | 2007-03-16 14:13:35 -0700 (Fri, 16 Mar 2007) | 1 line
Patch #1676994: Refactor test_popen2 to use unittest.
........
r54418 | collin.winter | 2007-03-16 14:15:35 -0700 (Fri, 16 Mar 2007) | 1 line
Remove test/output/test_popen2 (missed in r54417).
........
r54419 | collin.winter | 2007-03-16 15:16:08 -0700 (Fri, 16 Mar 2007) | 1 line
Patch 1339796: add a relpath() function to os.path.
........
r54421 | georg.brandl | 2007-03-17 09:08:45 -0700 (Sat, 17 Mar 2007) | 5 lines
Patch #1675423: PyComplex_AsCComplex() now tries to convert an object
to complex using its __complex__() method before falling back to the
__float__() method. Therefore, the functions in the cmath module now
can operate on objects that define a __complex__() method.
(backport)
........
r54423 | gregory.p.smith | 2007-03-17 15:33:35 -0700 (Sat, 17 Mar 2007) | 2 lines
move note to the correct section
........
r54426 | georg.brandl | 2007-03-18 01:25:00 -0700 (Sun, 18 Mar 2007) | 2 lines
Patch #1682878: the new socket methods are recv_into and recvfrom_into, not *_buf.
........
r54432 | georg.brandl | 2007-03-18 11:28:25 -0700 (Sun, 18 Mar 2007) | 2 lines
Patch #1678339: test case for bug in difflib.
........
r54439 | collin.winter | 2007-03-19 11:52:08 -0700 (Mon, 19 Mar 2007) | 1 line
Patch #1630118: add a SpooledTemporaryFile class to tempfile.
........
r54441 | georg.brandl | 2007-03-19 12:02:48 -0700 (Mon, 19 Mar 2007) | 2 lines
Patch #1683328: fixes and enhancements for "unparse" demo.
........
r54456 | neal.norwitz | 2007-03-19 22:07:28 -0700 (Mon, 19 Mar 2007) | 1 line
Add some doc that was left out from some change to platform.py
........
r54457 | neal.norwitz | 2007-03-19 22:08:23 -0700 (Mon, 19 Mar 2007) | 1 line
Add a comment about 3k migration
........
r54458 | neal.norwitz | 2007-03-19 22:21:21 -0700 (Mon, 19 Mar 2007) | 1 line
Get rid of deprecation warning when testing commands.getstatus()
........
r54459 | neal.norwitz | 2007-03-19 22:23:09 -0700 (Mon, 19 Mar 2007) | 4 lines
Try backing out 54407 to see if it corrects the problems on the Windows
buildbots. This rev was backported, so we will need to keep both branches
in sync, pending the outcome of the test after this checkin.
........
r54460 | neal.norwitz | 2007-03-19 23:13:25 -0700 (Mon, 19 Mar 2007) | 1 line
Try to make this test more resistant to dropping from previous runs (ie, files that may exist but cause the test to fail). Should be backported (assuming it works :-)
........
r54461 | neal.norwitz | 2007-03-19 23:16:26 -0700 (Mon, 19 Mar 2007) | 1 line
Try to make this test more resistant to dropping from previous runs (ie, files that may exist but cause the test to fail). Should be backported (assuming it works :-)
........
r54462 | neal.norwitz | 2007-03-19 23:53:17 -0700 (Mon, 19 Mar 2007) | 5 lines
Try to be a little more resilient to errors. This might help the test
pass, but my guess is that it won't. I'm guessing that some other
test is leaving this file open which means it can't be removed
under Windows AFAIK.
........
r54463 | neal.norwitz | 2007-03-20 01:14:57 -0700 (Tue, 20 Mar 2007) | 8 lines
Try to get test_urllib to pass on Windows by closing the file.
I'm guessing that's the problem. h.getfile() must be called *after*
h.getreply() and the fp can be None.
I'm not entirely convinced this is the best fix (or even correct).
The buildbots will tell us if things improve or not. I don't
know if this needs to be backported (assuming it actually works).
........
r54465 | raymond.hettinger | 2007-03-20 14:27:24 -0700 (Tue, 20 Mar 2007) | 1 line
Extend work on rev 52962 and 53829 eliminating redundant PyObject_Hash() calls and fixing set/dict interoperability.
........
r54468 | georg.brandl | 2007-03-20 16:05:14 -0700 (Tue, 20 Mar 2007) | 2 lines
Fix for glob.py if filesystem encoding is None.
........
r54479 | neal.norwitz | 2007-03-20 23:39:48 -0700 (Tue, 20 Mar 2007) | 1 line
Remove unused file spotted by Paul Hankin
........
r54480 | georg.brandl | 2007-03-21 02:00:39 -0700 (Wed, 21 Mar 2007) | 3 lines
Patch #1682205: a TypeError while unpacking an iterable is no longer
masked by a generic one with the message "unpack non-sequence".
........
r54482 | georg.brandl | 2007-03-21 02:10:29 -0700 (Wed, 21 Mar 2007) | 2 lines
New test for rev. 54407 which only uses directories under TESTFN.
........
r54483 | georg.brandl | 2007-03-21 02:16:53 -0700 (Wed, 21 Mar 2007) | 2 lines
Patch #1684834: document some utility C API functions.
........
r54485 | georg.brandl | 2007-03-21 04:51:25 -0700 (Wed, 21 Mar 2007) | 2 lines
Fix #1684254: split BROWSER contents with shlex to avoid displaying 'URL'.
........
r54487 | andrew.kuchling | 2007-03-21 07:32:43 -0700 (Wed, 21 Mar 2007) | 1 line
Add comments on maintenance of this file
........
r54489 | andrew.kuchling | 2007-03-21 09:57:32 -0700 (Wed, 21 Mar 2007) | 1 line
Fix sentence, and fix typo in example
........
r54490 | andrew.kuchling | 2007-03-21 09:59:20 -0700 (Wed, 21 Mar 2007) | 1 line
Put code examples at left margin instead of indenting them
........
r54491 | facundo.batista | 2007-03-21 12:41:24 -0700 (Wed, 21 Mar 2007) | 1 line
Minor clarification, saying that blocking means no timeout (from bug #882297)
........
r54492 | ziga.seilnacht | 2007-03-21 13:07:56 -0700 (Wed, 21 Mar 2007) | 2 lines
Bug #1675967: re patterns pickled with older Python versions can
now be unpickled. Will backport.
........
r54495 | raymond.hettinger | 2007-03-21 13:33:57 -0700 (Wed, 21 Mar 2007) | 1 line
Add test and fix for fromkeys() optional argument.
........
r54524 | georg.brandl | 2007-03-22 01:05:45 -0700 (Thu, 22 Mar 2007) | 2 lines
Bug #1685704: use -m switch in timeit docs.
........
r54533 | thomas.heller | 2007-03-22 12:44:31 -0700 (Thu, 22 Mar 2007) | 5 lines
Back out "Patch #1643874: memory leak in ctypes fixed."
The code in this patch leaves no way to give up the ownership of a
BSTR instance.
........
r54538 | thomas.heller | 2007-03-22 13:34:37 -0700 (Thu, 22 Mar 2007) | 2 lines
Explain the purpose of the b_needsfree flag (forward ported from release25-maint).
........
r54539 | guido.van.rossum | 2007-03-22 21:58:42 -0700 (Thu, 22 Mar 2007) | 12 lines
- Bug #1683368: The object.__init__() and object.__new__() methods are
now stricter in rejecting excess arguments. The only time when
either allows excess arguments is when it is not overridden and the
other one is. For backwards compatibility, when both are
overridden, it is a deprecation warning (for now; maybe a Py3k
warning later).
When merging this into 3.0, the warnings should become errors.
Note: without the change to string.py, lots of spurious warnings happen.
What's going on there?
........
r54540 | neal.norwitz | 2007-03-22 22:17:23 -0700 (Thu, 22 Mar 2007) | 1 line
Add Mark Dickinson for SF # 1675423.
........
r54541 | martin.v.loewis | 2007-03-23 03:35:49 -0700 (Fri, 23 Mar 2007) | 3 lines
Patch #1686451: Fix return type for PySequence_{Count,Index,Fast_GET_SIZE}.
Will backport.
........
r54543 | martin.v.loewis | 2007-03-23 06:27:15 -0700 (Fri, 23 Mar 2007) | 3 lines
Bug #978833: Revert r50844, as it broke _socketobject.dup.
Will backport.
........
r54545 | guido.van.rossum | 2007-03-23 11:53:03 -0700 (Fri, 23 Mar 2007) | 8 lines
Add a type.__init__() method that enforces the same signature as
type.__new__(), and then calls object.__init__(cls), just to be anal.
This allows us to restore the code in string.py's _TemplateMetaclass
that called super(...).__init__(name, bases, dct), which I commented
out yesterday since it broke due to the stricter argument checking
added to object.__init__().
........
r54546 | facundo.batista | 2007-03-23 11:54:07 -0700 (Fri, 23 Mar 2007) | 4 lines
Added a 'create_connect()' function to socket.py, which creates a
connection with an optional timeout, and modified httplib.py to
use this function in HTTPConnection. Applies patch 1676823.
........
r54547 | guido.van.rossum | 2007-03-23 12:39:01 -0700 (Fri, 23 Mar 2007) | 2 lines
Add note about type.__init__().
........
r54553 | thomas.heller | 2007-03-23 12:55:27 -0700 (Fri, 23 Mar 2007) | 5 lines
Prevent creation (followed by a segfault) of array types when the size
overflows the valid Py_ssize_t range. Check return values of
PyMem_Malloc.
Will backport to release25-maint.
........
r54555 | facundo.batista | 2007-03-23 13:23:08 -0700 (Fri, 23 Mar 2007) | 6 lines
Surrounded with try/finally to socket's default timeout setting
changes in the tests, so failing one test won't produce strange
results in others. Also relaxed the timeout settings in the test
(where actually the value didn't mean anything).
........
r54556 | collin.winter | 2007-03-23 15:24:39 -0700 (Fri, 23 Mar 2007) | 1 line
Make test_relpath() pass on Windows.
........
r54559 | ziga.seilnacht | 2007-03-24 07:24:26 -0700 (Sat, 24 Mar 2007) | 6 lines
Patch #1489771: update syntax rules in Python Reference Manual.
Python 2.5 added support for explicit relative import statements and
yield expressions, which were missing in the manual.
Also fix grammar productions that used the names from the Grammar file,
markup that broke the generated grammar.txt, and wrap some lines that
broke the pdf output. Will backport.
........
r54565 | georg.brandl | 2007-03-24 15:20:34 -0700 (Sat, 24 Mar 2007) | 2 lines
Remove typo accent.
........
r54566 | georg.brandl | 2007-03-24 15:27:56 -0700 (Sat, 24 Mar 2007) | 2 lines
Revert accidental change.
........
r54567 | brett.cannon | 2007-03-24 18:32:36 -0700 (Sat, 24 Mar 2007) | 3 lines
Change the docs to no longer claim that unittest is preferred over doctest for
regression tests.
........
r54568 | facundo.batista | 2007-03-24 18:53:21 -0700 (Sat, 24 Mar 2007) | 4 lines
Redone the tests, using the infrastructure already present
for threading and socket serving.
........
r54570 | facundo.batista | 2007-03-24 20:20:05 -0700 (Sat, 24 Mar 2007) | 3 lines
Closing the HTTP connection after each test, and listening more.
........
r54572 | georg.brandl | 2007-03-25 11:44:35 -0700 (Sun, 25 Mar 2007) | 2 lines
Markup fix.
........
r54573 | georg.brandl | 2007-03-25 12:04:55 -0700 (Sun, 25 Mar 2007) | 2 lines
Markup fix.
........
r54580 | facundo.batista | 2007-03-26 13:18:31 -0700 (Mon, 26 Mar 2007) | 5 lines
Added an optional timeout to FTP class. Also I started a test_ftplib.py
file to test the ftp lib (right now I included a basic test, the timeout
one, and nothing else).
........
r54581 | georg.brandl | 2007-03-26 13:28:28 -0700 (Mon, 26 Mar 2007) | 2 lines
Some nits.
........
r54582 | facundo.batista | 2007-03-26 13:56:09 -0700 (Mon, 26 Mar 2007) | 4 lines
Forgot to add the file before the previous commit, here go
the ftplib tests.
........
r54585 | facundo.batista | 2007-03-27 11:23:21 -0700 (Tue, 27 Mar 2007) | 5 lines
Added an optional timeout to poplib.POP3. Also created a
test_poplib.py file with a basic test and the timeout
ones. Docs are also updated.
........
r54586 | facundo.batista | 2007-03-27 11:50:29 -0700 (Tue, 27 Mar 2007) | 3 lines
The basic test cases of poplib.py.
........
r54594 | facundo.batista | 2007-03-27 20:45:20 -0700 (Tue, 27 Mar 2007) | 4 lines
Bug 1688393. Adds a control of negative values in
socket.recvfrom, which caused an ugly crash.
........
r54599 | facundo.batista | 2007-03-28 11:25:54 -0700 (Wed, 28 Mar 2007) | 5 lines
Added timeout to smtplib (to SMTP and SMTP_SSL). Also created
the test_smtplib.py file, with a basic test and the timeout
ones. Docs are updated too.
........
r54603 | collin.winter | 2007-03-28 16:34:06 -0700 (Wed, 28 Mar 2007) | 3 lines
Consolidate patches #1690164, 1683397, and 1690169, all of which refactor XML-related test suites. The patches are applied together because they use a common output/xmltests file.
Thanks to Jerry Seutter for all three patches.
........
r54604 | collin.winter | 2007-03-28 19:28:16 -0700 (Wed, 28 Mar 2007) | 1 line
Make test_zipfile clean up its temporary files properly.
........
r54605 | georg.brandl | 2007-03-29 00:41:32 -0700 (Thu, 29 Mar 2007) | 2 lines
These are actually methods.
........
r54606 | georg.brandl | 2007-03-29 05:42:07 -0700 (Thu, 29 Mar 2007) | 4 lines
In Windows' time.clock(), when QueryPerformanceFrequency() fails,
the C lib's clock() is used, but it must be divided by CLOCKS_PER_SEC
as for the POSIX implementation (thanks to #pypy).
........
r54608 | facundo.batista | 2007-03-29 11:22:35 -0700 (Thu, 29 Mar 2007) | 5 lines
Added timout parameter to telnetlib.Telnet. Also created
test_telnetlib.py with a basic test and timeout ones.
Docs are also updated.
........
r54613 | facundo.batista | 2007-03-30 06:00:35 -0700 (Fri, 30 Mar 2007) | 4 lines
Added the posibility to pass the timeout to FTP.connect, not only when
instantiating the class. Docs and tests are updated.
........
r54614 | collin.winter | 2007-03-30 07:01:25 -0700 (Fri, 30 Mar 2007) | 1 line
Bug #1688274: add documentation for C-level class objects.
........
r54615 | marc-andre.lemburg | 2007-03-30 08:01:42 -0700 (Fri, 30 Mar 2007) | 4 lines
Bump the patch level version of distutils since there were a few bug fixes since
the 2.5.0 release.
........
r54617 | georg.brandl | 2007-03-30 08:49:05 -0700 (Fri, 30 Mar 2007) | 2 lines
Markup fix.
........
r54618 | georg.brandl | 2007-03-30 10:39:39 -0700 (Fri, 30 Mar 2007) | 2 lines
Label name fix.
........
r54619 | georg.brandl | 2007-03-30 10:47:21 -0700 (Fri, 30 Mar 2007) | 2 lines
Duplicate label fix.
........
r54620 | georg.brandl | 2007-03-30 10:48:39 -0700 (Fri, 30 Mar 2007) | 2 lines
Markup fix.
........
r54623 | andrew.kuchling | 2007-03-30 11:00:15 -0700 (Fri, 30 Mar 2007) | 1 line
Add item. (Oops, accidentally checked this in on my branch)
........
r54624 | georg.brandl | 2007-03-30 12:01:38 -0700 (Fri, 30 Mar 2007) | 2 lines
Duplicate label fix.
........
r54625 | georg.brandl | 2007-03-30 12:14:02 -0700 (Fri, 30 Mar 2007) | 2 lines
Markup fix.
........
r54629 | georg.brandl | 2007-03-31 03:17:31 -0700 (Sat, 31 Mar 2007) | 2 lines
repair string literal.
........
r54630 | georg.brandl | 2007-03-31 04:54:58 -0700 (Sat, 31 Mar 2007) | 2 lines
Markup fix.
........
r54631 | georg.brandl | 2007-03-31 04:58:36 -0700 (Sat, 31 Mar 2007) | 2 lines
Duplicate label fix.
........
r54632 | georg.brandl | 2007-03-31 04:59:54 -0700 (Sat, 31 Mar 2007) | 2 lines
Typo fix.
........
r54633 | neal.norwitz | 2007-03-31 11:54:18 -0700 (Sat, 31 Mar 2007) | 1 line
Fix method names. Will backport.
........
r54634 | georg.brandl | 2007-03-31 11:56:11 -0700 (Sat, 31 Mar 2007) | 4 lines
Bug #1655392: don't add -L/usr/lib/pythonX.Y/config to the LDFLAGS
returned by python-config if Python was built with --enable-shared
because that prevented the shared library from being used.
........
r54637 | collin.winter | 2007-03-31 12:31:34 -0700 (Sat, 31 Mar 2007) | 1 line
Shut up an occaisonal buildbot error due to test files being left around.
........
r54644 | neal.norwitz | 2007-04-01 11:24:22 -0700 (Sun, 01 Apr 2007) | 11 lines
SF #1685563, MSVCCompiler creates redundant and long PATH strings
If MSVCCompiler.initialize() was called multiple times, the path
would get duplicated. On Windows, this is a problem because the
path is limited to 4k. There's no benefit in adding a path multiple
times, so prevent that from occuring. We also normalize the path
before checking for duplicates so things like /a and /a/ won't both
be stored.
Will backport.
........
r54646 | brett.cannon | 2007-04-01 11:47:27 -0700 (Sun, 01 Apr 2007) | 8 lines
time.strptime's caching of its locale object was being recreated when the
locale changed but not used during the function call it was recreated during.
The test in this checkin is untested (OS X does not have the proper locale
support for me to test), although the fix for the bug this deals with
was tested by the OP (#1290505). Once the buildbots verify the test at least
doesn't fail it becomes a backport candidate.
........
r54647 | brett.cannon | 2007-04-01 12:46:19 -0700 (Sun, 01 Apr 2007) | 3 lines
Fix the test for recreating the locale cache object by not worrying about if
one of the test locales cannot be set.
........
r54649 | georg.brandl | 2007-04-01 14:29:15 -0700 (Sun, 01 Apr 2007) | 2 lines
Fix a lot of markup and meta-information glitches.
........
r54650 | georg.brandl | 2007-04-01 14:39:52 -0700 (Sun, 01 Apr 2007) | 2 lines
Another fix.
........
r54651 | georg.brandl | 2007-04-01 15:39:10 -0700 (Sun, 01 Apr 2007) | 2 lines
Lots of explicit class names for method and member descs.
........
r54652 | georg.brandl | 2007-04-01 15:40:12 -0700 (Sun, 01 Apr 2007) | 2 lines
Explicit class names.
........
r54653 | georg.brandl | 2007-04-01 15:47:31 -0700 (Sun, 01 Apr 2007) | 2 lines
Some semantic fixes.
........
r54654 | georg.brandl | 2007-04-01 16:29:10 -0700 (Sun, 01 Apr 2007) | 2 lines
Remove bogus entry.
........
r54655 | georg.brandl | 2007-04-01 16:31:30 -0700 (Sun, 01 Apr 2007) | 2 lines
Fix the class name of strings.
........
r54658 | raymond.hettinger | 2007-04-02 10:29:30 -0700 (Mon, 02 Apr 2007) | 1 line
SF #1693079: Cannot save empty array in shelve
........
r54663 | raymond.hettinger | 2007-04-02 15:54:21 -0700 (Mon, 02 Apr 2007) | 3 lines
Array module's buffer interface can now handle empty arrays.
........
r54664 | guido.van.rossum | 2007-04-02 16:55:37 -0700 (Mon, 02 Apr 2007) | 5 lines
Fix warnings about object.__init__() signature.
Two (test_array and test_descr) were bug IMO; the third (copy_reg)
is a work-around which recognizes that object.__init__() doesn't do
anything.
........
r54666 | raymond.hettinger | 2007-04-02 17:02:11 -0700 (Mon, 02 Apr 2007) | 1 line
SF 1602378 Clarify docstrings for bisect
........
r54668 | raymond.hettinger | 2007-04-02 18:39:43 -0700 (Mon, 02 Apr 2007) | 3 lines
SF #1382213: Tutorial section 9.5.1 ignores MRO for new-style classes
........
r54669 | matthias.klose | 2007-04-02 21:35:59 -0700 (Mon, 02 Apr 2007) | 4 lines
- Fix an off-by-one bug in locale.strxfrm().
patch taken from http://bugs.debian.org/416934.
........
r54671 | georg.brandl | 2007-04-03 00:04:27 -0700 (Tue, 03 Apr 2007) | 9 lines
Fix the strange case of
\begin{methoddesc}[NNTP]{...}
where
\ifx#1\@undefined ended up comparing N and N, therefore executing
the true part of the conditional, blowing up at \@undefined.
........
r54672 | facundo.batista | 2007-04-03 07:05:08 -0700 (Tue, 03 Apr 2007) | 4 lines
Now using unittest for the tests infraestructure. Also split the
tests in those who need the network, and that who doesn't.
........
r54673 | walter.doerwald | 2007-04-03 09:08:10 -0700 (Tue, 03 Apr 2007) | 4 lines
Move the functionality for catching warnings in test_warnings.py into a separate
class to that reusing the functionality in test_structmembers.py doesn't rerun
the tests from test_warnings.py.
........
r54674 | walter.doerwald | 2007-04-03 09:16:24 -0700 (Tue, 03 Apr 2007) | 2 lines
Document that CatchWarningTests is reused by test_structmembers.py.
........
r54675 | walter.doerwald | 2007-04-03 09:53:43 -0700 (Tue, 03 Apr 2007) | 4 lines
Add tests for the filename.
Test that the stacklevel is handled correctly.
........
r54676 | facundo.batista | 2007-04-03 10:29:48 -0700 (Tue, 03 Apr 2007) | 6 lines
Added a SSL server to test_socket_ssl.py to be able to test
locally. Now, it checks if have openssl available and run
those specific tests (it starts openssl at the beggining of
all the tests and then kills it at the end).
........
r54677 | walter.doerwald | 2007-04-03 11:33:29 -0700 (Tue, 03 Apr 2007) | 6 lines
Implement a contextmanager test.test_support.catch_warning that can
be used to catch the last warning issued by the warning framework.
Change test_warnings.py and test_structmembers.py to use this
new contextmanager.
........
r54678 | facundo.batista | 2007-04-03 14:15:34 -0700 (Tue, 03 Apr 2007) | 4 lines
Changed the whole structure of startup and checking if the
server is available. Hope to not get more false alarms.
........
r54681 | facundo.batista | 2007-04-04 07:10:40 -0700 (Wed, 04 Apr 2007) | 4 lines
Fixed the way that the .pem files are looked for, and changed
how to kill the process in win32 to use the _handle attribute.
........
r54682 | guido.van.rossum | 2007-04-04 10:43:02 -0700 (Wed, 04 Apr 2007) | 4 lines
Fix a race condition in this test -- instead of assuming that it will take
the test server thread at most 0.5 seconds to get ready, use an event
variable.
........
r54683 | collin.winter | 2007-04-04 11:14:17 -0700 (Wed, 04 Apr 2007) | 1 line
Clean up imports.
........
r54684 | collin.winter | 2007-04-04 11:16:24 -0700 (Wed, 04 Apr 2007) | 1 line
Stop using test_support.verify().
........
r54685 | martin.v.loewis | 2007-04-04 11:30:36 -0700 (Wed, 04 Apr 2007) | 2 lines
Bug #1686475: Support stat'ing open files on Windows again.
Will backport to 2.5.
........
r54687 | collin.winter | 2007-04-04 11:33:40 -0700 (Wed, 04 Apr 2007) | 1 line
Make test_getopt use unittest.
........
r54688 | collin.winter | 2007-04-04 11:36:30 -0700 (Wed, 04 Apr 2007) | 1 line
Make test_softspace use unittest.
........
r54689 | ziga.seilnacht | 2007-04-04 11:38:47 -0700 (Wed, 04 Apr 2007) | 2 lines
Fix WalkTests.test_traversal() on Windows. The cleanup in
MakedirTests.setUp() can now be removed.
........
r54695 | raymond.hettinger | 2007-04-05 11:00:03 -0700 (Thu, 05 Apr 2007) | 3 lines
Bug #1563759: struct.unpack doens't support buffer protocol objects
........
r54697 | collin.winter | 2007-04-05 13:05:07 -0700 (Thu, 05 Apr 2007) | 1 line
Convert test_long_future to use unittest.
........
r54698 | collin.winter | 2007-04-05 13:08:56 -0700 (Thu, 05 Apr 2007) | 1 line
Convert test_normalization to use unittest.
........
r54699 | andrew.kuchling | 2007-04-05 18:11:58 -0700 (Thu, 05 Apr 2007) | 1 line
Some grammar fixes
........
r54704 | collin.winter | 2007-04-06 12:27:40 -0700 (Fri, 06 Apr 2007) | 1 line
Convert test_stringprep to use unittest.
........
r54705 | collin.winter | 2007-04-06 12:32:32 -0700 (Fri, 06 Apr 2007) | 1 line
Import cleanup in test_crypt.
........
r54706 | collin.winter | 2007-04-06 13:00:05 -0700 (Fri, 06 Apr 2007) | 1 line
Convert test_gc to use unittest.
........
r54707 | collin.winter | 2007-04-06 13:03:11 -0700 (Fri, 06 Apr 2007) | 1 line
Convert test_module to use unittest.
........
r54711 | collin.winter | 2007-04-06 21:40:43 -0700 (Fri, 06 Apr 2007) | 1 line
Convert test_fileinput to use unittest.
........
r54712 | brett.cannon | 2007-04-07 21:29:32 -0700 (Sat, 07 Apr 2007) | 5 lines
Doc that file.next() has undefined behaviour when called on a file opened with
'w'. Closes bug #1569057.
To be backported once 2.5 branch is unfrozen.
........
r54726 | vinay.sajip | 2007-04-09 09:16:10 -0700 (Mon, 09 Apr 2007) | 1 line
Added optional timeout to SocketHandler.makeSocket (SF #1695948)
........
r54727 | ziga.seilnacht | 2007-04-09 12:10:29 -0700 (Mon, 09 Apr 2007) | 3 lines
Patch #1695862: remove old test directory that causes test_urllib failures
on Windows buildbots. The change is a one time fix and will be removed
after a successful buildbot run.
........
r54729 | facundo.batista | 2007-04-09 20:00:37 -0700 (Mon, 09 Apr 2007) | 3 lines
Minor fix to the tests pass ok even with -O.
........
r54730 | collin.winter | 2007-04-09 21:44:49 -0700 (Mon, 09 Apr 2007) | 1 line
Typo fix.
........
r54732 | facundo.batista | 2007-04-10 05:58:45 -0700 (Tue, 10 Apr 2007) | 5 lines
General clean-up. Lot of margin corrections, comments, some typos.
Exceptions now are raised in the new style. And a mockup class is
now also new style. Thanks Santiago Pereson.
........
r54741 | georg.brandl | 2007-04-10 14:39:38 -0700 (Tue, 10 Apr 2007) | 2 lines
Repair a duplicate label and some obsolete uses of \setindexsubitem.
........
r54746 | andrew.kuchling | 2007-04-11 06:39:00 -0700 (Wed, 11 Apr 2007) | 1 line
Add window.chgat() method, submitted via e-mail by Fabian Kreutz
........
r54747 | andrew.kuchling | 2007-04-11 06:42:25 -0700 (Wed, 11 Apr 2007) | 1 line
Point readers at the patch submission instructions
........
r54748 | andrew.kuchling | 2007-04-11 06:47:13 -0700 (Wed, 11 Apr 2007) | 1 line
Describe undocumented third argument to touchline()
........
r54757 | georg.brandl | 2007-04-11 10:16:24 -0700 (Wed, 11 Apr 2007) | 3 lines
Add some missing NULL checks which trigger crashes on low-memory conditions.
Found by Victor Stinner. Will backport when 2.5 branch is unfrozen.
........
r54760 | raymond.hettinger | 2007-04-11 11:40:58 -0700 (Wed, 11 Apr 2007) | 1 line
SF 1191699: Make slices picklable
........
r54762 | georg.brandl | 2007-04-11 12:25:11 -0700 (Wed, 11 Apr 2007) | 2 lines
Exceptions are no longer old-style instances. Fix accordingly.
........
r54763 | georg.brandl | 2007-04-11 16:28:44 -0700 (Wed, 11 Apr 2007) | 2 lines
Repair missing spaces after \UNIX.
........
r54772 | raymond.hettinger | 2007-04-11 21:10:00 -0700 (Wed, 11 Apr 2007) | 1 line
SF 1193128: Let str.translate(None) be an identity transformation
........
r54784 | georg.brandl | 2007-04-12 00:01:19 -0700 (Thu, 12 Apr 2007) | 2 lines
Patch #1698951: clarify deprecation message in rexec and Bastion
........
r54785 | ziga.seilnacht | 2007-04-12 01:46:51 -0700 (Thu, 12 Apr 2007) | 2 lines
Patch #1695862: remove the cleanup code, now that Windows buildbots are green
again.
........
r54786 | walter.doerwald | 2007-04-12 03:35:00 -0700 (Thu, 12 Apr 2007) | 3 lines
Fix utf-8-sig incremental decoder, which didn't recognise a BOM when the
first chunk fed to the decoder started with a BOM, but was longer than 3 bytes.
........
r54807 | barry.warsaw | 2007-04-13 11:47:14 -0700 (Fri, 13 Apr 2007) | 8 lines
Port r54805 from python25-maint branch:
Add code to read from master_fd in the parent, breaking when we get an OSError
(EIO can occur on Linux) or there's no more data to read. Without this,
test_pty.py can hang on the waitpid() because the child is blocking on the
stdout write. This will definitely happen on Mac OS X and could potentially
happen on other platforms. See the comment for details.
........
r54812 | kristjan.jonsson | 2007-04-13 15:07:33 -0700 (Fri, 13 Apr 2007) | 1 line
Fix a bug when using the __lltrace__ opcode tracer, and a problem sith signed chars in frameobject.c which can occur with opcodes > 127
........
r54814 | kristjan.jonsson | 2007-04-13 15:20:13 -0700 (Fri, 13 Apr 2007) | 1 line
Fix potential crash in path manipulation on windows
........
r54816 | trent.mick | 2007-04-13 16:22:05 -0700 (Fri, 13 Apr 2007) | 4 lines
Add the necessary dependency for the Windows VC6 build to ensure 'pythoncore'
is built before '_ctypes' is attempted.
Will backport to 2.5 once it is unfrozen for 2.5.1.
........
r54825 | neal.norwitz | 2007-04-13 22:25:50 -0700 (Fri, 13 Apr 2007) | 3 lines
When __slots__ are set to a unicode string, make it work the same as
setting a plain string, ie don't expand to single letter identifiers.
........
r54841 | neal.norwitz | 2007-04-16 00:37:55 -0700 (Mon, 16 Apr 2007) | 1 line
SF #1701207, Fix bogus assertion (and test it!)
........
r54844 | collin.winter | 2007-04-16 15:10:32 -0700 (Mon, 16 Apr 2007) | 1 line
Check the availability of the urlfetch resource earlier than before.
........
r54849 | martin.v.loewis | 2007-04-16 22:02:01 -0700 (Mon, 16 Apr 2007) | 2 lines
Add Travis Oliphant.
........
r54873 | brett.cannon | 2007-04-18 20:44:17 -0700 (Wed, 18 Apr 2007) | 2 lines
Silence a compiler warning about incompatible pointer types.
........
r54874 | neal.norwitz | 2007-04-18 22:52:37 -0700 (Wed, 18 Apr 2007) | 2 lines
SF #1703270, add missing declaration in readline.c to avoid compiler warning.
........
r54875 | armin.rigo | 2007-04-19 07:44:48 -0700 (Thu, 19 Apr 2007) | 8 lines
Revert r53997 as per
http://mail.python.org/pipermail/python-dev/2007-March/071796.html .
I've kept a couple of still-valid extra tests in test_descr, but didn't
bother to sort through the new comments and refactorings added in r53997
to see if some of them could be kept. If so, they could go in a
follow-up check-in.
........
r54876 | armin.rigo | 2007-04-19 07:56:48 -0700 (Thu, 19 Apr 2007) | 2 lines
Fix a usage of the dangerous pattern decref - modify field - incref.
........
r54884 | neal.norwitz | 2007-04-19 22:20:38 -0700 (Thu, 19 Apr 2007) | 9 lines
Add an optional address to copy the failure mails to.
Detect a conflict in the only file that should have outstanding changes
when this script is run. This doesn't matter on the trunk, but does
when run on a branch. Trunk always has the date set to today in
boilerplate.tex. Each time a release is cut with a different date,
a conflict occurs. (We could copy a known good version, but then
we would lose changes to this file.)
........
r54918 | georg.brandl | 2007-04-21 13:35:38 -0700 (Sat, 21 Apr 2007) | 3 lines
Bug #1704790: bind name "sys" locally in __del__ method so that it is
not cleared before __del__ is run.
........
r54920 | facundo.batista | 2007-04-21 18:18:56 -0700 (Sat, 21 Apr 2007) | 5 lines
Added tests for other methods of SSL object. Now we cover
all the object methods. This is the final step to close
the #451607 bug.
........
r54927 | facundo.batista | 2007-04-23 10:08:31 -0700 (Mon, 23 Apr 2007) | 5 lines
As specified in RFC 2616, 2xx code indicates that the client's
request was successfully received, understood, and accepted.
Now in these cases no error is raised. Also fixed tests.
........
r54929 | collin.winter | 2007-04-23 20:43:46 -0700 (Mon, 23 Apr 2007) | 1 line
Convert PyUnit -> unittest.
........
r54931 | collin.winter | 2007-04-23 21:09:52 -0700 (Mon, 23 Apr 2007) | 1 line
Remove code that hasn't been called in years.
........
r54932 | neal.norwitz | 2007-04-23 21:53:12 -0700 (Mon, 23 Apr 2007) | 1 line
Fix SF #1703110, Incorrect example for add_password() (use uri, not host)
........
r54934 | georg.brandl | 2007-04-24 03:36:42 -0700 (Tue, 24 Apr 2007) | 2 lines
Some new year updates.
........
r54938 | facundo.batista | 2007-04-24 06:54:38 -0700 (Tue, 24 Apr 2007) | 4 lines
Added a comment about last change in urllib2.py (all 2xx responses
are ok now).
........
r54939 | georg.brandl | 2007-04-24 08:10:09 -0700 (Tue, 24 Apr 2007) | 2 lines
Bug #1705717: error in sys.argv docs.
........
r54941 | georg.brandl | 2007-04-24 08:27:13 -0700 (Tue, 24 Apr 2007) | 4 lines
Bug #1706381: Specifying the SWIG option "-c++" in the setup.py file
(as opposed to the command line) will now write file names ending in
".cpp" too.
........
r54944 | raymond.hettinger | 2007-04-24 15:13:43 -0700 (Tue, 24 Apr 2007) | 1 line
Fix markup
........
r54945 | kristjan.jonsson | 2007-04-24 17:10:50 -0700 (Tue, 24 Apr 2007) | 1 line
Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
........
r54947 | kristjan.jonsson | 2007-04-24 17:17:39 -0700 (Tue, 24 Apr 2007) | 1 line
Make pythoncore compile cleanly with VisualStudio 2005. Used an explicit typecast to get a 64 bit integer, and undefined the Yield macro that conflicts with winbase.h
........
r54948 | kristjan.jonsson | 2007-04-24 17:19:26 -0700 (Tue, 24 Apr 2007) | 1 line
Remove obsolete comment. Importing of .dll files has been discontinued, only .pyd files supported on windows now.
........
r54949 | georg.brandl | 2007-04-24 23:24:59 -0700 (Tue, 24 Apr 2007) | 2 lines
Patch #1698768: updated the "using Python on the Mac" intro.
........
r54951 | georg.brandl | 2007-04-24 23:25:55 -0700 (Tue, 24 Apr 2007) | 2 lines
Markup fix.
........
r54953 | neal.norwitz | 2007-04-24 23:30:05 -0700 (Tue, 24 Apr 2007) | 3 lines
Whitespace normalization. Ugh, we really need to do this more often.
You might want to review this change as it's my first time. Be gentle. :-)
........
r54956 | collin.winter | 2007-04-25 10:29:52 -0700 (Wed, 25 Apr 2007) | 1 line
Standardize on test.test_support.run_unittest() (as opposed to a mix of run_unittest() and run_suite()). Also, add functionality to run_unittest() that admits usage of unittest.TestLoader.loadTestsFromModule().
........
r54957 | collin.winter | 2007-04-25 10:37:35 -0700 (Wed, 25 Apr 2007) | 1 line
Remove functionality from test_datetime.test_main() that does reference count checking; 'regrtest.py -R' is the way to do this kind of testing.
........
r54958 | collin.winter | 2007-04-25 10:57:53 -0700 (Wed, 25 Apr 2007) | 1 line
Change test_support.have_unicode to use True/False instead of 1/0.
........
r54959 | tim.peters | 2007-04-25 11:47:18 -0700 (Wed, 25 Apr 2007) | 2 lines
Whitespace normalization.
........
r54960 | tim.peters | 2007-04-25 11:48:35 -0700 (Wed, 25 Apr 2007) | 2 lines
Set missing svn:eol-style property on text files.
........
r54961 | collin.winter | 2007-04-25 11:54:36 -0700 (Wed, 25 Apr 2007) | 1 line
Import and raise statement cleanup.
........
r54969 | collin.winter | 2007-04-25 13:41:34 -0700 (Wed, 25 Apr 2007) | 1 line
Convert test_ossaudiodev to use unittest.
........
r54974 | collin.winter | 2007-04-25 14:50:25 -0700 (Wed, 25 Apr 2007) | 1 line
Fix an issue related to the unittest conversion.
........
r54979 | fred.drake | 2007-04-25 21:42:19 -0700 (Wed, 25 Apr 2007) | 1 line
fix some markup errors
........
r54982 | kristjan.jonsson | 2007-04-26 02:15:08 -0700 (Thu, 26 Apr 2007) | 1 line
Export function sanitize_the_mode from fileobject.c as _PyFile_SanitizeMode(). Use this function in posixmodule.c when implementing fdopen(). This fixes test_subprocess.py for a VisualStudio 2005 compile.
........
r54983 | kristjan.jonsson | 2007-04-26 06:44:16 -0700 (Thu, 26 Apr 2007) | 1 line
The locale "En" appears not to be valid on windows underi VisualStudio.2005. Added "English" to the test_locale.py to make the testsuite pass for that build
........
r54984 | steve.holden | 2007-04-26 07:23:12 -0700 (Thu, 26 Apr 2007) | 1 line
Minor wording change on slicing aide-memoire.
........
r54985 | kristjan.jonsson | 2007-04-26 08:24:54 -0700 (Thu, 26 Apr 2007) | 1 line
Accomodate 64 bit time_t in the _bsddb module.
........
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 27 Apr 2007 19:54:29 +0000 |
| parents | f390793e75de |
| children | 15b810e21fe9 |
| rev | line source |
|---|---|
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /* Array object implementation */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 /* An array is a uniform list -- all items have the same type. |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 The item type is restricted to simple C types like int or float */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
6 #define PY_SSIZE_T_CLEAN |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
7 #include "Python.h" |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
8 #include "structmember.h" |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
9 |
| 1797 | 10 #ifdef STDC_HEADERS |
| 11 #include <stddef.h> | |
|
11242
0061ca4865d7
Tiny patch by Mark Hammond to avoid sys/types.h if we don't have it
Guido van Rossum <guido@python.org>
parents:
10434
diff
changeset
|
12 #else /* !STDC_HEADERS */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
13 #ifdef HAVE_SYS_TYPES_H |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
14 #include <sys/types.h> /* For size_t */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
15 #endif /* HAVE_SYS_TYPES_H */ |
|
11242
0061ca4865d7
Tiny patch by Mark Hammond to avoid sys/types.h if we don't have it
Guido van Rossum <guido@python.org>
parents:
10434
diff
changeset
|
16 #endif /* !STDC_HEADERS */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 struct arrayobject; /* Forward */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
20 /* All possible arraydescr values are defined in the vector "descriptors" |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
21 * below. That's defined later because the appropriate get and set |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
22 * functions aren't visible yet. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
23 */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 struct arraydescr { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 int typecode; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 int itemsize; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
27 PyObject * (*getitem)(struct arrayobject *, Py_ssize_t); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
28 int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 }; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 typedef struct arrayobject { |
|
36544
23e23e15e7e7
Bug #1432350: arrayobject should use PyObject_VAR_HEAD
Georg Brandl <georg@python.org>
parents:
36529
diff
changeset
|
32 PyObject_VAR_HEAD |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 char *ob_item; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
34 Py_ssize_t allocated; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 struct arraydescr *ob_descr; |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
36 PyObject *weakreflist; /* List of weak references */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 } arrayobject; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23929
diff
changeset
|
39 static PyTypeObject Arraytype; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
41 #define array_Check(op) PyObject_TypeCheck(op, &Arraytype) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
42 #define array_CheckExact(op) ((op)->ob_type == &Arraytype) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
44 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
45 array_resize(arrayobject *self, Py_ssize_t newsize) |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
46 { |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
47 char *items; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
48 size_t _new_size; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
49 |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
50 /* Bypass realloc() when a previous overallocation is large enough |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
51 to accommodate the newsize. If the newsize is 16 smaller than the |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
52 current size, then proceed with the realloc() to shrink the list. |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
53 */ |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
54 |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
55 if (self->allocated >= newsize && |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
56 self->ob_size < newsize + 16 && |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
57 self->ob_item != NULL) { |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
58 self->ob_size = newsize; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
59 return 0; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
60 } |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
61 |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
62 /* This over-allocates proportional to the array size, making room |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
63 * for additional growth. The over-allocation is mild, but is |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
64 * enough to give linear-time amortized behavior over a long |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
65 * sequence of appends() in the presence of a poorly-performing |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
66 * system realloc(). |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
67 * The growth pattern is: 0, 4, 8, 16, 25, 34, 46, 56, 67, 79, ... |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
68 * Note, the pattern starts out the same as for lists but then |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
69 * grows at a smaller rate so that larger arrays only overallocate |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
70 * by about 1/16th -- this is done because arrays are presumed to be more |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
71 * memory critical. |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
72 */ |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
73 |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
74 _new_size = (newsize >> 4) + (self->ob_size < 8 ? 3 : 7) + newsize; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
75 items = self->ob_item; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
76 /* XXX The following multiplication and division does not optimize away |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
77 like it does for lists since the size is not known at compile time */ |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
78 if (_new_size <= ((~(size_t)0) / self->ob_descr->itemsize)) |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
79 PyMem_RESIZE(items, char, (_new_size * self->ob_descr->itemsize)); |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
80 else |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
81 items = NULL; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
82 if (items == NULL) { |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
83 PyErr_NoMemory(); |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
84 return -1; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
85 } |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
86 self->ob_item = items; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
87 self->ob_size = newsize; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
88 self->allocated = _new_size; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
89 return 0; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
90 } |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
91 |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
92 /**************************************************************************** |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
93 Get and Set functions for each type. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
94 A Get function takes an arrayobject* and an integer index, returning the |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
95 array value at that index wrapped in an appropriate PyObject*. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
96 A Set function takes an arrayobject, integer index, and PyObject*; sets |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
97 the array value at that index to the raw C data extracted from the PyObject*, |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
98 and returns 0 if successful, else nonzero on failure (PyObject* not of an |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
99 appropriate type or value). |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
100 Note that the basic Get and Set functions do NOT check that the index is |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
101 in bounds; that's the responsibility of the caller. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
102 ****************************************************************************/ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
104 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
105 c_getitem(arrayobject *ap, Py_ssize_t i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
107 return PyString_FromStringAndSize(&((char *)ap->ob_item)[i], 1); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
111 c_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 char x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
114 if (!PyArg_Parse(v, "c;array item must be char", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 if (i >= 0) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
117 ((char *)ap->ob_item)[i] = x; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
121 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
122 b_getitem(arrayobject *ap, Py_ssize_t i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 long x = ((char *)ap->ob_item)[i]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 if (x >= 128) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 x -= 256; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
127 return PyInt_FromLong(x); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
131 b_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
133 short x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
134 /* PyArg_Parse's 'b' formatter is for an unsigned char, therefore |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
135 must use the next size up that is signed ('h') and manually do |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
136 the overflow checking */ |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
137 if (!PyArg_Parse(v, "h;array item must be integer", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 return -1; |
|
13263
84879ab71b9f
In b_setitem(), instead of the platform dependent CHAR_MIN and
Guido van Rossum <guido@python.org>
parents:
13256
diff
changeset
|
139 else if (x < -128) { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
140 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
141 "signed char is less than minimum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
142 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
143 } |
|
13263
84879ab71b9f
In b_setitem(), instead of the platform dependent CHAR_MIN and
Guido van Rossum <guido@python.org>
parents:
13256
diff
changeset
|
144 else if (x > 127) { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
145 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
146 "signed char is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
147 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
148 } |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 if (i >= 0) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
150 ((char *)ap->ob_item)[i] = (char)x; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
154 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
155 BB_getitem(arrayobject *ap, Py_ssize_t i) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
156 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
157 long x = ((unsigned char *)ap->ob_item)[i]; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
158 return PyInt_FromLong(x); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
159 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
160 |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
161 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
162 BB_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
163 { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
164 unsigned char x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
165 /* 'B' == unsigned char, maps to PyArg_Parse's 'b' formatter */ |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
166 if (!PyArg_Parse(v, "b;array item must be integer", &x)) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
167 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
168 if (i >= 0) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
169 ((char *)ap->ob_item)[i] = x; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
170 return 0; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
171 } |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
172 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
173 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
174 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
175 u_getitem(arrayobject *ap, Py_ssize_t i) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
176 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
177 return PyUnicode_FromUnicode(&((Py_UNICODE *) ap->ob_item)[i], 1); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
178 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
179 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
180 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
181 u_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
182 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
183 Py_UNICODE *p; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
184 Py_ssize_t len; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
185 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
186 if (!PyArg_Parse(v, "u#;array item must be unicode character", &p, &len)) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
187 return -1; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
188 if (len != 1) { |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36882
diff
changeset
|
189 PyErr_SetString(PyExc_TypeError, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36882
diff
changeset
|
190 "array item must be unicode character"); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
191 return -1; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
192 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
193 if (i >= 0) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
194 ((Py_UNICODE *)ap->ob_item)[i] = p[0]; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
195 return 0; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
196 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
197 #endif |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
198 |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
199 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
200 h_getitem(arrayobject *ap, Py_ssize_t i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
202 return PyInt_FromLong((long) ((short *)ap->ob_item)[i]); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
206 h_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 short x; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
209 /* 'h' == signed short, maps to PyArg_Parse's 'h' formatter */ |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
210 if (!PyArg_Parse(v, "h;array item must be integer", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 ((short *)ap->ob_item)[i] = x; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
217 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
218 HH_getitem(arrayobject *ap, Py_ssize_t i) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
219 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
220 return PyInt_FromLong((long) ((unsigned short *)ap->ob_item)[i]); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
221 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
222 |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
223 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
224 HH_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
225 { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
226 int x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
227 /* PyArg_Parse's 'h' formatter is for a signed short, therefore |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
228 must use the next size up and manually do the overflow checking */ |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
229 if (!PyArg_Parse(v, "i;array item must be integer", &x)) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
230 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
231 else if (x < 0) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
232 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
233 "unsigned short is less than minimum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
234 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
235 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
236 else if (x > USHRT_MAX) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
237 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
238 "unsigned short is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
239 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
240 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
241 if (i >= 0) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
242 ((short *)ap->ob_item)[i] = (short)x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
243 return 0; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
244 } |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
245 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
246 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
247 i_getitem(arrayobject *ap, Py_ssize_t i) |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
248 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
249 return PyInt_FromLong((long) ((int *)ap->ob_item)[i]); |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
250 } |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
251 |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
252 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
253 i_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
254 { |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
255 int x; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
256 /* 'i' == signed int, maps to PyArg_Parse's 'i' formatter */ |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
257 if (!PyArg_Parse(v, "i;array item must be integer", &x)) |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
258 return -1; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
259 if (i >= 0) |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
260 ((int *)ap->ob_item)[i] = x; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
261 return 0; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
262 } |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
263 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
264 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
265 II_getitem(arrayobject *ap, Py_ssize_t i) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
266 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
267 return PyLong_FromUnsignedLong( |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
268 (unsigned long) ((unsigned int *)ap->ob_item)[i]); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
269 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
270 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
271 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
272 II_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
273 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
274 unsigned long x; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
275 if (PyLong_Check(v)) { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
276 x = PyLong_AsUnsignedLong(v); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
277 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
278 return -1; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
279 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
280 else { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
281 long y; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
282 if (!PyArg_Parse(v, "l;array item must be integer", &y)) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
283 return -1; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
284 if (y < 0) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
285 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
286 "unsigned int is less than minimum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
287 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
288 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
289 x = (unsigned long)y; |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
290 |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
291 } |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
292 if (x > UINT_MAX) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
293 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
294 "unsigned int is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
295 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
296 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
297 |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
298 if (i >= 0) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
299 ((unsigned int *)ap->ob_item)[i] = (unsigned int)x; |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
300 return 0; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
301 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
302 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
303 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
304 l_getitem(arrayobject *ap, Py_ssize_t i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
306 return PyInt_FromLong(((long *)ap->ob_item)[i]); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
310 l_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 long x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
313 if (!PyArg_Parse(v, "l;array item must be integer", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 ((long *)ap->ob_item)[i] = x; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
320 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
321 LL_getitem(arrayobject *ap, Py_ssize_t i) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
322 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
323 return PyLong_FromUnsignedLong(((unsigned long *)ap->ob_item)[i]); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
324 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
325 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
326 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
327 LL_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
328 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
329 unsigned long x; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
330 if (PyLong_Check(v)) { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
331 x = PyLong_AsUnsignedLong(v); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
332 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
333 return -1; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
334 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
335 else { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
336 long y; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
337 if (!PyArg_Parse(v, "l;array item must be integer", &y)) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
338 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
339 if (y < 0) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
340 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
341 "unsigned long is less than minimum"); |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
342 return -1; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
343 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
344 x = (unsigned long)y; |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
345 |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
346 } |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
347 if (x > ULONG_MAX) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
348 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
349 "unsigned long is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
350 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
351 } |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
352 |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
353 if (i >= 0) |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
354 ((unsigned long *)ap->ob_item)[i] = x; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
355 return 0; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
356 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
357 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
358 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
359 f_getitem(arrayobject *ap, Py_ssize_t i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
361 return PyFloat_FromDouble((double) ((float *)ap->ob_item)[i]); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
365 f_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 float x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
368 if (!PyArg_Parse(v, "f;array item must be float", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 ((float *)ap->ob_item)[i] = x; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
375 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
376 d_getitem(arrayobject *ap, Py_ssize_t i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
378 return PyFloat_FromDouble(((double *)ap->ob_item)[i]); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
382 d_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 double x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
385 if (!PyArg_Parse(v, "d;array item must be float", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 ((double *)ap->ob_item)[i] = x; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
391 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 /* Description of types */ |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
393 static struct arraydescr descriptors[] = { |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 {'c', sizeof(char), c_getitem, c_setitem}, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 {'b', sizeof(char), b_getitem, b_setitem}, |
|
5542
cfc13f3f3876
Address the following problem on DOS and Win 3.1, reported by Jim
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
396 {'B', sizeof(char), BB_getitem, BB_setitem}, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
397 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
398 {'u', sizeof(Py_UNICODE), u_getitem, u_setitem}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
399 #endif |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 {'h', sizeof(short), h_getitem, h_setitem}, |
|
5542
cfc13f3f3876
Address the following problem on DOS and Win 3.1, reported by Jim
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
401 {'H', sizeof(short), HH_getitem, HH_setitem}, |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
402 {'i', sizeof(int), i_getitem, i_setitem}, |
|
5542
cfc13f3f3876
Address the following problem on DOS and Win 3.1, reported by Jim
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
403 {'I', sizeof(int), II_getitem, II_setitem}, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 {'l', sizeof(long), l_getitem, l_setitem}, |
|
5542
cfc13f3f3876
Address the following problem on DOS and Win 3.1, reported by Jim
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
405 {'L', sizeof(long), LL_getitem, LL_setitem}, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 {'f', sizeof(float), f_getitem, f_setitem}, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 {'d', sizeof(double), d_getitem, d_setitem}, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 {'\0', 0, 0, 0} /* Sentinel */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 }; |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
410 |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
411 /**************************************************************************** |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
412 Implementations of array object methods. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
413 ****************************************************************************/ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
415 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
416 newarrayobject(PyTypeObject *type, Py_ssize_t size, struct arraydescr *descr) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 arrayobject *op; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
419 size_t nbytes; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
420 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 if (size < 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
422 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
425 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 nbytes = size * descr->itemsize; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
427 /* Check for overflow */ |
|
5318
2c4b802a3b5d
Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
4875
diff
changeset
|
428 if (nbytes / descr->itemsize != (size_t)size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
429 return PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
431 op = (arrayobject *) type->tp_alloc(type, 0); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 if (op == NULL) { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
433 return NULL; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
435 op->ob_size = size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 if (size <= 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 op->ob_item = NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
438 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 else { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
440 op->ob_item = PyMem_NEW(char, nbytes); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 if (op->ob_item == NULL) { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11711
diff
changeset
|
442 PyObject_Del(op); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
443 return PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
446 op->ob_descr = descr; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
447 op->allocated = size; |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
448 op->weakreflist = NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
449 return (PyObject *) op; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
452 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
453 getarrayitem(PyObject *op, Py_ssize_t i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 register arrayobject *ap; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
456 assert(array_Check(op)); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 ap = (arrayobject *)op; |
|
29244
23ad8b5d7b4a
All calls to getarrayitem() (which is static) are done either in loops
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
458 assert(i>=0 && i<ap->ob_size); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 return (*ap->ob_descr->getitem)(ap, i); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
462 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
463 ins1(arrayobject *self, Py_ssize_t where, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 char *items; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
466 Py_ssize_t n = self->ob_size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
468 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 if ((*self->ob_descr->setitem)(self, -1, v) < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 return -1; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
473 |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
474 if (array_resize(self, n+1) == -1) |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
475 return -1; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
476 items = self->ob_item; |
|
29163
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
28760
diff
changeset
|
477 if (where < 0) { |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
478 where += n; |
|
29163
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
28760
diff
changeset
|
479 if (where < 0) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
28760
diff
changeset
|
480 where = 0; |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
28760
diff
changeset
|
481 } |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
482 if (where > n) |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
483 where = n; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
484 /* appends don't need to call memmove() */ |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
485 if (where != n) |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
486 memmove(items + (where+1)*self->ob_descr->itemsize, |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
487 items + where*self->ob_descr->itemsize, |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
488 (n-where)*self->ob_descr->itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
489 return (*self->ob_descr->setitem)(self, where, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
490 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
491 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
492 /* Methods */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
493 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
494 static void |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
495 array_dealloc(arrayobject *op) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
496 { |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
497 if (op->weakreflist != NULL) |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
498 PyObject_ClearWeakRefs((PyObject *) op); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
499 if (op->ob_item != NULL) |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
500 PyMem_DEL(op->ob_item); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
501 op->ob_type->tp_free((PyObject *)op); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
503 |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
504 static PyObject * |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
505 array_richcompare(PyObject *v, PyObject *w, int op) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
506 { |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
507 arrayobject *va, *wa; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
508 PyObject *vi = NULL; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
509 PyObject *wi = NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
510 Py_ssize_t i, k; |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
511 PyObject *res; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
512 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
513 if (!array_Check(v) || !array_Check(w)) { |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
514 Py_INCREF(Py_NotImplemented); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
515 return Py_NotImplemented; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
516 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
517 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
518 va = (arrayobject *)v; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
519 wa = (arrayobject *)w; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
520 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
521 if (va->ob_size != wa->ob_size && (op == Py_EQ || op == Py_NE)) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
522 /* Shortcut: if the lengths differ, the arrays differ */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
523 if (op == Py_EQ) |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
524 res = Py_False; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
525 else |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
526 res = Py_True; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
527 Py_INCREF(res); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
528 return res; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
529 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
530 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
531 /* Search for the first index where items are different */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
532 k = 1; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
533 for (i = 0; i < va->ob_size && i < wa->ob_size; i++) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
534 vi = getarrayitem(v, i); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
535 wi = getarrayitem(w, i); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
536 if (vi == NULL || wi == NULL) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
537 Py_XDECREF(vi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
538 Py_XDECREF(wi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
539 return NULL; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
540 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
541 k = PyObject_RichCompareBool(vi, wi, Py_EQ); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
542 if (k == 0) |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
543 break; /* Keeping vi and wi alive! */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
544 Py_DECREF(vi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
545 Py_DECREF(wi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
546 if (k < 0) |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
547 return NULL; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
548 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
549 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
550 if (k) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
551 /* No more items to compare -- compare sizes */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
552 Py_ssize_t vs = va->ob_size; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
553 Py_ssize_t ws = wa->ob_size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
554 int cmp; |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
555 switch (op) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
556 case Py_LT: cmp = vs < ws; break; |
|
16268
c2ce9b2e5bb4
Correct one-line typo, reported by yole @ SF, bug 130077.
Guido van Rossum <guido@python.org>
parents:
16232
diff
changeset
|
557 case Py_LE: cmp = vs <= ws; break; |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
558 case Py_EQ: cmp = vs == ws; break; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
559 case Py_NE: cmp = vs != ws; break; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
560 case Py_GT: cmp = vs > ws; break; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
561 case Py_GE: cmp = vs >= ws; break; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
562 default: return NULL; /* cannot happen */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
563 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
564 if (cmp) |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
565 res = Py_True; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
566 else |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
567 res = Py_False; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
568 Py_INCREF(res); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
569 return res; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
570 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
571 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
572 /* We have an item that differs. First, shortcuts for EQ/NE */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
573 if (op == Py_EQ) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
574 Py_INCREF(Py_False); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
575 res = Py_False; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
576 } |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
577 else if (op == Py_NE) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
578 Py_INCREF(Py_True); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
579 res = Py_True; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
580 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
581 else { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
582 /* Compare the final item again using the proper operator */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
583 res = PyObject_RichCompare(vi, wi, op); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
584 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
585 Py_DECREF(vi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
586 Py_DECREF(wi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
587 return res; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
588 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
589 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
590 static Py_ssize_t |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
591 array_length(arrayobject *a) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
592 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
593 return a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
594 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
596 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
597 array_item(arrayobject *a, Py_ssize_t i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
598 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
599 if (i < 0 || i >= a->ob_size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
600 PyErr_SetString(PyExc_IndexError, "array index out of range"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
601 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
602 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
603 return getarrayitem((PyObject *)a, i); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
604 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
605 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
606 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
607 array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
608 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
609 arrayobject *np; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
610 if (ilow < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
611 ilow = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
612 else if (ilow > a->ob_size) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
613 ilow = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 if (ihigh < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 ihigh = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 if (ihigh < ilow) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 ihigh = ilow; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 else if (ihigh > a->ob_size) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 ihigh = a->ob_size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
620 np = (arrayobject *) newarrayobject(&Arraytype, ihigh - ilow, a->ob_descr); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 if (np == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
623 memcpy(np->ob_item, a->ob_item + ilow * a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 (ihigh-ilow) * a->ob_descr->itemsize); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
625 return (PyObject *)np; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
626 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
627 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
628 static PyObject * |
|
31651
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
629 array_copy(arrayobject *a, PyObject *unused) |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
630 { |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
631 return array_slice(a, 0, a->ob_size); |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
632 } |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
633 |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
634 PyDoc_STRVAR(copy_doc, |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
635 "copy(array)\n\ |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
636 \n\ |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
637 Return a copy of the array."); |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
638 |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
639 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
640 array_concat(arrayobject *a, PyObject *bb) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
641 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
642 Py_ssize_t size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
643 arrayobject *np; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
644 if (!array_Check(bb)) { |
|
12814
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
645 PyErr_Format(PyExc_TypeError, |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
646 "can only append array (not \"%.200s\") to array", |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
647 bb->ob_type->tp_name); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
648 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
649 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
650 #define b ((arrayobject *)bb) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
651 if (a->ob_descr != b->ob_descr) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
652 PyErr_BadArgument(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
653 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
654 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
655 size = a->ob_size + b->ob_size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
656 np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
657 if (np == NULL) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
658 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
659 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
660 memcpy(np->ob_item, a->ob_item, a->ob_size*a->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
661 memcpy(np->ob_item + a->ob_size*a->ob_descr->itemsize, |
|
1397
1ce2c0f565ef
Fix stupib bug in concatenation
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
662 b->ob_item, b->ob_size*b->ob_descr->itemsize); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
663 return (PyObject *)np; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
664 #undef b |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
665 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
666 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
667 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
668 array_repeat(arrayobject *a, Py_ssize_t n) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
669 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
670 Py_ssize_t i; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
671 Py_ssize_t size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
672 arrayobject *np; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
673 char *p; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
674 Py_ssize_t nbytes; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
675 if (n < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
676 n = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
677 size = a->ob_size * n; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
678 np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
679 if (np == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
680 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
681 p = np->ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
682 nbytes = a->ob_size * a->ob_descr->itemsize; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
683 for (i = 0; i < n; i++) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
684 memcpy(p, a->ob_item, nbytes); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
685 p += nbytes; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
686 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
687 return (PyObject *) np; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
688 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
689 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 static int |
|
36518
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
691 array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
692 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
693 char *item; |
|
36518
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
694 Py_ssize_t n; /* Size of replacement array */ |
|
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
695 Py_ssize_t d; /* Change in size */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
696 #define b ((arrayobject *)v) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
697 if (v == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
698 n = 0; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
699 else if (array_Check(v)) { |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
700 n = b->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
701 if (a == b) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
702 /* Special case "a[i:j] = a" -- copy b first */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
703 int ret; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 v = array_slice(b, 0, n); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
705 if (!v) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
706 return -1; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
707 ret = array_ass_slice(a, ilow, ihigh, v); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
708 Py_DECREF(v); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
709 return ret; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
710 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
711 if (b->ob_descr != a->ob_descr) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
712 PyErr_BadArgument(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
713 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
714 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
715 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
716 else { |
|
12814
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
717 PyErr_Format(PyExc_TypeError, |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
718 "can only assign array (not \"%.200s\") to array slice", |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
719 v->ob_type->tp_name); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
720 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
721 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
722 if (ilow < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
723 ilow = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
724 else if (ilow > a->ob_size) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
725 ilow = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
726 if (ihigh < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
727 ihigh = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
728 if (ihigh < ilow) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
729 ihigh = ilow; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
730 else if (ihigh > a->ob_size) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
731 ihigh = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
732 item = a->ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
733 d = n - (ihigh-ilow); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
734 if (d < 0) { /* Delete -d items */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
735 memmove(item + (ihigh+d)*a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
736 item + ihigh*a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
737 (a->ob_size-ihigh)*a->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
738 a->ob_size += d; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
739 PyMem_RESIZE(item, char, a->ob_size*a->ob_descr->itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
740 /* Can't fail */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
741 a->ob_item = item; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
742 a->allocated = a->ob_size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
743 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
744 else if (d > 0) { /* Insert d items */ |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
745 PyMem_RESIZE(item, char, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
746 (a->ob_size + d)*a->ob_descr->itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
747 if (item == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
748 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
749 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
750 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
751 memmove(item + (ihigh+d)*a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
752 item + ihigh*a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
753 (a->ob_size-ihigh)*a->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
754 a->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
755 a->ob_size += d; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
756 a->allocated = a->ob_size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
757 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
758 if (n > 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
759 memcpy(item + ilow*a->ob_descr->itemsize, b->ob_item, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
760 n*b->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
761 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
762 #undef b |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
763 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
764 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
765 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
766 array_ass_item(arrayobject *a, Py_ssize_t i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
767 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
768 if (i < 0 || i >= a->ob_size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
769 PyErr_SetString(PyExc_IndexError, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
770 "array assignment index out of range"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
771 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
772 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
773 if (v == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
774 return array_ass_slice(a, i, i+1, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
775 return (*a->ob_descr->setitem)(a, i, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
776 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
777 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
778 static int |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
779 setarrayitem(PyObject *a, Py_ssize_t i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
780 { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
781 assert(array_Check(a)); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
782 return array_ass_item((arrayobject *)a, i, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
783 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
784 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
785 static int |
|
31660
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
786 array_iter_extend(arrayobject *self, PyObject *bb) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
787 { |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
788 PyObject *it, *v; |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
789 |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
790 it = PyObject_GetIter(bb); |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
791 if (it == NULL) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
792 return -1; |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
793 |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
794 while ((v = PyIter_Next(it)) != NULL) { |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
795 if (ins1(self, (int) self->ob_size, v) != 0) { |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
796 Py_DECREF(v); |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
797 Py_DECREF(it); |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
798 return -1; |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
799 } |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
800 Py_DECREF(v); |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
801 } |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
802 Py_DECREF(it); |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
803 if (PyErr_Occurred()) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
804 return -1; |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
805 return 0; |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
806 } |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
807 |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
808 static int |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
809 array_do_extend(arrayobject *self, PyObject *bb) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
810 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
811 Py_ssize_t size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
812 |
|
31660
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
813 if (!array_Check(bb)) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
814 return array_iter_extend(self, bb); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
815 #define b ((arrayobject *)bb) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
816 if (self->ob_descr != b->ob_descr) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
817 PyErr_SetString(PyExc_TypeError, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
818 "can only extend with array of same kind"); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
819 return -1; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
820 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
821 size = self->ob_size + b->ob_size; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
822 PyMem_RESIZE(self->ob_item, char, size*self->ob_descr->itemsize); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
823 if (self->ob_item == NULL) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
824 PyObject_Del(self); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
825 PyErr_NoMemory(); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
826 return -1; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
827 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
828 memcpy(self->ob_item + self->ob_size*self->ob_descr->itemsize, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
829 b->ob_item, b->ob_size*b->ob_descr->itemsize); |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
830 self->ob_size = size; |
|
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
831 self->allocated = size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
832 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
833 return 0; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
834 #undef b |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
835 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
836 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
837 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
838 array_inplace_concat(arrayobject *self, PyObject *bb) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
839 { |
|
31660
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
840 if (!array_Check(bb)) { |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
841 PyErr_Format(PyExc_TypeError, |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
842 "can only extend array with array (not \"%.200s\")", |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
843 bb->ob_type->tp_name); |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
844 return NULL; |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
845 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
846 if (array_do_extend(self, bb) == -1) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
847 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
848 Py_INCREF(self); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
849 return (PyObject *)self; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
850 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
851 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
852 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
853 array_inplace_repeat(arrayobject *self, Py_ssize_t n) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
854 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
855 char *items, *p; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
856 Py_ssize_t size, i; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
857 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
858 if (self->ob_size > 0) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
859 if (n < 0) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
860 n = 0; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
861 items = self->ob_item; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
862 size = self->ob_size * self->ob_descr->itemsize; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
863 if (n == 0) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
864 PyMem_FREE(items); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
865 self->ob_item = NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
866 self->ob_size = 0; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
867 self->allocated = 0; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
868 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
869 else { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
870 PyMem_Resize(items, char, n * size); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
871 if (items == NULL) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
872 return PyErr_NoMemory(); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
873 p = items; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
874 for (i = 1; i < n; i++) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
875 p += size; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
876 memcpy(p, items, size); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
877 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
878 self->ob_item = items; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
879 self->ob_size *= n; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
880 self->allocated = self->ob_size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
881 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
882 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
883 Py_INCREF(self); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
884 return (PyObject *)self; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
885 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
886 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
887 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
888 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
889 ins(arrayobject *self, Py_ssize_t where, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
890 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
891 if (ins1(self, where, v) != 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
892 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
893 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
894 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
895 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
896 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
897 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
898 array_count(arrayobject *self, PyObject *v) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
899 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
900 Py_ssize_t count = 0; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
901 Py_ssize_t i; |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
902 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
903 for (i = 0; i < self->ob_size; i++) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
904 PyObject *selfi = getarrayitem((PyObject *)self, i); |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
905 int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
906 Py_DECREF(selfi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
907 if (cmp > 0) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
908 count++; |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
909 else if (cmp < 0) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
910 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
911 } |
|
36518
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
912 return PyInt_FromSsize_t(count); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
913 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
914 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
915 PyDoc_STRVAR(count_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
916 "count(x)\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
917 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
918 Return number of occurences of x in the array."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
919 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
920 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
921 array_index(arrayobject *self, PyObject *v) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
922 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
923 Py_ssize_t i; |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
924 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
925 for (i = 0; i < self->ob_size; i++) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
926 PyObject *selfi = getarrayitem((PyObject *)self, i); |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
927 int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
928 Py_DECREF(selfi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
929 if (cmp > 0) { |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
930 return PyInt_FromLong((long)i); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
931 } |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
932 else if (cmp < 0) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
933 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
934 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
935 PyErr_SetString(PyExc_ValueError, "array.index(x): x not in list"); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
936 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
937 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
938 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
939 PyDoc_STRVAR(index_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
940 "index(x)\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
941 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
942 Return index of first occurence of x in the array."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
943 |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
944 static int |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
945 array_contains(arrayobject *self, PyObject *v) |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
946 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
947 Py_ssize_t i; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
948 int cmp; |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
949 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
950 for (i = 0, cmp = 0 ; cmp == 0 && i < self->ob_size; i++) { |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
951 PyObject *selfi = getarrayitem((PyObject *)self, i); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
952 cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
953 Py_DECREF(selfi); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
954 } |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
955 return cmp; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
956 } |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
957 |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
958 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
959 array_remove(arrayobject *self, PyObject *v) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
960 { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
961 int i; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
962 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
963 for (i = 0; i < self->ob_size; i++) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
964 PyObject *selfi = getarrayitem((PyObject *)self,i); |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
965 int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
966 Py_DECREF(selfi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
967 if (cmp > 0) { |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
968 if (array_ass_slice(self, i, i+1, |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
969 (PyObject *)NULL) != 0) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
970 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
971 Py_INCREF(Py_None); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
972 return Py_None; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
973 } |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
974 else if (cmp < 0) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
975 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
976 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
977 PyErr_SetString(PyExc_ValueError, "array.remove(x): x not in list"); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
978 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
979 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
980 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
981 PyDoc_STRVAR(remove_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
982 "remove(x)\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
983 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
984 Remove the first occurence of x in the array."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
985 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
986 static PyObject * |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
987 array_pop(arrayobject *self, PyObject *args) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
988 { |
|
36518
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
989 Py_ssize_t i = -1; |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
990 PyObject *v; |
|
36518
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
991 if (!PyArg_ParseTuple(args, "|n:pop", &i)) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
992 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
993 if (self->ob_size == 0) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
994 /* Special-case most common failure cause */ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
995 PyErr_SetString(PyExc_IndexError, "pop from empty array"); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
996 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
997 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
998 if (i < 0) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
999 i += self->ob_size; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1000 if (i < 0 || i >= self->ob_size) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1001 PyErr_SetString(PyExc_IndexError, "pop index out of range"); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1002 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1003 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1004 v = getarrayitem((PyObject *)self,i); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1005 if (array_ass_slice(self, i, i+1, (PyObject *)NULL) != 0) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1006 Py_DECREF(v); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1007 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1008 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1009 return v; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1010 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1011 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1012 PyDoc_STRVAR(pop_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1013 "pop([i])\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1014 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1015 Return the i-th element and delete it from the array. i defaults to -1."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1016 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1017 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1018 array_extend(arrayobject *self, PyObject *bb) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1019 { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1020 if (array_do_extend(self, bb) == -1) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1021 return NULL; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1022 Py_INCREF(Py_None); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1023 return Py_None; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1024 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1025 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1026 PyDoc_STRVAR(extend_doc, |
|
31660
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
1027 "extend(array or iterable)\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1028 \n\ |
|
31660
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
1029 Append items to the end of the array."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1030 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1031 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1032 array_insert(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1033 { |
|
36689
11484a72d966
Convert array.array.insert to use Py_ssize_t (like the rest already does.)
Thomas Wouters <thomas@python.org>
parents:
36544
diff
changeset
|
1034 Py_ssize_t i; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1035 PyObject *v; |
|
36689
11484a72d966
Convert array.array.insert to use Py_ssize_t (like the rest already does.)
Thomas Wouters <thomas@python.org>
parents:
36544
diff
changeset
|
1036 if (!PyArg_ParseTuple(args, "nO:insert", &i, &v)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1037 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1038 return ins(self, i, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1039 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1040 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1041 PyDoc_STRVAR(insert_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1042 "insert(i,x)\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1043 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1044 Insert a new item x into the array before position i."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1045 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1046 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1047 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1048 array_buffer_info(arrayobject *self, PyObject *unused) |
|
5982
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
1049 { |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1050 PyObject* retval = NULL; |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1051 retval = PyTuple_New(2); |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1052 if (!retval) |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1053 return NULL; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
1054 |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
1055 PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item)); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
1056 PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(self->ob_size))); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
1057 |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
1058 return retval; |
|
5982
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
1059 } |
|
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
1060 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1061 PyDoc_STRVAR(buffer_info_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1062 "buffer_info() -> (address, length)\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1063 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1064 Return a tuple (address, length) giving the current memory address and\n\ |
|
18851
ef2031c54875
Fix buffer_info() docstring to match reality. See SF bug #444842.
Guido van Rossum <guido@python.org>
parents:
18036
diff
changeset
|
1065 the length in items of the buffer used to hold array's contents\n\ |
|
ef2031c54875
Fix buffer_info() docstring to match reality. See SF bug #444842.
Guido van Rossum <guido@python.org>
parents:
18036
diff
changeset
|
1066 The length should be multiplied by the itemsize attribute to calculate\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1067 the buffer length in bytes."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1068 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1069 |
|
5982
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
1070 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1071 array_append(arrayobject *self, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1072 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1073 return ins(self, (int) self->ob_size, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1074 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1075 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1076 PyDoc_STRVAR(append_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1077 "append(x)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1078 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1079 Append new value x to the end of the array."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1080 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1081 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1082 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1083 array_byteswap(arrayobject *self, PyObject *unused) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1084 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1085 char *p; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1086 Py_ssize_t i; |
|
11522
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
1087 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1088 switch (self->ob_descr->itemsize) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1089 case 1: |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1090 break; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1091 case 2: |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1092 for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 2) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1093 char p0 = p[0]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1094 p[0] = p[1]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1095 p[1] = p0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1096 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1097 break; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1098 case 4: |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1099 for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 4) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1100 char p0 = p[0]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1101 char p1 = p[1]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1102 p[0] = p[3]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1103 p[1] = p[2]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1104 p[2] = p1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1105 p[3] = p0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1106 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1107 break; |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1108 case 8: |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1109 for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 8) { |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1110 char p0 = p[0]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1111 char p1 = p[1]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1112 char p2 = p[2]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1113 char p3 = p[3]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1114 p[0] = p[7]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1115 p[1] = p[6]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1116 p[2] = p[5]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1117 p[3] = p[4]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1118 p[4] = p3; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1119 p[5] = p2; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1120 p[6] = p1; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1121 p[7] = p0; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1122 } |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1123 break; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1124 default: |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1125 PyErr_SetString(PyExc_RuntimeError, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1126 "don't know how to byteswap this array type"); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1127 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1128 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1129 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1130 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1131 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1132 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1133 PyDoc_STRVAR(byteswap_doc, |
|
11522
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
1134 "byteswap()\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1135 \n\ |
|
11522
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
1136 Byteswap all items of the array. If the items in the array are not 1, 2,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1137 4, or 8 bytes in size, RuntimeError is raised."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1138 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1139 static PyObject * |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1140 array_reduce(arrayobject *array) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1141 { |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1142 PyObject *dict, *result; |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1143 |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1144 dict = PyObject_GetAttrString((PyObject *)array, "__dict__"); |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1145 if (dict == NULL) { |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1146 PyErr_Clear(); |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1147 dict = Py_None; |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1148 Py_INCREF(dict); |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1149 } |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1150 if (array->ob_size > 0) { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1151 result = Py_BuildValue("O(cs#)O", |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1152 array->ob_type, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1153 array->ob_descr->typecode, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1154 array->ob_item, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1155 array->ob_size * array->ob_descr->itemsize, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1156 dict); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1157 } else { |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1158 result = Py_BuildValue("O(c)O", |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1159 array->ob_type, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1160 array->ob_descr->typecode, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1161 dict); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1162 } |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1163 Py_DECREF(dict); |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1164 return result; |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1165 } |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1166 |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1167 PyDoc_STRVAR(array_doc, "Return state information for pickling."); |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1168 |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1169 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1170 array_reverse(arrayobject *self, PyObject *unused) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1171 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1172 register Py_ssize_t itemsize = self->ob_descr->itemsize; |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1173 register char *p, *q; |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1174 /* little buffer to hold items while swapping */ |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1175 char tmp[256]; /* 8 is probably enough -- but why skimp */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36882
diff
changeset
|
1176 assert((size_t)itemsize <= sizeof(tmp)); |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1177 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1178 if (self->ob_size > 1) { |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1179 for (p = self->ob_item, |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1180 q = self->ob_item + (self->ob_size - 1)*itemsize; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1181 p < q; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1182 p += itemsize, q -= itemsize) { |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1183 /* memory areas guaranteed disjoint, so memcpy |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1184 * is safe (& memmove may be slower). |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1185 */ |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1186 memcpy(tmp, p, itemsize); |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1187 memcpy(p, q, itemsize); |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1188 memcpy(q, tmp, itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1189 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1190 } |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
1191 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1192 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1193 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1194 } |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1195 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1196 PyDoc_STRVAR(reverse_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1197 "reverse()\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1198 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1199 Reverse the order of the items in the array."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1200 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1201 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1202 array_fromfile(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1203 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1204 PyObject *f; |
|
36518
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1205 Py_ssize_t n; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1206 FILE *fp; |
|
36529
442c0fb3c4ed
Use correct format specifier for Py_ssize_t variable to PyArg_ParseTuple().
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
1207 if (!PyArg_ParseTuple(args, "On:fromfile", &f, &n)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1208 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1209 fp = PyFile_AsFile(f); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1210 if (fp == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1211 PyErr_SetString(PyExc_TypeError, "arg1 must be open file"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1212 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1213 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1214 if (n > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1215 char *item = self->ob_item; |
|
36518
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1216 Py_ssize_t itemsize = self->ob_descr->itemsize; |
|
13081
0acec211a209
Trent Mick: use size_t instead of int where appropriate (in
Guido van Rossum <guido@python.org>
parents:
13068
diff
changeset
|
1217 size_t nread; |
|
36518
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1218 Py_ssize_t newlength; |
|
10283
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1219 size_t newbytes; |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1220 /* Be careful here about overflow */ |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1221 if ((newlength = self->ob_size + n) <= 0 || |
|
10434
a4768315948d
Use an unsigned cast to avoid a warning in VC++.
Guido van Rossum <guido@python.org>
parents:
10283
diff
changeset
|
1222 (newbytes = newlength * itemsize) / itemsize != |
|
a4768315948d
Use an unsigned cast to avoid a warning in VC++.
Guido van Rossum <guido@python.org>
parents:
10283
diff
changeset
|
1223 (size_t)newlength) |
|
10283
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1224 goto nomem; |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1225 PyMem_RESIZE(item, char, newbytes); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1226 if (item == NULL) { |
|
10283
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1227 nomem: |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1228 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1229 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1230 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1231 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1232 self->ob_size += n; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
1233 self->allocated = self->ob_size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1234 nread = fread(item + (self->ob_size - n) * itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1235 itemsize, n, fp); |
|
13081
0acec211a209
Trent Mick: use size_t instead of int where appropriate (in
Guido van Rossum <guido@python.org>
parents:
13068
diff
changeset
|
1236 if (nread < (size_t)n) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1237 self->ob_size -= (n - nread); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1238 PyMem_RESIZE(item, char, self->ob_size*itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1239 self->ob_item = item; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
1240 self->allocated = self->ob_size; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1241 PyErr_SetString(PyExc_EOFError, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1242 "not enough items in file"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1243 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1244 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1245 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1246 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1247 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1248 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1249 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1250 PyDoc_STRVAR(fromfile_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1251 "fromfile(f, n)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1252 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1253 Read n objects from the file object f and append them to the end of the\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1254 array. Also called as read."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1255 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1256 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1257 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1258 array_tofile(arrayobject *self, PyObject *f) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1259 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1260 FILE *fp; |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1261 |
|
41434
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1262 if (self->ob_size == 0) |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1263 goto done; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1264 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1265 fp = PyFile_AsFile(f); |
|
41434
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1266 if (fp != NULL) { |
|
13942
31b25ac1f019
Use safer comparisons (only matters when sizeof(int) != sizeof(size_t)). fread
Trent Mick <trentm@activestate.com>
parents:
13792
diff
changeset
|
1267 if (fwrite(self->ob_item, self->ob_descr->itemsize, |
|
31b25ac1f019
Use safer comparisons (only matters when sizeof(int) != sizeof(size_t)). fread
Trent Mick <trentm@activestate.com>
parents:
13792
diff
changeset
|
1268 self->ob_size, fp) != (size_t)self->ob_size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1269 PyErr_SetFromErrno(PyExc_IOError); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1270 clearerr(fp); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1271 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1272 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1273 } |
|
41434
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1274 else { |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1275 Py_ssize_t nbytes = self->ob_size * self->ob_descr->itemsize; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1276 /* Write 64K blocks at a time */ |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1277 /* XXX Make the block size settable */ |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1278 int BLOCKSIZE = 64*1024; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1279 Py_ssize_t nblocks = (nbytes + BLOCKSIZE - 1) / BLOCKSIZE; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1280 Py_ssize_t i; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1281 for (i = 0; i < nblocks; i++) { |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1282 char* ptr = self->ob_item + i*BLOCKSIZE; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1283 Py_ssize_t size = BLOCKSIZE; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1284 PyObject *bytes, *res; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1285 if (i*BLOCKSIZE + size > nbytes) |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1286 size = nbytes - i*BLOCKSIZE; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1287 bytes = PyBytes_FromStringAndSize(ptr, size); |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1288 if (bytes == NULL) |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1289 return NULL; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1290 res = PyObject_CallMethod(f, "write", "O", |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1291 bytes); |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1292 Py_DECREF(bytes); |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1293 if (res == NULL) |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1294 return NULL; |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1295 } |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1296 } |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1297 |
|
f390793e75de
Make array().tofile() work with a new I/O object.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1298 done: |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1299 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1300 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1301 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1302 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1303 PyDoc_STRVAR(tofile_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1304 "tofile(f)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1305 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1306 Write all items (as machine values) to the file object f. Also called as\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1307 write."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1308 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1309 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1310 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1311 array_fromlist(arrayobject *self, PyObject *list) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1312 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1313 Py_ssize_t n; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1314 Py_ssize_t itemsize = self->ob_descr->itemsize; |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1315 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1316 if (!PyList_Check(list)) { |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1317 PyErr_SetString(PyExc_TypeError, "arg must be list"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1318 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1319 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1320 n = PyList_Size(list); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1321 if (n > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1322 char *item = self->ob_item; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1323 Py_ssize_t i; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1324 PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1325 if (item == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1326 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1327 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1328 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1329 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1330 self->ob_size += n; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
1331 self->allocated = self->ob_size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1332 for (i = 0; i < n; i++) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1333 PyObject *v = PyList_GetItem(list, i); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1334 if ((*self->ob_descr->setitem)(self, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1335 self->ob_size - n + i, v) != 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1336 self->ob_size -= n; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1337 PyMem_RESIZE(item, char, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1338 self->ob_size * itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1339 self->ob_item = item; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
1340 self->allocated = self->ob_size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1341 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1342 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1343 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1344 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1345 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1346 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1347 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1348 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1349 PyDoc_STRVAR(fromlist_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1350 "fromlist(list)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1351 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1352 Append items to array from list."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1353 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1354 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1355 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1356 array_tolist(arrayobject *self, PyObject *unused) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1357 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1358 PyObject *list = PyList_New(self->ob_size); |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1359 Py_ssize_t i; |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1360 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1361 if (list == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1362 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1363 for (i = 0; i < self->ob_size; i++) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1364 PyObject *v = getarrayitem((PyObject *)self, i); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1365 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1366 Py_DECREF(list); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1367 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1368 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1369 PyList_SetItem(list, i, v); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1370 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1371 return list; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1372 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1373 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1374 PyDoc_STRVAR(tolist_doc, |
|
9360
4c23ae6c6e82
ACK! There was still an unescaped newline in a docstring.
Guido van Rossum <guido@python.org>
parents:
9343
diff
changeset
|
1375 "tolist() -> list\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1376 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1377 Convert array to an ordinary list with the same items."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1378 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1379 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1380 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1381 array_fromstring(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1382 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1383 char *str; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1384 Py_ssize_t n; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1385 int itemsize = self->ob_descr->itemsize; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1386 if (!PyArg_ParseTuple(args, "s#:fromstring", &str, &n)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1387 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1388 if (n % itemsize != 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1389 PyErr_SetString(PyExc_ValueError, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1390 "string length not a multiple of item size"); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1391 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1392 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1393 n = n / itemsize; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1394 if (n > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1395 char *item = self->ob_item; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1396 PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1397 if (item == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1398 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1399 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1400 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1401 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1402 self->ob_size += n; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
1403 self->allocated = self->ob_size; |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1404 memcpy(item + (self->ob_size - n) * itemsize, |
|
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1405 str, itemsize*n); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1406 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1407 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1408 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1409 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1410 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1411 PyDoc_STRVAR(fromstring_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1412 "fromstring(string)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1413 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1414 Appends items from the string, interpreting it as an array of machine\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1415 values,as if it had been read from a file using the fromfile() method)."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1416 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1417 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1418 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1419 array_tostring(arrayobject *self, PyObject *unused) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1420 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1421 return PyString_FromStringAndSize(self->ob_item, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1422 self->ob_size * self->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1423 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1424 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1425 PyDoc_STRVAR(tostring_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1426 "tostring() -> string\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1427 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1428 Convert the array to an array of machine values and return the string\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1429 representation."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1430 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1431 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1432 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1433 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1434 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1435 array_fromunicode(arrayobject *self, PyObject *args) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1436 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1437 Py_UNICODE *ustr; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1438 Py_ssize_t n; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1439 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1440 if (!PyArg_ParseTuple(args, "u#:fromunicode", &ustr, &n)) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1441 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1442 if (self->ob_descr->typecode != 'u') { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1443 PyErr_SetString(PyExc_ValueError, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1444 "fromunicode() may only be called on " |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1445 "type 'u' arrays"); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1446 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1447 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1448 if (n > 0) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1449 Py_UNICODE *item = (Py_UNICODE *) self->ob_item; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1450 PyMem_RESIZE(item, Py_UNICODE, self->ob_size + n); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1451 if (item == NULL) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1452 PyErr_NoMemory(); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1453 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1454 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1455 self->ob_item = (char *) item; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1456 self->ob_size += n; |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
1457 self->allocated = self->ob_size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1458 memcpy(item + self->ob_size - n, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1459 ustr, n * sizeof(Py_UNICODE)); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1460 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1461 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1462 Py_INCREF(Py_None); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1463 return Py_None; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1464 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1465 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1466 PyDoc_STRVAR(fromunicode_doc, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1467 "fromunicode(ustr)\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1468 \n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1469 Extends this array with data from the unicode string ustr.\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1470 The array must be a type 'u' array; otherwise a ValueError\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1471 is raised. Use array.fromstring(ustr.decode(...)) to\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1472 append Unicode data to an array of some other type."); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1473 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1474 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1475 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1476 array_tounicode(arrayobject *self, PyObject *unused) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1477 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1478 if (self->ob_descr->typecode != 'u') { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1479 PyErr_SetString(PyExc_ValueError, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1480 "tounicode() may only be called on type 'u' arrays"); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1481 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1482 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1483 return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, self->ob_size); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1484 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1485 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1486 PyDoc_STRVAR(tounicode_doc, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1487 "tounicode() -> unicode\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1488 \n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1489 Convert the array to a unicode string. The array must be\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1490 a type 'u' array; otherwise a ValueError is raised. Use\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1491 array.tostring().decode() to obtain a unicode string from\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1492 an array of some other type."); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1493 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1494 #endif /* Py_USING_UNICODE */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1495 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1496 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1497 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1498 array_get_typecode(arrayobject *a, void *closure) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1499 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1500 char tc = a->ob_descr->typecode; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1501 return PyString_FromStringAndSize(&tc, 1); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1502 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1503 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1504 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1505 array_get_itemsize(arrayobject *a, void *closure) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1506 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1507 return PyInt_FromLong((long)a->ob_descr->itemsize); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1508 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1509 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1510 static PyGetSetDef array_getsets [] = { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1511 {"typecode", (getter) array_get_typecode, NULL, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1512 "the typecode character used to create the array"}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1513 {"itemsize", (getter) array_get_itemsize, NULL, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1514 "the size, in bytes, of one array item"}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1515 {NULL} |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1516 }; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1517 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1518 PyMethodDef array_methods[] = { |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1519 {"append", (PyCFunction)array_append, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1520 append_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1521 {"buffer_info", (PyCFunction)array_buffer_info, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1522 buffer_info_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1523 {"byteswap", (PyCFunction)array_byteswap, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1524 byteswap_doc}, |
|
31651
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
1525 {"__copy__", (PyCFunction)array_copy, METH_NOARGS, |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
1526 copy_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1527 {"count", (PyCFunction)array_count, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1528 count_doc}, |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1529 {"__deepcopy__",(PyCFunction)array_copy, METH_O, |
|
31651
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30683
diff
changeset
|
1530 copy_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1531 {"extend", (PyCFunction)array_extend, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1532 extend_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1533 {"fromfile", (PyCFunction)array_fromfile, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1534 fromfile_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1535 {"fromlist", (PyCFunction)array_fromlist, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1536 fromlist_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1537 {"fromstring", (PyCFunction)array_fromstring, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1538 fromstring_doc}, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1539 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1540 {"fromunicode", (PyCFunction)array_fromunicode, METH_VARARGS, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1541 fromunicode_doc}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1542 #endif |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1543 {"index", (PyCFunction)array_index, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1544 index_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1545 {"insert", (PyCFunction)array_insert, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1546 insert_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1547 {"pop", (PyCFunction)array_pop, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1548 pop_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1549 {"read", (PyCFunction)array_fromfile, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1550 fromfile_doc}, |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1551 {"__reduce__", (PyCFunction)array_reduce, METH_NOARGS, |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
1552 array_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1553 {"remove", (PyCFunction)array_remove, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1554 remove_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1555 {"reverse", (PyCFunction)array_reverse, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1556 reverse_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1557 /* {"sort", (PyCFunction)array_sort, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1558 sort_doc},*/ |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1559 {"tofile", (PyCFunction)array_tofile, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1560 tofile_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1561 {"tolist", (PyCFunction)array_tolist, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1562 tolist_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1563 {"tostring", (PyCFunction)array_tostring, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1564 tostring_doc}, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1565 #ifdef Py_USING_UNICODE |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1566 {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1567 tounicode_doc}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1568 #endif |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1569 {"write", (PyCFunction)array_tofile, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1570 tofile_doc}, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1571 {NULL, NULL} /* sentinel */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1572 }; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1573 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1574 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1575 array_repr(arrayobject *a) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1576 { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1577 char buf[256], typecode; |
|
28742
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1578 PyObject *s, *t, *v = NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1579 Py_ssize_t len; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1580 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1581 len = a->ob_size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1582 typecode = a->ob_descr->typecode; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1583 if (len == 0) { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1584 PyOS_snprintf(buf, sizeof(buf), "array('%c')", typecode); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1585 return PyString_FromString(buf); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1586 } |
|
28742
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1587 |
|
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1588 if (typecode == 'c') |
|
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1589 v = array_tostring(a, NULL); |
|
23433
fb64f21176af
array_tounicode isn't defined in --disable-unicode builds...
Michael W. Hudson <mwh@python.net>
parents:
23365
diff
changeset
|
1590 #ifdef Py_USING_UNICODE |
|
28742
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1591 else if (typecode == 'u') |
|
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1592 v = array_tounicode(a, NULL); |
|
23433
fb64f21176af
array_tounicode isn't defined in --disable-unicode builds...
Michael W. Hudson <mwh@python.net>
parents:
23365
diff
changeset
|
1593 #endif |
|
28742
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1594 else |
|
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1595 v = array_tolist(a, NULL); |
|
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1596 t = PyObject_Repr(v); |
|
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1597 Py_XDECREF(v); |
|
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1598 |
|
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1599 PyOS_snprintf(buf, sizeof(buf), "array('%c', ", typecode); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1600 s = PyString_FromString(buf); |
|
28742
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1601 PyString_ConcatAndDel(&s, t); |
|
bd678e65f784
SF Patch 685051: fix for 680789: reprs in arraymodule
Raymond Hettinger <python@rcn.com>
parents:
28320
diff
changeset
|
1602 PyString_ConcatAndDel(&s, PyString_FromString(")")); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1603 return s; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1604 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1605 |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1606 static PyObject* |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1607 array_subscr(arrayobject* self, PyObject* item) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1608 { |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
1609 if (PyIndex_Check(item)) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
1610 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
1611 if (i==-1 && PyErr_Occurred()) { |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1612 return NULL; |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
1613 } |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1614 if (i < 0) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1615 i += self->ob_size; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1616 return array_item(self, i); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1617 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1618 else if (PySlice_Check(item)) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1619 Py_ssize_t start, stop, step, slicelength, cur, i; |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1620 PyObject* result; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1621 arrayobject* ar; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1622 int itemsize = self->ob_descr->itemsize; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1623 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1624 if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1625 &start, &stop, &step, &slicelength) < 0) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1626 return NULL; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1627 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1628 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1629 if (slicelength <= 0) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1630 return newarrayobject(&Arraytype, 0, self->ob_descr); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1631 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1632 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1633 result = newarrayobject(&Arraytype, slicelength, self->ob_descr); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1634 if (!result) return NULL; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1635 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1636 ar = (arrayobject*)result; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1637 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1638 for (cur = start, i = 0; i < slicelength; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1639 cur += step, i++) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1640 memcpy(ar->ob_item + i*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1641 self->ob_item + cur*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1642 itemsize); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1643 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1644 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1645 return result; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1646 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1647 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1648 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1649 PyErr_SetString(PyExc_TypeError, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1650 "list indices must be integers"); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1651 return NULL; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1652 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1653 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1654 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1655 static int |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1656 array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1657 { |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
1658 if (PyIndex_Check(item)) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
1659 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); |
|
36882
6a9c7165b17b
Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents:
36877
diff
changeset
|
1660 if (i==-1 && PyErr_Occurred()) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1661 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1662 if (i < 0) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1663 i += self->ob_size; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1664 return array_ass_item(self, i, value); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1665 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1666 else if (PySlice_Check(item)) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1667 Py_ssize_t start, stop, step, slicelength; |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1668 int itemsize = self->ob_descr->itemsize; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1669 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1670 if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1671 &start, &stop, &step, &slicelength) < 0) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1672 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1673 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1674 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1675 /* treat A[slice(a,b)] = v _exactly_ like A[a:b] = v */ |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1676 if (step == 1 && ((PySliceObject*)item)->step == Py_None) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1677 return array_ass_slice(self, start, stop, value); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1678 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1679 if (value == NULL) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1680 /* delete slice */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1681 Py_ssize_t cur, i, extra; |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1682 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1683 if (slicelength <= 0) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1684 return 0; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1685 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1686 if (step < 0) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1687 stop = start + 1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1688 start = stop + step*(slicelength - 1) - 1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1689 step = -step; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1690 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1691 |
| 24424 | 1692 for (cur = start, i = 0; i < slicelength - 1; |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1693 cur += step, i++) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1694 memmove(self->ob_item + (cur - i)*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1695 self->ob_item + (cur + 1)*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1696 (step - 1) * itemsize); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1697 } |
| 24424 | 1698 extra = self->ob_size - (cur + 1); |
| 1699 if (extra > 0) { | |
| 1700 memmove(self->ob_item + (cur - i)*itemsize, | |
| 1701 self->ob_item + (cur + 1)*itemsize, | |
| 1702 extra*itemsize); | |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1703 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1704 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1705 self->ob_size -= slicelength; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36882
diff
changeset
|
1706 self->ob_item = (char *)PyMem_REALLOC(self->ob_item, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36882
diff
changeset
|
1707 itemsize*self->ob_size); |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
1708 self->allocated = self->ob_size; |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1709 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1710 return 0; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1711 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1712 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1713 /* assign slice */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1714 Py_ssize_t cur, i; |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1715 arrayobject* av; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1716 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1717 if (!array_Check(value)) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1718 PyErr_Format(PyExc_TypeError, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1719 "must assign array (not \"%.200s\") to slice", |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1720 value->ob_type->tp_name); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1721 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1722 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1723 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1724 av = (arrayobject*)value; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1725 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1726 if (av->ob_size != slicelength) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1727 PyErr_Format(PyExc_ValueError, |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1728 "attempt to assign array of size %ld to extended slice of size %ld", |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1729 /*XXX*/(long)av->ob_size, /*XXX*/(long)slicelength); |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1730 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1731 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1732 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1733 if (!slicelength) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1734 return 0; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1735 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1736 /* protect against a[::-1] = a */ |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1737 if (self == av) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1738 value = array_slice(av, 0, av->ob_size); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1739 av = (arrayobject*)value; |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
1740 if (!av) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39536
diff
changeset
|
1741 return -1; |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1742 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1743 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1744 Py_INCREF(value); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1745 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1746 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1747 for (cur = start, i = 0; i < slicelength; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1748 cur += step, i++) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1749 memcpy(self->ob_item + cur*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1750 av->ob_item + i*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1751 itemsize); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1752 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1753 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1754 Py_DECREF(value); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1755 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1756 return 0; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1757 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1758 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1759 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1760 PyErr_SetString(PyExc_TypeError, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1761 "list indices must be integers"); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1762 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1763 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1764 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1765 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1766 static PyMappingMethods array_as_mapping = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1767 (lenfunc)array_length, |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1768 (binaryfunc)array_subscr, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1769 (objobjargproc)array_ass_subscr |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1770 }; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1771 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1772 static const void *emptybuf = ""; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1773 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1774 static Py_ssize_t |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1775 array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr) |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1776 { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1777 if ( index != 0 ) { |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1778 PyErr_SetString(PyExc_SystemError, |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1779 "Accessing non-existent array segment"); |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1780 return -1; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1781 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1782 *ptr = (void *)self->ob_item; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1783 if (*ptr == NULL) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1784 *ptr = emptybuf; |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1785 return self->ob_size*self->ob_descr->itemsize; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1786 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1787 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1788 static Py_ssize_t |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1789 array_buffer_getwritebuf(arrayobject *self, Py_ssize_t index, const void **ptr) |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1790 { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1791 if ( index != 0 ) { |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1792 PyErr_SetString(PyExc_SystemError, |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1793 "Accessing non-existent array segment"); |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1794 return -1; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1795 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1796 *ptr = (void *)self->ob_item; |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1797 if (*ptr == NULL) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
1798 *ptr = emptybuf; |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1799 return self->ob_size*self->ob_descr->itemsize; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1800 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1801 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1802 static Py_ssize_t |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1803 array_buffer_getsegcount(arrayobject *self, Py_ssize_t *lenp) |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1804 { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1805 if ( lenp ) |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1806 *lenp = self->ob_size*self->ob_descr->itemsize; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1807 return 1; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1808 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1809 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1810 static PySequenceMethods array_as_sequence = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1811 (lenfunc)array_length, /*sq_length*/ |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1812 (binaryfunc)array_concat, /*sq_concat*/ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1813 (ssizeargfunc)array_repeat, /*sq_repeat*/ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1814 (ssizeargfunc)array_item, /*sq_item*/ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1815 (ssizessizeargfunc)array_slice, /*sq_slice*/ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1816 (ssizeobjargproc)array_ass_item, /*sq_ass_item*/ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1817 (ssizessizeobjargproc)array_ass_slice, /*sq_ass_slice*/ |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
1818 (objobjproc)array_contains, /*sq_contains*/ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1819 (binaryfunc)array_inplace_concat, /*sq_inplace_concat*/ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1820 (ssizeargfunc)array_inplace_repeat /*sq_inplace_repeat*/ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1821 }; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1822 |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1823 static PyBufferProcs array_as_buffer = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1824 (readbufferproc)array_buffer_getreadbuf, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1825 (writebufferproc)array_buffer_getwritebuf, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1826 (segcountproc)array_buffer_getsegcount, |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
39222
diff
changeset
|
1827 NULL, |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1828 }; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1829 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1830 static PyObject * |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1831 array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1832 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1833 char c; |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1834 PyObject *initial = NULL, *it = NULL; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1835 struct arraydescr *descr; |
|
35449
1fdfd0130e28
Disallow keyword arguments for type constructors that don't use them.
Georg Brandl <georg@python.org>
parents:
34174
diff
changeset
|
1836 |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40450
diff
changeset
|
1837 if (type == &Arraytype && !_PyArg_NoKeywords("array.array()", kwds)) |
|
35449
1fdfd0130e28
Disallow keyword arguments for type constructors that don't use them.
Georg Brandl <georg@python.org>
parents:
34174
diff
changeset
|
1838 return NULL; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1839 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1840 if (!PyArg_ParseTuple(args, "c|O:array", &c, &initial)) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1841 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1842 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1843 if (!(initial == NULL || PyList_Check(initial) |
|
28760
22d177682ae1
SF 686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
28742
diff
changeset
|
1844 || PyString_Check(initial) || PyTuple_Check(initial) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1845 || (c == 'u' && PyUnicode_Check(initial)))) { |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1846 it = PyObject_GetIter(initial); |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1847 if (it == NULL) |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1848 return NULL; |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1849 /* We set initial to NULL so that the subsequent code |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1850 will create an empty array of the appropriate type |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1851 and afterwards we can use array_iter_extend to populate |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1852 the array. |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1853 */ |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1854 initial = NULL; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1855 } |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1856 for (descr = descriptors; descr->typecode != '\0'; descr++) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1857 if (descr->typecode == c) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1858 PyObject *a; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1859 Py_ssize_t len; |
|
28760
22d177682ae1
SF 686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
28742
diff
changeset
|
1860 |
|
22d177682ae1
SF 686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
28742
diff
changeset
|
1861 if (initial == NULL || !(PyList_Check(initial) |
|
22d177682ae1
SF 686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
28742
diff
changeset
|
1862 || PyTuple_Check(initial))) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1863 len = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1864 else |
|
28760
22d177682ae1
SF 686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
28742
diff
changeset
|
1865 len = PySequence_Size(initial); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1866 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1867 a = newarrayobject(type, len, descr); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1868 if (a == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1869 return NULL; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1870 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1871 if (len > 0) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1872 Py_ssize_t i; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1873 for (i = 0; i < len; i++) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1874 PyObject *v = |
|
28760
22d177682ae1
SF 686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
28742
diff
changeset
|
1875 PySequence_GetItem(initial, i); |
|
30066
ae0242e3459e
SF bug #782369: Massive memory leak in array module
Raymond Hettinger <python@rcn.com>
parents:
29244
diff
changeset
|
1876 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1877 Py_DECREF(a); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1878 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1879 } |
|
30066
ae0242e3459e
SF bug #782369: Massive memory leak in array module
Raymond Hettinger <python@rcn.com>
parents:
29244
diff
changeset
|
1880 if (setarrayitem(a, i, v) != 0) { |
|
ae0242e3459e
SF bug #782369: Massive memory leak in array module
Raymond Hettinger <python@rcn.com>
parents:
29244
diff
changeset
|
1881 Py_DECREF(v); |
|
ae0242e3459e
SF bug #782369: Massive memory leak in array module
Raymond Hettinger <python@rcn.com>
parents:
29244
diff
changeset
|
1882 Py_DECREF(a); |
|
ae0242e3459e
SF bug #782369: Massive memory leak in array module
Raymond Hettinger <python@rcn.com>
parents:
29244
diff
changeset
|
1883 return NULL; |
|
ae0242e3459e
SF bug #782369: Massive memory leak in array module
Raymond Hettinger <python@rcn.com>
parents:
29244
diff
changeset
|
1884 } |
|
ae0242e3459e
SF bug #782369: Massive memory leak in array module
Raymond Hettinger <python@rcn.com>
parents:
29244
diff
changeset
|
1885 Py_DECREF(v); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1886 } |
|
30066
ae0242e3459e
SF bug #782369: Massive memory leak in array module
Raymond Hettinger <python@rcn.com>
parents:
29244
diff
changeset
|
1887 } else if (initial != NULL && PyString_Check(initial)) { |
|
36877
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36689
diff
changeset
|
1888 PyObject *t_initial, *v; |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36689
diff
changeset
|
1889 t_initial = PyTuple_Pack(1, initial); |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36689
diff
changeset
|
1890 if (t_initial == NULL) { |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36689
diff
changeset
|
1891 Py_DECREF(a); |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36689
diff
changeset
|
1892 return NULL; |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36689
diff
changeset
|
1893 } |
|
e9a7a2784e17
SF #1444030: Fix several potential defects found by Coverity.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
36689
diff
changeset
|
1894 v = array_fromstring((arrayobject *)a, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1895 t_initial); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1896 Py_DECREF(t_initial); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1897 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1898 Py_DECREF(a); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1899 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1900 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1901 Py_DECREF(v); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1902 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1903 } else if (initial != NULL && PyUnicode_Check(initial)) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1904 Py_ssize_t n = PyUnicode_GET_DATA_SIZE(initial); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1905 if (n > 0) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1906 arrayobject *self = (arrayobject *)a; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1907 char *item = self->ob_item; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36882
diff
changeset
|
1908 item = (char *)PyMem_Realloc(item, n); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1909 if (item == NULL) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1910 PyErr_NoMemory(); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1911 Py_DECREF(a); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1912 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1913 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1914 self->ob_item = item; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1915 self->ob_size = n / sizeof(Py_UNICODE); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1916 memcpy(item, PyUnicode_AS_DATA(initial), n); |
|
31659
206d8575f644
Update the array overallocation scheme to match the approach used for
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
1917 self->allocated = self->ob_size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1918 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1919 #endif |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1920 } |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1921 if (it != NULL) { |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1922 if (array_iter_extend((arrayobject *)a, it) == -1) { |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1923 Py_DECREF(it); |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1924 Py_DECREF(a); |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1925 return NULL; |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1926 } |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1927 Py_DECREF(it); |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1928 } |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1929 return a; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1930 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1931 } |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1932 PyErr_SetString(PyExc_ValueError, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1933 "bad typecode (must be c, b, B, u, h, H, i, I, l, L, f or d)"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1934 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1935 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1936 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1937 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1938 PyDoc_STRVAR(module_doc, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1939 "This module defines an object type which can efficiently represent\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1940 an array of basic values: characters, integers, floating point\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1941 numbers. Arrays are sequence types and behave very much like lists,\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1942 except that the type of objects stored in them is constrained. The\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1943 type is specified at object creation time by using a type code, which\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1944 is a single character. The following type codes are defined:\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1945 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1946 Type code C Type Minimum size in bytes \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1947 'c' character 1 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1948 'b' signed integer 1 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1949 'B' unsigned integer 1 \n\ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1950 'u' Unicode character 2 \n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1951 'h' signed integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1952 'H' unsigned integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1953 'i' signed integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1954 'I' unsigned integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1955 'l' signed integer 4 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1956 'L' unsigned integer 4 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1957 'f' floating point 4 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1958 'd' floating point 8 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1959 \n\ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1960 The constructor is:\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1961 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1962 array(typecode [, initializer]) -- create a new array\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1963 "); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1964 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1965 PyDoc_STRVAR(arraytype_doc, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1966 "array(typecode [, initializer]) -> array\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1967 \n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1968 Return a new array whose items are restricted by typecode, and\n\ |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1969 initialized from the optional initializer value, which must be a list,\n\ |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1970 string. or iterable over elements of the appropriate type.\n\ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1971 \n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1972 Arrays represent basic values and behave very much like lists, except\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1973 the type of objects stored in them is constrained.\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1974 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1975 Methods:\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1976 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1977 append() -- append a new item to the end of the array\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1978 buffer_info() -- return information giving the current memory info\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1979 byteswap() -- byteswap all the items of the array\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1980 count() -- return number of occurences of an object\n\ |
|
31660
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31659
diff
changeset
|
1981 extend() -- extend array by appending multiple elements from an iterable\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1982 fromfile() -- read items from a file object\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1983 fromlist() -- append items from the list\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1984 fromstring() -- append items from the string\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1985 index() -- return index of first occurence of an object\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1986 insert() -- insert a new item into the array at a provided position\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1987 pop() -- remove and return item (default last)\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1988 read() -- DEPRECATED, use fromfile()\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1989 remove() -- remove first occurence of an object\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1990 reverse() -- reverse the order of the items in the array\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1991 tofile() -- write all items to a file object\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1992 tolist() -- return the array converted to an ordinary list\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1993 tostring() -- return the array converted to a string\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1994 write() -- DEPRECATED, use tofile()\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1995 \n\ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1996 Attributes:\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1997 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1998 typecode -- the typecode character used to create the array\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1999 itemsize -- the length in bytes of one array item\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
2000 "); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
2001 |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2002 static PyObject *array_iter(arrayobject *ao); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2003 |
|
24283
c0a67a1cab09
Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents:
24280
diff
changeset
|
2004 static PyTypeObject Arraytype = { |
|
11711
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
11673
diff
changeset
|
2005 PyObject_HEAD_INIT(NULL) |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
2006 0, |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
21073
diff
changeset
|
2007 "array.array", |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
2008 sizeof(arrayobject), |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
2009 0, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2010 (destructor)array_dealloc, /* tp_dealloc */ |
| 22124 | 2011 0, /* tp_print */ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2012 0, /* tp_getattr */ |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2013 0, /* tp_setattr */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2014 0, /* tp_compare */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2015 (reprfunc)array_repr, /* tp_repr */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2016 0, /* tp_as_number*/ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2017 &array_as_sequence, /* tp_as_sequence*/ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
2018 &array_as_mapping, /* tp_as_mapping*/ |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2019 0, /* tp_hash */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2020 0, /* tp_call */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2021 0, /* tp_str */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27044
diff
changeset
|
2022 PyObject_GenericGetAttr, /* tp_getattro */ |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2023 0, /* tp_setattro */ |
|
18036
a02085871c3f
Make it possible to find the use of tp_as_buffer here with a global search.
Tim Peters <tim.peters@gmail.com>
parents:
16268
diff
changeset
|
2024 &array_as_buffer, /* tp_as_buffer*/ |
|
39222
b0cdcbcc5f45
Get rid of most of the flags (in tp_flags) that keep track of various
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
2025 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2026 arraytype_doc, /* tp_doc */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2027 0, /* tp_traverse */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2028 0, /* tp_clear */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
2029 array_richcompare, /* tp_richcompare */ |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
2030 offsetof(arrayobject, weakreflist), /* tp_weaklistoffset */ |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2031 (getiterfunc)array_iter, /* tp_iter */ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2032 0, /* tp_iternext */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2033 array_methods, /* tp_methods */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2034 0, /* tp_members */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2035 array_getsets, /* tp_getset */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2036 0, /* tp_base */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2037 0, /* tp_dict */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2038 0, /* tp_descr_get */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2039 0, /* tp_descr_set */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2040 0, /* tp_dictoffset */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2041 0, /* tp_init */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27044
diff
changeset
|
2042 PyType_GenericAlloc, /* tp_alloc */ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2043 array_new, /* tp_new */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27044
diff
changeset
|
2044 PyObject_Del, /* tp_free */ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
2045 }; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
2046 |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2047 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2048 /*********************** Array Iterator **************************/ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2049 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2050 typedef struct { |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2051 PyObject_HEAD |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
2052 Py_ssize_t index; |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2053 arrayobject *ao; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
2054 PyObject * (*getitem)(struct arrayobject *, Py_ssize_t); |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2055 } arrayiterobject; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2056 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2057 static PyTypeObject PyArrayIter_Type; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2058 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2059 #define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type) |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2060 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2061 static PyObject * |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2062 array_iter(arrayobject *ao) |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2063 { |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2064 arrayiterobject *it; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2065 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2066 if (!array_Check(ao)) { |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2067 PyErr_BadInternalCall(); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2068 return NULL; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2069 } |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2070 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2071 it = PyObject_GC_New(arrayiterobject, &PyArrayIter_Type); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2072 if (it == NULL) |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2073 return NULL; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2074 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2075 Py_INCREF(ao); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2076 it->ao = ao; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2077 it->index = 0; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2078 it->getitem = ao->ob_descr->getitem; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2079 PyObject_GC_Track(it); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2080 return (PyObject *)it; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2081 } |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2082 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2083 static PyObject * |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2084 arrayiter_next(arrayiterobject *it) |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2085 { |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2086 assert(PyArrayIter_Check(it)); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2087 if (it->index < it->ao->ob_size) |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2088 return (*it->getitem)(it->ao, it->index++); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2089 return NULL; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2090 } |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2091 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2092 static void |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2093 arrayiter_dealloc(arrayiterobject *it) |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2094 { |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2095 PyObject_GC_UnTrack(it); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2096 Py_XDECREF(it->ao); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2097 PyObject_GC_Del(it); |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2098 } |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2099 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2100 static int |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2101 arrayiter_traverse(arrayiterobject *it, visitproc visit, void *arg) |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2102 { |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36882
diff
changeset
|
2103 Py_VISIT(it->ao); |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2104 return 0; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2105 } |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2106 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2107 static PyTypeObject PyArrayIter_Type = { |
|
27804
8d1b272c9e71
Patch #676837: Cygwin array module patch
Jason Tishler <jason@tishler.net>
parents:
27128
diff
changeset
|
2108 PyObject_HEAD_INIT(NULL) |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2109 0, /* ob_size */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2110 "arrayiterator", /* tp_name */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2111 sizeof(arrayiterobject), /* tp_basicsize */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2112 0, /* tp_itemsize */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2113 /* methods */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2114 (destructor)arrayiter_dealloc, /* tp_dealloc */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2115 0, /* tp_print */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2116 0, /* tp_getattr */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2117 0, /* tp_setattr */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2118 0, /* tp_compare */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2119 0, /* tp_repr */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2120 0, /* tp_as_number */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2121 0, /* tp_as_sequence */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2122 0, /* tp_as_mapping */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2123 0, /* tp_hash */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2124 0, /* tp_call */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2125 0, /* tp_str */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2126 PyObject_GenericGetAttr, /* tp_getattro */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2127 0, /* tp_setattro */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2128 0, /* tp_as_buffer */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2129 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2130 0, /* tp_doc */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2131 (traverseproc)arrayiter_traverse, /* tp_traverse */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2132 0, /* tp_clear */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2133 0, /* tp_richcompare */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2134 0, /* tp_weaklistoffset */ |
|
28320
fd5ef7003469
Renamed PyObject_GenericGetIter to PyObject_SelfIter
Raymond Hettinger <python@rcn.com>
parents:
28309
diff
changeset
|
2135 PyObject_SelfIter, /* tp_iter */ |
|
27128
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2136 (iternextfunc)arrayiter_next, /* tp_iternext */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2137 0, /* tp_methods */ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2138 }; |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2139 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2140 |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2141 /*********************** Install Module **************************/ |
|
047b6e16ab2e
SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents:
27104
diff
changeset
|
2142 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2143 /* No functions in array module. */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2144 static PyMethodDef a_methods[] = { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2145 {NULL, NULL, 0, NULL} /* Sentinel */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2146 }; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2147 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
2148 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24424
diff
changeset
|
2149 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13590
diff
changeset
|
2150 initarray(void) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2151 { |
|
22722
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
2152 PyObject *m; |
|
11711
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
11673
diff
changeset
|
2153 |
|
39536
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
2154 if (PyType_Ready(&Arraytype) < 0) |
|
8f5b9982beba
Completely get rid of PyClass and PyInstance.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
2155 return; |
|
27804
8d1b272c9e71
Patch #676837: Cygwin array module patch
Jason Tishler <jason@tishler.net>
parents:
27128
diff
changeset
|
2156 PyArrayIter_Type.ob_type = &PyType_Type; |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
2157 m = Py_InitModule3("array", a_methods, module_doc); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35449
diff
changeset
|
2158 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35449
diff
changeset
|
2159 return; |
|
22722
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
2160 |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
2161 Py_INCREF((PyObject *)&Arraytype); |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
2162 PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype); |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
2163 Py_INCREF((PyObject *)&Arraytype); |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
2164 PyModule_AddObject(m, "array", (PyObject *)&Arraytype); |
|
9362
50e0631cf117
No need to issue a fatal error if the PyDict_SetItemString fails; the
Guido van Rossum <guido@python.org>
parents:
9360
diff
changeset
|
2165 /* No need to check the error here, the caller will do that */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2166 } |
