@@ -1014,6 +1014,8 @@ PyObject *
10141014PyMarshal_WriteObjectToString (PyObject * x , int version )
10151015{
10161016 WFILE wf ;
1017+ PyObject * res = NULL ;
1018+
10171019 wf .fp = NULL ;
10181020 wf .str = PyString_FromStringAndSize ((char * )NULL , 50 );
10191021 if (wf .str == NULL )
@@ -1034,7 +1036,8 @@ PyMarshal_WriteObjectToString(PyObject *x, int version)
10341036 "too much marshal data for a string" );
10351037 return NULL ;
10361038 }
1037- _PyString_Resize (& wf .str , (Py_ssize_t )(wf .ptr - base ));
1039+ if (_PyString_Resize (& wf .str , (Py_ssize_t )(wf .ptr - base )) < 0 )
1040+ return NULL ;
10381041 }
10391042 if (wf .error ) {
10401043 Py_XDECREF (wf .str );
@@ -1043,7 +1046,12 @@ PyMarshal_WriteObjectToString(PyObject *x, int version)
10431046 :"object too deeply nested to marshal" );
10441047 return NULL ;
10451048 }
1046- return wf .str ;
1049+ if (wf .str != NULL ) {
1050+ /* XXX Quick hack -- need to do this differently */
1051+ res = PyBytes_FromObject (wf .str );
1052+ Py_DECREF (wf .str );
1053+ }
1054+ return res ;
10471055}
10481056
10491057/* And an interface for Python programs... */
@@ -1092,9 +1100,34 @@ marshal_load(PyObject *self, PyObject *f)
10921100 RFILE rf ;
10931101 PyObject * result ;
10941102 if (!PyFile_Check (f )) {
1095- PyErr_SetString (PyExc_TypeError ,
1096- "marshal.load() arg must be file" );
1097- return NULL ;
1103+ /* XXX Quick hack -- need to do this differently */
1104+ PyObject * data , * result ;
1105+ RFILE rf ;
1106+ data = PyObject_CallMethod (f , "read" , "" );
1107+ if (data == NULL )
1108+ return NULL ;
1109+ rf .fp = NULL ;
1110+ if (PyString_Check (data )) {
1111+ rf .ptr = PyString_AS_STRING (data );
1112+ rf .end = rf .ptr + PyString_GET_SIZE (data );
1113+ }
1114+ else if (PyBytes_Check (data )) {
1115+ rf .ptr = PyBytes_AS_STRING (data );
1116+ rf .end = rf .ptr + PyBytes_GET_SIZE (data );
1117+ }
1118+ else {
1119+ PyErr_Format (PyExc_TypeError ,
1120+ "f.read() returned neither string "
1121+ "nor bytes but %.100s" ,
1122+ data -> ob_type -> tp_name );
1123+ Py_DECREF (data );
1124+ return NULL ;
1125+ }
1126+ rf .strings = PyList_New (0 );
1127+ result = read_object (& rf );
1128+ Py_DECREF (rf .strings );
1129+ Py_DECREF (data );
1130+ return result ;
10981131 }
10991132 rf .fp = PyFile_AsFile (f );
11001133 rf .strings = PyList_New (0 );
0 commit comments