summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-09-17 03:28:34 (GMT)
committerBrett Cannon <bcannon@gmail.com>2007-09-17 03:28:34 (GMT)
commit0153159e67bf4247c4402a1a6e717819372c9337 (patch)
treeef58a6813bfb4011b0cd542f250f292f8cba8076 /Objects/stringobject.c
parentd36a60e1e3410450d337d4de732e127e48a6a042 (diff)
downloadcpython-0153159e67bf4247c4402a1a6e717819372c9337.zip
cpython-0153159e67bf4247c4402a1a6e717819372c9337.tar.gz
cpython-0153159e67bf4247c4402a1a6e717819372c9337.tar.bz2
Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print(). Closes issue #1164.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index fb7548d..22b50d5 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -788,7 +788,7 @@ PyString_AsStringAndSize(register PyObject *obj,
static int
string_print(PyStringObject *op, FILE *fp, int flags)
{
- Py_ssize_t i;
+ Py_ssize_t i, str_len;
char c;
int quote;
@@ -806,6 +806,7 @@ string_print(PyStringObject *op, FILE *fp, int flags)
if (flags & Py_PRINT_RAW) {
char *data = op->ob_sval;
Py_ssize_t size = Py_Size(op);
+ Py_BEGIN_ALLOW_THREADS
while (size > INT_MAX) {
/* Very long strings cannot be written atomically.
* But don't write exactly INT_MAX bytes at a time
@@ -821,6 +822,7 @@ string_print(PyStringObject *op, FILE *fp, int flags)
#else
fwrite(data, 1, (int)size, fp);
#endif
+ Py_END_ALLOW_THREADS
return 0;
}
@@ -830,8 +832,13 @@ string_print(PyStringObject *op, FILE *fp, int flags)
!memchr(op->ob_sval, '"', Py_Size(op)))
quote = '"';
+ str_len = Py_Size(op);
+ Py_BEGIN_ALLOW_THREADS
fputc(quote, fp);
- for (i = 0; i < Py_Size(op); i++) {
+ for (i = 0; i < str_len; i++) {
+ /* Since strings are immutable and the caller should have a
+ reference, accessing the interal buffer should not be an issue
+ with the GIL released. */
c = op->ob_sval[i];
if (c == quote || c == '\\')
fprintf(fp, "\\%c", c);
@@ -847,6 +854,7 @@ string_print(PyStringObject *op, FILE *fp, int flags)
fputc(c, fp);
}
fputc(quote, fp);
+ Py_END_ALLOW_THREADS
return 0;
}