Back to index

python3.2  3.2.2
Classes | Defines | Functions | Variables
_testcapimodule.c File Reference
#include "Python.h"
#include <float.h>
#include "structmember.h"
#include "datetime.h"
#include "testcapi_long.h"

Go to the source code of this file.

Classes

struct  known_capsule
struct  all_structmembers
struct  test_structmembers

Defines

#define PY_SSIZE_T_CLEAN
#define CHECK_SIZEOF(FATNAME, TYPE)
#define NLIST   30
#define UNBIND(X)   Py_DECREF(X); (X) = NULL
#define TESTNAME   test_long_api_inner
#define TYPENAME   long
#define F_S_TO_PY   PyLong_FromLong
#define F_PY_TO_S   PyLong_AsLong
#define F_U_TO_PY   PyLong_FromUnsignedLong
#define F_PY_TO_U   PyLong_AsUnsignedLong
#define CHECK_1_FORMAT(FORMAT, TYPE)
#define CHECK_STRING(STR, expected)
#define CHECK_INVALID(STR)
#define KNOWN_CAPSULE(module, name)   { module "." name, module, name }
#define FAIL(x)   { error = (x); goto exit; }
#define CHECK_DESTRUCTOR
#define FAIL(x)
#define AddSym(d, n, f, v)   {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);}

Functions

static PyObjectraiseTestError (const char *test_name, const char *msg)
static PyObjectsizeof_error (const char *fatname, const char *typname, int expected, int got)
static PyObjecttest_config (PyObject *self)
static PyObjecttest_list_api (PyObject *self)
static int test_dict_inner (int count)
static PyObjecttest_dict_iteration (PyObject *self)
static PyObjecttest_lazy_hash_inheritance (PyObject *self)
static int broken_buffer_getbuffer (PyObject *self, Py_buffer *view, int flags)
static PyObjecttest_broken_memoryview (PyObject *self)
static PyObjectraise_test_long_error (const char *msg)
static PyObjecttest_long_api (PyObject *self)
static PyObjectgetargs_tuple (PyObject *self, PyObject *args)
static PyObjectgetargs_keywords (PyObject *self, PyObject *args, PyObject *kwargs)
static PyObjectgetargs_b (PyObject *self, PyObject *args)
static PyObjectgetargs_B (PyObject *self, PyObject *args)
static PyObjectgetargs_h (PyObject *self, PyObject *args)
static PyObjectgetargs_H (PyObject *self, PyObject *args)
static PyObjectgetargs_I (PyObject *self, PyObject *args)
static PyObjectgetargs_k (PyObject *self, PyObject *args)
static PyObjectgetargs_i (PyObject *self, PyObject *args)
static PyObjectgetargs_l (PyObject *self, PyObject *args)
static PyObjectgetargs_n (PyObject *self, PyObject *args)
static PyObjecttest_k_code (PyObject *self)
static PyObjectgetargs_s (PyObject *self, PyObject *args)
static PyObjectgetargs_s_star (PyObject *self, PyObject *args)
static PyObjectgetargs_s_hash (PyObject *self, PyObject *args)
static PyObjectgetargs_z (PyObject *self, PyObject *args)
static PyObjectgetargs_z_star (PyObject *self, PyObject *args)
static PyObjectgetargs_z_hash (PyObject *self, PyObject *args)
static PyObjectgetargs_y (PyObject *self, PyObject *args)
static PyObjectgetargs_y_star (PyObject *self, PyObject *args)
static PyObjectgetargs_y_hash (PyObject *self, PyObject *args)
static PyObjectgetargs_u (PyObject *self, PyObject *args)
static PyObjectgetargs_u_hash (PyObject *self, PyObject *args)
static PyObjectgetargs_Z (PyObject *self, PyObject *args)
static PyObjectgetargs_Z_hash (PyObject *self, PyObject *args)
static PyObjecttest_s_code (PyObject *self)
static PyObjecttest_bug_7414 (PyObject *self)
static PyObjecttest_u_code (PyObject *self)
static PyObjecttest_Z_code (PyObject *self)
static PyObjecttest_widechar (PyObject *self)
static PyObjectunicode_aswidechar (PyObject *self, PyObject *args)
static PyObjectunicode_aswidecharstring (PyObject *self, PyObject *args)
static PyObjectgetargs_w_star (PyObject *self, PyObject *args)
static PyObjecttest_empty_argparse (PyObject *self)
static PyObjectcodec_incrementalencoder (PyObject *self, PyObject *args)
static PyObjectcodec_incrementaldecoder (PyObject *self, PyObject *args)
static PyObjecttest_long_numbits (PyObject *self)
static PyObjecttest_null_strings (PyObject *self)
static PyObjectraise_exception (PyObject *self, PyObject *args)
static PyObjecttest_datetime_capi (PyObject *self, PyObject *args)
static PyObjecttest_string_from_format (PyObject *self, PyObject *args)
static PyObjecttest_unicode_compare_with_ascii (PyObject *self)
static PyObjecttest_with_docstring (PyObject *self)
static PyObjecttest_string_to_double (PyObject *self)
static void capsule_destructor (PyObject *o)
static PyObjecttest_capsule (PyObject *self, PyObject *args)
static PyObjecttraceback_print (PyObject *self, PyObject *args)
static PyObjectexception_print (PyObject *self, PyObject *args)
static PyObjectraise_memoryerror (PyObject *self)
static int failing_converter (PyObject *obj, void *arg)
static PyObjectargparsing (PyObject *o, PyObject *args)
static PyObjectcode_newempty (PyObject *self, PyObject *args)
static PyObjectmake_exception_with_doc (PyObject *self, PyObject *args, PyObject *kwargs)
static PyObjectmake_memoryview_from_NULL_pointer (PyObject *self)
static PyObjectcrash_no_current_thread (PyObject *self)
static PyObjecttest_structmembers_new (PyTypeObject *type, PyObject *args, PyObject *kwargs)
static void test_structmembers_free (PyObject *ob)
PyMODINIT_FUNC PyInit__testcapi (void)

Variables

static PyObjectTestError
static PyTypeObject _HashInheritanceTester_Type
static PyBufferProcs memoryviewtester_as_buffer
static PyTypeObject _MemoryViewTester_Type
static volatile int x
static int test_run_counter = 0
static const char * capsule_name = "capsule name"
static char * capsule_pointer = "capsule pointer"
static char * capsule_context = "capsule context"
static const char * capsule_error = NULL
static int capsule_destructor_call_count = 0
static PyObjectstr1
static PyObjectstr2
static PyMethodDef TestMethods []
static struct PyMemberDef []
static PyTypeObject test_structmembersType
static struct PyModuleDef

Class Documentation

struct known_capsule

Definition at line 1876 of file _testcapimodule.c.

Class Members
char * attribute
char * module
char * name
struct all_structmembers

Definition at line 2346 of file _testcapimodule.c.

Class Members
char bool_member
char byte_member
double double_member
float float_member
char inplace_member
int int_member
long long_member
Py_ssize_t pyssizet_member
short short_member
unsigned char ubyte_member
unsigned int uint_member
unsigned long ulong_member
unsigned short ushort_member
struct test_structmembers

Definition at line 2366 of file _testcapimodule.c.

Collaboration diagram for test_structmembers:
Class Members
PyObject_HEAD all_structmembers structmembers

Define Documentation

#define AddSym (   d,
  n,
  f,
  v 
)    {PyObject *o = f(v); PyDict_SetItemString(d, n, o); Py_DECREF(o);}

Definition at line 2344 of file _testcapimodule.c.

#define CHECK_1_FORMAT (   FORMAT,
  TYPE 
)
Value:
result = PyUnicode_FromFormat(FORMAT, (TYPE)1);                 \
    if (result == NULL)                                             \
        return NULL;                                                \
    if (Py_UNICODE_strcmp(PyUnicode_AS_UNICODE(result), one)) {     \
        msg = FORMAT " failed at 1";                                \
        goto Fail;                                                  \
    }                                                               \
    Py_DECREF(result)
Value:
if (capsule_error) { \
        FAIL(capsule_error); \
    } \
    else if (!capsule_destructor_call_count) {          \
        FAIL("destructor not called!"); \
    } \
    capsule_destructor_call_count = 0; \
#define CHECK_INVALID (   STR)
Value:
result = PyOS_string_to_double(STR, NULL, NULL);                    \
    if (result == -1.0 && PyErr_Occurred()) {                           \
        if (PyErr_ExceptionMatches(PyExc_ValueError))                   \
            PyErr_Clear();                                              \
        else                                                            \
            return NULL;                                                \
    }                                                                   \
    else {                                                              \
        msg = "conversion of " STR " didn't raise ValueError";          \
        goto fail;                                                      \
    }
#define CHECK_SIZEOF (   FATNAME,
  TYPE 
)
Value:
if (FATNAME != sizeof(TYPE)) \
                return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE))
#define CHECK_STRING (   STR,
  expected 
)
Value:
result = PyOS_string_to_double(STR, NULL, NULL);            \
    if (result == -1.0 && PyErr_Occurred())                     \
        return NULL;                                            \
    if (result != expected) {                                   \
        msg = "conversion of " STR " to float failed";          \
        goto fail;                                              \
    }
#define F_PY_TO_S   PyLong_AsLong

Definition at line 402 of file _testcapimodule.c.

Definition at line 404 of file _testcapimodule.c.

#define F_S_TO_PY   PyLong_FromLong

Definition at line 401 of file _testcapimodule.c.

Definition at line 403 of file _testcapimodule.c.

#define FAIL (   x)    { error = (x); goto exit; }
#define FAIL (   x)
Value:
{ \
        sprintf(buffer, "%s module: \"%s\" attribute: \"%s\"", \
            x, known->module, known->attribute); \
        error = buffer; \
        goto exit; \
        } \
#define KNOWN_CAPSULE (   module,
  name 
)    { module "." name, module, name }
#define NLIST   30

Definition at line 8 of file _testcapimodule.c.

#define TESTNAME   test_long_api_inner

Definition at line 399 of file _testcapimodule.c.

#define TYPENAME   long

Definition at line 400 of file _testcapimodule.c.

#define UNBIND (   X)    Py_DECREF(X); (X) = NULL

Definition at line 391 of file _testcapimodule.c.


Function Documentation

static PyObject* argparsing ( PyObject o,
PyObject args 
) [static]

Definition at line 2180 of file _testcapimodule.c.

