Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r44062:66eaacec27db
Date: 2011-05-10 17:11 -0400
http://bitbucket.org/pypy/pypy/changeset/66eaacec27db/
Log: Implemented PyFile_Name, thanks timonator.
diff --git a/pypy/module/cpyext/pyfile.py b/pypy/module/cpyext/pyfile.py
--- a/pypy/module/cpyext/pyfile.py
+++ b/pypy/module/cpyext/pyfile.py
@@ -1,8 +1,7 @@
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import (
cpython_api, CONST_STRING, FILEP, build_type_checkers)
-from pypy.module.cpyext.pyobject import (
- PyObject)
+from pypy.module.cpyext.pyobject import PyObject, borrow_from
from pypy.interpreter.error import OperationError
from pypy.module._file.interp_file import W_File
@@ -66,3 +65,7 @@
space.call_method(w_p, "write", w_s)
return 0
+@cpython_api([PyObject], PyObject)
+def PyFile_Name(space, w_p):
+ """Return the name of the file specified by p as a string object."""
+ return borrow_from(w_p, space.getattr(w_p, space.wrap("name")))
\ No newline at end of file
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -47,7 +47,7 @@
allows for complicated memory sharing possibilities, but some caller may
not be able to handle all the complexity but may want to see if the
exporter will let them take a simpler view to its memory.
-
+
Some exporters may not be able to share memory in every possible way and
may need to raise errors to signal to some consumers that something is
just not possible. These errors should be a BufferError unless
@@ -55,17 +55,17 @@
exporter can use flags information to simplify how much of the
Py_buffer structure is filled in with non-default values and/or
raise an error if the object can't support a simpler view of its memory.
-
+
0 is returned on success and -1 on error.
-
+
The following table gives possible values to the flags arguments.
-
+
Flag
-
+
Description
-
+
PyBUF_SIMPLE
-
+
This is the default flag state. The returned
buffer may or may not have writable memory. The
format of the data will be assumed to be unsigned
@@ -73,14 +73,14 @@
never needs to be '|'d to the others. The exporter
will raise an error if it cannot provide such a
contiguous buffer of bytes.
-
+
PyBUF_WRITABLE
-
+
The returned buffer must be writable. If it is
not writable, then raise an error.
-
+
PyBUF_STRIDES
-
+
This implies PyBUF_ND. The returned
buffer must provide strides information (i.e. the
strides cannot be NULL). This would be used when
@@ -89,20 +89,20 @@
you can handle shape. The exporter can raise an
error if a strided representation of the data is
not possible (i.e. without the suboffsets).
-
+
PyBUF_ND
-
+
The returned buffer must provide shape
information. The memory will be assumed C-style
contiguous (last dimension varies the
fastest). The exporter may raise an error if it
cannot provide this kind of contiguous buffer. If
this is not given then shape will be NULL.
-
+
PyBUF_C_CONTIGUOUS
PyBUF_F_CONTIGUOUS
PyBUF_ANY_CONTIGUOUS
-
+
These flags indicate that the contiguity returned
buffer must be respectively, C-contiguous (last
dimension varies the fastest), Fortran contiguous
@@ -111,18 +111,18 @@
PyBUF_STRIDES and guarantee that the
strides buffer info structure will be filled in
correctly.
-
+
PyBUF_INDIRECT
-
+
This flag indicates the returned buffer must have
suboffsets information (which can be NULL if no
suboffsets are needed). This can be used when
the consumer can handle indirect array
referencing implied by these suboffsets. This
implies PyBUF_STRIDES.
-
+
PyBUF_FORMAT
-
+
The returned buffer must have true format
information if this flag is provided. This would
be used when the consumer is going to be checking
@@ -132,43 +132,43 @@
explicitly requested then the format must be
returned as NULL (which means 'B', or
unsigned bytes)
-
+
PyBUF_STRIDED
-
+
This is equivalent to (PyBUF_STRIDES |
PyBUF_WRITABLE).
-
+
PyBUF_STRIDED_RO
-
+
This is equivalent to (PyBUF_STRIDES).
-
+
PyBUF_RECORDS
-
+
This is equivalent to (PyBUF_STRIDES |
PyBUF_FORMAT | PyBUF_WRITABLE).
-
+
PyBUF_RECORDS_RO
-
+
This is equivalent to (PyBUF_STRIDES |
PyBUF_FORMAT).
-
+
PyBUF_FULL
-
+
This is equivalent to (PyBUF_INDIRECT |
PyBUF_FORMAT | PyBUF_WRITABLE).
-
+
PyBUF_FULL_RO
-
+
This is equivalent to (PyBUF_INDIRECT |
PyBUF_FORMAT).
-
+
PyBUF_CONTIG
-
+
This is equivalent to (PyBUF_ND |
PyBUF_WRITABLE).
-
+
PyBUF_CONTIG_RO
-
+
This is equivalent to (PyBUF_ND)."""
raise NotImplementedError
@@ -251,7 +251,7 @@
def PyByteArray_FromObject(space, o):
"""Return a new bytearray object from any object, o, that implements the
buffer protocol.
-
+
XXX expand about the buffer protocol, at least somewhere"""
raise NotImplementedError
@@ -354,7 +354,7 @@
@cpython_api([PyObject], rffi.INT_real, error=-1)
def PyCodec_Register(space, search_function):
"""Register a new codec search function.
-
+
As side effect, this tries to load the encodings package, if not yet
done, to make sure that it is always first in the list of search
functions."""
raise NotImplementedError
@@ -362,7 +362,7 @@
@cpython_api([PyObject, rffi.CCHARP, rffi.CCHARP], PyObject)
def PyCodec_Encode(space, object, encoding, errors):
"""Generic codec based encoding API.
-
+
object is passed through the encoder function found for the given
encoding using the error handling method defined by errors. errors may
be NULL to use the default method defined for the codec. Raises a
@@ -372,7 +372,7 @@
@cpython_api([PyObject, rffi.CCHARP, rffi.CCHARP], PyObject)
def PyCodec_Decode(space, object, encoding, errors):
"""Generic codec based decoding API.
-
+
object is passed through the decoder function found for the given
encoding using the error handling method defined by errors. errors may
be NULL to use the default method defined for the codec. Raises a
@@ -405,7 +405,7 @@
This callback function will be called by a codec when it encounters
unencodable characters/undecodable bytes and name is specified as the error
parameter in the call to the encode/decode function.
-
+
The callback gets a single argument, an instance of
UnicodeEncodeError, UnicodeDecodeError or
UnicodeTranslateError that holds information about the problematic
@@ -415,7 +415,7 @@
containing the replacement for the problematic sequence, and an integer
giving the offset in the original string at which encoding/decoding should
be
resumed.
-
+
Return 0 on success, -1 on error."""
raise NotImplementedError
@@ -500,18 +500,18 @@
the set of strings accepted by Python's float() constructor,
except that s must not have leading or trailing whitespace.
The conversion is independent of the current locale.
-
+
If endptr is NULL, convert the whole string. Raise
ValueError and return -1.0 if the string is not a valid
representation of a floating-point number.
-
+
If endptr is not NULL, convert as much of the string as
possible and set *endptr to point to the first unconverted
character. If no initial segment of the string is the valid
representation of a floating-point number, set *endptr to point
to the beginning of the string, raise ValueError, and return
-1.0.
-
+
If s represents a value that is too large to store in a float
(for example, "1e500" is such a string on many platforms) then
if overflow_exception is NULL return Py_HUGE_VAL (with
@@ -519,7 +519,7 @@
overflow_exception must point to a Python exception object;
raise that exception and return -1.0. In both cases, set
*endptr to point to the first character after the converted value.
-
+
If any other error occurs during the conversion (for example an
out-of-memory error), set the appropriate Python exception and
return -1.0.
@@ -531,12 +531,12 @@
"""Convert a string to a double. This function behaves like the Standard C
function strtod() does in the C locale. It does this without changing the
current locale, since that would not be thread-safe.
-
+
PyOS_ascii_strtod() should typically be used for reading configuration
files or other non-user input that should be locale independent.
-
+
See the Unix man page strtod(2) for details.
-
+
Use PyOS_string_to_double() instead."""
raise NotImplementedError
@@ -546,10 +546,10 @@
separator. format is a printf()-style format string specifying the
number format. Allowed conversion characters are 'e', 'E', 'f',
'F', 'g' and 'G'.
-
+
The return value is a pointer to buffer with the converted string or NULL
if
the conversion failed.
-
+
This function is removed in Python 2.7 and 3.1. Use
PyOS_double_to_string()
instead."""
raise NotImplementedError
@@ -558,29 +558,29 @@
def PyOS_double_to_string(space, val, format_code, precision, flags, ptype):
"""Convert a double val to a string using supplied
format_code, precision, and flags.
-
+
format_code must be one of 'e', 'E', 'f', 'F',
'g', 'G' or 'r'. For 'r', the supplied precision
must be 0 and is ignored. The 'r' format code specifies the
standard repr() format.
-
+
flags can be zero or more of the values Py_DTSF_SIGN,
Py_DTSF_ADD_DOT_0, or Py_DTSF_ALT, or-ed together:
-
+
Py_DTSF_SIGN means to always precede the returned string with a sign
character, even if val is non-negative.
-
+
Py_DTSF_ADD_DOT_0 means to ensure that the returned string will not look
like an integer.
-
+
Py_DTSF_ALT means to apply "alternate" formatting rules. See the
documentation for the PyOS_snprintf() '#' specifier for
details.
-
+
If ptype is non-NULL, then the value it points to will be set to one of
Py_DTST_FINITE, Py_DTST_INFINITE, or Py_DTST_NAN, signifying that
val is a finite number, an infinite number, or not a number, respectively.
-
+
The return value is a pointer to buffer with the converted string or
NULL if the conversion failed. The caller is responsible for freeing the
returned string by calling PyMem_Free().
@@ -590,9 +590,9 @@
@cpython_api([rffi.CCHARP], rffi.DOUBLE, error=CANNOT_FAIL)
def PyOS_ascii_atof(space, nptr):
"""Convert a string to a double in a locale-independent way.
-
+
See the Unix man page atof(2) for details.
-
+
Use PyOS_string_to_double() instead."""
raise NotImplementedError
@@ -683,7 +683,7 @@
override is true, else the first wins. Return 0 on success or -1
if an exception was raised. Equivalent Python (except for the return
value):
-
+
def PyDict_MergeFromSeq2(a, seq2, override):
for key, value in seq2:
if override or key not in a:
@@ -708,7 +708,7 @@
def PyErr_SetExcFromWindowsErr(space, type, ierr):
"""Similar to PyErr_SetFromWindowsErr(), with an additional parameter
specifying the exception type to be raised. Availability: Windows.
-
+
Return value: always NULL."""
raise NotImplementedError
@@ -724,7 +724,7 @@
def PyErr_SetExcFromWindowsErrWithFilename(space, type, ierr, filename):
"""Similar to PyErr_SetFromWindowsErrWithFilename(), with an additional
parameter specifying the exception type to be raised. Availability:
Windows.
-
+
Return value: always NULL."""
raise NotImplementedError
@@ -815,15 +815,15 @@
@cpython_api([rffi.CCHARP], rffi.INT_real, error=1)
def Py_EnterRecursiveCall(space, where):
"""Marks a point where a recursive C-level call is about to be performed.
-
+
If USE_STACKCHECK is defined, this function checks if the the OS
stack overflowed using PyOS_CheckStack(). In this is the case, it
sets a MemoryError and returns a nonzero value.
-
+
The function then checks if the recursion limit is reached. If this is the
case, a RuntimeError is set and a nonzero value is returned.
Otherwise, zero is returned.
-
+
where should be a string such as " in instance check" to be
concatenated to the RuntimeError message caused by the recursion depth
limit."""
@@ -843,12 +843,12 @@
Callers of this must call PyFile_DecUseCount() when they are
finished with the FILE*. Otherwise the file object will
never be closed by Python.
-
+
The GIL must be held while calling this function.
-
+
The suggested use is to call this after PyFile_AsFile() and before
you release the GIL:
-
+
FILE *fp = PyFile_AsFile(p);
PyFile_IncUseCount(p);
/* ... */
@@ -865,18 +865,12 @@
"""Decrements the PyFileObject's internal unlocked_count member to
indicate that the caller is done with its own use of the FILE*.
This may only be called to undo a prior call to PyFile_IncUseCount().
-
+
The GIL must be held while calling this function (see the example
above).
"""
raise NotImplementedError
-@cpython_api([PyObject], PyObject)
-def PyFile_Name(space, p):
- """Return the name of the file specified by p as a string object."""
- borrow_from()
- raise NotImplementedError
-
@cpython_api([PyFileObject, rffi.CCHARP], rffi.INT_real, error=0)
def PyFile_SetEncoding(space, p, enc):
"""Set the file's encoding for Unicode output to enc. Return 1 on success
and 0
@@ -944,10 +938,10 @@
def PyFloat_AsString(space, buf, v):
"""Convert the argument v to a string, using the same rules as
str(). The length of buf should be at least 100.
-
+
This function is unsafe to call because it writes to a buffer whose
length it does not know.
-
+
Use PyObject_Str() or PyOS_double_to_string() instead."""
raise NotImplementedError
@@ -955,10 +949,10 @@
def PyFloat_AsReprString(space, buf, v):
"""Same as PyFloat_AsString, except uses the same rules as
repr(). The length of buf should be at least 100.
-
+
This function is unsafe to call because it writes to a buffer whose
length it does not know.
-
+
Use PyObject_Repr() or PyOS_double_to_string() instead."""
raise NotImplementedError
@@ -966,7 +960,7 @@
def PyFunction_New(space, code, globals):
"""Return a new function object associated with the code object code.
globals
must be a dictionary with the global variables accessible to the function.
-
+
The function's docstring, name and __module__ are retrieved from the code
object, the argument defaults and closure are set to NULL."""
raise NotImplementedError
@@ -1002,7 +996,7 @@
def PyFunction_SetDefaults(space, op, defaults):
"""Set the argument default values for the function object op. defaults
must be
Py_None or a tuple.
-
+
Raises SystemError and returns -1 on failure."""
raise NotImplementedError
@@ -1017,7 +1011,7 @@
def PyFunction_SetClosure(space, op, closure):
"""Set the closure associated with the function object op. closure must be
Py_None or a tuple of cell objects.
-
+
Raises SystemError and returns -1 on failure."""
raise NotImplementedError
@@ -1025,7 +1019,7 @@
def PyObject_GC_NewVar(space, type, size):
"""Analogous to PyObject_NewVar() but for container objects with the
Py_TPFLAGS_HAVE_GC flag set.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -1034,7 +1028,7 @@
def PyObject_GC_Resize(space, op, newsize):
"""Resize an object allocated by PyObject_NewVar(). Returns the
resized object or NULL on failure.
-
+
This function used an int type for newsize. This might
require changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -1074,15 +1068,15 @@
"""Import a module. This is best described by referring to the built-in
Python function __import__(), as the standard __import__() function calls
this function directly.
-
+
The return value is a new reference to the imported module or top-level
package,
or NULL with an exception set on failure (before Python 2.4, the module may
still be created in this case). Like for __import__(), the return value
when a submodule of a package was requested is normally the top-level
package,
unless a non-empty fromlist was given.
-
+
Failing imports remove incomplete module objects.
-
+
The function is an alias for PyImport_ImportModuleLevel() with
-1 as level, meaning relative import."""
raise NotImplementedError
@@ -1092,7 +1086,7 @@
"""Import a module. This is best described by referring to the built-in
Python
function __import__(), as the standard __import__() function calls
this function directly.
-
+
The return value is a new reference to the imported module or top-level
package,
or NULL with an exception set on failure. Like for __import__(),
the return value when a submodule of a package was requested is normally
the
@@ -1120,16 +1114,16 @@
incompletely initialized modules in sys.modules is dangerous, as imports of
such modules have no way to know that the module object is an unknown (and
probably damaged with respect to the module author's intents) state.
-
+
The module's __file__ attribute will be set to the code object's
co_filename.
-
+
This function will reload the module if it was already imported. See
PyImport_ReloadModule() for the intended way to reload a module.
-
+
If name points to a dotted name of the form package.module, any package
structures not already created will still not be created.
-
+
name is removed from sys.modules in error cases."""
raise NotImplementedError
@@ -1250,7 +1244,7 @@
allocated by the Python interpreter. This is a no-op when called for a
second
time (without calling Py_Initialize() again first). There is no return
value; errors during finalization are ignored.
-
+
This function is provided for a number of reasons. An embedding
application
might want to restart Python without having to restart the application
itself.
An application that has loaded the Python interpreter from a dynamically
@@ -1258,7 +1252,7 @@
before unloading the DLL. During a hunt for memory leaks in an application
a
developer might want to free all memory allocated by Python before exiting
from
the application.
-
+
Bugs and caveats: The destruction of modules and objects in modules is done
in random order; this may cause destructors (__del__() methods) to fail
when they depend on other objects (even functions) or modules. Dynamically
@@ -1308,13 +1302,13 @@
variable in the top-level Makefile and the --exec-prefix
argument to the configure script at build time. The value is
available to Python code as sys.exec_prefix. It is only useful on Unix.
-
+
Background: The exec-prefix differs from the prefix when platform dependent
files (such as executables and shared libraries) are installed in a
different
directory tree. In a typical installation, platform dependent files may be
installed in the /usr/local/plat subtree while platform independent may
be installed in /usr/local.
-
+
Generally speaking, a platform is a combination of hardware and software
families, e.g. Sparc machines running the Solaris 2.x operating system are
considered the same platform, but Intel machines running Solaris 2.x are
another
@@ -1325,7 +1319,7 @@
meaningless, and set to the empty string. Note that compiled Python
bytecode
files are platform independent (but not independent from the Python
version by
which they were compiled!).
-
+
System administrators will know how to configure the mount or
automount programs to share /usr/local between platforms
while having /usr/local/plat be a different filesystem for each
@@ -1351,7 +1345,7 @@
storage; the caller should not modify its value. The list sys.path is
initialized with this value on interpreter startup; it can be (and usually
is) modified later to change the search path for loading modules.
-
+
XXX should give the exact rules"""
raise NotImplementedError
@@ -1359,9 +1353,9 @@
def Py_GetVersion(space):
"""Return the version of this Python interpreter. This is a string that
looks
something like
-
+
"1.5 (\#67, Dec 31 1997, 22:34:28) [GCC 2.7.2.2]"
-
+
The first word (up to the first space character) is the current Python
version;
the first three characters are the major and minor version separated by a
period. The returned string points into static storage; the caller should
not
@@ -1382,9 +1376,9 @@
@cpython_api([], rffi.CCHARP)
def Py_GetCopyright(space):
"""Return the official copyright string for the current Python version,
for example
-
+
'Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam'
-
+
The returned string points into static storage; the caller should not
modify its
value. The value is available to Python code as sys.copyright."""
raise NotImplementedError
@@ -1393,9 +1387,9 @@
def Py_GetCompiler(space):
"""Return an indication of the compiler used to build the current Python
version,
in square brackets, for example:
-
+
"[GCC 2.7.2.2]"
-
+
The returned string points into static storage; the caller should not
modify its
value. The value is available to Python code as part of the variable
sys.version."""
@@ -1405,9 +1399,9 @@
def Py_GetBuildInfo(space):
"""Return information about the sequence number and build date and time
of the
current Python interpreter instance, for example
-
+
"\#67, Aug 1 1997, 22:34:28"
-
+
The returned string points into static storage; the caller should not
modify its
value. The value is available to Python code as part of the variable
sys.version."""
@@ -1422,31 +1416,31 @@
will be run, the first entry in argv can be an empty string. If this
function fails to initialize sys.argv, a fatal condition is signalled using
Py_FatalError().
-
+
If updatepath is zero, this is all the function does. If updatepath
is non-zero, the function also modifies sys.path according to the
following algorithm:
-
+
If the name of an existing script is passed in argv[0], the absolute
path of the directory where the script is located is prepended to
sys.path.
-
+
Otherwise (that is, if argc is 0 or argv[0] doesn't point
to an existing file name), an empty string is prepended to
sys.path, which is the same as prepending the current working
directory (".").
-
+
It is recommended that applications embedding the Python interpreter
for purposes other than executing a single script pass 0 as updatepath,
and update sys.path themselves if desired.
See CVE-2008-5983.
-
+
On versions before 2.6.6, you can achieve the same effect by manually
popping the first sys.path element after having called
PySys_SetArgv(), for example using:
-
+
PyRun_SimpleString("import sys; sys.path.pop(0)\n");
-
+
XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
check w/ Guido."""
raise NotImplementedError
@@ -1461,7 +1455,7 @@
"""Set the default "home" directory, that is, the location of the standard
Python libraries. See PYTHONHOME for the meaning of the
argument string.
-
+
The argument should point to a zero-terminated character string in static
storage whose contents will not change for the duration of the program's
execution. No code in the Python interpreter will change the contents of
@@ -1509,7 +1503,7 @@
the dictionary. It is okay to call this function when no current thread
state
is available. If this function returns NULL, no exception has been raised
and
the caller should assume no current thread state is available.
-
+
Previously this could only be called when a current thread is active, and
NULL
meant that an exception was raised."""
borrow_from()
@@ -1531,7 +1525,7 @@
def PyEval_AcquireLock(space):
"""Acquire the global interpreter lock. The lock must have been created
earlier.
If this thread already has the lock, a deadlock ensues.
-
+
This function does not change the current thread state. Please use
PyEval_RestoreThread() or PyEval_AcquireThread()
instead."""
@@ -1540,7 +1534,7 @@
@cpython_api([], lltype.Void)
def PyEval_ReleaseLock(space):
"""Release the global interpreter lock. The lock must have been created
earlier.
-
+
This function does not change the current thread state. Please use
PyEval_SaveThread() or PyEval_ReleaseThread()
instead."""
@@ -1556,7 +1550,7 @@
separate. The new environment has no sys.argv variable. It has new
standard
I/O stream file objects sys.stdin, sys.stdout and sys.stderr (however these
refer to the same underlying file descriptors).
-
+
The return value points to the first thread state created in the new
sub-interpreter. This thread state is made in the current thread state.
Note that no actual thread is created; see the discussion of thread states
@@ -1567,7 +1561,7 @@
calling this function and is still held when it returns; however, unlike
most
other Python/C API functions, there needn't be a current thread state on
entry.)
-
+
Extension modules are shared between (sub-)interpreters as follows: the
first
time a particular extension is imported, it is initialized normally, and a
(shallow) copy of its module's dictionary is squirreled away. When the
same
@@ -1601,11 +1595,11 @@
asynchronous notification recursively, but it can still be interrupted to
switch threads if the global interpreter lock is released, for example, if
it
calls back into Python code.
-
+
This function returns 0 on success in which case the notification has been
scheduled. Otherwise, for example if the notification buffer is full, it
returns -1 without setting any exception.
-
+
This function can be called on any thread, be it a Python thread or some
other system thread. If it is a Python thread, it doesn't matter if it
holds
the global interpreter lock or not.
@@ -1633,62 +1627,62 @@
def PyEval_GetCallStats(space, self):
"""Return a tuple of function call counts. There are constants defined
for the
positions within the tuple:
-
+
Name
-
+
Value
-
+
PCALL_ALL
-
+
0
-
+
PCALL_FUNCTION
-
+
1
-
+
PCALL_FAST_FUNCTION
-
+
2
-
+
PCALL_FASTER_FUNCTION
-
+
3
-
+
PCALL_METHOD
-
+
4
-
+
PCALL_BOUND_METHOD
-
+
5
-
+
PCALL_CFUNCTION
-
+
6
-
+
PCALL_TYPE
-
+
7
-
+
PCALL_GENERATOR
-
+
8
-
+
PCALL_OTHER
-
+
9
-
+
PCALL_POP
-
+
10
-
+
PCALL_FAST_FUNCTION means no argument tuple needs to be created.
PCALL_FASTER_FUNCTION means that the fast-path frame setup code is used.
-
+
If there is a method call where the call can be optimized by changing
the argument tuple and calling the function directly, it gets recorded
twice.
-
+
This function is only present if Python is compiled with CALL_PROFILE
defined."""
raise NotImplementedError
@@ -1747,7 +1741,7 @@
and high. Return NULL and set an exception if unsuccessful. Analogous
to list[low:high]. Negative indices, as when slicing from Python, are not
supported.
-
+
This function used an int for low and high. This might
require changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -1773,7 +1767,7 @@
gives the number of characters, and base is the radix for the conversion.
The
radix must be in the range [2, 36]; if it is out of range, ValueError
will be raised.
-
+
This function used an int for length. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -1803,21 +1797,21 @@
"""Marshal a long integer, value, to file. This will only write
the least-significant 32 bits of value; regardless of the size of the
native long type.
-
+
version indicates the file format."""
raise NotImplementedError
@cpython_api([PyObject, FILE, rffi.INT_real], lltype.Void)
def PyMarshal_WriteObjectToFile(space, value, file, version):
"""Marshal a Python object, value, to file.
-
+
version indicates the file format."""
raise NotImplementedError
@cpython_api([PyObject, rffi.INT_real], PyObject)
def PyMarshal_WriteObjectToString(space, value, version):
"""Return a string object containing the marshalled representation of
value.
-
+
version indicates the file format."""
raise NotImplementedError
@@ -1860,7 +1854,7 @@
containing len bytes pointed to by string. On error, sets the
appropriate exception (EOFError or TypeError) and returns
NULL.
-
+
This function used an int type for len. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2012,7 +2006,7 @@
"""Return the result of repeating sequence object o count times, or NULL on
failure. The operation is done in-place when o supports it. This is the
equivalent of the Python expression o *= count.
-
+
This function used an int type for count. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2022,7 +2016,7 @@
"""Return the number of occurrences of value in o, that is, return the
number
of keys for which o[key] == value. On failure, return -1. This is
equivalent to the Python expression o.count(value).
-
+
This function returned an int type. This might require changes
in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2031,7 +2025,7 @@
def PySequence_Index(space, o, value):
"""Return the first index i for which o[i] == value. On error, return
-1. This is equivalent to the Python expression o.index(value).
-
+
This function returned an int type. This might require changes
in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2040,7 +2034,7 @@
def PySequence_Fast_ITEMS(space, o):
"""Return the underlying array of PyObject pointers. Assumes that o was
returned
by PySequence_Fast() and o is not NULL.
-
+
Note, if a list gets resized, the reallocation may relocate the items
array.
So, only use the underlying array pointer in contexts where the sequence
cannot change.
@@ -2053,7 +2047,7 @@
PySequence_GetItem() but without checking that
PySequence_Check(o)() is true and without adjustment for negative
indices.
-
+
This function used an int type for i. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2104,7 +2098,7 @@
The iterable may be NULL to create a new empty frozenset. Return the new
set on success or NULL on failure. Raise TypeError if iterable is
not actually iterable.
-
+
Now guaranteed to return a brand-new frozenset. Formerly,
frozensets of zero-length were a singleton. This got in the way of
building-up new frozensets with PySet_Add()."""
@@ -2115,7 +2109,7 @@
"""Return the length of a set or frozenset object. Equivalent to
len(anyset). Raises a PyExc_SystemError if anyset is not a set, frozenset,
or an instance of a subtype.
-
+
This function returned an int. This might require changes in
your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2141,7 +2135,7 @@
the key is unhashable. Raise a MemoryError if there is no room to grow.
Raise a SystemError if set is an not an instance of set or its
subtype.
-
+
Now works with instances of frozenset or its subtypes.
Like PyTuple_SetItem() in that it can be used to fill-in the
values of brand new frozensets before they are exposed to other code."""
@@ -2181,7 +2175,7 @@
though there is a lot of talk about reference counts, think of this
function as
reference-count-neutral; you own the object after the call if and only if
you
owned it before the call.)
-
+
This function is not available in 3.x and does not have a PyBytes alias."""
raise NotImplementedError
@@ -2192,9 +2186,9 @@
as the parameters of the same name in the unicode() built-in function.
The codec to be used is looked up using the Python codec registry. Return
NULL if an exception was raised by the codec.
-
+
This function is not available in 3.x and does not have a PyBytes alias.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2206,7 +2200,7 @@
meaning as the parameters of the same name in the string encode() method.
The codec to be used is looked up using the Python codec registry. Return
NULL
if an exception was raised by the codec.
-
+
This function is not available in 3.x and does not have a PyBytes alias."""
raise NotImplementedError
@@ -2217,9 +2211,9 @@
have the same meaning as the parameters of the same name in the string
encode() method. The codec to be used is looked up using the Python codec
registry. Return NULL if an exception was raised by the codec.
-
+
This function is not available in 3.x and does not have a PyBytes alias.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2296,7 +2290,7 @@
def PyTuple_GetSlice(space, p, low, high):
"""Take a slice of the tuple pointed to by p from low to high and return it
as a new tuple.
-
+
This function used an int type for low and high. This might
require changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2384,93 +2378,93 @@
a string with the values formatted into it. The variable arguments must
be C
types and must correspond exactly to the format characters in the format
string. The following format characters are allowed:
-
+
Format Characters
-
+
Type
-
+
Comment
-
+
%%
-
+
n/a
-
+
The literal % character.
-
+
%c
-
+
int
-
+
A single character,
represented as an C int.
-
+
%d
-
+
int
-
+
Exactly equivalent to
printf("%d").
-
+
%u
-
+
unsigned int
-
+
Exactly equivalent to
printf("%u").
-
+
%ld
-
+
long
-
+
Exactly equivalent to
printf("%ld").
-
+
%lu
-
+
unsigned long
-
+
Exactly equivalent to
printf("%lu").
-
+
%zd
-
+
Py_ssize_t
-
+
Exactly equivalent to
printf("%zd").
-
+
%zu
-
+
size_t
-
+
Exactly equivalent to
printf("%zu").
-
+
%i
-
+
int
-
+
Exactly equivalent to
printf("%i").
-
+
%x
-
+
int
-
+
Exactly equivalent to
printf("%x").
-
+
%s
-
+
char*
-
+
A null-terminated C character
array.
-
+
%p
-
+
void*
-
+
The hex representation of a C
pointer. Mostly equivalent to
printf("%p") except that
@@ -2478,38 +2472,38 @@
the literal 0x regardless
of what the platform's
printf yields.
-
+
%U
-
+
PyObject*
-
+
A unicode object.
-
+
%V
-
+
PyObject*, char *
-
+
A unicode object (which may be
NULL) and a null-terminated
C character array as a second
parameter (which will be used,
if the first parameter is
NULL).
-
+
%S
-
+
PyObject*
-
+
The result of calling
PyObject_Unicode().
-
+
%R
-
+
PyObject*
-
+
The result of calling
PyObject_Repr().
-
+
An unrecognized format character causes all the rest of the format string
to be
copied as-is to the result string, and any extra arguments discarded.
"""
@@ -2529,7 +2523,7 @@
of the same name in the Unicode encode() method. The codec to be used is
looked up using the Python codec registry. Return NULL if an exception was
raised by the codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2540,7 +2534,7 @@
consumed is not NULL, trailing incomplete UTF-8 byte sequences will not be
treated as an error. Those bytes will not be decoded and the number of
bytes
that have been decoded will be stored in consumed.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2549,7 +2543,7 @@
def PyUnicode_EncodeUTF8(space, s, size, errors):
"""Encode the Py_UNICODE buffer of the given size using UTF-8 and return a
Python string object. Return NULL if an exception was raised by the codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2559,26 +2553,26 @@
"""Decode length bytes from a UTF-32 encoded buffer string and return the
corresponding Unicode object. errors (if non-NULL) defines the error
handling. It defaults to "strict".
-
+
If byteorder is non-NULL, the decoder starts decoding using the given byte
order:
-
+
*byteorder == -1: little endian
*byteorder == 0: native order
*byteorder == 1: big endian
-
+
If *byteorder is zero, and the first four bytes of the input data are a
byte order mark (BOM), the decoder switches to this byte order and the BOM
is
not copied into the resulting Unicode string. If *byteorder is -1 or
1, any byte order mark is copied to the output.
-
+
After completion, *byteorder is set to the current byte order at the end
of input data.
-
+
In a narrow build codepoints outside the BMP will be decoded as surrogate
pairs.
-
+
If byteorder is NULL, the codec starts in native order mode.
-
+
Return NULL if an exception was raised by the codec.
"""
raise NotImplementedError
@@ -2597,17 +2591,17 @@
def PyUnicode_EncodeUTF32(space, s, size, errors, byteorder):
"""Return a Python bytes object holding the UTF-32 encoded value of the
Unicode
data in s. Output is written according to the following byte order:
-
+
byteorder == -1: little endian
byteorder == 0: native byte order (writes a BOM mark)
byteorder == 1: big endian
-
+
If byteorder is 0, the output string will always start with the Unicode BOM
mark (U+FEFF). In the other two modes, no BOM mark is prepended.
-
+
If Py_UNICODE_WIDE is not defined, surrogate pairs will be output
as a single codepoint.
-
+
Return NULL if an exception was raised by the codec.
"""
raise NotImplementedError
@@ -2627,7 +2621,7 @@
trailing incomplete UTF-16 byte sequences (such as an odd number of bytes
or a
split surrogate pair) as an error. Those bytes will not be decoded and the
number of bytes that have been decoded will be stored in consumed.
-
+
This function used an int type for size and an int *
type for consumed. This might require changes in your code for
properly supporting 64-bit systems."""
@@ -2637,20 +2631,20 @@
def PyUnicode_EncodeUTF16(space, s, size, errors, byteorder):
"""Return a Python string object holding the UTF-16 encoded value of the
Unicode
data in s. Output is written according to the following byte order:
-
+
byteorder == -1: little endian
byteorder == 0: native byte order (writes a BOM mark)
byteorder == 1: big endian
-
+
If byteorder is 0, the output string will always start with the Unicode BOM
mark (U+FEFF). In the other two modes, no BOM mark is prepended.
-
+
If Py_UNICODE_WIDE is defined, a single Py_UNICODE value may get
represented as a surrogate pair. If it is not defined, each Py_UNICODE
values is interpreted as an UCS-2 character.
-
+
Return NULL if an exception was raised by the codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2681,7 +2675,7 @@
"""Encode the Py_UNICODE buffer of the given size using UTF-7 and
return a Python bytes object. Return NULL if an exception was raised by
the codec.
-
+
If base64SetO is nonzero, "Set O" (punctuation that has no otherwise
special meaning) will be encoded in base-64. If base64WhiteSpace is
nonzero, whitespace will be encoded in base-64. Both are set to zero for
the
@@ -2692,7 +2686,7 @@
def PyUnicode_DecodeUnicodeEscape(space, s, size, errors):
"""Create a Unicode object by decoding size bytes of the Unicode-Escape
encoded
string s. Return NULL if an exception was raised by the codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2702,7 +2696,7 @@
"""Encode the Py_UNICODE buffer of the given size using Unicode-Escape and
return a Python string object. Return NULL if an exception was raised by
the
codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2711,7 +2705,7 @@
def PyUnicode_DecodeRawUnicodeEscape(space, s, size, errors):
"""Create a Unicode object by decoding size bytes of the Raw-Unicode-Escape
encoded string s. Return NULL if an exception was raised by the codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2721,7 +2715,7 @@
"""Encode the Py_UNICODE buffer of the given size using Raw-Unicode-Escape
and return a Python string object. Return NULL if an exception was raised
by
the codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2737,7 +2731,7 @@
def PyUnicode_DecodeLatin1(space, s, size, errors):
"""Create a Unicode object by decoding size bytes of the Latin-1 encoded
string
s. Return NULL if an exception was raised by the codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2746,7 +2740,7 @@
def PyUnicode_EncodeLatin1(space, s, size, errors):
"""Encode the Py_UNICODE buffer of the given size using Latin-1 and return
a Python string object. Return NULL if an exception was raised by the
codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2766,9 +2760,9 @@
dictionary mapping byte or a unicode string, which is treated as a lookup
table.
Byte values greater that the length of the string and U+FFFE "characters"
are
treated as "undefined mapping".
-
+
Allowed unicode string as mapping argument.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2778,7 +2772,7 @@
"""Encode the Py_UNICODE buffer of the given size using the given
mapping object and return a Python string object. Return NULL if an
exception was raised by the codec.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2795,14 +2789,14 @@
"""Translate a Py_UNICODE buffer of the given length by applying a
character mapping table to it and return the resulting Unicode object.
Return
NULL when an exception was raised by the codec.
-
+
The mapping table must map Unicode ordinal integers to Unicode ordinal
integers or None (causing deletion of the character).
-
+
Mapping tables need only provide the __getitem__() interface; dictionaries
and sequences work well. Unmapped character ordinals (ones which cause a
LookupError) are left untouched and are copied as-is.
-
+
This function used an int type for size. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2834,7 +2828,7 @@
will be done at all whitespace substrings. Otherwise, splits occur at the
given
separator. At most maxsplit splits will be done. If negative, no limit is
set. Separators are not included in the resulting list.
-
+
This function used an int type for maxsplit. This might require
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2850,14 +2844,14 @@
def PyUnicode_Translate(space, str, table, errors):
"""Translate a string by applying a character mapping table to it and
return the
resulting Unicode object.
-
+
The mapping table must map Unicode ordinal integers to Unicode ordinal
integers
or None (causing deletion of the character).
-
+
Mapping tables need only provide the __getitem__() interface; dictionaries
and sequences work well. Unmapped character ordinals (ones which cause a
LookupError) are left untouched and are copied as-is.
-
+
errors has the usual meaning for codecs. It may be NULL which indicates to
use the default error handling."""
raise NotImplementedError
@@ -2873,7 +2867,7 @@
"""Return 1 if substr matches str*[*start:end] at the given tail end
(direction == -1 means to do a prefix match, direction == 1 a suffix
match),
0 otherwise. Return -1 if an error occurred.
-
+
This function used an int type for start and end. This
might require changes in your code for properly supporting 64-bit
systems."""
@@ -2886,7 +2880,7 @@
backward search). The return value is the index of the first match; a
value of
-1 indicates that no match was found, and -2 indicates that an error
occurred and an exception has been set.
-
+
This function used an int type for start and end. This
might require changes in your code for properly supporting 64-bit
systems."""
@@ -2896,7 +2890,7 @@
def PyUnicode_Count(space, str, substr, start, end):
"""Return the number of non-overlapping occurrences of substr in
str[start:end]. Return -1 if an error occurred.
-
+
This function returned an int type and used an int
type for start and end. This might require changes in your code for
properly supporting 64-bit systems."""
@@ -2907,7 +2901,7 @@
"""Replace at most maxcount occurrences of substr in str with replstr and
return the resulting Unicode object. maxcount == -1 means replace all
occurrences.
-
+
This function used an int type for maxcount. This might
require changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
@@ -2915,17 +2909,17 @@
@cpython_api([PyObject, PyObject, rffi.INT_real], PyObject)
def PyUnicode_RichCompare(space, left, right, op):
"""Rich compare two unicode strings and return one of the following:
-
+
NULL in case an exception was raised
-
+
Py_True or Py_False for successful comparisons
-
+
Py_NotImplemented in case the type combination is unknown
-
+
Note that Py_EQ and Py_NE comparisons can cause a
UnicodeWarning in case the conversion of the arguments to Unicode fails
with a UnicodeDecodeError.
-
+
Possible values for op are Py_GT, Py_GE, Py_EQ,
Py_NE, Py_LT, and Py_LE."""
raise NotImplementedError
@@ -2940,7 +2934,7 @@
def PyUnicode_Contains(space, container, element):
"""Check whether element is contained in container and return true or false
accordingly.
-
+
element has to coerce to a one element Unicode string. -1 is returned if
there was an error."""
raise NotImplementedError
@@ -2955,7 +2949,7 @@
value will be the integer passed to the sys.exit() function, 1 if the
interpreter exits due to an exception, or 2 if the parameter list does not
represent a valid Python command line.
-
+
Note that if an otherwise unhandled SystemError is raised, this
function will not return 1, but exit the process, as long as
Py_InspectFlag is not set."""
@@ -2995,7 +2989,7 @@
is created. Returns 0 on success or -1 if an exception was raised. If
there was an error, there is no way to get the exception information. For
the
meaning of flags, see below.
-
+
Note that if an otherwise unhandled SystemError is raised, this
function will not return -1, but exit the process, as long as
Py_InspectFlag is not set."""
@@ -3097,7 +3091,7 @@
dictionaries globals and locals with the compiler flags specified by
flags. The parameter start specifies the start token that should be used
to
parse the source code.
-
+
Returns the result of executing the code as a Python object, or NULL if an
exception was raised."""
raise NotImplementedError
diff --git a/pypy/module/cpyext/test/test_pyfile.py
b/pypy/module/cpyext/test/test_pyfile.py
--- a/pypy/module/cpyext/test/test_pyfile.py
+++ b/pypy/module/cpyext/test/test_pyfile.py
@@ -52,6 +52,13 @@
space.call_method(w_file, "close")
+ def test_file_name(self, space, api):
+ name = str(udir / "_test_file")
+ with rffi.scoped_str2charp(name) as filename:
+ with rffi.scoped_str2charp("wb") as mode:
+ w_file = api.PyFile_FromString(filename, mode)
+ assert space.str_w(api.PyFile_Name(w_file)) == name
+
@pytest.mark.xfail
def test_file_fromfile(self, space, api):
api.PyFile_Fromfile()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit