@@ -417,31 +417,6 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...)
417417 return NULL ;
418418}
419419
420- static int
421- write_file (Picklerobject * self , const char * s , Py_ssize_t n )
422- {
423- size_t nbyteswritten ;
424-
425- if (s == NULL ) {
426- return 0 ;
427- }
428-
429- if (n > INT_MAX ) {
430- /* String too large */
431- return -1 ;
432- }
433-
434- Py_BEGIN_ALLOW_THREADS
435- nbyteswritten = fwrite (s , sizeof (char ), n , self -> fp );
436- Py_END_ALLOW_THREADS
437- if (nbyteswritten != (size_t )n ) {
438- PyErr_SetFromErrno (PyExc_IOError );
439- return -1 ;
440- }
441-
442- return (int )n ;
443- }
444-
445420static int
446421write_cStringIO (Picklerobject * self , const char * s , Py_ssize_t n )
447422{
@@ -516,92 +491,6 @@ write_other(Picklerobject *self, const char *s, Py_ssize_t _n)
516491}
517492
518493
519- static Py_ssize_t
520- read_file (Unpicklerobject * self , char * * s , Py_ssize_t n )
521- {
522- size_t nbytesread ;
523-
524- if (self -> buf_size == 0 ) {
525- int size ;
526-
527- size = ((n < 32 ) ? 32 : n );
528- if (!( self -> buf = (char * )malloc (size ))) {
529- PyErr_NoMemory ();
530- return -1 ;
531- }
532-
533- self -> buf_size = size ;
534- }
535- else if (n > self -> buf_size ) {
536- char * newbuf = (char * )realloc (self -> buf , n );
537- if (!newbuf ) {
538- PyErr_NoMemory ();
539- return -1 ;
540- }
541- self -> buf = newbuf ;
542- self -> buf_size = n ;
543- }
544-
545- Py_BEGIN_ALLOW_THREADS
546- nbytesread = fread (self -> buf , sizeof (char ), n , self -> fp );
547- Py_END_ALLOW_THREADS
548- if (nbytesread != (size_t )n ) {
549- if (feof (self -> fp )) {
550- PyErr_SetNone (PyExc_EOFError );
551- return -1 ;
552- }
553-
554- PyErr_SetFromErrno (PyExc_IOError );
555- return -1 ;
556- }
557-
558- * s = self -> buf ;
559-
560- return n ;
561- }
562-
563-
564- static Py_ssize_t
565- readline_file (Unpicklerobject * self , char * * s )
566- {
567- int i ;
568-
569- if (self -> buf_size == 0 ) {
570- if (!( self -> buf = (char * )malloc (40 ))) {
571- PyErr_NoMemory ();
572- return -1 ;
573- }
574- self -> buf_size = 40 ;
575- }
576-
577- i = 0 ;
578- while (1 ) {
579- int bigger ;
580- char * newbuf ;
581- for (; i < (self -> buf_size - 1 ); i ++ ) {
582- if (feof (self -> fp ) ||
583- (self -> buf [i ] = getc (self -> fp )) == '\n' ) {
584- self -> buf [i + 1 ] = '\0' ;
585- * s = self -> buf ;
586- return i + 1 ;
587- }
588- }
589- bigger = self -> buf_size << 1 ;
590- if (bigger <= 0 ) { /* overflow */
591- PyErr_NoMemory ();
592- return -1 ;
593- }
594- newbuf = (char * )realloc (self -> buf , bigger );
595- if (!newbuf ) {
596- PyErr_NoMemory ();
597- return -1 ;
598- }
599- self -> buf = newbuf ;
600- self -> buf_size = bigger ;
601- }
602- }
603-
604-
605494static Py_ssize_t
606495read_cStringIO (Unpicklerobject * self , char * * s , Py_ssize_t n )
607496{
@@ -2665,16 +2554,7 @@ newPicklerobject(PyObject *file, int proto)
26652554 if (!( self -> memo = PyDict_New ()))
26662555 goto err ;
26672556
2668- if (PyFile_Check (file )) {
2669- self -> fp = PyFile_AsFile (file );
2670- if (self -> fp == NULL ) {
2671- PyErr_SetString (PyExc_ValueError ,
2672- "I/O operation on closed file" );
2673- goto err ;
2674- }
2675- self -> write_func = write_file ;
2676- }
2677- else if (PycStringIO_OutputCheck (file )) {
2557+ if (PycStringIO_OutputCheck (file )) {
26782558 self -> write_func = write_cStringIO ;
26792559 }
26802560 else if (file == Py_None ) {
@@ -4988,17 +4868,7 @@ newUnpicklerobject(PyObject *f)
49884868 self -> file = f ;
49894869
49904870 /* Set read, readline based on type of f */
4991- if (PyFile_Check (f )) {
4992- self -> fp = PyFile_AsFile (f );
4993- if (self -> fp == NULL ) {
4994- PyErr_SetString (PyExc_ValueError ,
4995- "I/O operation on closed file" );
4996- goto err ;
4997- }
4998- self -> read_func = read_file ;
4999- self -> readline_func = readline_file ;
5000- }
5001- else if (PycStringIO_InputCheck (f )) {
4871+ if (PycStringIO_InputCheck (f )) {
50024872 self -> fp = NULL ;
50034873 self -> read_func = read_cStringIO ;
50044874 self -> readline_func = readline_cStringIO ;
0 commit comments