{
    PyObject *res;
    str1 = str2 = NULL;
    if (!PyArg_ParseTuple(args, "O&O&",
                          PyUnicode_FSConverter, &str1,
                          failing_converter, &str2)) {
        if (!str2)
            /* argument converter not called? */
            return NULL;
        /* Should be 1 */
        res = PyLong_FromSsize_t(Py_REFCNT(str2));
        Py_DECREF(str2);
        PyErr_Clear();
        return res;
    }
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static int broken_buffer_getbuffer ( PyObject self,
Py_buffer view,
int  flags 
) [static]

Definition at line 292 of file _testcapimodule.c.

{
    PyErr_SetString(
        TestError,
        "test_broken_memoryview: expected error in bf_getbuffer");
    return -1;
}

Here is the call graph for this function:

static void capsule_destructor ( PyObject o) [static]

Definition at line 1863 of file _testcapimodule.c.

                                {
    capsule_destructor_call_count++;
    if (PyCapsule_GetContext(o) != capsule_context) {
        capsule_error = "context did not match in destructor!";
    } else if (PyCapsule_GetDestructor(o) != capsule_destructor) {
        capsule_error = "destructor did not match in destructor!  (woah!)";
    } else if (PyCapsule_GetName(o) != capsule_name) {
        capsule_error = "name did not match in destructor!";
    } else if (PyCapsule_GetPointer(o, capsule_name) != capsule_pointer) {
        capsule_error = "pointer did not match in destructor!";
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* code_newempty ( PyObject self,
PyObject args 
) [static]

Definition at line 2201 of file _testcapimodule.c.

{
    const char *filename;
    const char *funcname;
    int firstlineno;

    if (!PyArg_ParseTuple(args, "ssi:code_newempty",
                          &filename, &funcname, &firstlineno))
        return NULL;

    return (PyObject *)PyCode_NewEmpty(filename, funcname, firstlineno);
}

Here is the call graph for this function:

static PyObject* codec_incrementaldecoder ( PyObject self,
PyObject args 
) [static]

Definition at line 1499 of file _testcapimodule.c.

{
    const char *encoding, *errors = NULL;
    if (!PyArg_ParseTuple(args, "s|s:test_incrementaldecoder",
                          &encoding, &errors))
        return NULL;
    return PyCodec_IncrementalDecoder(encoding, errors);
}

Here is the call graph for this function:

static PyObject* codec_incrementalencoder ( PyObject self,
PyObject args 
) [static]

Definition at line 1489 of file _testcapimodule.c.

{
    const char *encoding, *errors = NULL;
    if (!PyArg_ParseTuple(args, "s|s:test_incrementalencoder",
                          &encoding, &errors))
        return NULL;
    return PyCodec_IncrementalEncoder(encoding, errors);
}

Here is the call graph for this function:

static PyObject* crash_no_current_thread ( PyObject self) [static]

Definition at line 2246 of file _testcapimodule.c.

{
    Py_BEGIN_ALLOW_THREADS
    /* Using PyThreadState_Get() directly allows the test to pass in
       !pydebug mode. However, the test only actually tests anything
       in pydebug mode, since that's where the infinite loop was in
       the first place. */
    PyThreadState_Get();
    Py_END_ALLOW_THREADS
    return NULL;
}

Here is the call graph for this function:

static PyObject* exception_print ( PyObject self,
PyObject args 
) [static]

Definition at line 2137 of file _testcapimodule.c.

{
    PyObject *value;
    PyObject *tb;

    if (!PyArg_ParseTuple(args, "O:exception_print",
                            &value))
        return NULL;
    if (!PyExceptionInstance_Check(value)) {
        PyErr_Format(PyExc_TypeError, "an exception instance is required");
        return NULL;
    }

    tb = PyException_GetTraceback(value);
    PyErr_Display((PyObject *) Py_TYPE(value), value, tb);
    Py_XDECREF(tb);

    Py_RETURN_NONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int failing_converter ( PyObject obj,
void arg 
) [static]

Definition at line 2171 of file _testcapimodule.c.

{
    /* Clone str1, then let the conversion fail. */
    assert(str1);
    str2 = str1;
    Py_INCREF(str2);
    return 0;
}

Here is the caller graph for this function:

static PyObject* getargs_b ( PyObject self,
PyObject args 
) [static]

Definition at line 859 of file _testcapimodule.c.

{
    unsigned char value;
    if (!PyArg_ParseTuple(args, "b", &value))
        return NULL;
    return PyLong_FromUnsignedLong((unsigned long)value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_B ( PyObject self,
PyObject args 
) [static]

Definition at line 868 of file _testcapimodule.c.

{
    unsigned char value;
    if (!PyArg_ParseTuple(args, "B", &value))
        return NULL;
    return PyLong_FromUnsignedLong((unsigned long)value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_h ( PyObject self,
PyObject args 
) [static]

Definition at line 877 of file _testcapimodule.c.

{
    short value;
    if (!PyArg_ParseTuple(args, "h", &value))
        return NULL;
    return PyLong_FromLong((long)value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_H ( PyObject self,
PyObject args 
) [static]

Definition at line 886 of file _testcapimodule.c.

{
    unsigned short value;
    if (!PyArg_ParseTuple(args, "H", &value))
        return NULL;
    return PyLong_FromUnsignedLong((unsigned long)value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_I ( PyObject self,
PyObject args 
) [static]

Definition at line 895 of file _testcapimodule.c.

{
    unsigned int value;
    if (!PyArg_ParseTuple(args, "I", &value))
        return NULL;
    return PyLong_FromUnsignedLong((unsigned long)value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_i ( PyObject self,
PyObject args 
) [static]

Definition at line 913 of file _testcapimodule.c.

{
    int value;
    if (!PyArg_ParseTuple(args, "i", &value))
        return NULL;
    return PyLong_FromLong((long)value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_k ( PyObject self,
PyObject args 
) [static]

Definition at line 904 of file _testcapimodule.c.

{
    unsigned long value;
    if (!PyArg_ParseTuple(args, "k", &value))
        return NULL;
    return PyLong_FromUnsignedLong(value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_keywords ( PyObject self,
PyObject args,
PyObject kwargs 
) [static]

Definition at line 840 of file _testcapimodule.c.

{
    static char *keywords[] = {"arg1","arg2","arg3","arg4","arg5", NULL};
    static char *fmt="(ii)i|(i(ii))(iii)i";
    int int_args[10]={-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords,
        &int_args[0], &int_args[1], &int_args[2], &int_args[3], &int_args[4],
        &int_args[5], &int_args[6], &int_args[7], &int_args[8], &int_args[9]))
        return NULL;
    return Py_BuildValue("iiiiiiiiii",
        int_args[0], int_args[1], int_args[2], int_args[3], int_args[4],
        int_args[5], int_args[6], int_args[7], int_args[8], int_args[9]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_l ( PyObject self,
PyObject args 
) [static]

Definition at line 922 of file _testcapimodule.c.

{
    long value;
    if (!PyArg_ParseTuple(args, "l", &value))
        return NULL;
    return PyLong_FromLong(value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_n ( PyObject self,
PyObject args 
) [static]

Definition at line 931 of file _testcapimodule.c.

{
    Py_ssize_t value;
    if (!PyArg_ParseTuple(args, "n", &value))
        return NULL;
    return PyLong_FromSsize_t(value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_s ( PyObject self,
PyObject args 
) [static]

Definition at line 1015 of file _testcapimodule.c.

{
    char *str;
    if (!PyArg_ParseTuple(args, "s", &str))
        return NULL;
    return PyBytes_FromString(str);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_s_hash ( PyObject self,
PyObject args 
) [static]

Definition at line 1036 of file _testcapimodule.c.

{
    char *str;
    Py_ssize_t size;
    if (!PyArg_ParseTuple(args, "s#", &str, &size))
        return NULL;
    return PyBytes_FromStringAndSize(str, size);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_s_star ( PyObject self,
PyObject args 
) [static]

Definition at line 1024 of file _testcapimodule.c.

{
    Py_buffer buffer;
    PyObject *bytes;
    if (!PyArg_ParseTuple(args, "s*", &buffer))
        return NULL;
    bytes = PyBytes_FromStringAndSize(buffer.buf, buffer.len);
    PyBuffer_Release(&buffer);
    return bytes;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_tuple ( PyObject self,
PyObject args 
) [static]

Definition at line 831 of file _testcapimodule.c.

{
    int a, b, c;
    if (!PyArg_ParseTuple(args, "i(ii)", &a, &b, &c))
        return NULL;
    return Py_BuildValue("iii", a, b, c);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_u ( PyObject self,
PyObject args 
) [static]

Definition at line 1119 of file _testcapimodule.c.

{
    Py_UNICODE *str;
    Py_ssize_t size;
    if (!PyArg_ParseTuple(args, "u", &str))
        return NULL;
    size = Py_UNICODE_strlen(str);
    return PyUnicode_FromUnicode(str, size);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_u_hash ( PyObject self,
PyObject args 
) [static]

Definition at line 1130 of file _testcapimodule.c.

{
    Py_UNICODE *str;
    Py_ssize_t size;
    if (!PyArg_ParseTuple(args, "u#", &str, &size))
        return NULL;
    return PyUnicode_FromUnicode(str, size);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_w_star ( PyObject self,
PyObject args 
) [static]

Definition at line 1441 of file _testcapimodule.c.

{
    Py_buffer buffer;
    PyObject *result;
    char *str;

    if (!PyArg_ParseTuple(args, "w*:getargs_w_star", &buffer))
        return NULL;

    if (2 <= buffer.len) {
        str = buffer.buf;
        str[0] = '[';
        str[buffer.len-1] = ']';
    }

    result = PyBytes_FromStringAndSize(buffer.buf, buffer.len);
    PyBuffer_Release(&buffer);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_y ( PyObject self,
PyObject args 
) [static]

Definition at line 1088 of file _testcapimodule.c.

{
    char *str;
    if (!PyArg_ParseTuple(args, "y", &str))
        return NULL;
    return PyBytes_FromString(str);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_y_hash ( PyObject self,
PyObject args 
) [static]

Definition at line 1109 of file _testcapimodule.c.

{
    char *str;
    Py_ssize_t size;
    if (!PyArg_ParseTuple(args, "y#", &str, &size))
        return NULL;
    return PyBytes_FromStringAndSize(str, size);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_y_star ( PyObject self,
PyObject args 
) [static]

Definition at line 1097 of file _testcapimodule.c.

{
    Py_buffer buffer;
    PyObject *bytes;
    if (!PyArg_ParseTuple(args, "y*", &buffer))
        return NULL;
    bytes = PyBytes_FromStringAndSize(buffer.buf, buffer.len);
    PyBuffer_Release(&buffer);
    return bytes;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_z ( PyObject self,
PyObject args 
) [static]

Definition at line 1046 of file _testcapimodule.c.

{
    char *str;
    if (!PyArg_ParseTuple(args, "z", &str))
        return NULL;
    if (str != NULL)
        return PyBytes_FromString(str);
    else
        Py_RETURN_NONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_Z ( PyObject self,
PyObject args 
) [static]

Definition at line 1140 of file _testcapimodule.c.

{
    Py_UNICODE *str;
    Py_ssize_t size;
    if (!PyArg_ParseTuple(args, "Z", &str))
        return NULL;
    if (str != NULL) {
        size = Py_UNICODE_strlen(str);
        return PyUnicode_FromUnicode(str, size);
    } else
        Py_RETURN_NONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_z_hash ( PyObject self,
PyObject args 
) [static]

Definition at line 1075 of file _testcapimodule.c.

{
    char *str;
    Py_ssize_t size;
    if (!PyArg_ParseTuple(args, "z#", &str, &size))
        return NULL;
    if (str != NULL)
        return PyBytes_FromStringAndSize(str, size);
    else
        Py_RETURN_NONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_Z_hash ( PyObject self,
PyObject args 
) [static]

Definition at line 1154 of file _testcapimodule.c.

{
    Py_UNICODE *str;
    Py_ssize_t size;
    if (!PyArg_ParseTuple(args, "Z#", &str, &size))
        return NULL;
    if (str != NULL)
        return PyUnicode_FromUnicode(str, size);
    else
        Py_RETURN_NONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* getargs_z_star ( PyObject self,
PyObject args 
) [static]

Definition at line 1058 of file _testcapimodule.c.

{
    Py_buffer buffer;
    PyObject *bytes;
    if (!PyArg_ParseTuple(args, "z*", &buffer))
        return NULL;
    if (buffer.buf != NULL)
        bytes = PyBytes_FromStringAndSize(buffer.buf, buffer.len);
    else {
        Py_INCREF(Py_None);
        bytes = Py_None;
    }
    PyBuffer_Release(&buffer);
    return bytes;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* make_exception_with_doc ( PyObject self,
PyObject args,
PyObject kwargs 
) [static]

Definition at line 2217 of file _testcapimodule.c.

{
    const char *name;
    const char *doc = NULL;
    PyObject *base = NULL;
    PyObject *dict = NULL;

    static char *kwlist[] = {"name", "doc", "base", "dict", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                    "s|sOO:make_exception_with_doc", kwlist,
                                     &name, &doc, &base, &dict))
        return NULL;

    return PyErr_NewExceptionWithDoc(name, doc, base, dict);
}

Here is the call graph for this function:

static PyObject* make_memoryview_from_NULL_pointer ( PyObject self) [static]

Definition at line 2235 of file _testcapimodule.c.

{
    Py_buffer info;
    if (PyBuffer_FillInfo(&info, NULL, NULL, 1, 1, PyBUF_FULL_RO) < 0)
        return NULL;
    return PyMemoryView_FromBuffer(&info);
}

Here is the call graph for this function:

Definition at line 2514 of file _testcapimodule.c.

{
    PyObject *m;

    m = PyModule_Create(&_testcapimodule);
    if (m == NULL)
        return NULL;

    Py_TYPE(&_HashInheritanceTester_Type)=&PyType_Type;
    Py_TYPE(&_MemoryViewTester_Type)=&PyType_Type;

    Py_TYPE(&test_structmembersType)=&PyType_Type;
    Py_INCREF(&test_structmembersType);
    /* don't use a name starting with "test", since we don't want
       test_capi to automatically call this */
    PyModule_AddObject(m, "_test_structmembersType", (PyObject *)&test_structmembersType);

    PyModule_AddObject(m, "CHAR_MAX", PyLong_FromLong(CHAR_MAX));
    PyModule_AddObject(m, "CHAR_MIN", PyLong_FromLong(CHAR_MIN));
    PyModule_AddObject(m, "UCHAR_MAX", PyLong_FromLong(UCHAR_MAX));
    PyModule_AddObject(m, "SHRT_MAX", PyLong_FromLong(SHRT_MAX));
    PyModule_AddObject(m, "SHRT_MIN", PyLong_FromLong(SHRT_MIN));
    PyModule_AddObject(m, "USHRT_MAX", PyLong_FromLong(USHRT_MAX));
    PyModule_AddObject(m, "INT_MAX",  PyLong_FromLong(INT_MAX));
    PyModule_AddObject(m, "INT_MIN",  PyLong_FromLong(INT_MIN));
    PyModule_AddObject(m, "UINT_MAX",  PyLong_FromUnsignedLong(UINT_MAX));
    PyModule_AddObject(m, "LONG_MAX", PyLong_FromLong(LONG_MAX));
    PyModule_AddObject(m, "LONG_MIN", PyLong_FromLong(LONG_MIN));
    PyModule_AddObject(m, "ULONG_MAX", PyLong_FromUnsignedLong(ULONG_MAX));
    PyModule_AddObject(m, "FLT_MAX", PyFloat_FromDouble(FLT_MAX));
    PyModule_AddObject(m, "FLT_MIN", PyFloat_FromDouble(FLT_MIN));
    PyModule_AddObject(m, "DBL_MAX", PyFloat_FromDouble(DBL_MAX));
    PyModule_AddObject(m, "DBL_MIN", PyFloat_FromDouble(DBL_MIN));
    PyModule_AddObject(m, "LLONG_MAX", PyLong_FromLongLong(PY_LLONG_MAX));
    PyModule_AddObject(m, "LLONG_MIN", PyLong_FromLongLong(PY_LLONG_MIN));
    PyModule_AddObject(m, "ULLONG_MAX", PyLong_FromUnsignedLongLong(PY_ULLONG_MAX));
    PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyLong_FromSsize_t(PY_SSIZE_T_MAX));
    PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyLong_FromSsize_t(PY_SSIZE_T_MIN));
    PyModule_AddObject(m, "SIZEOF_PYGC_HEAD", PyLong_FromSsize_t(sizeof(PyGC_Head)));
    Py_INCREF(&PyInstanceMethod_Type);
    PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type);

    TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
    Py_INCREF(TestError);
    PyModule_AddObject(m, "error", TestError);
    return m;
}

Here is the call graph for this function:

static PyObject* raise_exception ( PyObject self,
PyObject args 
) [static]

Definition at line 1564 of file _testcapimodule.c.

{
    PyObject *exc;
    PyObject *exc_args, *v;
    int num_args, i;

    if (!PyArg_ParseTuple(args, "Oi:raise_exception",
                          &exc, &num_args))
        return NULL;

    exc_args = PyTuple_New(num_args);
    if (exc_args == NULL)
        return NULL;
    for (i = 0; i < num_args; ++i) {
        v = PyLong_FromLong(i);
        if (v == NULL) {
            Py_DECREF(exc_args);
            return NULL;
        }
        PyTuple_SET_ITEM(exc_args, i, v);
    }
    PyErr_SetObject(exc, exc_args);
    Py_DECREF(exc_args);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* raise_memoryerror ( PyObject self) [static]

Definition at line 2162 of file _testcapimodule.c.

{
    PyErr_NoMemory();
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* raise_test_long_error ( const char *  msg) [static]

Definition at line 394 of file _testcapimodule.c.

{
    return raiseTestError("test_long_api", msg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* raiseTestError ( const char *  test_name,
const char *  msg 
) [static]

Definition at line 23 of file _testcapimodule.c.

{
    char buf[2048];

    if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50)
        PyErr_SetString(TestError, "internal error msg too large");
    else {
        PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg);
        PyErr_SetString(TestError, buf);
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* sizeof_error ( const char *  fatname,
const char *  typname,
int  expected,
int  got 
) [static]

Definition at line 43 of file _testcapimodule.c.

{
    char buf[1024];
    PyOS_snprintf(buf, sizeof(buf),
        "%.200s #define == %d but sizeof(%.200s) == %d",
        fatname, expected, typname, got);
    PyErr_SetString(TestError, buf);
    return (PyObject*)NULL;
}

Here is the call graph for this function:

static PyObject* test_broken_memoryview ( PyObject self) [static]

Definition at line 347 of file _testcapimodule.c.

{
    PyObject *obj = PyObject_New(PyObject, &_MemoryViewTester_Type);
    PyObject *res;

    if (obj == NULL) {
        PyErr_Clear();
        PyErr_SetString(
            TestError,
            "test_broken_memoryview: failed to create object");
        return NULL;
    }

    res = PyMemoryView_FromObject(obj);
    if (res || !PyErr_Occurred()){
        PyErr_SetString(
            TestError,
            "test_broken_memoryview: memoryview() didn't raise an Exception");
        Py_XDECREF(res);
        Py_DECREF(obj);
        return NULL;
    }

    PyErr_Clear();
    Py_DECREF(obj);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* test_bug_7414 ( PyObject self) [static]

Definition at line 1200 of file _testcapimodule.c.

{
    /* Issue #7414: for PyArg_ParseTupleAndKeywords, 'C' code wasn't being
       skipped properly in skipitem() */
    int a = 0, b = 0, result;
    char *kwlist[] = {"a", "b", NULL};
    PyObject *tuple = NULL, *dict = NULL, *b_str;

    tuple = PyTuple_New(0);
    if (tuple == NULL)
        goto failure;
    dict = PyDict_New();
    if (dict == NULL)
        goto failure;
    b_str = PyUnicode_FromString("b");
    if (b_str == NULL)
        goto failure;
    result = PyDict_SetItemString(dict, "b", b_str);
    Py_DECREF(b_str);
    if (result < 0)
        goto failure;

    result = PyArg_ParseTupleAndKeywords(tuple, dict, "|CC",
                                         kwlist, &a, &b);
    if (!result)
        goto failure;

    if (a != 0)
        return raiseTestError("test_bug_7414",
            "C format code not skipped properly");
    if (b != 'b')
        return raiseTestError("test_bug_7414",
            "C format code returned wrong value");

    Py_DECREF(dict);
    Py_DECREF(tuple);
    Py_RETURN_NONE;

  failure:
    Py_XDECREF(dict);
    Py_XDECREF(tuple);
    return NULL;
}

Here is the call graph for this function:

static PyObject* test_capsule ( PyObject self,
PyObject args 
) [static]

Definition at line 1883 of file _testcapimodule.c.

{
    PyObject *object;
    const char *error = NULL;
    void *pointer;
    void *pointer2;
    known_capsule known_capsules[] = {
        #define KNOWN_CAPSULE(module, name)             { module "." name, module, name }
        KNOWN_CAPSULE("_socket", "CAPI"),
        KNOWN_CAPSULE("_curses", "_C_API"),
        KNOWN_CAPSULE("datetime", "datetime_CAPI"),
        { NULL, NULL },
    };
    known_capsule *known = &known_capsules[0];

#define FAIL(x) { error = (x); goto exit; }

#define CHECK_DESTRUCTOR \
    if (capsule_error) { \
        FAIL(capsule_error); \
    } \
    else if (!capsule_destructor_call_count) {          \
        FAIL("destructor not called!"); \
    } \
    capsule_destructor_call_count = 0; \

    object = PyCapsule_New(capsule_pointer, capsule_name, capsule_destructor);
    PyCapsule_SetContext(object, capsule_context);
    capsule_destructor(object);
    CHECK_DESTRUCTOR;
    Py_DECREF(object);
    CHECK_DESTRUCTOR;

    object = PyCapsule_New(known, "ignored", NULL);
    PyCapsule_SetPointer(object, capsule_pointer);
    PyCapsule_SetName(object, capsule_name);
    PyCapsule_SetDestructor(object, capsule_destructor);
    PyCapsule_SetContext(object, capsule_context);
    capsule_destructor(object);
    CHECK_DESTRUCTOR;
    /* intentionally access using the wrong name */
    pointer2 = PyCapsule_GetPointer(object, "the wrong name");
    if (!PyErr_Occurred()) {
        FAIL("PyCapsule_GetPointer should have failed but did not!");
    }
    PyErr_Clear();
    if (pointer2) {
        if (pointer2 == capsule_pointer) {
            FAIL("PyCapsule_GetPointer should not have"
                     " returned the internal pointer!");
        } else {
            FAIL("PyCapsule_GetPointer should have "
                     "returned NULL pointer but did not!");
        }
    }
    PyCapsule_SetDestructor(object, NULL);
    Py_DECREF(object);
    if (capsule_destructor_call_count) {
        FAIL("destructor called when it should not have been!");
    }

    for (known = &known_capsules[0]; known->module != NULL; known++) {
        /* yeah, ordinarily I wouldn't do this either,
           but it's fine for this test harness.
        */
        static char buffer[256];
#undef FAIL
#define FAIL(x) \
        { \
        sprintf(buffer, "%s module: \"%s\" attribute: \"%s\"", \
            x, known->module, known->attribute); \
        error = buffer; \
        goto exit; \
        } \

        PyObject *module = PyImport_ImportModule(known->module);
        if (module) {
            pointer = PyCapsule_Import(known->name, 0);
            if (!pointer) {
                Py_DECREF(module);
                FAIL("PyCapsule_GetPointer returned NULL unexpectedly!");
            }
            object = PyObject_GetAttrString(module, known->attribute);
            if (!object) {
                Py_DECREF(module);
                return NULL;
            }
            pointer2 = PyCapsule_GetPointer(object,
                                    "weebles wobble but they don't fall down");
            if (!PyErr_Occurred()) {
                Py_DECREF(object);
                Py_DECREF(module);
                FAIL("PyCapsule_GetPointer should have failed but did not!");
            }
            PyErr_Clear();
            if (pointer2) {
                Py_DECREF(module);
                Py_DECREF(object);
                if (pointer2 == pointer) {
                    FAIL("PyCapsule_GetPointer should not have"
                             " returned its internal pointer!");
                } else {
                    FAIL("PyCapsule_GetPointer should have"
                             " returned NULL pointer but did not!");
                }
            }
            Py_DECREF(object);
            Py_DECREF(module);
        }
        else
            PyErr_Clear();
    }

  exit:
    if (error) {
        return raiseTestError("test_capsule", error);
    }
    Py_RETURN_NONE;
#undef FAIL
}

Here is the call graph for this function:

static PyObject* test_config ( PyObject self) [static]

Definition at line 55 of file _testcapimodule.c.

{
#define CHECK_SIZEOF(FATNAME, TYPE) \
            if (FATNAME != sizeof(TYPE)) \
                return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE))

    CHECK_SIZEOF(SIZEOF_SHORT, short);
    CHECK_SIZEOF(SIZEOF_INT, int);
    CHECK_SIZEOF(SIZEOF_LONG, long);
    CHECK_SIZEOF(SIZEOF_VOID_P, void*);
    CHECK_SIZEOF(SIZEOF_TIME_T, time_t);
#ifdef HAVE_LONG_LONG
    CHECK_SIZEOF(SIZEOF_LONG_LONG, PY_LONG_LONG);
#endif

#undef CHECK_SIZEOF

    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject* test_datetime_capi ( PyObject self,
PyObject args 
) [static]

Definition at line 1594 of file _testcapimodule.c.

                                                   {
    if (PyDateTimeAPI) {
        if (test_run_counter) {
            /* Probably regrtest.py -R */
            Py_RETURN_NONE;
        }
        else {
            PyErr_SetString(PyExc_AssertionError,
                            "PyDateTime_CAPI somehow initialized");
            return NULL;
        }
    }
    test_run_counter++;
    PyDateTime_IMPORT;
    if (PyDateTimeAPI)
        Py_RETURN_NONE;
    else
        return NULL;
}

Here is the call graph for this function:

static int test_dict_inner ( int  count) [static]

Definition at line 120 of file _testcapimodule.c.

{
    Py_ssize_t pos = 0, iterations = 0;
    int i;
    PyObject *dict = PyDict_New();
    PyObject *v, *k;

    if (dict == NULL)
        return -1;

    for (i = 0; i < count; i++) {
        v = PyLong_FromLong(i);
        PyDict_SetItem(dict, v, v);
        Py_DECREF(v);
    }

    while (PyDict_Next(dict, &pos, &k, &v)) {
        PyObject *o;
        iterations++;

        i = PyLong_AS_LONG(v) + 1;
        o = PyLong_FromLong(i);
        if (o == NULL)
            return -1;
        if (PyDict_SetItem(dict, k, o) < 0) {
            Py_DECREF(o);
            return -1;
        }
        Py_DECREF(o);
    }

    Py_DECREF(dict);

    if (iterations != count) {
        PyErr_SetString(
            TestError,
            "test_dict_iteration: dict iteration went wrong ");
        return -1;
    } else {
        return 0;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* test_dict_iteration ( PyObject self) [static]

Definition at line 164 of file _testcapimodule.c.

{
    int i;

    for (i = 0; i < 200; i++) {
        if (test_dict_inner(i) < 0) {
            return NULL;
        }
    }

    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* test_empty_argparse ( PyObject self) [static]

Definition at line 1463 of file _testcapimodule.c.

{
    /* Test that formats can begin with '|'. See issue #4720. */
    PyObject *tuple, *dict = NULL;
    static char *kwlist[] = {NULL};
    int result;
    tuple = PyTuple_New(0);
    if (!tuple)
        return NULL;
    if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0)
        goto done;
    dict = PyDict_New();
    if (!dict)
        goto done;
    result = PyArg_ParseTupleAndKeywords(tuple, dict, "|:test_empty_argparse", kwlist);
  done:
    Py_DECREF(tuple);
    Py_XDECREF(dict);
    if (result < 0)
        return NULL;
    else {
        Py_RETURN_NONE;
    }
}

Here is the call graph for this function:

static PyObject* test_k_code ( PyObject self) [static]

Definition at line 962 of file _testcapimodule.c.

{
    PyObject *tuple, *num;
    unsigned long value;

    tuple = PyTuple_New(1);
    if (tuple == NULL)
        return NULL;

    /* a number larger than ULONG_MAX even on 64-bit platforms */
    num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
    if (num == NULL)
        return NULL;

    value = PyLong_AsUnsignedLongMask(num);
    if (value != ULONG_MAX)
        return raiseTestError("test_k_code",
        "PyLong_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");

    PyTuple_SET_ITEM(tuple, 0, num);

    value = 0;
    if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0)
        return NULL;
    if (value != ULONG_MAX)
        return raiseTestError("test_k_code",
            "k code returned wrong value for long 0xFFF...FFF");

    Py_DECREF(num);
    num = PyLong_FromString("-FFFFFFFF000000000000000042", NULL, 16);
    if (num == NULL)
        return NULL;

    value = PyLong_AsUnsignedLongMask(num);
    if (value != (unsigned long)-0x42)
        return raiseTestError("test_k_code",
        "PyLong_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");

    PyTuple_SET_ITEM(tuple, 0, num);

    value = 0;
    if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0)
        return NULL;
    if (value != (unsigned long)-0x42)
        return raiseTestError("test_k_code",
            "k code returned wrong value for long -0xFFF..000042");

    Py_DECREF(tuple);
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* test_lazy_hash_inheritance ( PyObject self) [static]

Definition at line 224 of file _testcapimodule.c.

{
    PyTypeObject *type;
    PyObject *obj;
    Py_hash_t hash;

    type = &_HashInheritanceTester_Type;

    if (type->tp_dict != NULL)
        /* The type has already been initialized. This probably means
           -R is being used. */
        Py_RETURN_NONE;


    obj = PyObject_New(PyObject, type);
    if (obj == NULL) {
        PyErr_Clear();
        PyErr_SetString(
            TestError,
            "test_lazy_hash_inheritance: failed to create object");
        return NULL;
    }

    if (type->tp_dict != NULL) {
        PyErr_SetString(
            TestError,
            "test_lazy_hash_inheritance: type initialised too soon");
        Py_DECREF(obj);
        return NULL;
    }

    hash = PyObject_Hash(obj);
    if ((hash == -1) && PyErr_Occurred()) {
        PyErr_Clear();
        PyErr_SetString(
            TestError,
            "test_lazy_hash_inheritance: could not hash object");
        Py_DECREF(obj);
        return NULL;
    }

    if (type->tp_dict == NULL) {
        PyErr_SetString(
            TestError,
            "test_lazy_hash_inheritance: type not initialised by hash()");
        Py_DECREF(obj);
        return NULL;
    }

    if (type->tp_hash != PyType_Type.tp_hash) {
        PyErr_SetString(
            TestError,
            "test_lazy_hash_inheritance: unexpected hash function");
        Py_DECREF(obj);
        return NULL;
    }

    Py_DECREF(obj);

    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* test_list_api ( PyObject self) [static]

Definition at line 77 of file _testcapimodule.c.

{
    PyObject* list;
    int i;

    /* SF bug 132008:  PyList_Reverse segfaults */
#define NLIST 30
    list = PyList_New(NLIST);
    if (list == (PyObject*)NULL)
        return (PyObject*)NULL;
    /* list = range(NLIST) */
    for (i = 0; i < NLIST; ++i) {
        PyObject* anint = PyLong_FromLong(i);
        if (anint == (PyObject*)NULL) {
            Py_DECREF(list);
            return (PyObject*)NULL;
        }
        PyList_SET_ITEM(list, i, anint);
    }
    /* list.reverse(), via PyList_Reverse() */
    i = PyList_Reverse(list);   /* should not blow up! */
    if (i != 0) {
        Py_DECREF(list);
        return (PyObject*)NULL;
    }
    /* Check that list == range(29, -1, -1) now */
    for (i = 0; i < NLIST; ++i) {
        PyObject* anint = PyList_GET_ITEM(list, i);
        if (PyLong_AS_LONG(anint) != NLIST-1-i) {
            PyErr_SetString(TestError,
                            "test_list_api: reverse screwed up");
            Py_DECREF(list);
            return (PyObject*)NULL;
        }
    }
    Py_DECREF(list);
#undef NLIST

    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* test_long_api ( PyObject self) [static]

Definition at line 409 of file _testcapimodule.c.

Here is the call graph for this function:

static PyObject* test_long_numbits ( PyObject self) [static]

Definition at line 1511 of file _testcapimodule.c.

{
    struct triple {
        long input;
        size_t nbits;
        int sign;
    } testcases[] = {{0, 0, 0},
                     {1L, 1, 1},
                     {-1L, 1, -1},
                     {2L, 2, 1},
                     {-2L, 2, -1},
                     {3L, 2, 1},
                     {-3L, 2, -1},
                     {4L, 3, 1},
                     {-4L, 3, -1},
                     {0x7fffL, 15, 1},          /* one Python long digit */
             {-0x7fffL, 15, -1},
             {0xffffL, 16, 1},
             {-0xffffL, 16, -1},
             {0xfffffffL, 28, 1},
             {-0xfffffffL, 28, -1}};
    int i;

    for (i = 0; i < sizeof(testcases) / sizeof(struct triple); ++i) {
        PyObject *plong = PyLong_FromLong(testcases[i].input);
        size_t nbits = _PyLong_NumBits(plong);
        int sign = _PyLong_Sign(plong);

        Py_DECREF(plong);
        if (nbits != testcases[i].nbits)
            return raiseTestError("test_long_numbits",
                            "wrong result for _PyLong_NumBits");
        if (sign != testcases[i].sign)
            return raiseTestError("test_long_numbits",
                            "wrong result for _PyLong_Sign");
    }
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* test_null_strings ( PyObject self) [static]

Definition at line 1554 of file _testcapimodule.c.

{
    PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Str(NULL);
    PyObject *tuple = PyTuple_Pack(2, o1, o2);
    Py_XDECREF(o1);
    Py_XDECREF(o2);
    return tuple;
}

Here is the call graph for this function:

static PyObject* test_s_code ( PyObject self) [static]

Definition at line 1169 of file _testcapimodule.c.

{
    /* Unicode strings should be accepted */
    PyObject *tuple, *obj;
    char *value;

    tuple = PyTuple_New(1);
    if (tuple == NULL)
    return NULL;

    obj = PyUnicode_Decode("t\xeate", strlen("t\xeate"),
                           "latin-1", NULL);
    if (obj == NULL)
    return NULL;

    PyTuple_SET_ITEM(tuple, 0, obj);

    /* These two blocks used to raise a TypeError:
     * "argument must be string without null bytes, not str"
     */
    if (PyArg_ParseTuple(tuple, "s:test_s_code1", &value) < 0)
    return NULL;

    if (PyArg_ParseTuple(tuple, "z:test_s_code2", &value) < 0)
    return NULL;

    Py_DECREF(tuple);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* test_string_from_format ( PyObject self,
PyObject args 
) [static]

Definition at line 1740 of file _testcapimodule.c.

{
    PyObject *result;
    char *msg;
    static const Py_UNICODE one[] = {'1', 0};

#define CHECK_1_FORMAT(FORMAT, TYPE)                                \
    result = PyUnicode_FromFormat(FORMAT, (TYPE)1);                 \
    if (result == NULL)                                             \
        return NULL;                                                \
    if (Py_UNICODE_strcmp(PyUnicode_AS_UNICODE(result), one)) {     \
        msg = FORMAT " failed at 1";                                \
        goto Fail;                                                  \
    }                                                               \
    Py_DECREF(result)

    CHECK_1_FORMAT("%d", int);
    CHECK_1_FORMAT("%ld", long);
    /* The z width modifier was added in Python 2.5. */
    CHECK_1_FORMAT("%zd", Py_ssize_t);

    /* The u type code was added in Python 2.5. */
    CHECK_1_FORMAT("%u", unsigned int);
    CHECK_1_FORMAT("%lu", unsigned long);
    CHECK_1_FORMAT("%zu", size_t);

    /* "%lld" and "%llu" support added in Python 2.7. */
#ifdef HAVE_LONG_LONG
    CHECK_1_FORMAT("%llu", unsigned PY_LONG_LONG);
    CHECK_1_FORMAT("%lld", PY_LONG_LONG);
#endif

    Py_RETURN_NONE;

 Fail:
    Py_XDECREF(result);
    return raiseTestError("test_string_from_format", msg);

#undef CHECK_1_FORMAT
}

Here is the call graph for this function:

static PyObject* test_string_to_double ( PyObject self) [static]

Definition at line 1807 of file _testcapimodule.c.

                                      {
    double result;
    char *msg;

#define CHECK_STRING(STR, expected)                             \
    result = PyOS_string_to_double(STR, NULL, NULL);            \
    if (result == -1.0 && PyErr_Occurred())                     \
        return NULL;                                            \
    if (result != expected) {                                   \
        msg = "conversion of " STR " to float failed";          \
        goto fail;                                              \
    }

#define CHECK_INVALID(STR)                                              \
    result = PyOS_string_to_double(STR, NULL, NULL);                    \
    if (result == -1.0 && PyErr_Occurred()) {                           \
        if (PyErr_ExceptionMatches(PyExc_ValueError))                   \
            PyErr_Clear();                                              \
        else                                                            \
            return NULL;                                                \
    }                                                                   \
    else {                                                              \
        msg = "conversion of " STR " didn't raise ValueError";          \
        goto fail;                                                      \
    }

    CHECK_STRING("0.1", 0.1);
    CHECK_STRING("1.234", 1.234);
    CHECK_STRING("-1.35", -1.35);
    CHECK_STRING(".1e01", 1.0);
    CHECK_STRING("2.e-2", 0.02);

    CHECK_INVALID(" 0.1");
    CHECK_INVALID("\t\n-3");
    CHECK_INVALID(".123 ");
    CHECK_INVALID("3\n");
    CHECK_INVALID("123abc");

    Py_RETURN_NONE;
  fail:
    return raiseTestError("test_string_to_double", msg);
#undef CHECK_STRING
#undef CHECK_INVALID
}

Here is the call graph for this function:

static void test_structmembers_free ( PyObject ob) [static]

Definition at line 2453 of file _testcapimodule.c.

{
    PyObject_FREE(ob);
}
static PyObject* test_structmembers_new ( PyTypeObject type,
PyObject args,
PyObject kwargs 
) [static]

Definition at line 2394 of file _testcapimodule.c.

{
    static char *keywords[] = {
        "T_BOOL", "T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT",
        "T_INT", "T_UINT", "T_LONG", "T_ULONG", "T_PYSSIZET",
        "T_FLOAT", "T_DOUBLE", "T_STRING_INPLACE",
#ifdef HAVE_LONG_LONG
        "T_LONGLONG", "T_ULONGLONG",
#endif
        NULL};
    static char *fmt = "|bbBhHiIlknfds#"
#ifdef HAVE_LONG_LONG
        "LK"
#endif
        ;
    test_structmembers *ob;
    const char *s = NULL;
    Py_ssize_t string_len = 0;
    ob = PyObject_New(test_structmembers, type);
    if (ob == NULL)
        return NULL;
    memset(&ob->structmembers, 0, sizeof(all_structmembers));
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords,
                                     &ob->structmembers.bool_member,
                                     &ob->structmembers.byte_member,
                                     &ob->structmembers.ubyte_member,
                                     &ob->structmembers.short_member,
                                     &ob->structmembers.ushort_member,
                                     &ob->structmembers.int_member,
                                     &ob->structmembers.uint_member,
                                     &ob->structmembers.long_member,
                                     &ob->structmembers.ulong_member,
                                     &ob->structmembers.pyssizet_member,
                                     &ob->structmembers.float_member,
                                     &ob->structmembers.double_member,
                                     &s, &string_len
#ifdef HAVE_LONG_LONG
                                     , &ob->structmembers.longlong_member,
                                     &ob->structmembers.ulonglong_member
#endif
        )) {
        Py_DECREF(ob);
        return NULL;
    }
    if (s != NULL) {
        if (string_len > 5) {
            Py_DECREF(ob);
            PyErr_SetString(PyExc_ValueError, "string too long");
            return NULL;
        }
        strcpy(ob->structmembers.inplace_member, s);
    }
    else {
        strcpy(ob->structmembers.inplace_member, "");
    }
    return (PyObject *)ob;
}

Here is the call graph for this function:

static PyObject* test_u_code ( PyObject self) [static]

Definition at line 1251 of file _testcapimodule.c.

{
    PyObject *tuple, *obj;
    Py_UNICODE *value;
    Py_ssize_t len;

    /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */
    /* Just use the macro and check that it compiles */
    x = Py_UNICODE_ISSPACE(25);

    tuple = PyTuple_New(1);
    if (tuple == NULL)
        return NULL;

    obj = PyUnicode_Decode("test", strlen("test"),
                           "ascii", NULL);
    if (obj == NULL)
        return NULL;

    PyTuple_SET_ITEM(tuple, 0, obj);

    value = 0;
    if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0)
        return NULL;
    if (value != PyUnicode_AS_UNICODE(obj))
        return raiseTestError("test_u_code",
            "u code returned wrong value for u'test'");
    value = 0;
    if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0)
        return NULL;
    if (value != PyUnicode_AS_UNICODE(obj) ||
        len != PyUnicode_GET_SIZE(obj))
        return raiseTestError("test_u_code",
            "u# code returned wrong values for u'test'");

    Py_DECREF(tuple);
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* test_unicode_compare_with_ascii ( PyObject self) [static]

Definition at line 1783 of file _testcapimodule.c.

                                                {
    PyObject *py_s = PyUnicode_FromStringAndSize("str\0", 4);
    int result;
    if (py_s == NULL)
        return NULL;
    result = PyUnicode_CompareWithASCIIString(py_s, "str");
    Py_DECREF(py_s);
    if (!result) {
        PyErr_SetString(TestError, "Python string ending in NULL "
                        "should not compare equal to c string.");
        return NULL;
    }
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* test_widechar ( PyObject self) [static]

Definition at line 1345 of file _testcapimodule.c.

{
#if defined(SIZEOF_WCHAR_T) && (SIZEOF_WCHAR_T == 4)
    const wchar_t wtext[2] = {(wchar_t)0x10ABCDu};
    size_t wtextlen = 1;
#else
    const wchar_t wtext[3] = {(wchar_t)0xDBEAu, (wchar_t)0xDFCDu};
    size_t wtextlen = 2;
#endif
    PyObject *wide, *utf8;

    wide = PyUnicode_FromWideChar(wtext, wtextlen);
    if (wide == NULL)
        return NULL;

    utf8 = PyUnicode_FromString("\xf4\x8a\xaf\x8d");
    if (utf8 == NULL) {
        Py_DECREF(wide);
        return NULL;
    }

    if (PyUnicode_GET_SIZE(wide) != PyUnicode_GET_SIZE(utf8)) {
        Py_DECREF(wide);
        Py_DECREF(utf8);
        return raiseTestError("test_widechar",
                              "wide string and utf8 string "
                              "have different length");
    }
    if (PyUnicode_Compare(wide, utf8)) {
        Py_DECREF(wide);
        Py_DECREF(utf8);
        if (PyErr_Occurred())
            return NULL;
        return raiseTestError("test_widechar",
                              "wide string and utf8 string "
                              "are different");
    }

    Py_DECREF(wide);
    Py_DECREF(utf8);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* test_with_docstring ( PyObject self) [static]

Definition at line 1800 of file _testcapimodule.c.

static PyObject* test_Z_code ( PyObject self) [static]

Definition at line 1293 of file _testcapimodule.c.

{
    PyObject *tuple, *obj;
    Py_UNICODE *value1, *value2;
    Py_ssize_t len1, len2;

    tuple = PyTuple_New(2);
    if (tuple == NULL)
        return NULL;

    obj = PyUnicode_FromString("test");
    PyTuple_SET_ITEM(tuple, 0, obj);
    Py_INCREF(Py_None);
    PyTuple_SET_ITEM(tuple, 1, Py_None);

    /* swap values on purpose */
    value1 = NULL;
    value2 = PyUnicode_AS_UNICODE(obj);

    /* Test Z for both values */
    if (PyArg_ParseTuple(tuple, "ZZ:test_Z_code", &value1, &value2) < 0)
        return NULL;
    if (value1 != PyUnicode_AS_UNICODE(obj))
        return raiseTestError("test_Z_code",
            "Z code returned wrong value for 'test'");
    if (value2 != NULL)
        return raiseTestError("test_Z_code",
            "Z code returned wrong value for None");

    value1 = NULL;
    value2 = PyUnicode_AS_UNICODE(obj);
    len1 = -1;
    len2 = -1;

    /* Test Z# for both values */
    if (PyArg_ParseTuple(tuple, "Z#Z#:test_Z_code", &value1, &len1,
                         &value2, &len2) < 0)
        return NULL;
    if (value1 != PyUnicode_AS_UNICODE(obj) ||
        len1 != PyUnicode_GET_SIZE(obj))
        return raiseTestError("test_Z_code",
            "Z# code returned wrong values for 'test'");
    if (value2 != NULL ||
        len2 != 0)
        return raiseTestError("test_Z_code",
            "Z# code returned wrong values for None'");

    Py_DECREF(tuple);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* traceback_print ( PyObject self,
PyObject args 
) [static]

Definition at line 2119 of file _testcapimodule.c.

{
    PyObject *file;
    PyObject *traceback;
    int result;

    if (!PyArg_ParseTuple(args, "OO:traceback_print",
                            &traceback, &file))
        return NULL;

    result = PyTraceBack_Print(traceback, file);
    if (result < 0)
        return NULL;
    Py_RETURN_NONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* unicode_aswidechar ( PyObject self,
PyObject args 
) [static]

Definition at line 1389 of file _testcapimodule.c.

{
    PyObject *unicode, *result;
    Py_ssize_t buflen, size;
    wchar_t *buffer;

    if (!PyArg_ParseTuple(args, "Un", &unicode, &buflen))
        return NULL;
    buffer = PyMem_Malloc(buflen * sizeof(wchar_t));
    if (buffer == NULL)
        return PyErr_NoMemory();

    size = PyUnicode_AsWideChar(unicode, buffer, buflen);
    if (size == -1) {
        PyMem_Free(buffer);
        return NULL;
    }

    if (size < buflen)
        buflen = size + 1;
    else
        buflen = size;
    result = PyUnicode_FromWideChar(buffer, buflen);
    PyMem_Free(buffer);
    if (result == NULL)
        return NULL;

    return Py_BuildValue("(Nn)", result, size);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* unicode_aswidecharstring ( PyObject self,
PyObject args 
) [static]

Definition at line 1420 of file _testcapimodule.c.

{
    PyObject *unicode, *result;
    Py_ssize_t size;
    wchar_t *buffer;

    if (!PyArg_ParseTuple(args, "U", &unicode))
        return NULL;

    buffer = PyUnicode_AsWideCharString(unicode, &size);
    if (buffer == NULL)
        return NULL;

    result = PyUnicode_FromWideChar(buffer, size + 1);
    PyMem_Free(buffer);
    if (result == NULL)
        return NULL;
    return Py_BuildValue("(Nn)", result, size);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 182 of file _testcapimodule.c.

Definition at line 305 of file _testcapimodule.c.

char* capsule_context = "capsule context" [static]

Definition at line 1857 of file _testcapimodule.c.

Definition at line 1860 of file _testcapimodule.c.

const char* capsule_error = NULL [static]

Definition at line 1858 of file _testcapimodule.c.

const char* capsule_name = "capsule name" [static]

Definition at line 1855 of file _testcapimodule.c.

char* capsule_pointer = "capsule pointer" [static]

Definition at line 1856 of file _testcapimodule.c.

Initial value:

Definition at line 300 of file _testcapimodule.c.

struct PyMemberDef[] [static]
Initial value:
 {
    {"T_BOOL", T_BOOL, offsetof(test_structmembers, structmembers.bool_member), 0, NULL},
    {"T_BYTE", T_BYTE, offsetof(test_structmembers, structmembers.byte_member), 0, NULL},
    {"T_UBYTE", T_UBYTE, offsetof(test_structmembers, structmembers.ubyte_member), 0, NULL},
    {"T_SHORT", T_SHORT, offsetof(test_structmembers, structmembers.short_member), 0, NULL},
    {"T_USHORT", T_USHORT, offsetof(test_structmembers, structmembers.ushort_member), 0, NULL},
    {"T_INT", T_INT, offsetof(test_structmembers, structmembers.int_member), 0, NULL},
    {"T_UINT", T_UINT, offsetof(test_structmembers, structmembers.uint_member), 0, NULL},
    {"T_LONG", T_LONG, offsetof(test_structmembers, structmembers.long_member), 0, NULL},
    {"T_ULONG", T_ULONG, offsetof(test_structmembers, structmembers.ulong_member), 0, NULL},
    {"T_PYSSIZET", T_PYSSIZET, offsetof(test_structmembers, structmembers.pyssizet_member), 0, NULL},
    {"T_FLOAT", T_FLOAT, offsetof(test_structmembers, structmembers.float_member), 0, NULL},
    {"T_DOUBLE", T_DOUBLE, offsetof(test_structmembers, structmembers.double_member), 0, NULL},
    {"T_STRING_INPLACE", T_STRING_INPLACE, offsetof(test_structmembers, structmembers.inplace_member), 0, NULL},




    {NULL}
}

Definition at line 2371 of file _testcapimodule.c.

struct PyModuleDef [static]
Initial value:
 {
    PyModuleDef_HEAD_INIT,
    "_testcapi",
    NULL,
    -1,
    TestMethods,
    NULL,
    NULL,
    NULL,
    NULL
}

Definition at line 2501 of file _testcapimodule.c.

PyObject* str1 [static]

Definition at line 2169 of file _testcapimodule.c.

PyObject * str2 [static]

Definition at line 2169 of file _testcapimodule.c.

int test_run_counter = 0 [static]

Definition at line 1591 of file _testcapimodule.c.

Definition at line 2458 of file _testcapimodule.c.

PyObject* TestError [static]

Definition at line 18 of file _testcapimodule.c.

Definition at line 2258 of file _testcapimodule.c.

volatile int x [static]

Definition at line 1245 of file _testcapimodule.c.