summaryrefslogtreecommitdiffstats
path: root/tests/lreplace.test
blob: 868d98edb9c70ec03e0104ac6a0839d9addf120f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Commands covered:  lreplace
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1991-1993 The Regents of the University of California.
# Copyright (c) 1994 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: lreplace.test,v 1.5 1999/05/06 18:46:43 stanton Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    source [file join [pwd] [file dirname [info script]] defs.tcl]
}

test lreplace-1.1 {lreplace command} {
    lreplace {1 2 3 4 5} 0 0 a
} {a 2 3 4 5}
test lreplace-1.2 {lreplace command} {
    lreplace {1 2 3 4 5} 1 1 a
} {1 a 3 4 5}
test lreplace-1.3 {lreplace command} {
    lreplace {1 2 3 4 5} 2 2 a
} {1 2 a 4 5}
test lreplace-1.4 {lreplace command} {
    lreplace {1 2 3 4 5} 3 3 a
} {1 2 3 a 5}
test lreplace-1.5 {lreplace command} {
    lreplace {1 2 3 4 5} 4 4 a
} {1 2 3 4 a}
test lreplace-1.6 {lreplace command} {
    lreplace {1 2 3 4 5} 4 5 a
} {1 2 3 4 a}
test lreplace-1.7 {lreplace command} {
    lreplace {1 2 3 4 5} -1 -1 a
} {a 1 2 3 4 5}
test lreplace-1.8 {lreplace command} {
    lreplace {1 2 3 4 5} 2 end a b c d
} {1 2 a b c d}
test lreplace-1.9 {lreplace command} {
    lreplace {1 2 3 4 5} 0 3
} {5}
test lreplace-1.10 {lreplace command} {
    lreplace {1 2 3 4 5} 0 4
} {}
test lreplace-1.11 {lreplace command} {
    lreplace {1 2 3 4 5} 0 1
} {3 4 5}
test lreplace-1.12 {lreplace command} {
    lreplace {1 2 3 4 5} 2 3
} {1 2 5}
test lreplace-1.13 {lreplace command} {
    lreplace {1 2 3 4 5} 3 end
} {1 2 3}
test lreplace-1.14 {lreplace command} {
    lreplace {1 2 3 4 5} -1 4 a b c
} {a b c}
test lreplace-1.15 {lreplace command} {
    lreplace {a b "c c" d e f} 3 3
} {a b {c c} e f}
test lreplace-1.16 {lreplace command} {
    lreplace { 1 2 3 4 5} 0 0 a
} {a 2 3 4 5}
test lreplace-1.17 {lreplace command} {
    lreplace {1 2 3 4 "5 6"} 4 4 a
} {1 2 3 4 a}
test lreplace-1.18 {lreplace command} {
    lreplace {1 2 3 4 {5 6}} 4 4 a
} {1 2 3 4 a}
test lreplace-1.19 {lreplace command} {
    lreplace {1 2 3 4} 2 end x y z
} {1 2 x y z}
test lreplace-1.20 {lreplace command} {
    lreplace {1 2 3 4} end end a
} {1 2 3 a}
test lreplace-1.21 {lreplace command} {
    lreplace {1 2 3 4} end 3 a
} {1 2 3 a}
test lreplace-1.22 {lreplace command} {
    lreplace {1 2 3 4} end end
} {1 2 3}
test lreplace-1.23 {lreplace command} {
    lreplace {1 2 3 4} 2 -1 xy
} {1 2 xy 3 4}
test lreplace-1.24 {lreplace command} {
    lreplace {1 2 3 4} end -1 z
} {1 2 3 z 4}
test lreplace-1.25 {lreplace command} {
    concat \"[lreplace {\}\     hello} end end]\"
} {"\}\ "}
test lreplace-1.26 {lreplace command} {
    catch {unset foo}
    set foo {a b}
    list [set foo [lreplace $foo end end]] \
        [set foo [lreplace $foo end end]] \
        [set foo [lreplace $foo end end]]
} {a {} {}}


test lreplace-2.1 {lreplace errors} {
    list [catch lreplace msg] $msg
} {1 {wrong # args: should be "lreplace list first last ?element element ...?"}}
test lreplace-2.2 {lreplace errors} {
    list [catch {lreplace a b} msg] $msg
} {1 {wrong # args: should be "lreplace list first last ?element element ...?"}}
test lreplace-2.3 {lreplace errors} {
    list [catch {lreplace x a 10} msg] $msg
} {1 {bad index "a": must be integer or end?-integer?}}
test lreplace-2.4 {lreplace errors} {
    list [catch {lreplace x 10 x} msg] $msg
} {1 {bad index "x": must be integer or end?-integer?}}
test lreplace-2.5 {lreplace errors} {
    list [catch {lreplace x 10 1x} msg] $msg
} {1 {bad index "1x": must be integer or end?-integer?}}
test lreplace-2.6 {lreplace errors} {
    list [catch {lreplace x 3 2} msg] $msg
} {1 {list doesn't contain element 3}}
test lreplace-2.7 {lreplace errors} {
    list [catch {lreplace x 1 1} msg] $msg
} {1 {list doesn't contain element 1}}

test lreplace-3.1 {lreplace won't modify shared argument objects} {
    proc p {} {
        lreplace "a b c" 1 1 "x y"
        return "a b c"
    }
    p
} "a b c"

# cleanup
catch {unset foo}
::tcltest::cleanupTests
return
-Modules/spwdmodule.c196
-rw-r--r--Modules/symtablemodule.c148
-rw-r--r--Modules/syslogmodule.c290
-rw-r--r--Modules/termios.c904
-rw-r--r--Modules/testcapi_long.h348
-rw-r--r--Modules/timemodule.c1274
-rw-r--r--Modules/tkappinit.c192
-rw-r--r--Modules/unicodedata.c286
-rw-r--r--Modules/xxmodule.c520
-rw-r--r--Modules/xxsubtype.c410
-rw-r--r--Modules/zipimport.c1736
-rw-r--r--Modules/zlibmodule.c462
-rw-r--r--Objects/abstract.c3730
-rw-r--r--Objects/boolobject.c226
-rw-r--r--Objects/bytes_methods.c314
-rw-r--r--Objects/bytesobject.c5186
-rw-r--r--Objects/cellobject.c240
-rw-r--r--Objects/classobject.c888
-rw-r--r--Objects/codeobject.c954
-rw-r--r--Objects/complexobject.c1640
-rw-r--r--Objects/descrobject.c1866
-rw-r--r--Objects/dictobject.c4070
-rw-r--r--Objects/enumobject.c566
-rw-r--r--Objects/exceptions.c46
-rw-r--r--Objects/fileobject.c744
-rw-r--r--Objects/floatobject.c3710
-rw-r--r--Objects/frameobject.c1438
-rw-r--r--Objects/funcobject.c1324
-rw-r--r--Objects/genobject.c596
-rw-r--r--Objects/iterobject.c328
-rw-r--r--Objects/listobject.c4206
-rw-r--r--Objects/longobject.c6668
-rw-r--r--Objects/methodobject.c396
-rw-r--r--Objects/moduleobject.c632
-rw-r--r--Objects/object.c2442
-rw-r--r--Objects/obmalloc.c2064
-rw-r--r--Objects/rangeobject.c254
-rw-r--r--Objects/setobject.c3578
-rw-r--r--Objects/sliceobject.c518
-rw-r--r--Objects/stringlib/eq.h22
-rw-r--r--Objects/stringlib/partition.h46
-rw-r--r--Objects/stringlib/string_format.h174
-rw-r--r--Objects/stringlib/transmogrify.h84
-rw-r--r--Objects/structseq.c822
-rw-r--r--Objects/tupleobject.c1472
-rw-r--r--Objects/typeobject.c9558
-rw-r--r--Objects/unicodectype.c116
-rw-r--r--Objects/weakrefobject.c116
-rw-r--r--PC/VS7.1/make_buildinfo.c126
-rw-r--r--PC/VS8.0/make_buildinfo.c128
-rw-r--r--PC/_msi.c538
-rw-r--r--PC/_subprocess.c792
-rw-r--r--PC/bdist_wininst/archive.h94
-rw-r--r--PC/bdist_wininst/extract.c534
-rw-r--r--PC/bdist_wininst/install.c4214
-rw-r--r--PC/config.c134
-rw-r--r--PC/dl_nt.c90
-rw-r--r--PC/errmap.h148
-rw-r--r--PC/example_nt/example.c30
-rw-r--r--PC/frozen_dllmain.c116
-rw-r--r--PC/generrmap.c24
-rw-r--r--PC/getpathp.c910
-rw-r--r--PC/import_nt.c122
-rw-r--r--PC/make_versioninfo.c26
-rwxr-xr-xPC/msvcrtmodule.c456
-rw-r--r--PC/os2emx/config.c110
-rw-r--r--PC/os2emx/dlfcn.c286
-rw-r--r--PC/os2emx/dllentry.c44
-rw-r--r--PC/os2emx/getpathp.c480
-rw-r--r--PC/os2emx/pythonpm.c144
-rw-r--r--PC/os2vacpp/getpathp.c636
-rw-r--r--PC/winreg.c1940
-rw-r--r--PC/winsound.c138
-rw-r--r--PCbuild/make_buildinfo.c128
-rw-r--r--Parser/acceler.c168
-rw-r--r--Parser/bitset.c58
-rw-r--r--Parser/firstsets.c180
-rw-r--r--Parser/grammar.c380
-rw-r--r--Parser/grammar1.c70
-rw-r--r--Parser/intrcheck.c70
-rw-r--r--Parser/listnode.c78
-rw-r--r--Parser/metagrammar.c170
-rw-r--r--Parser/myreadline.c240
-rw-r--r--Parser/node.c122
-rw-r--r--Parser/parser.c540
-rw-r--r--Parser/parsetok.c348
-rw-r--r--Parser/pgen.c964
-rw-r--r--Parser/pgenmain.c194
-rw-r--r--Parser/printgrammar.c152
-rw-r--r--Parser/tokenizer.c2676
-rw-r--r--Parser/tokenizer.h88
-rw-r--r--Python/_warnings.c80
-rw-r--r--Python/asdl.c88
-rw-r--r--Python/ast.c188
-rw-r--r--Python/bltinmodule.c3258
-rw-r--r--Python/ceval.c6980
-rw-r--r--Python/codecs.c1044
-rw-r--r--Python/compile.c6496
-rw-r--r--Python/dynload_aix.c280
-rw-r--r--Python/dynload_atheos.c62
-rw-r--r--Python/dynload_hpux.c74
-rw-r--r--Python/dynload_next.c150
-rw-r--r--Python/dynload_os2.c58
-rw-r--r--Python/dynload_shlib.c152
-rw-r--r--Python/dynload_win.c420
-rw-r--r--Python/errors.c1244
-rw-r--r--Python/frozen.c28
-rw-r--r--Python/frozenmain.c154
-rw-r--r--Python/future.c232
-rw-r--r--Python/getargs.c3284
-rw-r--r--Python/getcwd.c78
-rw-r--r--Python/getopt.c150
-rw-r--r--Python/import.c5010
-rw-r--r--Python/importdl.c116
-rw-r--r--Python/importdl.h28
-rwxr-xr-xPython/makeopcodetargets.py2
-rw-r--r--Python/marshal.c2138
-rw-r--r--Python/modsupport.c964
-rw-r--r--Python/mysnprintf.c112
-rw-r--r--Python/mystrtoul.c440
-rw-r--r--Python/opcode_targets.h512
-rw-r--r--Python/peephole.c1196
-rw-r--r--Python/pyarena.c300
-rw-r--r--Python/pymath.c276
-rw-r--r--Python/pystate.c776
-rw-r--r--Python/pystrcmp.c24
-rw-r--r--Python/pystrtod.c1966
-rw-r--r--Python/pythonrun.c3284
-rw-r--r--Python/structmember.c548
-rw-r--r--Python/symtable.c2628
-rw-r--r--Python/sysmodule.c1852
-rw-r--r--Python/thread.c264
-rw-r--r--Python/thread_atheos.h270
-rw-r--r--Python/thread_cthread.h136
-rw-r--r--Python/thread_foobar.h70
-rw-r--r--Python/thread_lwp.h150
-rw-r--r--Python/thread_nt.h334
-rw-r--r--Python/thread_os2.h316
-rw-r--r--Python/thread_pth.h218
-rw-r--r--Python/thread_pthread.h474
-rw-r--r--Python/thread_sgi.h480
-rw-r--r--Python/thread_solaris.h186
-rw-r--r--Python/thread_wince.h96
-rw-r--r--Python/traceback.c562
-rw-r--r--Tools/msi/msisupport.c112
251 files changed, 117669 insertions, 117669 deletions
diff --git a/Demo/embed/demo.c b/Demo/embed/demo.c
index b9ea6f5..22bfaff 100644
--- a/Demo/embed/demo.c
+++ b/Demo/embed/demo.c
@@ -6,44 +6,44 @@ PyObject* PyInit_xyzzy(void); /* Forward */
main(int argc, char **argv)
{
- /* Ignore passed-in argc/argv. If desired, conversion
- should use mbstowcs to convert them. */
- wchar_t *args[] = {L"embed", L"hello", 0};
+ /* Ignore passed-in argc/argv. If desired, conversion
+ should use mbstowcs to convert them. */
+ wchar_t *args[] = {L"embed", L"hello", 0};
- /* Pass argv[0] to the Python interpreter */
- Py_SetProgramName(args[0]);
+ /* Pass argv[0] to the Python interpreter */
+ Py_SetProgramName(args[0]);
- /* Add a static module */
- PyImport_AppendInittab("xyzzy", PyInit_xyzzy);
+ /* Add a static module */
+ PyImport_AppendInittab("xyzzy", PyInit_xyzzy);
- /* Initialize the Python interpreter. Required. */
- Py_Initialize();
+ /* Initialize the Python interpreter. Required. */
+ Py_Initialize();
- /* Define sys.argv. It is up to the application if you
- want this; you can also let it undefined (since the Python
- code is generally not a main program it has no business
- touching sys.argv...) */
- PySys_SetArgv(2, args);
+ /* Define sys.argv. It is up to the application if you
+ want this; you can also let it undefined (since the Python
+ code is generally not a main program it has no business
+ touching sys.argv...) */
+ PySys_SetArgv(2, args);
- /* Do some application specific code */
- printf("Hello, brave new world\n\n");
+ /* Do some application specific code */
+ printf("Hello, brave new world\n\n");
- /* Execute some Python statements (in module __main__) */
- PyRun_SimpleString("import sys\n");
- PyRun_SimpleString("print(sys.builtin_module_names)\n");
- PyRun_SimpleString("print(sys.modules.keys())\n");
- PyRun_SimpleString("print(sys.executable)\n");
- PyRun_SimpleString("print(sys.argv)\n");
+ /* Execute some Python statements (in module __main__) */
+ PyRun_SimpleString("import sys\n");
+ PyRun_SimpleString("print(sys.builtin_module_names)\n");
+ PyRun_SimpleString("print(sys.modules.keys())\n");
+ PyRun_SimpleString("print(sys.executable)\n");
+ PyRun_SimpleString("print(sys.argv)\n");
- /* Note that you can call any public function of the Python
- interpreter here, e.g. call_object(). */
+ /* Note that you can call any public function of the Python
+ interpreter here, e.g. call_object(). */
- /* Some more application specific code */
- printf("\nGoodbye, cruel world\n");
+ /* Some more application specific code */
+ printf("\nGoodbye, cruel world\n");
- /* Exit, cleaning up the interpreter */
- Py_Exit(0);
- /*NOTREACHED*/
+ /* Exit, cleaning up the interpreter */
+ Py_Exit(0);
+ /*NOTREACHED*/
}
/* A static module */
@@ -52,29 +52,29 @@ main(int argc, char **argv)
static PyObject *
xyzzy_foo(PyObject *self, PyObject* args)
{
- return PyLong_FromLong(42L);
+ return PyLong_FromLong(42L);
}
static PyMethodDef xyzzy_methods[] = {
- {"foo", xyzzy_foo, METH_NOARGS,
- "Return the meaning of everything."},
- {NULL, NULL} /* sentinel */
+ {"foo", xyzzy_foo, METH_NOARGS,
+ "Return the meaning of everything."},
+ {NULL, NULL} /* sentinel */
};
static struct PyModuleDef xyzzymodule = {
- {}, /* m_base */
- "xyzzy", /* m_name */
- 0, /* m_doc */
- 0, /* m_size */
- xyzzy_methods, /* m_methods */
- 0, /* m_reload */
- 0, /* m_traverse */
- 0, /* m_clear */
- 0, /* m_free */
+ {}, /* m_base */
+ "xyzzy", /* m_name */
+ 0, /* m_doc */
+ 0, /* m_size */
+ xyzzy_methods, /* m_methods */
+ 0, /* m_reload */
+ 0, /* m_traverse */
+ 0, /* m_clear */
+ 0, /* m_free */
};
PyObject*
PyInit_xyzzy(void)
{
- return PyModule_Create(&xyzzymodule);
+ return PyModule_Create(&xyzzymodule);
}
diff --git a/Demo/embed/loop.c b/Demo/embed/loop.c
index d5af829..2f7fe62 100644
--- a/Demo/embed/loop.c
+++ b/Demo/embed/loop.c
@@ -6,28 +6,28 @@
main(int argc, char **argv)
{
- int count = -1;
- char *command;
+ int count = -1;
+ char *command;
- if (argc < 2 || argc > 3) {
- fprintf(stderr, "usage: loop <python-command> [count]\n");
- exit(2);
- }
- command = argv[1];
+ if (argc < 2 || argc > 3) {
+ fprintf(stderr, "usage: loop <python-command> [count]\n");
+ exit(2);
+ }
+ command = argv[1];
- if (argc == 3) {
- count = atoi(argv[2]);
- }
+ if (argc == 3) {
+ count = atoi(argv[2]);
+ }
- Py_SetProgramName(argv[0]);
+ Py_SetProgramName(argv[0]);
- /* uncomment this if you don't want to load site.py */
- /* Py_NoSiteFlag = 1; */
+ /* uncomment this if you don't want to load site.py */
+ /* Py_NoSiteFlag = 1; */
- while (count == -1 || --count >= 0 ) {
- Py_Initialize();
- PyRun_SimpleString(command);
- Py_Finalize();
- }
- return 0;
+ while (count == -1 || --count >= 0 ) {
+ Py_Initialize();
+ PyRun_SimpleString(command);
+ Py_Finalize();
+ }
+ return 0;
}
diff --git a/Demo/pysvr/pysvr.c b/Demo/pysvr/pysvr.c
index cced6da..706cd2a 100644
--- a/Demo/pysvr/pysvr.c
+++ b/Demo/pysvr/pysvr.c
@@ -34,8 +34,8 @@ extern int Py_VerboseFlag;
#endif
struct workorder {
- int conn;
- struct sockaddr_in addr;
+ int conn;
+ struct sockaddr_in addr;
};
/* Forward */
@@ -55,40 +55,40 @@ static PyThreadState *gtstate;
main(int argc, char **argv)
{
- int port = PORT;
- int c;
-
- if (argc > 0 && argv[0] != NULL && argv[0][0] != '\0')
- progname = argv[0];
-
- while ((c = getopt(argc, argv, "v")) != EOF) {
- switch (c) {
- case 'v':
- Py_VerboseFlag++;
- break;
- default:
- usage();
- }
- }
-
- if (optind < argc) {
- if (optind+1 < argc) {
- oprogname();
- fprintf(stderr, "too many arguments\n");
- usage();
- }
- port = atoi(argv[optind]);
- if (port <= 0) {
- fprintf(stderr, "bad port (%s)\n", argv[optind]);
- usage();
- }
- }
-
- main_thread(port);
-
- fprintf(stderr, "Bye.\n");
-
- exit(0);
+ int port = PORT;
+ int c;
+
+ if (argc > 0 && argv[0] != NULL && argv[0][0] != '\0')
+ progname = argv[0];
+
+ while ((c = getopt(argc, argv, "v")) != EOF) {
+ switch (c) {
+ case 'v':
+ Py_VerboseFlag++;
+ break;
+ default:
+ usage();
+ }
+ }
+
+ if (optind < argc) {
+ if (optind+1 < argc) {
+ oprogname();
+ fprintf(stderr, "too many arguments\n");
+ usage();
+ }
+ port = atoi(argv[optind]);
+ if (port <= 0) {
+ fprintf(stderr, "bad port (%s)\n", argv[optind]);
+ usage();
+ }
+ }
+
+ main_thread(port);
+
+ fprintf(stderr, "Bye.\n");
+
+ exit(0);
}
static char usage_line[] = "usage: %s [port]\n";
@@ -96,120 +96,120 @@ static char usage_line[] = "usage: %s [port]\n";
static void
usage(void)
{
- fprintf(stderr, usage_line, progname);
- exit(2);
+ fprintf(stderr, usage_line, progname);
+ exit(2);
}
static void
main_thread(int port)
{
- int sock, conn, size, i;
- struct sockaddr_in addr, clientaddr;
+ int sock, conn, size, i;
+ struct sockaddr_in addr, clientaddr;
- sock = socket(PF_INET, SOCK_STREAM, 0);
- if (sock < 0) {
- oprogname();
- perror("can't create socket");
- exit(1);
- }
+ sock = socket(PF_INET, SOCK_STREAM, 0);
+ if (sock < 0) {
+ oprogname();
+ perror("can't create socket");
+ exit(1);
+ }
#ifdef SO_REUSEADDR
- i = 1;
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof i);
+ i = 1;
+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof i);
#endif
- memset((char *)&addr, '\0', sizeof addr);
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- addr.sin_addr.s_addr = 0L;
- if (bind(sock, (struct sockaddr *)&addr, sizeof addr) < 0) {
- oprogname();
- perror("can't bind socket to address");
- exit(1);
- }
-
- if (listen(sock, 5) < 0) {
- oprogname();
- perror("can't listen on socket");
- exit(1);
- }
-
- fprintf(stderr, "Listening on port %d...\n", port);
-
- for (i = 0; ; i++) {
- size = sizeof clientaddr;
- memset((char *) &clientaddr, '\0', size);
- conn = accept(sock, (struct sockaddr *) &clientaddr, &size);
- if (conn < 0) {
- oprogname();
- perror("can't accept connection from socket");
- exit(1);
- }
-
- size = sizeof addr;
- memset((char *) &addr, '\0', size);
- if (getsockname(conn, (struct sockaddr *)&addr, &size) < 0) {
- oprogname();
- perror("can't get socket name of connection");
- exit(1);
- }
- if (clientaddr.sin_addr.s_addr != addr.sin_addr.s_addr) {
- oprogname();
- perror("connection from non-local host refused");
- fprintf(stderr, "(addr=%lx, clientaddr=%lx)\n",
- ntohl(addr.sin_addr.s_addr),
- ntohl(clientaddr.sin_addr.s_addr));
- close(conn);
- continue;
- }
- if (i == 4) {
- close(conn);
- break;
- }
- create_thread(conn, &clientaddr);
- }
-
- close(sock);
-
- if (gtstate) {
- PyEval_AcquireThread(gtstate);
- gtstate = NULL;
- Py_Finalize();
- /* And a second time, just because we can. */
- Py_Finalize(); /* This should be harmless. */
- }
- exit(0);
+ memset((char *)&addr, '\0', sizeof addr);
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+ addr.sin_addr.s_addr = 0L;
+ if (bind(sock, (struct sockaddr *)&addr, sizeof addr) < 0) {
+ oprogname();
+ perror("can't bind socket to address");
+ exit(1);
+ }
+
+ if (listen(sock, 5) < 0) {
+ oprogname();
+ perror("can't listen on socket");
+ exit(1);
+ }
+
+ fprintf(stderr, "Listening on port %d...\n", port);
+
+ for (i = 0; ; i++) {
+ size = sizeof clientaddr;
+ memset((char *) &clientaddr, '\0', size);
+ conn = accept(sock, (struct sockaddr *) &clientaddr, &size);
+ if (conn < 0) {
+ oprogname();
+ perror("can't accept connection from socket");
+ exit(1);
+ }
+
+ size = sizeof addr;
+ memset((char *) &addr, '\0', size);
+ if (getsockname(conn, (struct sockaddr *)&addr, &size) < 0) {
+ oprogname();
+ perror("can't get socket name of connection");
+ exit(1);
+ }
+ if (clientaddr.sin_addr.s_addr != addr.sin_addr.s_addr) {
+ oprogname();
+ perror("connection from non-local host refused");
+ fprintf(stderr, "(addr=%lx, clientaddr=%lx)\n",
+ ntohl(addr.sin_addr.s_addr),
+ ntohl(clientaddr.sin_addr.s_addr));
+ close(conn);
+ continue;
+ }
+ if (i == 4) {
+ close(conn);
+ break;
+ }
+ create_thread(conn, &clientaddr);
+ }
+
+ close(sock);
+
+ if (gtstate) {
+ PyEval_AcquireThread(gtstate);
+ gtstate = NULL;
+ Py_Finalize();
+ /* And a second time, just because we can. */
+ Py_Finalize(); /* This should be harmless. */
+ }
+ exit(0);
}
static void
create_thread(int conn, struct sockaddr_in *addr)
{
- struct workorder *work;
- pthread_t tdata;
-
- work = malloc(sizeof(struct workorder));
- if (work == NULL) {
- oprogname();
- fprintf(stderr, "out of memory for thread.\n");
- close(conn);
- return;
- }
- work->conn = conn;
- work->addr = *addr;
-
- init_python();
-
- if (pthread_create(&tdata, NULL, (void *)service_thread, work) < 0) {
- oprogname();
- perror("can't create new thread");
- close(conn);
- return;
- }
-
- if (pthread_detach(tdata) < 0) {
- oprogname();
- perror("can't detach from thread");
- }
+ struct workorder *work;
+ pthread_t tdata;
+
+ work = malloc(sizeof(struct workorder));
+ if (work == NULL) {
+ oprogname();
+ fprintf(stderr, "out of memory for thread.\n");
+ close(conn);
+ return;
+ }
+ work->conn = conn;
+ work->addr = *addr;
+
+ init_python();
+
+ if (pthread_create(&tdata, NULL, (void *)service_thread, work) < 0) {
+ oprogname();
+ perror("can't create new thread");
+ close(conn);
+ return;
+ }
+
+ if (pthread_detach(tdata) < 0) {
+ oprogname();
+ perror("can't detach from thread");
+ }
}
static PyThreadState *the_tstate;
@@ -219,152 +219,152 @@ static PyObject *the_builtins;
static void
init_python(void)
{
- if (gtstate)
- return;
- Py_Initialize(); /* Initialize the interpreter */
- PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */
- gtstate = PyEval_SaveThread(); /* Release the thread state */
+ if (gtstate)
+ return;
+ Py_Initialize(); /* Initialize the interpreter */
+ PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */
+ gtstate = PyEval_SaveThread(); /* Release the thread state */
}
static void *
service_thread(struct workorder *work)
{
- FILE *input, *output;
+ FILE *input, *output;
- fprintf(stderr, "Start thread for connection %d.\n", work->conn);
+ fprintf(stderr, "Start thread for connection %d.\n", work->conn);
- ps();
+ ps();
- input = fdopen(work->conn, "r");
- if (input == NULL) {
- oprogname();
- perror("can't create input stream");
- goto done;
- }
+ input = fdopen(work->conn, "r");
+ if (input == NULL) {
+ oprogname();
+ perror("can't create input stream");
+ goto done;
+ }
- output = fdopen(work->conn, "w");
- if (output == NULL) {
- oprogname();
- perror("can't create output stream");
- fclose(input);
- goto done;
- }
+ output = fdopen(work->conn, "w");
+ if (output == NULL) {
+ oprogname();
+ perror("can't create output stream");
+ fclose(input);
+ goto done;
+ }
- setvbuf(input, NULL, _IONBF, 0);
- setvbuf(output, NULL, _IONBF, 0);
+ setvbuf(input, NULL, _IONBF, 0);
+ setvbuf(output, NULL, _IONBF, 0);
- run_interpreter(input, output);
+ run_interpreter(input, output);
- fclose(input);
- fclose(output);
+ fclose(input);
+ fclose(output);
done:
- fprintf(stderr, "End thread for connection %d.\n", work->conn);
- close(work->conn);
- free(work);
+ fprintf(stderr, "End thread for connection %d.\n", work->conn);
+ close(work->conn);
+ free(work);
}
static void
oprogname(void)
{
- int save = errno;
- fprintf(stderr, "%s: ", progname);
- errno = save;
+ int save = errno;
+ fprintf(stderr, "%s: ", progname);
+ errno = save;
}
static void
run_interpreter(FILE *input, FILE *output)
{
- PyThreadState *tstate;
- PyObject *new_stdin, *new_stdout;
- PyObject *mainmod, *globals;
- char buffer[1000];
- char *p, *q;
- int n, end;
-
- PyEval_AcquireLock();
- tstate = Py_NewInterpreter();
- if (tstate == NULL) {
- fprintf(output, "Sorry -- can't create an interpreter\n");
- return;
- }
-
- mainmod = PyImport_AddModule("__main__");
- globals = PyModule_GetDict(mainmod);
- Py_INCREF(globals);
-
- new_stdin = PyFile_FromFile(input, "<socket-in>", "r", NULL);
- new_stdout = PyFile_FromFile(output, "<socket-out>", "w", NULL);
-
- PySys_SetObject("stdin", new_stdin);
- PySys_SetObject("stdout", new_stdout);
- PySys_SetObject("stderr", new_stdout);
-
- for (n = 1; !PyErr_Occurred(); n++) {
- Py_BEGIN_ALLOW_THREADS
- fprintf(output, "%d> ", n);
- p = fgets(buffer, sizeof buffer, input);
- Py_END_ALLOW_THREADS
-
- if (p == NULL)
- break;
- if (p[0] == '\377' && p[1] == '\354')
- break;
-
- q = strrchr(p, '\r');
- if (q && q[1] == '\n' && q[2] == '\0') {
- *q++ = '\n';
- *q++ = '\0';
- }
-
- while (*p && isspace(*p))
- p++;
- if (p[0] == '#' || p[0] == '\0')
- continue;
-
- end = run_command(buffer, globals);
- if (end < 0)
- PyErr_Print();
-
- if (end)
- break;
- }
-
- Py_XDECREF(globals);
- Py_XDECREF(new_stdin);
- Py_XDECREF(new_stdout);
-
- Py_EndInterpreter(tstate);
- PyEval_ReleaseLock();
-
- fprintf(output, "Goodbye!\n");
+ PyThreadState *tstate;
+ PyObject *new_stdin, *new_stdout;
+ PyObject *mainmod, *globals;
+ char buffer[1000];
+ char *p, *q;
+ int n, end;
+
+ PyEval_AcquireLock();
+ tstate = Py_NewInterpreter();
+ if (tstate == NULL) {
+ fprintf(output, "Sorry -- can't create an interpreter\n");
+ return;
+ }
+
+ mainmod = PyImport_AddModule("__main__");
+ globals = PyModule_GetDict(mainmod);
+ Py_INCREF(globals);
+
+ new_stdin = PyFile_FromFile(input, "<socket-in>", "r", NULL);
+ new_stdout = PyFile_FromFile(output, "<socket-out>", "w", NULL);
+
+ PySys_SetObject("stdin", new_stdin);
+ PySys_SetObject("stdout", new_stdout);
+ PySys_SetObject("stderr", new_stdout);
+
+ for (n = 1; !PyErr_Occurred(); n++) {
+ Py_BEGIN_ALLOW_THREADS
+ fprintf(output, "%d> ", n);
+ p = fgets(buffer, sizeof buffer, input);
+ Py_END_ALLOW_THREADS
+
+ if (p == NULL)
+ break;
+ if (p[0] == '\377' && p[1] == '\354')
+ break;
+
+ q = strrchr(p, '\r');
+ if (q && q[1] == '\n' && q[2] == '\0') {
+ *q++ = '\n';
+ *q++ = '\0';
+ }
+
+ while (*p && isspace(*p))
+ p++;
+ if (p[0] == '#' || p[0] == '\0')
+ continue;
+
+ end = run_command(buffer, globals);
+ if (end < 0)
+ PyErr_Print();
+
+ if (end)
+ break;
+ }
+
+ Py_XDECREF(globals);
+ Py_XDECREF(new_stdin);
+ Py_XDECREF(new_stdout);
+
+ Py_EndInterpreter(tstate);
+ PyEval_ReleaseLock();
+
+ fprintf(output, "Goodbye!\n");
}
static int
run_command(char *buffer, PyObject *globals)
{
- PyObject *m, *d, *v;
- fprintf(stderr, "run_command: %s", buffer);
- if (strchr(buffer, '\n') == NULL)
- fprintf(stderr, "\n");
- v = PyRun_String(buffer, Py_single_input, globals, globals);
- if (v == NULL) {
- if (PyErr_Occurred() == PyExc_SystemExit) {
- PyErr_Clear();
- return 1;
- }
- PyErr_Print();
- return 0;
- }
- Py_DECREF(v);
- return 0;
+ PyObject *m, *d, *v;
+ fprintf(stderr, "run_command: %s", buffer);
+ if (strchr(buffer, '\n') == NULL)
+ fprintf(stderr, "\n");
+ v = PyRun_String(buffer, Py_single_input, globals, globals);
+ if (v == NULL) {
+ if (PyErr_Occurred() == PyExc_SystemExit) {
+ PyErr_Clear();
+ return 1;
+ }
+ PyErr_Print();
+ return 0;
+ }
+ Py_DECREF(v);
+ return 0;
}
static void
ps(void)
{
- char buffer[100];
- PyOS_snprintf(buffer, sizeof(buffer),
- "ps -l -p %d </dev/null | sed 1d\n", getpid());
- system(buffer);
+ char buffer[100];
+ PyOS_snprintf(buffer, sizeof(buffer),
+ "ps -l -p %d </dev/null | sed 1d\n", getpid());
+ system(buffer);
}
diff --git a/Include/abstract.h b/Include/abstract.h
index 6d40ef7..6a6c94c 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -32,7 +32,7 @@ Problem
If the programmer wants to get an item from another type of object
that provides sequence behavior, there is no clear way to do it
- correctly.
+ correctly.
The persistent programmer may peruse object.h and find that the
_typeobject structure provides a means of invoking up to (currently
@@ -44,7 +44,7 @@ Problem
Also, certain semantics, especially memory management semantics, may
differ by the type of object being used. Unfortunately, these
semantics are not clearly described in the current include files.
- An abstract interface providing more consistent semantics is needed.
+ An abstract interface providing more consistent semantics is needed.
Proposal
@@ -77,7 +77,7 @@ Proposal
Python distributions.
From the point of view of Python accessing services provided by C
- modules:
+ modules:
- "Python module interface": this interface consist of the basic
routines used to define modules and their members. Most of the
@@ -133,11 +133,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyObject_Print(PyObject *o, FILE *fp, int flags);
- Print an object, o, on file, fp. Returns -1 on
- error. The flags argument is used to enable certain printing
- options. The only option currently supported is Py_Print_RAW.
+ Print an object, o, on file, fp. Returns -1 on
+ error. The flags argument is used to enable certain printing
+ options. The only option currently supported is Py_Print_RAW.
- (What should be said about Py_Print_RAW?)
+ (What should be said about Py_Print_RAW?)
*/
@@ -145,11 +145,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyObject_HasAttrString(PyObject *o, char *attr_name);
- Returns 1 if o has the attribute attr_name, and 0 otherwise.
- This is equivalent to the Python expression:
- hasattr(o,attr_name).
+ Returns 1 if o has the attribute attr_name, and 0 otherwise.
+ This is equivalent to the Python expression:
+ hasattr(o,attr_name).
- This function always succeeds.
+ This function always succeeds.
*/
@@ -157,9 +157,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyObject* PyObject_GetAttrString(PyObject *o, char *attr_name);
- Retrieve an attributed named attr_name form object o.
- Returns the attribute value on success, or NULL on failure.
- This is the equivalent of the Python expression: o.attr_name.
+ Retrieve an attributed named attr_name form object o.
+ Returns the attribute value on success, or NULL on failure.
+ This is the equivalent of the Python expression: o.attr_name.
*/
@@ -167,11 +167,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
- Returns 1 if o has the attribute attr_name, and 0 otherwise.
- This is equivalent to the Python expression:
- hasattr(o,attr_name).
+ Returns 1 if o has the attribute attr_name, and 0 otherwise.
+ This is equivalent to the Python expression:
+ hasattr(o,attr_name).
- This function always succeeds.
+ This function always succeeds.
*/
@@ -179,9 +179,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
- Retrieve an attributed named attr_name form object o.
- Returns the attribute value on success, or NULL on failure.
- This is the equivalent of the Python expression: o.attr_name.
+ Retrieve an attributed named attr_name form object o.
+ Returns the attribute value on success, or NULL on failure.
+ This is the equivalent of the Python expression: o.attr_name.
*/
@@ -190,9 +190,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyObject_SetAttrString(PyObject *o, char *attr_name, PyObject *v);
- Set the value of the attribute named attr_name, for object o,
- to the value, v. Returns -1 on failure. This is
- the equivalent of the Python statement: o.attr_name=v.
+ Set the value of the attribute named attr_name, for object o,
+ to the value, v. Returns -1 on failure. This is
+ the equivalent of the Python statement: o.attr_name=v.
*/
@@ -200,9 +200,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
- Set the value of the attribute named attr_name, for object o,
- to the value, v. Returns -1 on failure. This is
- the equivalent of the Python statement: o.attr_name=v.
+ Set the value of the attribute named attr_name, for object o,
+ to the value, v. Returns -1 on failure. This is
+ the equivalent of the Python statement: o.attr_name=v.
*/
@@ -210,9 +210,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyObject_DelAttrString(PyObject *o, char *attr_name);
- Delete attribute named attr_name, for object o. Returns
- -1 on failure. This is the equivalent of the Python
- statement: del o.attr_name.
+ Delete attribute named attr_name, for object o. Returns
+ -1 on failure. This is the equivalent of the Python
+ statement: del o.attr_name.
*/
#define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL)
@@ -221,9 +221,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
- Delete attribute named attr_name, for object o. Returns -1
- on failure. This is the equivalent of the Python
- statement: del o.attr_name.
+ Delete attribute named attr_name, for object o. Returns -1
+ on failure. This is the equivalent of the Python
+ statement: del o.attr_name.
*/
#define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL)
@@ -232,11 +232,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyObject *PyObject_Repr(PyObject *o);
- Compute the string representation of object, o. Returns the
- string representation on success, NULL on failure. This is
- the equivalent of the Python expression: repr(o).
+ Compute the string representation of object, o. Returns the
+ string representation on success, NULL on failure. This is
+ the equivalent of the Python expression: repr(o).
- Called by the repr() built-in function.
+ Called by the repr() built-in function.
*/
@@ -244,11 +244,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyObject *PyObject_Str(PyObject *o);
- Compute the string representation of object, o. Returns the
- string representation on success, NULL on failure. This is
- the equivalent of the Python expression: str(o).)
+ Compute the string representation of object, o. Returns the
+ string representation on success, NULL on failure. This is
+ the equivalent of the Python expression: str(o).)
- Called by the str() and print() built-in functions.
+ Called by the str() and print() built-in functions.
*/
@@ -256,42 +256,42 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(int) PyCallable_Check(PyObject *o);
- Determine if the object, o, is callable. Return 1 if the
- object is callable and 0 otherwise.
+ Determine if the object, o, is callable. Return 1 if the
+ object is callable and 0 otherwise.
- This function always succeeds.
+ This function always succeeds.
*/
PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object,
- PyObject *args, PyObject *kw);
+ PyObject *args, PyObject *kw);
/*
- Call a callable Python object, callable_object, with
- arguments and keywords arguments. The 'args' argument can not be
- NULL, but the 'kw' argument can be NULL.
+ Call a callable Python object, callable_object, with
+ arguments and keywords arguments. The 'args' argument can not be
+ NULL, but the 'kw' argument can be NULL.
*/
-
+
PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object,
PyObject *args);
/*
- Call a callable Python object, callable_object, with
- arguments given by the tuple, args. If no arguments are
- needed, then args may be NULL. Returns the result of the
- call on success, or NULL on failure. This is the equivalent
- of the Python expression: o(*args).
+ Call a callable Python object, callable_object, with
+ arguments given by the tuple, args. If no arguments are
+ needed, then args may be NULL. Returns the result of the
+ call on success, or NULL on failure. This is the equivalent
+ of the Python expression: o(*args).
*/
PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object,
char *format, ...);
/*
- Call a callable Python object, callable_object, with a
- variable number of C arguments. The C arguments are described
- using a mkvalue-style format string. The format may be NULL,
- indicating that no arguments are provided. Returns the
- result of the call on success, or NULL on failure. This is
- the equivalent of the Python expression: o(*args).
+ Call a callable Python object, callable_object, with a
+ variable number of C arguments. The C arguments are described
+ using a mkvalue-style format string. The format may be NULL,
+ indicating that no arguments are provided. Returns the
+ result of the call on success, or NULL on failure. This is
+ the equivalent of the Python expression: o(*args).
*/
@@ -299,29 +299,29 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
char *format, ...);
/*
- Call the method named m of object o with a variable number of
- C arguments. The C arguments are described by a mkvalue
- format string. The format may be NULL, indicating that no
- arguments are provided. Returns the result of the call on
- success, or NULL on failure. This is the equivalent of the
- Python expression: o.method(args).
+ Call the method named m of object o with a variable number of
+ C arguments. The C arguments are described by a mkvalue
+ format string. The format may be NULL, indicating that no
+ arguments are provided. Returns the result of the call on
+ success, or NULL on failure. This is the equivalent of the
+ Python expression: o.method(args).
*/
PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
- char *format, ...);
+ char *format, ...);
PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o,
- char *name,
- char *format, ...);
+ char *name,
+ char *format, ...);
PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
...);
/*
- Call a callable Python object, callable_object, with a
- variable number of C arguments. The C arguments are provided
- as PyObject * values, terminated by a NULL. Returns the
- result of the call on success, or NULL on failure. This is
- the equivalent of the Python expression: o(*args).
+ Call a callable Python object, callable_object, with a
+ variable number of C arguments. The C arguments are provided
+ as PyObject * values, terminated by a NULL. Returns the
+ result of the call on success, or NULL on failure. This is
+ the equivalent of the Python expression: o(*args).
*/
@@ -329,11 +329,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyObject *method, ...);
/*
- Call the method named m of object o with a variable number of
- C arguments. The C arguments are provided as PyObject *
- values, terminated by NULL. Returns the result of the call
- on success, or NULL on failure. This is the equivalent of
- the Python expression: o.method(args).
+ Call the method named m of object o with a variable number of
+ C arguments. The C arguments are provided as PyObject *
+ values, terminated by NULL. Returns the result of the call
+ on success, or NULL on failure. This is the equivalent of
+ the Python expression: o.method(args).
*/
@@ -341,9 +341,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
long PyObject_Hash(PyObject *o);
- Compute and return the hash, hash_value, of an object, o. On
- failure, return -1. This is the equivalent of the Python
- expression: hash(o).
+ Compute and return the hash, hash_value, of an object, o. On
+ failure, return -1. This is the equivalent of the Python
+ expression: hash(o).
*/
@@ -351,35 +351,35 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyObject_IsTrue(PyObject *o);
- Returns 1 if the object, o, is considered to be true, 0 if o is
- considered to be false and -1 on failure. This is equivalent to the
- Python expression: not not o
+ Returns 1 if the object, o, is considered to be true, 0 if o is
+ considered to be false and -1 on failure. This is equivalent to the
+ Python expression: not not o
*/
/* Implemented elsewhere:
int PyObject_Not(PyObject *o);
- Returns 0 if the object, o, is considered to be true, 1 if o is
- considered to be false and -1 on failure. This is equivalent to the
- Python expression: not o
+ Returns 0 if the object, o, is considered to be true, 1 if o is
+ considered to be false and -1 on failure. This is equivalent to the
+ Python expression: not o
*/
PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
/*
- On success, returns a type object corresponding to the object
- type of object o. On failure, returns NULL. This is
- equivalent to the Python expression: type(o).
+ On success, returns a type object corresponding to the object
+ type of object o. On failure, returns NULL. This is
+ equivalent to the Python expression: type(o).
*/
PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
/*
- Return the size of object o. If the object, o, provides
- both sequence and mapping protocols, the sequence size is
- returned. On error, -1 is returned. This is the equivalent
- to the Python expression: len(o).
+ Return the size of object o. If the object, o, provides
+ both sequence and mapping protocols, the sequence size is
+ returned. On error, -1 is returned. This is the equivalent
+ to the Python expression: len(o).
*/
/* For DLL compatibility */
@@ -390,203 +390,203 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o, Py_ssize_t);
/*
- Guess the size of object o using len(o) or o.__length_hint__().
- If neither of those return a non-negative value, then return the
- default value. If one of the calls fails, this function returns -1.
+ Guess the size of object o using len(o) or o.__length_hint__().
+ If neither of those return a non-negative value, then return the
+ default value. If one of the calls fails, this function returns -1.
*/
PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
/*
- Return element of o corresponding to the object, key, or NULL
- on failure. This is the equivalent of the Python expression:
- o[key].
+ Return element of o corresponding to the object, key, or NULL
+ on failure. This is the equivalent of the Python expression:
+ o[key].
*/
PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
/*
- Map the object, key, to the value, v. Returns
- -1 on failure. This is the equivalent of the Python
- statement: o[key]=v.
+ Map the object, key, to the value, v. Returns
+ -1 on failure. This is the equivalent of the Python
+ statement: o[key]=v.
*/
PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key);
/*
- Remove the mapping for object, key, from the object *o.
- Returns -1 on failure. This is equivalent to
- the Python statement: del o[key].
+ Remove the mapping for object, key, from the object *o.
+ Returns -1 on failure. This is equivalent to
+ the Python statement: del o[key].
*/
PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
/*
- Delete the mapping for key from *o. Returns -1 on failure.
- This is the equivalent of the Python statement: del o[key].
+ Delete the mapping for key from *o. Returns -1 on failure.
+ This is the equivalent of the Python statement: del o[key].
*/
- /* old buffer API
- FIXME: usage of these should all be replaced in Python itself
- but for backwards compatibility we will implement them.
- Their usage without a corresponding "unlock" mechansim
- may create issues (but they would already be there). */
+ /* old buffer API
+ FIXME: usage of these should all be replaced in Python itself
+ but for backwards compatibility we will implement them.
+ Their usage without a corresponding "unlock" mechansim
+ may create issues (but they would already be there). */
PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
- const char **buffer,
- Py_ssize_t *buffer_len);
+ const char **buffer,
+ Py_ssize_t *buffer_len);
- /*
- Takes an arbitrary object which must support the (character,
- single segment) buffer interface and returns a pointer to a
- read-only memory location useable as character based input
- for subsequent processing.
+ /*
+ Takes an arbitrary object which must support the (character,
+ single segment) buffer interface and returns a pointer to a
+ read-only memory location useable as character based input
+ for subsequent processing.
- 0 is returned on success. buffer and buffer_len are only
- set in case no error occurs. Otherwise, -1 is returned and
- an exception set.
+ 0 is returned on success. buffer and buffer_len are only
+ set in case no error occurs. Otherwise, -1 is returned and
+ an exception set.
*/
PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
- /*
- Checks whether an arbitrary object supports the (character,
- single segment) buffer interface. Returns 1 on success, 0
- on failure.
+ /*
+ Checks whether an arbitrary object supports the (character,
+ single segment) buffer interface. Returns 1 on success, 0
+ on failure.
*/
PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
- const void **buffer,
- Py_ssize_t *buffer_len);
+ const void **buffer,
+ Py_ssize_t *buffer_len);
- /*
- Same as PyObject_AsCharBuffer() except that this API expects
- (readable, single segment) buffer interface and returns a
- pointer to a read-only memory location which can contain
- arbitrary data.
+ /*
+ Same as PyObject_AsCharBuffer() except that this API expects
+ (readable, single segment) buffer interface and returns a
+ pointer to a read-only memory location which can contain
+ arbitrary data.
- 0 is returned on success. buffer and buffer_len are only
- set in case no error occurrs. Otherwise, -1 is returned and
- an exception set.
+ 0 is returned on success. buffer and buffer_len are only
+ set in case no error occurrs. Otherwise, -1 is returned and
+ an exception set.
*/
PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
- void **buffer,
- Py_ssize_t *buffer_len);
+ void **buffer,
+ Py_ssize_t *buffer_len);
- /*
- Takes an arbitrary object which must support the (writable,
- single segment) buffer interface and returns a pointer to a
- writable memory location in buffer of size buffer_len.
+ /*
+ Takes an arbitrary object which must support the (writable,
+ single segment) buffer interface and returns a pointer to a
+ writable memory location in buffer of size buffer_len.
- 0 is returned on success. buffer and buffer_len are only
- set in case no error occurrs. Otherwise, -1 is returned and
- an exception set.
+ 0 is returned on success. buffer and buffer_len are only
+ set in case no error occurrs. Otherwise, -1 is returned and
+ an exception set.
*/
- /* new buffer API */
+ /* new buffer API */
#define PyObject_CheckBuffer(obj) \
- (((obj)->ob_type->tp_as_buffer != NULL) && \
- ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL))
+ (((obj)->ob_type->tp_as_buffer != NULL) && \
+ ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL))
- /* Return 1 if the getbuffer function is available, otherwise
- return 0 */
+ /* Return 1 if the getbuffer function is available, otherwise
+ return 0 */
- PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,
- int flags);
+ PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,
+ int flags);
- /* This is a C-API version of the getbuffer function call. It checks
- to make sure object has the required function pointer and issues the
- call. Returns -1 and raises an error on failure and returns 0 on
- success
- */
+ /* This is a C-API version of the getbuffer function call. It checks
+ to make sure object has the required function pointer and issues the
+ call. Returns -1 and raises an error on failure and returns 0 on
+ success
+ */
PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices);
-
- /* Get the memory area pointed to by the indices for the buffer given.
- Note that view->ndim is the assumed size of indices
- */
+
+ /* Get the memory area pointed to by the indices for the buffer given.
+ Note that view->ndim is the assumed size of indices
+ */
PyAPI_FUNC(int) PyBuffer_SizeFromFormat(const char *);
-
- /* Return the implied itemsize of the data-format area from a
- struct-style description */
-
-
+ /* Return the implied itemsize of the data-format area from a
+ struct-style description */
+
+
+
PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view,
- Py_ssize_t len, char fort);
+ Py_ssize_t len, char fort);
- PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf,
- Py_ssize_t len, char fort);
+ PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf,
+ Py_ssize_t len, char fort);
- /* Copy len bytes of data from the contiguous chunk of memory
- pointed to by buf into the buffer exported by obj. Return
- 0 on success and return -1 and raise a PyBuffer_Error on
- error (i.e. the object does not have a buffer interface or
- it is not working).
+ /* Copy len bytes of data from the contiguous chunk of memory
+ pointed to by buf into the buffer exported by obj. Return
+ 0 on success and return -1 and raise a PyBuffer_Error on
+ error (i.e. the object does not have a buffer interface or
+ it is not working).
- If fort is 'F', then if the object is multi-dimensional,
- then the data will be copied into the array in
- Fortran-style (first dimension varies the fastest). If
- fort is 'C', then the data will be copied into the array
- in C-style (last dimension varies the fastest). If fort
- is 'A', then it does not matter and the copy will be made
- in whatever way is more efficient.
+ If fort is 'F', then if the object is multi-dimensional,
+ then the data will be copied into the array in
+ Fortran-style (first dimension varies the fastest). If
+ fort is 'C', then the data will be copied into the array
+ in C-style (last dimension varies the fastest). If fort
+ is 'A', then it does not matter and the copy will be made
+ in whatever way is more efficient.
- */
+ */
PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src);
-
- /* Copy the data from the src buffer to the buffer of destination
- */
+
+ /* Copy the data from the src buffer to the buffer of destination
+ */
PyAPI_FUNC(int) PyBuffer_IsContiguous(Py_buffer *view, char fort);
- PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,
- Py_ssize_t *shape,
- Py_ssize_t *strides,
- int itemsize,
- char fort);
+ PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,
+ Py_ssize_t *shape,
+ Py_ssize_t *strides,
+ int itemsize,
+ char fort);
- /* Fill the strides array with byte-strides of a contiguous
- (Fortran-style if fort is 'F' or C-style otherwise)
- array of the given shape with the given number of bytes
- per element.
- */
+ /* Fill the strides array with byte-strides of a contiguous
+ (Fortran-style if fort is 'F' or C-style otherwise)
+ array of the given shape with the given number of bytes
+ per element.
+ */
PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,
- Py_ssize_t len, int readonly,
- int flags);
+ Py_ssize_t len, int readonly,
+ int flags);
- /* Fills in a buffer-info structure correctly for an exporter
- that can only share a contiguous chunk of memory of
- "unsigned bytes" of the given length. Returns 0 on success
- and -1 (with raising an error) on error.
- */
+ /* Fills in a buffer-info structure correctly for an exporter
+ that can only share a contiguous chunk of memory of
+ "unsigned bytes" of the given length. Returns 0 on success
+ and -1 (with raising an error) on error.
+ */
PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);
/* Releases a Py_buffer obtained from getbuffer ParseTuple's s*.
- */
+ */
PyAPI_FUNC(PyObject *) PyObject_Format(PyObject* obj,
- PyObject *format_spec);
+ PyObject *format_spec);
/*
- Takes an arbitrary object and returns the result of
- calling obj.__format__(format_spec).
+ Takes an arbitrary object and returns the result of
+ calling obj.__format__(format_spec).
*/
/* Iterators */
PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
/* Takes an object and returns an iterator for it.
- This is typically a new iterator but if the argument
- is an iterator, this returns itself. */
+ This is typically a new iterator but if the argument
+ is an iterator, this returns itself. */
#define PyIter_Check(obj) \
((obj)->ob_type->tp_iternext != NULL && \
@@ -594,314 +594,314 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
/* Takes an iterator object and calls its tp_iternext slot,
- returning the next value. If the iterator is exhausted,
- this returns NULL without setting an exception.
- NULL with an exception means an error occurred. */
+ returning the next value. If the iterator is exhausted,
+ this returns NULL without setting an exception.
+ NULL with an exception means an error occurred. */
/* Number Protocol:*/
PyAPI_FUNC(int) PyNumber_Check(PyObject *o);
/*
- Returns 1 if the object, o, provides numeric protocols, and
- false otherwise.
+ Returns 1 if the object, o, provides numeric protocols, and
+ false otherwise.
- This function always succeeds.
+ This function always succeeds.
*/
PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
/*
- Returns the result of adding o1 and o2, or null on failure.
- This is the equivalent of the Python expression: o1+o2.
+ Returns the result of adding o1 and o2, or null on failure.
+ This is the equivalent of the Python expression: o1+o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
/*
- Returns the result of subtracting o2 from o1, or null on
- failure. This is the equivalent of the Python expression:
- o1-o2.
+ Returns the result of subtracting o2 from o1, or null on
+ failure. This is the equivalent of the Python expression:
+ o1-o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
/*
- Returns the result of multiplying o1 and o2, or null on
- failure. This is the equivalent of the Python expression:
- o1*o2.
+ Returns the result of multiplying o1 and o2, or null on
+ failure. This is the equivalent of the Python expression:
+ o1*o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
/*
- Returns the result of dividing o1 by o2 giving an integral result,
- or null on failure.
- This is the equivalent of the Python expression: o1//o2.
+ Returns the result of dividing o1 by o2 giving an integral result,
+ or null on failure.
+ This is the equivalent of the Python expression: o1//o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
/*
- Returns the result of dividing o1 by o2 giving a float result,
- or null on failure.
- This is the equivalent of the Python expression: o1/o2.
+ Returns the result of dividing o1 by o2 giving a float result,
+ or null on failure.
+ This is the equivalent of the Python expression: o1/o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
/*
- Returns the remainder of dividing o1 by o2, or null on
- failure. This is the equivalent of the Python expression:
- o1%o2.
+ Returns the remainder of dividing o1 by o2, or null on
+ failure. This is the equivalent of the Python expression:
+ o1%o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
/*
- See the built-in function divmod. Returns NULL on failure.
- This is the equivalent of the Python expression:
- divmod(o1,o2).
+ See the built-in function divmod. Returns NULL on failure.
+ This is the equivalent of the Python expression:
+ divmod(o1,o2).
*/
PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
PyObject *o3);
/*
- See the built-in function pow. Returns NULL on failure.
- This is the equivalent of the Python expression:
- pow(o1,o2,o3), where o3 is optional.
+ See the built-in function pow. Returns NULL on failure.
+ This is the equivalent of the Python expression:
+ pow(o1,o2,o3), where o3 is optional.
*/
PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
/*
- Returns the negation of o on success, or null on failure.
- This is the equivalent of the Python expression: -o.
+ Returns the negation of o on success, or null on failure.
+ This is the equivalent of the Python expression: -o.
*/
PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
/*
- Returns the (what?) of o on success, or NULL on failure.
- This is the equivalent of the Python expression: +o.
+ Returns the (what?) of o on success, or NULL on failure.
+ This is the equivalent of the Python expression: +o.
*/
PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
/*
- Returns the absolute value of o, or null on failure. This is
- the equivalent of the Python expression: abs(o).
+ Returns the absolute value of o, or null on failure. This is
+ the equivalent of the Python expression: abs(o).
*/
PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
/*
- Returns the bitwise negation of o on success, or NULL on
- failure. This is the equivalent of the Python expression:
- ~o.
+ Returns the bitwise negation of o on success, or NULL on
+ failure. This is the equivalent of the Python expression:
+ ~o.
*/
PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
/*
- Returns the result of left shifting o1 by o2 on success, or
- NULL on failure. This is the equivalent of the Python
- expression: o1 << o2.
+ Returns the result of left shifting o1 by o2 on success, or
+ NULL on failure. This is the equivalent of the Python
+ expression: o1 << o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
/*
- Returns the result of right shifting o1 by o2 on success, or
- NULL on failure. This is the equivalent of the Python
- expression: o1 >> o2.
+ Returns the result of right shifting o1 by o2 on success, or
+ NULL on failure. This is the equivalent of the Python
+ expression: o1 >> o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
/*
- Returns the result of bitwise and of o1 and o2 on success, or
- NULL on failure. This is the equivalent of the Python
- expression: o1&o2.
+ Returns the result of bitwise and of o1 and o2 on success, or
+ NULL on failure. This is the equivalent of the Python
+ expression: o1&o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
/*
- Returns the bitwise exclusive or of o1 by o2 on success, or
- NULL on failure. This is the equivalent of the Python
- expression: o1^o2.
+ Returns the bitwise exclusive or of o1 by o2 on success, or
+ NULL on failure. This is the equivalent of the Python
+ expression: o1^o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
/*
- Returns the result of bitwise or on o1 and o2 on success, or
- NULL on failure. This is the equivalent of the Python
- expression: o1|o2.
+ Returns the result of bitwise or on o1 and o2 on success, or
+ NULL on failure. This is the equivalent of the Python
+ expression: o1|o2.
*/
#define PyIndex_Check(obj) \
((obj)->ob_type->tp_as_number != NULL && \
(obj)->ob_type->tp_as_number->nb_index != NULL)
-
+
PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
/*
- Returns the object converted to a Python long or int
- or NULL with an error raised on failure.
+ Returns the object converted to a Python long or int
+ or NULL with an error raised on failure.
*/
PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
/*
- Returns the Integral instance converted to an int. The
- instance is expected to be int or long or have an __int__
- method. Steals integral's reference. error_format will be
- used to create the TypeError if integral isn't actually an
- Integral instance. error_format should be a format string
- that can accept a char* naming integral's type.
+ Returns the Integral instance converted to an int. The
+ instance is expected to be int or long or have an __int__
+ method. Steals integral's reference. error_format will be
+ used to create the TypeError if integral isn't actually an
+ Integral instance. error_format should be a format string
+ that can accept a char* naming integral's type.
*/
PyAPI_FUNC(PyObject *) _PyNumber_ConvertIntegralToInt(
- PyObject *integral,
- const char* error_format);
+ PyObject *integral,
+ const char* error_format);
/*
- Returns the object converted to Py_ssize_t by going through
- PyNumber_Index first. If an overflow error occurs while
- converting the int-or-long to Py_ssize_t, then the second argument
- is the error-type to return. If it is NULL, then the overflow error
- is cleared and the value is clipped.
+ Returns the object converted to Py_ssize_t by going through
+ PyNumber_Index first. If an overflow error occurs while
+ converting the int-or-long to Py_ssize_t, then the second argument
+ is the error-type to return. If it is NULL, then the overflow error
+ is cleared and the value is clipped.
*/
PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
/*
- Returns the o converted to an integer object on success, or
- NULL on failure. This is the equivalent of the Python
- expression: int(o).
+ Returns the o converted to an integer object on success, or
+ NULL on failure. This is the equivalent of the Python
+ expression: int(o).
*/
PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
/*
- Returns the o converted to a float object on success, or NULL
- on failure. This is the equivalent of the Python expression:
- float(o).
+ Returns the o converted to a float object on success, or NULL
+ on failure. This is the equivalent of the Python expression:
+ float(o).
*/
-
+
/* In-place variants of (some of) the above number protocol functions */
PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
/*
- Returns the result of adding o2 to o1, possibly in-place, or null
- on failure. This is the equivalent of the Python expression:
- o1 += o2.
+ Returns the result of adding o2 to o1, possibly in-place, or null
+ on failure. This is the equivalent of the Python expression:
+ o1 += o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
/*
- Returns the result of subtracting o2 from o1, possibly in-place or
- null on failure. This is the equivalent of the Python expression:
- o1 -= o2.
+ Returns the result of subtracting o2 from o1, possibly in-place or
+ null on failure. This is the equivalent of the Python expression:
+ o1 -= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
/*
- Returns the result of multiplying o1 by o2, possibly in-place, or
- null on failure. This is the equivalent of the Python expression:
- o1 *= o2.
+ Returns the result of multiplying o1 by o2, possibly in-place, or
+ null on failure. This is the equivalent of the Python expression:
+ o1 *= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
- PyObject *o2);
+ PyObject *o2);
/*
- Returns the result of dividing o1 by o2 giving an integral result,
- possibly in-place, or null on failure.
- This is the equivalent of the Python expression:
- o1 /= o2.
+ Returns the result of dividing o1 by o2 giving an integral result,
+ possibly in-place, or null on failure.
+ This is the equivalent of the Python expression:
+ o1 /= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
- PyObject *o2);
+ PyObject *o2);
/*
- Returns the result of dividing o1 by o2 giving a float result,
- possibly in-place, or null on failure.
- This is the equivalent of the Python expression:
- o1 /= o2.
+ Returns the result of dividing o1 by o2 giving a float result,
+ possibly in-place, or null on failure.
+ This is the equivalent of the Python expression:
+ o1 /= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
/*
- Returns the remainder of dividing o1 by o2, possibly in-place, or
- null on failure. This is the equivalent of the Python expression:
- o1 %= o2.
+ Returns the remainder of dividing o1 by o2, possibly in-place, or
+ null on failure. This is the equivalent of the Python expression:
+ o1 %= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
- PyObject *o3);
+ PyObject *o3);
/*
- Returns the result of raising o1 to the power of o2, possibly
- in-place, or null on failure. This is the equivalent of the Python
- expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present.
+ Returns the result of raising o1 to the power of o2, possibly
+ in-place, or null on failure. This is the equivalent of the Python
+ expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
/*
- Returns the result of left shifting o1 by o2, possibly in-place, or
- null on failure. This is the equivalent of the Python expression:
- o1 <<= o2.
+ Returns the result of left shifting o1 by o2, possibly in-place, or
+ null on failure. This is the equivalent of the Python expression:
+ o1 <<= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
/*
- Returns the result of right shifting o1 by o2, possibly in-place or
- null on failure. This is the equivalent of the Python expression:
- o1 >>= o2.
+ Returns the result of right shifting o1 by o2, possibly in-place or
+ null on failure. This is the equivalent of the Python expression:
+ o1 >>= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
/*
- Returns the result of bitwise and of o1 and o2, possibly in-place,
- or null on failure. This is the equivalent of the Python
- expression: o1 &= o2.
+ Returns the result of bitwise and of o1 and o2, possibly in-place,
+ or null on failure. This is the equivalent of the Python
+ expression: o1 &= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
/*
- Returns the bitwise exclusive or of o1 by o2, possibly in-place, or
- null on failure. This is the equivalent of the Python expression:
- o1 ^= o2.
+ Returns the bitwise exclusive or of o1 by o2, possibly in-place, or
+ null on failure. This is the equivalent of the Python expression:
+ o1 ^= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
/*
- Returns the result of bitwise or of o1 and o2, possibly in-place,
- or null on failure. This is the equivalent of the Python
- expression: o1 |= o2.
+ Returns the result of bitwise or of o1 and o2, possibly in-place,
+ or null on failure. This is the equivalent of the Python
+ expression: o1 |= o2.
*/
PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
/*
- Returns the integer n converted to a string with a base, with a base
- marker of 0b, 0o or 0x prefixed if applicable.
- If n is not an int object, it is converted with PyNumber_Index first.
+ Returns the integer n converted to a string with a base, with a base
+ marker of 0b, 0o or 0x prefixed if applicable.
+ If n is not an int object, it is converted with PyNumber_Index first.
*/
@@ -910,16 +910,16 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(int) PySequence_Check(PyObject *o);
/*
- Return 1 if the object provides sequence protocol, and zero
- otherwise.
+ Return 1 if the object provides sequence protocol, and zero
+ otherwise.
- This function always succeeds.
+ This function always succeeds.
*/
PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
/*
- Return the size of sequence object o, or -1 on failure.
+ Return the size of sequence object o, or -1 on failure.
*/
/* For DLL compatibility */
@@ -931,147 +931,147 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
/*
- Return the concatenation of o1 and o2 on success, and NULL on
- failure. This is the equivalent of the Python
- expression: o1+o2.
+ Return the concatenation of o1 and o2 on success, and NULL on
+ failure. This is the equivalent of the Python
+ expression: o1+o2.
*/
PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
/*
- Return the result of repeating sequence object o count times,
- or NULL on failure. This is the equivalent of the Python
- expression: o1*count.
+ Return the result of repeating sequence object o count times,
+ or NULL on failure. This is the equivalent of the Python
+ expression: o1*count.
*/
PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
/*
- Return the ith element of o, or NULL on failure. This is the
- equivalent of the Python expression: o[i].
+ Return the ith element of o, or NULL on failure. This is the
+ equivalent of the Python expression: o[i].
*/
PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
/*
- Return the slice of sequence object o between i1 and i2, or
- NULL on failure. This is the equivalent of the Python
- expression: o[i1:i2].
+ Return the slice of sequence object o between i1 and i2, or
+ NULL on failure. This is the equivalent of the Python
+ expression: o[i1:i2].
*/
PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
/*
- Assign object v to the ith element of o. Returns
- -1 on failure. This is the equivalent of the Python
- statement: o[i]=v.
+ Assign object v to the ith element of o. Returns
+ -1 on failure. This is the equivalent of the Python
+ statement: o[i]=v.
*/
PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
/*
- Delete the ith element of object v. Returns
- -1 on failure. This is the equivalent of the Python
- statement: del o[i].
+ Delete the ith element of object v. Returns
+ -1 on failure. This is the equivalent of the Python
+ statement: del o[i].
*/
PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
PyObject *v);
/*
- Assign the sequence object, v, to the slice in sequence
- object, o, from i1 to i2. Returns -1 on failure. This is the
- equivalent of the Python statement: o[i1:i2]=v.
+ Assign the sequence object, v, to the slice in sequence
+ object, o, from i1 to i2. Returns -1 on failure. This is the
+ equivalent of the Python statement: o[i1:i2]=v.
*/
PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
/*
- Delete the slice in sequence object, o, from i1 to i2.
- Returns -1 on failure. This is the equivalent of the Python
- statement: del o[i1:i2].
+ Delete the slice in sequence object, o, from i1 to i2.
+ Returns -1 on failure. This is the equivalent of the Python
+ statement: del o[i1:i2].
*/
PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);
/*
- Returns the sequence, o, as a tuple on success, and NULL on failure.
- This is equivalent to the Python expression: tuple(o)
+ Returns the sequence, o, as a tuple on success, and NULL on failure.
+ This is equivalent to the Python expression: tuple(o)
*/
PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);
/*
- Returns the sequence, o, as a list on success, and NULL on failure.
- This is equivalent to the Python expression: list(o)
+ Returns the sequence, o, as a list on success, and NULL on failure.
+ This is equivalent to the Python expression: list(o)
*/
PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
/*
- Returns the sequence, o, as a tuple, unless it's already a
- tuple or list. Use PySequence_Fast_GET_ITEM to access the
- members of this list, and PySequence_Fast_GET_SIZE to get its length.
+ Returns the sequence, o, as a tuple, unless it's already a
+ tuple or list. Use PySequence_Fast_GET_ITEM to access the
+ members of this list, and PySequence_Fast_GET_SIZE to get its length.
- Returns NULL on failure. If the object does not support iteration,
- raises a TypeError exception with m as the message text.
+ Returns NULL on failure. If the object does not support iteration,
+ raises a TypeError exception with m as the message text.
*/
#define PySequence_Fast_GET_SIZE(o) \
- (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
+ (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
/*
- Return the size of o, assuming that o was returned by
- PySequence_Fast and is not NULL.
+ Return the size of o, assuming that o was returned by
+ PySequence_Fast and is not NULL.
*/
#define PySequence_Fast_GET_ITEM(o, i)\
(PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
/*
- Return the ith element of o, assuming that o was returned by
- PySequence_Fast, and that i is within bounds.
+ Return the ith element of o, assuming that o was returned by
+ PySequence_Fast, and that i is within bounds.
*/
#define PySequence_ITEM(o, i)\
- ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )
+ ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )
/* Assume tp_as_sequence and sq_item exist and that i does not
- need to be corrected for a negative index
- */
+ need to be corrected for a negative index
+ */
#define PySequence_Fast_ITEMS(sf) \
- (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
- : ((PyTupleObject *)(sf))->ob_item)
- /* Return a pointer to the underlying item array for
- an object retured by PySequence_Fast */
+ (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
+ : ((PyTupleObject *)(sf))->ob_item)
+ /* Return a pointer to the underlying item array for
+ an object retured by PySequence_Fast */
PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
/*
- Return the number of occurrences on value on 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).
+ Return the number of occurrences on value on 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).
*/
PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
/*
- Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
- Use __contains__ if possible, else _PySequence_IterSearch().
+ Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
+ Use __contains__ if possible, else _PySequence_IterSearch().
*/
#define PY_ITERSEARCH_COUNT 1
#define PY_ITERSEARCH_INDEX 2
#define PY_ITERSEARCH_CONTAINS 3
PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,
- PyObject *obj, int operation);
- /*
- Iterate over seq. Result depends on the operation:
- PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
- error.
- PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of
- obj in seq; set ValueError and return -1 if none found;
- also return -1 on error.
- PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
- error.
- */
+ PyObject *obj, int operation);
+ /*
+ Iterate over seq. Result depends on the operation:
+ PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
+ error.
+ PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of
+ obj in seq; set ValueError and return -1 if none found;
+ also return -1 on error.
+ PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
+ error.
+ */
/* For DLL-level backwards compatibility */
#undef PySequence_In
@@ -1081,17 +1081,17 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
#define PySequence_In PySequence_Contains
/*
- Determine if o contains value. If an item in o is equal to
- X, return 1, otherwise return 0. On error, return -1. This
- is equivalent to the Python expression: value in o.
+ Determine if o contains value. If an item in o is equal to
+ X, return 1, otherwise return 0. On error, return -1. This
+ is equivalent to the Python expression: value in o.
*/
PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);
/*
- Return the first index for which o[i]=value. On error,
- return -1. This is equivalent to the Python
- expression: o.index(value).
+ Return the first index for which o[i]=value. On error,
+ return -1. This is equivalent to the Python
+ expression: o.index(value).
*/
/* In-place versions of some of the above Sequence functions. */
@@ -1099,18 +1099,18 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
/*
- Append o2 to o1, in-place when possible. Return the resulting
- object, which could be o1, or NULL on failure. This is the
- equivalent of the Python expression: o1 += o2.
+ Append o2 to o1, in-place when possible. Return the resulting
+ object, which could be o1, or NULL on failure. This is the
+ equivalent of the Python expression: o1 += o2.
*/
PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
/*
- Repeat o1 by count, in-place when possible. Return the resulting
- object, which could be o1, or NULL on failure. This is the
- equivalent of the Python expression: o1 *= count.
+ Repeat o1 by count, in-place when possible. Return the resulting
+ object, which could be o1, or NULL on failure. This is the
+ equivalent of the Python expression: o1 *= count.
*/
@@ -1119,18 +1119,18 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(int) PyMapping_Check(PyObject *o);
/*
- Return 1 if the object provides mapping protocol, and zero
- otherwise.
+ Return 1 if the object provides mapping protocol, and zero
+ otherwise.
- This function always succeeds.
+ This function always succeeds.
*/
PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
/*
- Returns the number of keys in object o on success, and -1 on
- failure. For objects that do not provide sequence protocol,
- this is equivalent to the Python expression: len(o).
+ Returns the number of keys in object o on success, and -1 on
+ failure. For objects that do not provide sequence protocol,
+ this is equivalent to the Python expression: len(o).
*/
/* For DLL compatibility */
@@ -1143,9 +1143,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyMapping_DelItemString(PyObject *o, char *key);
- Remove the mapping for object, key, from the object *o.
- Returns -1 on failure. This is equivalent to
- the Python statement: del o[key].
+ Remove the mapping for object, key, from the object *o.
+ Returns -1 on failure. This is equivalent to
+ the Python statement: del o[key].
*/
#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
@@ -1153,71 +1153,71 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
int PyMapping_DelItem(PyObject *o, PyObject *key);
- Remove the mapping for object, key, from the object *o.
- Returns -1 on failure. This is equivalent to
- the Python statement: del o[key].
+ Remove the mapping for object, key, from the object *o.
+ Returns -1 on failure. This is equivalent to
+ the Python statement: del o[key].
*/
#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, char *key);
/*
- On success, return 1 if the mapping object has the key, key,
- and 0 otherwise. This is equivalent to the Python expression:
- key in o.
+ On success, return 1 if the mapping object has the key, key,
+ and 0 otherwise. This is equivalent to the Python expression:
+ key in o.
- This function always succeeds.
+ This function always succeeds.
*/
PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);
/*
- Return 1 if the mapping object has the key, key,
- and 0 otherwise. This is equivalent to the Python expression:
- key in o.
+ Return 1 if the mapping object has the key, key,
+ and 0 otherwise. This is equivalent to the Python expression:
+ key in o.
- This function always succeeds.
+ This function always succeeds.
*/
PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o);
/*
- On success, return a list or tuple of the keys in object o.
- On failure, return NULL.
+ On success, return a list or tuple of the keys in object o.
+ On failure, return NULL.
*/
PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o);
/*
- On success, return a list or tuple of the values in object o.
- On failure, return NULL.
+ On success, return a list or tuple of the values in object o.
+ On failure, return NULL.
*/
PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o);
/*
- On success, return a list or tuple of the items in object o,
- where each item is a tuple containing a key-value pair.
- On failure, return NULL.
+ On success, return a list or tuple of the items in object o,
+ where each item is a tuple containing a key-value pair.
+ On failure, return NULL.
*/
PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, char *key);
/*
- Return element of o corresponding to the object, key, or NULL
- on failure. This is the equivalent of the Python expression:
- o[key].
+ Return element of o corresponding to the object, key, or NULL
+ on failure. This is the equivalent of the Python expression:
+ o[key].
*/
PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, char *key,
PyObject *value);
/*
- Map the object, key, to the value, v. Returns
- -1 on failure. This is the equivalent of the Python
- statement: o[key]=v.
+ Map the object, key, to the value, v. Returns
+ -1 on failure. This is the equivalent of the Python
+ statement: o[key]=v.
*/
diff --git a/Include/ceval.h b/Include/ceval.h
index 7bd8179..6d240e5 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -8,7 +8,7 @@ extern "C" {
/* Interface to random parts in ceval.c */
PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
- PyObject *, PyObject *, PyObject *);
+ PyObject *, PyObject *, PyObject *);
/* DLL-level Backwards compatibility: */
#undef PyEval_CallObject
@@ -16,7 +16,7 @@ PyAPI_FUNC(PyObject *) PyEval_CallObject(PyObject *, PyObject *);
/* Inline this */
#define PyEval_CallObject(func,arg) \
- PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
+ PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj,
const char *format, ...);
@@ -49,7 +49,7 @@ PyAPI_FUNC(int) Py_MakePendingCalls(void);
exceeds the current recursion limit. It raises a RuntimeError, and sets
the "overflowed" flag in the thread state structure. This flag
temporarily *disables* the normal protection; this allows cleanup code
- to potentially outgrow the recursion limit while processing the
+ to potentially outgrow the recursion limit while processing the
RuntimeError.
* "last chance" anti-recursion protection is triggered when the recursion
level exceeds "current recursion limit + 50". By construction, this
@@ -71,12 +71,12 @@ PyAPI_FUNC(void) Py_SetRecursionLimit(int);
PyAPI_FUNC(int) Py_GetRecursionLimit(void);
#define Py_EnterRecursiveCall(where) \
- (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
- _Py_CheckRecursiveCall(where))
-#define Py_LeaveRecursiveCall() \
+ (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
+ _Py_CheckRecursiveCall(where))
+#define Py_LeaveRecursiveCall() \
do{ if(_Py_MakeEndRecCheck(PyThreadState_GET()->recursion_depth)) \
- PyThreadState_GET()->overflowed = 0; \
- } while(0)
+ PyThreadState_GET()->overflowed = 0; \
+ } while(0)
PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);
PyAPI_DATA(int) _Py_CheckRecursionLimit;
@@ -87,15 +87,15 @@ PyAPI_DATA(int) _Py_CheckRecursionLimit;
of _Py_CheckRecursionLimit for _Py_MakeEndRecCheck() to function properly.
*/
# define _Py_MakeRecCheck(x) \
- (++(x) > (_Py_CheckRecursionLimit += PyThreadState_GET()->overflowed - 1))
+ (++(x) > (_Py_CheckRecursionLimit += PyThreadState_GET()->overflowed - 1))
#else
# define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
#endif
#define _Py_MakeEndRecCheck(x) \
- (--(x) < ((_Py_CheckRecursionLimit > 100) \
- ? (_Py_CheckRecursionLimit - 50) \
- : (3 * (_Py_CheckRecursionLimit >> 2))))
+ (--(x) < ((_Py_CheckRecursionLimit > 100) \
+ ? (_Py_CheckRecursionLimit - 50) \
+ : (3 * (_Py_CheckRecursionLimit >> 2))))
#define Py_ALLOW_RECURSION \
do { unsigned char _old = PyThreadState_GET()->recursion_critical;\
@@ -122,31 +122,31 @@ PyAPI_DATA(int) _Py_CheckInterval;
that lasts a long time and doesn't touch Python data) can allow other
threads to run as follows:
- ...preparations here...
- Py_BEGIN_ALLOW_THREADS
- ...blocking system call here...
- Py_END_ALLOW_THREADS
- ...interpret result here...
+ ...preparations here...
+ Py_BEGIN_ALLOW_THREADS
+ ...blocking system call here...
+ Py_END_ALLOW_THREADS
+ ...interpret result here...
The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
{}-surrounded block.
To leave the block in the middle (e.g., with return), you must insert
a line containing Py_BLOCK_THREADS before the return, e.g.
- if (...premature_exit...) {
- Py_BLOCK_THREADS
- PyErr_SetFromErrno(PyExc_IOError);
- return NULL;
- }
+ if (...premature_exit...) {
+ Py_BLOCK_THREADS
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
+ }
An alternative is:
- Py_BLOCK_THREADS
- if (...premature_exit...) {
- PyErr_SetFromErrno(PyExc_IOError);
- return NULL;
- }
- Py_UNBLOCK_THREADS
+ Py_BLOCK_THREADS
+ if (...premature_exit...) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
+ }
+ Py_UNBLOCK_THREADS
For convenience, that the value of 'errno' is restored across
Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
@@ -175,12 +175,12 @@ PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
PyAPI_FUNC(void) PyEval_ReInitThreads(void);
#define Py_BEGIN_ALLOW_THREADS { \
- PyThreadState *_save; \
- _save = PyEval_SaveThread();
-#define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
-#define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
-#define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
- }
+ PyThreadState *_save; \
+ _save = PyEval_SaveThread();
+#define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
+#define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
+#define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
+ }
#else /* !WITH_THREAD */
diff --git a/Include/datetime.h b/Include/datetime.h
index 4b506b2..cb96799 100644
--- a/Include/datetime.h
+++ b/Include/datetime.h
@@ -11,13 +11,13 @@ extern "C" {
* big-endian, unless otherwise noted:
*
* byte offset
- * 0 year 2 bytes, 1-9999
- * 2 month 1 byte, 1-12
- * 3 day 1 byte, 1-31
- * 4 hour 1 byte, 0-23
- * 5 minute 1 byte, 0-59
- * 6 second 1 byte, 0-59
- * 7 usecond 3 bytes, 0-999999
+ * 0 year 2 bytes, 1-9999
+ * 2 month 1 byte, 1-12
+ * 3 day 1 byte, 1-31
+ * 4 hour 1 byte, 0-23
+ * 5 minute 1 byte, 0-59
+ * 6 second 1 byte, 0-59
+ * 7 usecond 3 bytes, 0-999999
* 10
*/
@@ -33,26 +33,26 @@ extern "C" {
typedef struct
{
- PyObject_HEAD
- long hashcode; /* -1 when unknown */
- int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
- int seconds; /* 0 <= seconds < 24*3600 is invariant */
- int microseconds; /* 0 <= microseconds < 1000000 is invariant */
+ PyObject_HEAD
+ long hashcode; /* -1 when unknown */
+ int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
+ int seconds; /* 0 <= seconds < 24*3600 is invariant */
+ int microseconds; /* 0 <= microseconds < 1000000 is invariant */
} PyDateTime_Delta;
typedef struct
{
- PyObject_HEAD /* a pure abstract base clase */
+ PyObject_HEAD /* a pure abstract base clase */
} PyDateTime_TZInfo;
/* The datetime and time types have hashcodes, and an optional tzinfo member,
* present if and only if hastzinfo is true.
*/
-#define _PyTZINFO_HEAD \
- PyObject_HEAD \
- long hashcode; \
- char hastzinfo; /* boolean flag */
+#define _PyTZINFO_HEAD \
+ PyObject_HEAD \
+ long hashcode; \
+ char hastzinfo; /* boolean flag */
/* No _PyDateTime_BaseTZInfo is allocated; it's just to have something
* convenient to cast to, when getting at the hastzinfo member of objects
@@ -60,7 +60,7 @@ typedef struct
*/
typedef struct
{
- _PyTZINFO_HEAD
+ _PyTZINFO_HEAD
} _PyDateTime_BaseTZInfo;
/* All time objects are of PyDateTime_TimeType, but that can be allocated
@@ -69,20 +69,20 @@ typedef struct
* internal struct used to allocate the right amount of space for the
* "without" case.
*/
-#define _PyDateTime_TIMEHEAD \
- _PyTZINFO_HEAD \
- unsigned char data[_PyDateTime_TIME_DATASIZE];
+#define _PyDateTime_TIMEHEAD \
+ _PyTZINFO_HEAD \
+ unsigned char data[_PyDateTime_TIME_DATASIZE];
typedef struct
{
- _PyDateTime_TIMEHEAD
-} _PyDateTime_BaseTime; /* hastzinfo false */
+ _PyDateTime_TIMEHEAD
+} _PyDateTime_BaseTime; /* hastzinfo false */
typedef struct
{
- _PyDateTime_TIMEHEAD
- PyObject *tzinfo;
-} PyDateTime_Time; /* hastzinfo true */
+ _PyDateTime_TIMEHEAD
+ PyObject *tzinfo;
+} PyDateTime_Time; /* hastzinfo true */
/* All datetime objects are of PyDateTime_DateTimeType, but that can be
@@ -92,48 +92,48 @@ typedef struct
*/
typedef struct
{
- _PyTZINFO_HEAD
- unsigned char data[_PyDateTime_DATE_DATASIZE];
+ _PyTZINFO_HEAD
+ unsigned char data[_PyDateTime_DATE_DATASIZE];
} PyDateTime_Date;
-#define _PyDateTime_DATETIMEHEAD \
- _PyTZINFO_HEAD \
- unsigned char data[_PyDateTime_DATETIME_DATASIZE];
+#define _PyDateTime_DATETIMEHEAD \
+ _PyTZINFO_HEAD \
+ unsigned char data[_PyDateTime_DATETIME_DATASIZE];
typedef struct
{
- _PyDateTime_DATETIMEHEAD
-} _PyDateTime_BaseDateTime; /* hastzinfo false */
+ _PyDateTime_DATETIMEHEAD
+} _PyDateTime_BaseDateTime; /* hastzinfo false */
typedef struct
{
- _PyDateTime_DATETIMEHEAD
- PyObject *tzinfo;
-} PyDateTime_DateTime; /* hastzinfo true */
+ _PyDateTime_DATETIMEHEAD
+ PyObject *tzinfo;
+} PyDateTime_DateTime; /* hastzinfo true */
/* Apply for date and datetime instances. */
#define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \
- ((PyDateTime_Date*)o)->data[1])
+ ((PyDateTime_Date*)o)->data[1])
#define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2])
#define PyDateTime_GET_DAY(o) (((PyDateTime_Date*)o)->data[3])
#define PyDateTime_DATE_GET_HOUR(o) (((PyDateTime_DateTime*)o)->data[4])
#define PyDateTime_DATE_GET_MINUTE(o) (((PyDateTime_DateTime*)o)->data[5])
#define PyDateTime_DATE_GET_SECOND(o) (((PyDateTime_DateTime*)o)->data[6])
-#define PyDateTime_DATE_GET_MICROSECOND(o) \
- ((((PyDateTime_DateTime*)o)->data[7] << 16) | \
- (((PyDateTime_DateTime*)o)->data[8] << 8) | \
- ((PyDateTime_DateTime*)o)->data[9])
+#define PyDateTime_DATE_GET_MICROSECOND(o) \
+ ((((PyDateTime_DateTime*)o)->data[7] << 16) | \
+ (((PyDateTime_DateTime*)o)->data[8] << 8) | \
+ ((PyDateTime_DateTime*)o)->data[9])
/* Apply for time instances. */
#define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0])
#define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)o)->data[1])
#define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)o)->data[2])
-#define PyDateTime_TIME_GET_MICROSECOND(o) \
- ((((PyDateTime_Time*)o)->data[3] << 16) | \
- (((PyDateTime_Time*)o)->data[4] << 8) | \
- ((PyDateTime_Time*)o)->data[5])
+#define PyDateTime_TIME_GET_MICROSECOND(o) \
+ ((((PyDateTime_Time*)o)->data[3] << 16) | \
+ (((PyDateTime_Time*)o)->data[4] << 8) | \
+ ((PyDateTime_Time*)o)->data[5])
/* Define structure for C API. */
@@ -148,7 +148,7 @@ typedef struct {
/* constructors */
PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*);
PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int,
- PyObject*, PyTypeObject*);
+ PyObject*, PyTypeObject*);
PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*);
PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*);
@@ -185,7 +185,7 @@ typedef struct {
static PyDateTime_CAPI *PyDateTimeAPI;
#define PyDateTime_IMPORT \
- PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
+ PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
/* Macros for type checking when not building the Python core. */
#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
@@ -205,30 +205,30 @@ static PyDateTime_CAPI *PyDateTimeAPI;
/* Macros for accessing constructors in a simplified fashion. */
#define PyDate_FromDate(year, month, day) \
- PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)
+ PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)
#define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \
- PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \
- min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)
+ PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \
+ min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)
#define PyTime_FromTime(hour, minute, second, usecond) \
- PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \
- Py_None, PyDateTimeAPI->TimeType)
+ PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \
+ Py_None, PyDateTimeAPI->TimeType)
#define PyDelta_FromDSU(days, seconds, useconds) \
- PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \
- PyDateTimeAPI->DeltaType)
+ PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \
+ PyDateTimeAPI->DeltaType)
/* Macros supporting the DB API. */
#define PyDateTime_FromTimestamp(args) \
- PyDateTimeAPI->DateTime_FromTimestamp( \
- (PyObject*) (PyDateTimeAPI->DateTimeType), args, NULL)
+ PyDateTimeAPI->DateTime_FromTimestamp( \
+ (PyObject*) (PyDateTimeAPI->DateTimeType), args, NULL)
#define PyDate_FromTimestamp(args) \
- PyDateTimeAPI->Date_FromTimestamp( \
- (PyObject*) (PyDateTimeAPI->DateType), args)
+ PyDateTimeAPI->Date_FromTimestamp( \
+ (PyObject*) (PyDateTimeAPI->DateType), args)
-#endif /* Py_BUILD_CORE */
+#endif /* Py_BUILD_CORE */
#ifdef __cplusplus
}
diff --git a/Include/descrobject.h b/Include/descrobject.h
index f06b421..d2fe109 100644
--- a/Include/descrobject.h
+++ b/Include/descrobject.h
@@ -9,27 +9,27 @@ typedef PyObject *(*getter)(PyObject *, void *);
typedef int (*setter)(PyObject *, PyObject *, void *);
typedef struct PyGetSetDef {
- char *name;
- getter get;
- setter set;
- char *doc;
- void *closure;
+ char *name;
+ getter get;
+ setter set;
+ char *doc;
+ void *closure;
} PyGetSetDef;
typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
- void *wrapped);
+ void *wrapped);
typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args,
- void *wrapped, PyObject *kwds);
+ void *wrapped, PyObject *kwds);
struct wrapperbase {
- char *name;
- int offset;
- void *function;
- wrapperfunc wrapper;
- char *doc;
- int flags;
- PyObject *name_strobj;
+ char *name;
+ int offset;
+ void *function;
+ wrapperfunc wrapper;
+ char *doc;
+ int flags;
+ PyObject *name_strobj;
};
/* Flags for above struct */
@@ -38,33 +38,33 @@ struct wrapperbase {
/* Various kinds of descriptor objects */
#define PyDescr_COMMON \
- PyObject_HEAD \
- PyTypeObject *d_type; \
- PyObject *d_name
+ PyObject_HEAD \
+ PyTypeObject *d_type; \
+ PyObject *d_name
typedef struct {
- PyDescr_COMMON;
+ PyDescr_COMMON;
} PyDescrObject;
typedef struct {
- PyDescr_COMMON;
- PyMethodDef *d_method;
+ PyDescr_COMMON;
+ PyMethodDef *d_method;
} PyMethodDescrObject;
typedef struct {
- PyDescr_COMMON;
- struct PyMemberDef *d_member;
+ PyDescr_COMMON;
+ struct PyMemberDef *d_member;
} PyMemberDescrObject;
typedef struct {
- PyDescr_COMMON;
- PyGetSetDef *d_getset;
+ PyDescr_COMMON;
+ PyGetSetDef *d_getset;
} PyGetSetDescrObject;
typedef struct {
- PyDescr_COMMON;
- struct wrapperbase *d_base;
- void *d_wrapped; /* This can be any function pointer */
+ PyDescr_COMMON;
+ struct wrapperbase *d_base;
+ void *d_wrapped; /* This can be any function pointer */
} PyWrapperDescrObject;
PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
@@ -77,11 +77,11 @@ PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
- struct PyMemberDef *);
+ struct PyMemberDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
- struct PyGetSetDef *);
+ struct PyGetSetDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
- struct wrapperbase *, void *);
+ struct wrapperbase *, void *);
#define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL)
PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
diff --git a/Include/dictobject.h b/Include/dictobject.h
index d8c409e..d1b576c 100644
--- a/Include/dictobject.h
+++ b/Include/dictobject.h
@@ -48,13 +48,13 @@ meaning otherwise.
#define PyDict_MINSIZE 8
typedef struct {
- /* Cached hash code of me_key. Note that hash codes are C longs.
- * We have to use Py_ssize_t instead because dict_popitem() abuses
- * me_hash to hold a search finger.
- */
- Py_ssize_t me_hash;
- PyObject *me_key;
- PyObject *me_value;
+ /* Cached hash code of me_key. Note that hash codes are C longs.
+ * We have to use Py_ssize_t instead because dict_popitem() abuses
+ * me_hash to hold a search finger.
+ */
+ Py_ssize_t me_hash;
+ PyObject *me_key;
+ PyObject *me_value;
} PyDictEntry;
/*
@@ -68,24 +68,24 @@ it's two-thirds full.
*/
typedef struct _dictobject PyDictObject;
struct _dictobject {
- PyObject_HEAD
- Py_ssize_t ma_fill; /* # Active + # Dummy */
- Py_ssize_t ma_used; /* # Active */
-
- /* The table contains ma_mask + 1 slots, and that's a power of 2.
- * We store the mask instead of the size because the mask is more
- * frequently needed.
- */
- Py_ssize_t ma_mask;
-
- /* ma_table points to ma_smalltable for small tables, else to
- * additional malloc'ed memory. ma_table is never NULL! This rule
- * saves repeated runtime null-tests in the workhorse getitem and
- * setitem calls.
- */
- PyDictEntry *ma_table;
- PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash);
- PyDictEntry ma_smalltable[PyDict_MINSIZE];
+ PyObject_HEAD
+ Py_ssize_t ma_fill; /* # Active + # Dummy */
+ Py_ssize_t ma_used; /* # Active */
+
+ /* The table contains ma_mask + 1 slots, and that's a power of 2.
+ * We store the mask instead of the size because the mask is more
+ * frequently needed.
+ */
+ Py_ssize_t ma_mask;
+
+ /* ma_table points to ma_smalltable for small tables, else to
+ * additional malloc'ed memory. ma_table is never NULL! This rule
+ * saves repeated runtime null-tests in the workhorse getitem and
+ * setitem calls.
+ */
+ PyDictEntry *ma_table;
+ PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash);
+ PyDictEntry ma_smalltable[PyDict_MINSIZE];
};
PyAPI_DATA(PyTypeObject) PyDict_Type;
@@ -104,7 +104,7 @@ PyAPI_DATA(PyTypeObject) PyDictValues_Type;
#define PyDictValues_Check(op) (Py_TYPE(op) == &PyDictValues_Type)
/* This excludes Values, since they are not sets. */
# define PyDictViewSet_Check(op) \
- (PyDictKeys_Check(op) || PyDictItems_Check(op))
+ (PyDictKeys_Check(op) || PyDictItems_Check(op))
PyAPI_FUNC(PyObject *) PyDict_New(void);
@@ -114,9 +114,9 @@ PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);
PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key);
PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);
PyAPI_FUNC(int) PyDict_Next(
- PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
+ PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
PyAPI_FUNC(int) _PyDict_Next(
- PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, long *hash);
+ PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, long *hash);
PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);
PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);
PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);
@@ -136,8 +136,8 @@ PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);
dict.update(other) is equivalent to PyDict_Merge(dict, other, 1).
*/
PyAPI_FUNC(int) PyDict_Merge(PyObject *mp,
- PyObject *other,
- int override);
+ PyObject *other,
+ int override);
/* PyDict_MergeFromSeq2 updates/merges from an iterable object producing
iterable objects of length 2. If override is true, the last occurrence
@@ -145,8 +145,8 @@ PyAPI_FUNC(int) PyDict_Merge(PyObject *mp,
is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1).
*/
PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d,
- PyObject *seq2,
- int override);
+ PyObject *seq2,
+ int override);
PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);
PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);
diff --git a/Include/object.h b/Include/object.h
index 772bbb3..6e744bc 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -63,9 +63,9 @@ whose size is determined when the object is allocated.
#ifdef Py_TRACE_REFS
/* Define pointers to support a doubly-linked list of all live heap objects. */
-#define _PyObject_HEAD_EXTRA \
- struct _object *_ob_next; \
- struct _object *_ob_prev;
+#define _PyObject_HEAD_EXTRA \
+ struct _object *_ob_next; \
+ struct _object *_ob_prev;
#define _PyObject_EXTRA_INIT 0, 0,
@@ -75,14 +75,14 @@ whose size is determined when the object is allocated.
#endif
/* PyObject_HEAD defines the initial segment of every PyObject. */
-#define PyObject_HEAD PyObject ob_base;
+#define PyObject_HEAD PyObject ob_base;
-#define PyObject_HEAD_INIT(type) \
- { _PyObject_EXTRA_INIT \
- 1, type },
+#define PyObject_HEAD_INIT(type) \
+ { _PyObject_EXTRA_INIT \
+ 1, type },
-#define PyVarObject_HEAD_INIT(type, size) \
- { PyObject_HEAD_INIT(type) size },
+#define PyVarObject_HEAD_INIT(type, size) \
+ { PyObject_HEAD_INIT(type) size },
/* PyObject_VAR_HEAD defines the initial segment of all variable-size
* container objects. These end with a declaration of an array with 1
@@ -99,19 +99,19 @@ whose size is determined when the object is allocated.
* in addition, be cast to PyVarObject*.
*/
typedef struct _object {
- _PyObject_HEAD_EXTRA
- Py_ssize_t ob_refcnt;
- struct _typeobject *ob_type;
+ _PyObject_HEAD_EXTRA
+ Py_ssize_t ob_refcnt;
+ struct _typeobject *ob_type;
} PyObject;
typedef struct {
- PyObject ob_base;
- Py_ssize_t ob_size; /* Number of items in variable part */
+ PyObject ob_base;
+ Py_ssize_t ob_size; /* Number of items in variable part */
} PyVarObject;
-#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
-#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
-#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
+#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
+#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
/*
Type objects contain a string containing the type name (to help somewhat
@@ -142,26 +142,26 @@ typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
/* buffer interface */
typedef struct bufferinfo {
- void *buf;
- PyObject *obj; /* owned reference */
- Py_ssize_t len;
- Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
- pointed to by strides in simple case.*/
- int readonly;
- int ndim;
- char *format;
- Py_ssize_t *shape;
- Py_ssize_t *strides;
- Py_ssize_t *suboffsets;
- Py_ssize_t smalltable[2]; /* static store for shape and strides of
- mono-dimensional buffers. */
- void *internal;
+ void *buf;
+ PyObject *obj; /* owned reference */
+ Py_ssize_t len;
+ Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
+ pointed to by strides in simple case.*/
+ int readonly;
+ int ndim;
+ char *format;
+ Py_ssize_t *shape;
+ Py_ssize_t *strides;
+ Py_ssize_t *suboffsets;
+ Py_ssize_t smalltable[2]; /* static store for shape and strides of
+ mono-dimensional buffers. */
+ void *internal;
} Py_buffer;
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
- /* Flags for getting buffers */
+ /* Flags for getting buffers */
#define PyBUF_SIMPLE 0
#define PyBUF_WRITABLE 0x0001
/* we used to include an E, backwards compatible alias */
@@ -198,67 +198,67 @@ typedef int (*visitproc)(PyObject *, void *);
typedef int (*traverseproc)(PyObject *, visitproc, void *);
typedef struct {
- /* Number implementations must check *both*
- arguments for proper type and implement the necessary conversions
- in the slot functions themselves. */
-
- binaryfunc nb_add;
- binaryfunc nb_subtract;
- binaryfunc nb_multiply;
- binaryfunc nb_remainder;
- binaryfunc nb_divmod;
- ternaryfunc nb_power;
- unaryfunc nb_negative;
- unaryfunc nb_positive;
- unaryfunc nb_absolute;
- inquiry nb_bool;
- unaryfunc nb_invert;
- binaryfunc nb_lshift;
- binaryfunc nb_rshift;
- binaryfunc nb_and;
- binaryfunc nb_xor;
- binaryfunc nb_or;
- unaryfunc nb_int;
- void *nb_reserved; /* the slot formerly known as nb_long */
- unaryfunc nb_float;
-
- binaryfunc nb_inplace_add;
- binaryfunc nb_inplace_subtract;
- binaryfunc nb_inplace_multiply;
- binaryfunc nb_inplace_remainder;
- ternaryfunc nb_inplace_power;
- binaryfunc nb_inplace_lshift;
- binaryfunc nb_inplace_rshift;
- binaryfunc nb_inplace_and;
- binaryfunc nb_inplace_xor;
- binaryfunc nb_inplace_or;
-
- binaryfunc nb_floor_divide;
- binaryfunc nb_true_divide;
- binaryfunc nb_inplace_floor_divide;
- binaryfunc nb_inplace_true_divide;
-
- unaryfunc nb_index;
+ /* Number implementations must check *both*
+ arguments for proper type and implement the necessary conversions
+ in the slot functions themselves. */
+
+ binaryfunc nb_add;
+ binaryfunc nb_subtract;
+ binaryfunc nb_multiply;
+ binaryfunc nb_remainder;
+ binaryfunc nb_divmod;
+ ternaryfunc nb_power;
+ unaryfunc nb_negative;
+ unaryfunc nb_positive;
+ unaryfunc nb_absolute;
+ inquiry nb_bool;
+ unaryfunc nb_invert;
+ binaryfunc nb_lshift;
+ binaryfunc nb_rshift;
+ binaryfunc nb_and;
+ binaryfunc nb_xor;
+ binaryfunc nb_or;
+ unaryfunc nb_int;
+ void *nb_reserved; /* the slot formerly known as nb_long */
+ unaryfunc nb_float;
+
+ binaryfunc nb_inplace_add;
+ binaryfunc nb_inplace_subtract;
+ binaryfunc nb_inplace_multiply;
+ binaryfunc nb_inplace_remainder;
+ ternaryfunc nb_inplace_power;
+ binaryfunc nb_inplace_lshift;
+ binaryfunc nb_inplace_rshift;
+ binaryfunc nb_inplace_and;
+ binaryfunc nb_inplace_xor;
+ binaryfunc nb_inplace_or;
+
+ binaryfunc nb_floor_divide;
+ binaryfunc nb_true_divide;
+ binaryfunc nb_inplace_floor_divide;
+ binaryfunc nb_inplace_true_divide;
+
+ unaryfunc nb_index;
} PyNumberMethods;
typedef struct {
- lenfunc sq_length;
- binaryfunc sq_concat;
- ssizeargfunc sq_repeat;
- ssizeargfunc sq_item;
- void *was_sq_slice;
- ssizeobjargproc sq_ass_item;
- void *was_sq_ass_slice;
- objobjproc sq_contains;
-
- binaryfunc sq_inplace_concat;
- ssizeargfunc sq_inplace_repeat;
+ lenfunc sq_length;
+ binaryfunc sq_concat;
+ ssizeargfunc sq_repeat;
+ ssizeargfunc sq_item;
+ void *was_sq_slice;
+ ssizeobjargproc sq_ass_item;
+ void *was_sq_ass_slice;
+ objobjproc sq_contains;
+
+ binaryfunc sq_inplace_concat;
+ ssizeargfunc sq_inplace_repeat;
} PySequenceMethods;
typedef struct {
- lenfunc mp_length;
- binaryfunc mp_subscript;
- objobjargproc mp_ass_subscript;
+ lenfunc mp_length;
+ binaryfunc mp_subscript;
+ objobjargproc mp_ass_subscript;
} PyMappingMethods;
@@ -286,109 +286,109 @@ typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
typedef struct _typeobject {
- PyObject_VAR_HEAD
- const char *tp_name; /* For printing, in format "<module>.<name>" */
- Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
-
- /* Methods to implement standard operations */
-
- destructor tp_dealloc;
- printfunc tp_print;
- getattrfunc tp_getattr;
- setattrfunc tp_setattr;
- void *tp_reserved; /* formerly known as tp_compare */
- reprfunc tp_repr;
-
- /* Method suites for standard classes */
-
- PyNumberMethods *tp_as_number;
- PySequenceMethods *tp_as_sequence;
- PyMappingMethods *tp_as_mapping;
-
- /* More standard operations (here for binary compatibility) */
-
- hashfunc tp_hash;
- ternaryfunc tp_call;
- reprfunc tp_str;
- getattrofunc tp_getattro;
- setattrofunc tp_setattro;
-
- /* Functions to access object as input/output buffer */
- PyBufferProcs *tp_as_buffer;
-
- /* Flags to define presence of optional/expanded features */
- long tp_flags;
-
- const char *tp_doc; /* Documentation string */
-
- /* Assigned meaning in release 2.0 */
- /* call function for all accessible objects */
- traverseproc tp_traverse;
-
- /* delete references to contained objects */
- inquiry tp_clear;
-
- /* Assigned meaning in release 2.1 */
- /* rich comparisons */
- richcmpfunc tp_richcompare;
-
- /* weak reference enabler */
- Py_ssize_t tp_weaklistoffset;
-
- /* Iterators */
- getiterfunc tp_iter;
- iternextfunc tp_iternext;
-
- /* Attribute descriptor and subclassing stuff */
- struct PyMethodDef *tp_methods;
- struct PyMemberDef *tp_members;
- struct PyGetSetDef *tp_getset;
- struct _typeobject *tp_base;
- PyObject *tp_dict;
- descrgetfunc tp_descr_get;
- descrsetfunc tp_descr_set;
- Py_ssize_t tp_dictoffset;
- initproc tp_init;
- allocfunc tp_alloc;
- newfunc tp_new;
- freefunc tp_free; /* Low-level free-memory routine */
- inquiry tp_is_gc; /* For PyObject_IS_GC */
- PyObject *tp_bases;
- PyObject *tp_mro; /* method resolution order */
- PyObject *tp_cache;
- PyObject *tp_subclasses;
- PyObject *tp_weaklist;
- destructor tp_del;
-
- /* Type attribute cache version tag. Added in version 2.6 */
- unsigned int tp_version_tag;
+ PyObject_VAR_HEAD
+ const char *tp_name; /* For printing, in format "<module>.<name>" */
+ Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
+
+ /* Methods to implement standard operations */
+
+ destructor tp_dealloc;
+ printfunc tp_print;
+ getattrfunc tp_getattr;
+ setattrfunc tp_setattr;
+ void *tp_reserved; /* formerly known as tp_compare */
+ reprfunc tp_repr;
+
+ /* Method suites for standard classes */
+
+ PyNumberMethods *tp_as_number;
+ PySequenceMethods *tp_as_sequence;
+ PyMappingMethods *tp_as_mapping;
+
+ /* More standard operations (here for binary compatibility) */
+
+ hashfunc tp_hash;
+ ternaryfunc tp_call;
+ reprfunc tp_str;
+ getattrofunc tp_getattro;
+ setattrofunc tp_setattro;
+
+ /* Functions to access object as input/output buffer */
+ PyBufferProcs *tp_as_buffer;
+
+ /* Flags to define presence of optional/expanded features */
+ long tp_flags;
+
+ const char *tp_doc; /* Documentation string */
+
+ /* Assigned meaning in release 2.0 */
+ /* call function for all accessible objects */
+ traverseproc tp_traverse;
+
+ /* delete references to contained objects */
+ inquiry tp_clear;
+
+ /* Assigned meaning in release 2.1 */
+ /* rich comparisons */
+ richcmpfunc tp_richcompare;
+
+ /* weak reference enabler */
+ Py_ssize_t tp_weaklistoffset;
+
+ /* Iterators */
+ getiterfunc tp_iter;
+ iternextfunc tp_iternext;
+
+ /* Attribute descriptor and subclassing stuff */
+ struct PyMethodDef *tp_methods;
+ struct PyMemberDef *tp_members;
+ struct PyGetSetDef *tp_getset;
+ struct _typeobject *tp_base;
+ PyObject *tp_dict;
+ descrgetfunc tp_descr_get;
+ descrsetfunc tp_descr_set;
+ Py_ssize_t tp_dictoffset;
+ initproc tp_init;
+ allocfunc tp_alloc;
+ newfunc tp_new;
+ freefunc tp_free; /* Low-level free-memory routine */
+ inquiry tp_is_gc; /* For PyObject_IS_GC */
+ PyObject *tp_bases;
+ PyObject *tp_mro; /* method resolution order */
+ PyObject *tp_cache;
+ PyObject *tp_subclasses;
+ PyObject *tp_weaklist;
+ destructor tp_del;
+
+ /* Type attribute cache version tag. Added in version 2.6 */
+ unsigned int tp_version_tag;
#ifdef COUNT_ALLOCS
- /* these must be last and never explicitly initialized */
- Py_ssize_t tp_allocs;
- Py_ssize_t tp_frees;
- Py_ssize_t tp_maxalloc;
- struct _typeobject *tp_prev;
- struct _typeobject *tp_next;
+ /* these must be last and never explicitly initialized */
+ Py_ssize_t tp_allocs;
+ Py_ssize_t tp_frees;
+ Py_ssize_t tp_maxalloc;
+ struct _typeobject *tp_prev;
+ struct _typeobject *tp_next;
#endif
} PyTypeObject;
/* The *real* layout of a type object when allocated on the heap */
typedef struct _heaptypeobject {
- /* Note: there's a dependency on the order of these members
- in slotptr() in typeobject.c . */
- PyTypeObject ht_type;
- PyNumberMethods as_number;
- PyMappingMethods as_mapping;
- PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
- so that the mapping wins when both
- the mapping and the sequence define
- a given operator (e.g. __getitem__).
- see add_operators() in typeobject.c . */
- PyBufferProcs as_buffer;
- PyObject *ht_name, *ht_slots;
- /* here are optional user slots, followed by the members. */
+ /* Note: there's a dependency on the order of these members
+ in slotptr() in typeobject.c . */
+ PyTypeObject ht_type;
+ PyNumberMethods as_number;
+ PyMappingMethods as_mapping;
+ PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
+ so that the mapping wins when both
+ the mapping and the sequence define
+ a given operator (e.g. __getitem__).
+ see add_operators() in typeobject.c . */
+ PyBufferProcs as_buffer;
+ PyObject *ht_name, *ht_slots;
+ /* here are optional user slots, followed by the members. */
} PyHeapTypeObject;
/* access macro to the members which are floating "behind" the object */
@@ -399,20 +399,20 @@ typedef struct _heaptypeobject {
/* Generic type check */
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
#define PyObject_TypeCheck(ob, tp) \
- (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
+ (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
#define PyType_Check(op) \
- PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
+ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
- PyObject *, PyObject *);
+ PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, char *, PyObject **);
PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
@@ -439,7 +439,7 @@ PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
- PyObject *, PyObject *);
+ PyObject *, PyObject *);
PyAPI_FUNC(long) PyObject_Hash(PyObject *);
PyAPI_FUNC(long) PyObject_HashNotImplemented(PyObject *);
PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
@@ -469,7 +469,7 @@ PyAPI_FUNC(long) _Py_HashPointer(void*);
#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
/* Flag bits for printing: */
-#define Py_PRINT_RAW 1 /* No string quotes etc. */
+#define Py_PRINT_RAW 1 /* No string quotes etc. */
/*
`Type flags (tp_flags)
@@ -524,20 +524,20 @@ given type object has a specified feature.
#define Py_TPFLAGS_IS_ABSTRACT (1L<<20)
/* These flags are used to determine if a type is a subclass. */
-#define Py_TPFLAGS_INT_SUBCLASS (1L<<23)
-#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
-#define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
-#define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
-#define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27)
-#define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
-#define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
-#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)
-#define Py_TPFLAGS_TYPE_SUBCLASS (1L<<31)
+#define Py_TPFLAGS_INT_SUBCLASS (1L<<23)
+#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
+#define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
+#define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
+#define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27)
+#define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
+#define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
+#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)
+#define Py_TPFLAGS_TYPE_SUBCLASS (1L<<31)
#define Py_TPFLAGS_DEFAULT ( \
- Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
- Py_TPFLAGS_HAVE_VERSION_TAG | \
- 0)
+ Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
+ Py_TPFLAGS_HAVE_VERSION_TAG | \
+ 0)
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
#define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
@@ -589,32 +589,32 @@ environment the global variable trick is not safe.)
#ifdef Py_REF_DEBUG
PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
- int lineno, PyObject *op);
+ int lineno, PyObject *op);
PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);
PyAPI_FUNC(PyObject *) _PySet_Dummy(void);
PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
-#define _Py_INC_REFTOTAL _Py_RefTotal++
-#define _Py_DEC_REFTOTAL _Py_RefTotal--
-#define _Py_REF_DEBUG_COMMA ,
-#define _Py_CHECK_REFCNT(OP) \
-{ if (((PyObject*)OP)->ob_refcnt < 0) \
- _Py_NegativeRefcount(__FILE__, __LINE__, \
- (PyObject *)(OP)); \
+#define _Py_INC_REFTOTAL _Py_RefTotal++
+#define _Py_DEC_REFTOTAL _Py_RefTotal--
+#define _Py_REF_DEBUG_COMMA ,
+#define _Py_CHECK_REFCNT(OP) \
+{ if (((PyObject*)OP)->ob_refcnt < 0) \
+ _Py_NegativeRefcount(__FILE__, __LINE__, \
+ (PyObject *)(OP)); \
}
#else
#define _Py_INC_REFTOTAL
#define _Py_DEC_REFTOTAL
#define _Py_REF_DEBUG_COMMA
-#define _Py_CHECK_REFCNT(OP) /* a semicolon */;
+#define _Py_CHECK_REFCNT(OP) /* a semicolon */;
#endif /* Py_REF_DEBUG */
#ifdef COUNT_ALLOCS
PyAPI_FUNC(void) inc_count(PyTypeObject *);
PyAPI_FUNC(void) dec_count(PyTypeObject *);
-#define _Py_INC_TPALLOCS(OP) inc_count(Py_TYPE(OP))
-#define _Py_INC_TPFREES(OP) dec_count(Py_TYPE(OP))
-#define _Py_DEC_TPFREES(OP) Py_TYPE(OP)->tp_frees--
-#define _Py_COUNT_ALLOCS_COMMA ,
+#define _Py_INC_TPALLOCS(OP) inc_count(Py_TYPE(OP))
+#define _Py_INC_TPFREES(OP) dec_count(Py_TYPE(OP))
+#define _Py_DEC_TPFREES(OP) Py_TYPE(OP)->tp_frees--
+#define _Py_COUNT_ALLOCS_COMMA ,
#else
#define _Py_INC_TPALLOCS(OP)
#define _Py_INC_TPFREES(OP)
@@ -635,30 +635,30 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
/* Without Py_TRACE_REFS, there's little enough to do that we expand code
* inline.
*/
-#define _Py_NewReference(op) ( \
- _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA \
- _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
- Py_REFCNT(op) = 1)
+#define _Py_NewReference(op) ( \
+ _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA \
+ _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
+ Py_REFCNT(op) = 1)
#define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
-#define _Py_Dealloc(op) ( \
- _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
- (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
+#define _Py_Dealloc(op) ( \
+ _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
+ (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
#endif /* !Py_TRACE_REFS */
-#define Py_INCREF(op) ( \
- _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
- ((PyObject*)(op))->ob_refcnt++)
+#define Py_INCREF(op) ( \
+ _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
+ ((PyObject*)(op))->ob_refcnt++)
-#define Py_DECREF(op) \
- do { \
- if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
- --((PyObject*)(op))->ob_refcnt != 0) \
- _Py_CHECK_REFCNT(op) \
- else \
- _Py_Dealloc((PyObject *)(op)); \
- } while (0)
+#define Py_DECREF(op) \
+ do { \
+ if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
+ --((PyObject*)(op))->ob_refcnt != 0) \
+ _Py_CHECK_REFCNT(op) \
+ else \
+ _Py_Dealloc((PyObject *)(op)); \
+ } while (0)
/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
* and tp_dealloc implementatons.
@@ -694,14 +694,14 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
* Python integers aren't currently weakly referencable. Best practice is
* to use Py_CLEAR() even if you can't think of a reason for why you need to.
*/
-#define Py_CLEAR(op) \
- do { \
- if (op) { \
- PyObject *_py_tmp = (PyObject *)(op); \
- (op) = NULL; \
- Py_DECREF(_py_tmp); \
- } \
- } while (0)
+#define Py_CLEAR(op) \
+ do { \
+ if (op) { \
+ PyObject *_py_tmp = (PyObject *)(op); \
+ (op) = NULL; \
+ Py_DECREF(_py_tmp); \
+ } \
+ } while (0)
/* Macros to use in case the object pointer may be NULL: */
#define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
@@ -813,13 +813,13 @@ bracketing the body of its tp_dealloc function with a pair of macros:
static void
mytype_dealloc(mytype *p)
{
- ... declarations go here ...
+ ... declarations go here ...
- PyObject_GC_UnTrack(p); // must untrack first
- Py_TRASHCAN_SAFE_BEGIN(p)
- ... The body of the deallocator goes here, including all calls ...
- ... to Py_DECREF on contained objects. ...
- Py_TRASHCAN_SAFE_END(p)
+ PyObject_GC_UnTrack(p); // must untrack first
+ Py_TRASHCAN_SAFE_BEGIN(p)
+ ... The body of the deallocator goes here, including all calls ...
+ ... to Py_DECREF on contained objects. ...
+ Py_TRASHCAN_SAFE_END(p)
}
CAUTION: Never return from the middle of the body! If the body needs to
@@ -849,16 +849,16 @@ PyAPI_DATA(PyObject *) _PyTrash_delete_later;
#define PyTrash_UNWIND_LEVEL 50
#define Py_TRASHCAN_SAFE_BEGIN(op) \
- if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
- ++_PyTrash_delete_nesting;
- /* The body of the deallocator is here. */
+ if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
+ ++_PyTrash_delete_nesting;
+ /* The body of the deallocator is here. */
#define Py_TRASHCAN_SAFE_END(op) \
- --_PyTrash_delete_nesting; \
- if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
- _PyTrash_destroy_chain(); \
- } \
- else \
- _PyTrash_deposit_object((PyObject*)op);
+ --_PyTrash_delete_nesting; \
+ if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
+ _PyTrash_destroy_chain(); \
+ } \
+ else \
+ _PyTrash_deposit_object((PyObject*)op);
#ifdef __cplusplus
}
diff --git a/Include/objimpl.h b/Include/objimpl.h
index 5a27382..6d5a0c4 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -101,35 +101,35 @@ PyAPI_FUNC(void) PyObject_Free(void *);
/* Macros */
#ifdef WITH_PYMALLOC
-#ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */
+#ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */
PyAPI_FUNC(void *) _PyObject_DebugMalloc(size_t nbytes);
PyAPI_FUNC(void *) _PyObject_DebugRealloc(void *p, size_t nbytes);
PyAPI_FUNC(void) _PyObject_DebugFree(void *p);
PyAPI_FUNC(void) _PyObject_DebugDumpAddress(const void *p);
PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p);
PyAPI_FUNC(void) _PyObject_DebugMallocStats(void);
-#define PyObject_MALLOC _PyObject_DebugMalloc
-#define PyObject_Malloc _PyObject_DebugMalloc
-#define PyObject_REALLOC _PyObject_DebugRealloc
-#define PyObject_Realloc _PyObject_DebugRealloc
-#define PyObject_FREE _PyObject_DebugFree
-#define PyObject_Free _PyObject_DebugFree
-
-#else /* WITH_PYMALLOC && ! PYMALLOC_DEBUG */
-#define PyObject_MALLOC PyObject_Malloc
-#define PyObject_REALLOC PyObject_Realloc
-#define PyObject_FREE PyObject_Free
+#define PyObject_MALLOC _PyObject_DebugMalloc
+#define PyObject_Malloc _PyObject_DebugMalloc
+#define PyObject_REALLOC _PyObject_DebugRealloc
+#define PyObject_Realloc _PyObject_DebugRealloc
+#define PyObject_FREE _PyObject_DebugFree
+#define PyObject_Free _PyObject_DebugFree
+
+#else /* WITH_PYMALLOC && ! PYMALLOC_DEBUG */
+#define PyObject_MALLOC PyObject_Malloc
+#define PyObject_REALLOC PyObject_Realloc
+#define PyObject_FREE PyObject_Free
#endif
-#else /* ! WITH_PYMALLOC */
-#define PyObject_MALLOC PyMem_MALLOC
-#define PyObject_REALLOC PyMem_REALLOC
-#define PyObject_FREE PyMem_FREE
+#else /* ! WITH_PYMALLOC */
+#define PyObject_MALLOC PyMem_MALLOC
+#define PyObject_REALLOC PyMem_REALLOC
+#define PyObject_FREE PyMem_FREE
-#endif /* WITH_PYMALLOC */
+#endif /* WITH_PYMALLOC */
-#define PyObject_Del PyObject_Free
-#define PyObject_DEL PyObject_FREE
+#define PyObject_Del PyObject_Free
+#define PyObject_DEL PyObject_FREE
/*
* Generic object allocator interface
@@ -144,16 +144,16 @@ PyAPI_FUNC(PyObject *) _PyObject_New(PyTypeObject *);
PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
#define PyObject_New(type, typeobj) \
- ( (type *) _PyObject_New(typeobj) )
+ ( (type *) _PyObject_New(typeobj) )
#define PyObject_NewVar(type, typeobj, n) \
- ( (type *) _PyObject_NewVar((typeobj), (n)) )
+ ( (type *) _PyObject_NewVar((typeobj), (n)) )
/* Macros trading binary compatibility for speed. See also pymem.h.
Note that these macros expect non-NULL object pointers.*/
#define PyObject_INIT(op, typeobj) \
- ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
+ ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
#define PyObject_INIT_VAR(op, typeobj, size) \
- ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )
+ ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )
#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
@@ -171,17 +171,17 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
# error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"
#endif
-#define _PyObject_VAR_SIZE(typeobj, nitems) \
- (size_t) \
- ( ( (typeobj)->tp_basicsize + \
- (nitems)*(typeobj)->tp_itemsize + \
- (SIZEOF_VOID_P - 1) \
- ) & ~(SIZEOF_VOID_P - 1) \
- )
+#define _PyObject_VAR_SIZE(typeobj, nitems) \
+ (size_t) \
+ ( ( (typeobj)->tp_basicsize + \
+ (nitems)*(typeobj)->tp_itemsize + \
+ (SIZEOF_VOID_P - 1) \
+ ) & ~(SIZEOF_VOID_P - 1) \
+ )
#define PyObject_NEW(type, typeobj) \
( (type *) PyObject_Init( \
- (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )
+ (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )
#define PyObject_NEW_VAR(type, typeobj, n) \
( (type *) PyObject_InitVar( \
@@ -193,7 +193,7 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
distinction between two steps (at least):
1) the actual allocation of the object storage;
2) the initialization of the Python specific fields
- in this storage with PyObject_{Init, InitVar}.
+ in this storage with PyObject_{Init, InitVar}.
PyObject *
YourObject_New(...)
@@ -202,7 +202,7 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
op = (PyObject *) Your_Allocator(_PyObject_SIZE(YourTypeStruct));
if (op == NULL)
- return PyErr_NoMemory();
+ return PyErr_NoMemory();
PyObject_Init(op, &YourTypeStruct);
@@ -229,44 +229,44 @@ PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);
/* Test if an object has a GC head */
#define PyObject_IS_GC(o) (PyType_IS_GC(Py_TYPE(o)) && \
- (Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o)))
+ (Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o)))
PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t);
#define PyObject_GC_Resize(type, op, n) \
- ( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) )
+ ( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) )
/* for source compatibility with 2.2 */
#define _PyObject_GC_Del PyObject_GC_Del
/* GC information is stored BEFORE the object structure. */
typedef union _gc_head {
- struct {
- union _gc_head *gc_next;
- union _gc_head *gc_prev;
- Py_ssize_t gc_refs;
- } gc;
- long double dummy; /* force worst-case alignment */
+ struct {
+ union _gc_head *gc_next;
+ union _gc_head *gc_prev;
+ Py_ssize_t gc_refs;
+ } gc;
+ long double dummy; /* force worst-case alignment */
} PyGC_Head;
extern PyGC_Head *_PyGC_generation0;
#define _Py_AS_GC(o) ((PyGC_Head *)(o)-1)
-#define _PyGC_REFS_UNTRACKED (-2)
-#define _PyGC_REFS_REACHABLE (-3)
-#define _PyGC_REFS_TENTATIVELY_UNREACHABLE (-4)
+#define _PyGC_REFS_UNTRACKED (-2)
+#define _PyGC_REFS_REACHABLE (-3)
+#define _PyGC_REFS_TENTATIVELY_UNREACHABLE (-4)
/* Tell the GC to track this object. NB: While the object is tracked the
* collector it must be safe to call the ob_traverse method. */
#define _PyObject_GC_TRACK(o) do { \
- PyGC_Head *g = _Py_AS_GC(o); \
- if (g->gc.gc_refs != _PyGC_REFS_UNTRACKED) \
- Py_FatalError("GC object already tracked"); \
- g->gc.gc_refs = _PyGC_REFS_REACHABLE; \
- g->gc.gc_next = _PyGC_generation0; \
- g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \
- g->gc.gc_prev->gc.gc_next = g; \
- _PyGC_generation0->gc.gc_prev = g; \
+ PyGC_Head *g = _Py_AS_GC(o); \
+ if (g->gc.gc_refs != _PyGC_REFS_UNTRACKED) \
+ Py_FatalError("GC object already tracked"); \
+ g->gc.gc_refs = _PyGC_REFS_REACHABLE; \
+ g->gc.gc_next = _PyGC_generation0; \
+ g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \
+ g->gc.gc_prev->gc.gc_next = g; \
+ _PyGC_generation0->gc.gc_prev = g; \
} while (0);
/* Tell the GC to stop tracking this object.
@@ -274,23 +274,23 @@ extern PyGC_Head *_PyGC_generation0;
* way to provoke memory errors if calling code is confused.
*/
#define _PyObject_GC_UNTRACK(o) do { \
- PyGC_Head *g = _Py_AS_GC(o); \
- assert(g->gc.gc_refs != _PyGC_REFS_UNTRACKED); \
- g->gc.gc_refs = _PyGC_REFS_UNTRACKED; \
- g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \
- g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \
- g->gc.gc_next = NULL; \
+ PyGC_Head *g = _Py_AS_GC(o); \
+ assert(g->gc.gc_refs != _PyGC_REFS_UNTRACKED); \
+ g->gc.gc_refs = _PyGC_REFS_UNTRACKED; \
+ g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \
+ g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \
+ g->gc.gc_next = NULL; \
} while (0);
/* True if the object is currently tracked by the GC. */
#define _PyObject_GC_IS_TRACKED(o) \
- ((_Py_AS_GC(o))->gc.gc_refs != _PyGC_REFS_UNTRACKED)
-
+ ((_Py_AS_GC(o))->gc.gc_refs != _PyGC_REFS_UNTRACKED)
+
/* True if the object may be tracked by the GC in the future, or already is.
This can be useful to implement some optimizations. */
#define _PyObject_GC_MAY_BE_TRACKED(obj) \
- (PyObject_IS_GC(obj) && \
- (!PyTuple_CheckExact(obj) || _PyObject_GC_IS_TRACKED(obj)))
+ (PyObject_IS_GC(obj) && \
+ (!PyTuple_CheckExact(obj) || _PyObject_GC_IS_TRACKED(obj)))
PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t);
@@ -301,9 +301,9 @@ PyAPI_FUNC(void) PyObject_GC_UnTrack(void *);
PyAPI_FUNC(void) PyObject_GC_Del(void *);
#define PyObject_GC_New(type, typeobj) \
- ( (type *) _PyObject_GC_New(typeobj) )
+ ( (type *) _PyObject_GC_New(typeobj) )
#define PyObject_GC_NewVar(type, typeobj, n) \
- ( (type *) _PyObject_GC_NewVar((typeobj), (n)) )
+ ( (type *) _PyObject_GC_NewVar((typeobj), (n)) )
/* Utility macro to help write tp_traverse functions.
@@ -311,14 +311,14 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
* "visit" and "arg". This is intended to keep tp_traverse functions
* looking as much alike as possible.
*/
-#define Py_VISIT(op) \
- do { \
- if (op) { \
- int vret = visit((PyObject *)(op), arg); \
- if (vret) \
- return vret; \
- } \
- } while (0)
+#define Py_VISIT(op) \
+ do { \
+ if (op) { \
+ int vret = visit((PyObject *)(op), arg); \
+ if (vret) \
+ return vret; \
+ } \
+ } while (0)
/* This is here for the sake of backwards compatibility. Extensions that
* use the old GC API will still compile but the objects will not be
@@ -334,7 +334,7 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
#define PyObject_GET_WEAKREFS_LISTPTR(o) \
- ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))
+ ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))
#ifdef __cplusplus
}
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index aafb2a0..66a7030 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -8,8 +8,8 @@ extern "C" {
/* PyException_HEAD defines the initial segment of every exception class. */
#define PyException_HEAD PyObject_HEAD PyObject *dict;\
- PyObject *args; PyObject *traceback;\
- PyObject *context; PyObject *cause;
+ PyObject *args; PyObject *traceback;\
+ PyObject *context; PyObject *cause;
typedef struct {
PyException_HEAD
@@ -92,15 +92,15 @@ PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *);
/* */
-#define PyExceptionClass_Check(x) \
- (PyType_Check((x)) && \
- PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
+#define PyExceptionClass_Check(x) \
+ (PyType_Check((x)) && \
+ PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
-#define PyExceptionInstance_Check(x) \
- PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS)
+#define PyExceptionInstance_Check(x) \
+ PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS)
#define PyExceptionClass_Name(x) \
- ((char *)(((PyTypeObject*)(x))->tp_name))
+ ((char *)(((PyTypeObject*)(x))->tp_name))
#define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type))
@@ -175,29 +175,29 @@ PyAPI_FUNC(int) PyErr_BadArgument(void);
PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
- PyObject *, PyObject *);
+ PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, const char *);
#ifdef MS_WINDOWS
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
- PyObject *, const Py_UNICODE *);
+ PyObject *, const Py_UNICODE *);
#endif /* MS_WINDOWS */
PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...);
#ifdef MS_WINDOWS
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(
- int, const char *);
+ int, const char *);
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
- int, const char *);
+ int, const char *);
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
- int, const Py_UNICODE *);
+ int, const Py_UNICODE *);
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
- PyObject *,int, PyObject *);
+ PyObject *,int, PyObject *);
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
- PyObject *,int, const char *);
+ PyObject *,int, const char *);
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
- PyObject *,int, const Py_UNICODE *);
+ PyObject *,int, const Py_UNICODE *);
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
#endif /* MS_WINDOWS */
@@ -229,15 +229,15 @@ PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
/* create a UnicodeDecodeError object */
PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
- const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
+ const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
/* create a UnicodeEncodeError object */
PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
- const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
+ const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
/* create a UnicodeTranslateError object */
PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
- const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
+ const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
/* get the encoding attribute */
PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
@@ -280,11 +280,11 @@ PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
/* assign a new value to the reason attribute
return 0 on success, -1 on failure */
PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
- PyObject *, const char *);
+ PyObject *, const char *);
PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
- PyObject *, const char *);
+ PyObject *, const char *);
PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
- PyObject *, const char *);
+ PyObject *, const char *);
/* These APIs aren't really part of the error implementation, but
@@ -303,9 +303,9 @@ PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
#include <stdarg.h>
PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
- Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
+ Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
- Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
+ Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
#ifdef __cplusplus
}
diff --git a/Include/pymacconfig.h b/Include/pymacconfig.h