|
161 | 161 | import com.oracle.truffle.api.dsl.Specialization;
|
162 | 162 | import com.oracle.truffle.api.dsl.TypeSystemReference;
|
163 | 163 | import com.oracle.truffle.api.frame.VirtualFrame;
|
| 164 | +import com.oracle.truffle.api.interop.UnsupportedMessageException; |
164 | 165 | import com.oracle.truffle.api.library.CachedLibrary;
|
165 | 166 | import com.oracle.truffle.api.profiles.BranchProfile;
|
166 | 167 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
@@ -1202,6 +1203,21 @@ Object write(VirtualFrame frame, int fd, PBytesLike data,
|
1202 | 1203 | return write(frame, fd, getByteArray(data.getSequenceStorage()), channelClassProfile);
|
1203 | 1204 | }
|
1204 | 1205 |
|
| 1206 | + @Specialization(limit = "getCallSiteInlineCacheMaxDepth()") |
| 1207 | + Object write(VirtualFrame frame, int fd, Object data, |
| 1208 | + @CachedLibrary("data") PythonObjectLibrary lib, |
| 1209 | + @Cached("createClassProfile()") ValueProfile channelClassProfile) { |
| 1210 | + if (lib.isBuffer(data)) { |
| 1211 | + try { |
| 1212 | + byte[] b = lib.getBufferBytes(data); |
| 1213 | + return write(frame, fd, b, channelClassProfile); |
| 1214 | + } catch (UnsupportedMessageException e) { |
| 1215 | + throw CompilerDirectives.shouldNotReachHere("Buffer-like object does not support getBufferBytes()"); |
| 1216 | + } |
| 1217 | + } |
| 1218 | + throw raise(TypeError, ErrorMessages.BYTESLIKE_OBJ_REQUIRED, data); |
| 1219 | + } |
| 1220 | + |
1205 | 1221 | @Specialization(limit = "getCallSiteInlineCacheMaxDepth()")
|
1206 | 1222 | static Object writePInt(VirtualFrame frame, Object fd, Object data,
|
1207 | 1223 | @CachedLibrary("fd") PythonObjectLibrary lib,
|
|
0 commit comments