@@ -1192,8 +1192,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
11921192 }
11931193
11941194 @ Specialization
1195- PNone ftruncate (VirtualFrame frame , int fd , long length ,
1195+ static PNone ftruncate (VirtualFrame frame , int fd , long length ,
11961196 @ Bind ("this" ) Node inliningTarget ,
1197+ @ Bind ("getPosixSupport()" ) PosixSupport posixSupport ,
11971198 @ CachedLibrary (limit = "1" ) PosixSupportLibrary posixLib ,
11981199 @ Cached SysModuleBuiltins .AuditNode auditNode ,
11991200 @ Cached GilNode gil ,
@@ -1204,15 +1205,15 @@ PNone ftruncate(VirtualFrame frame, int fd, long length,
12041205 try {
12051206 gil .release (true );
12061207 try {
1207- posixLib .ftruncate (getPosixSupport () , fd , length );
1208+ posixLib .ftruncate (posixSupport , fd , length );
12081209 } finally {
12091210 gil .acquire ();
12101211 }
12111212 return PNone .NONE ;
12121213 } catch (PosixException e ) {
12131214 errorProfile .enter (inliningTarget );
12141215 if (e .getErrorCode () == OSErrorEnum .EINTR .getNumber ()) {
1215- PythonContext .triggerAsyncActions (this );
1216+ PythonContext .triggerAsyncActions (inliningTarget );
12161217 } else {
12171218 throw constructAndRaiseNode .get (inliningTarget ).raiseOSErrorFromPosixException (frame , e );
12181219 }
@@ -1221,6 +1222,52 @@ PNone ftruncate(VirtualFrame frame, int fd, long length,
12211222 }
12221223 }
12231224
1225+ @ Builtin (name = "truncate" , minNumOfPositionalArgs = 2 , parameterNames = {"path" , "length" })
1226+ @ ArgumentClinic (name = "path" , conversionClass = PathConversionNode .class , args = {"false" , "true" })
1227+ @ ArgumentClinic (name = "length" , conversionClass = OffsetConversionNode .class )
1228+ @ GenerateNodeFactory
1229+ public abstract static class TruncateNode extends PythonBinaryClinicBuiltinNode {
1230+
1231+ @ Override
1232+ protected ArgumentClinicProvider getArgumentClinic () {
1233+ return PosixModuleBuiltinsClinicProviders .TruncateNodeClinicProviderGen .INSTANCE ;
1234+ }
1235+
1236+ @ Specialization
1237+ static PNone truncate (VirtualFrame frame , PosixPath path , long length ,
1238+ @ Bind ("this" ) Node inliningTarget ,
1239+ @ Bind ("getPosixSupport()" ) PosixSupport posixSupport ,
1240+ @ Shared @ CachedLibrary (limit = "1" ) PosixSupportLibrary posixLib ,
1241+ @ Shared @ Cached SysModuleBuiltins .AuditNode auditNode ,
1242+ @ Shared @ Cached GilNode gil ,
1243+ @ Shared @ Cached PConstructAndRaiseNode .Lazy constructAndRaiseNode ) {
1244+ auditNode .audit (inliningTarget , "os.truncate" , path .originalObject , length );
1245+ try {
1246+ gil .release (true );
1247+ try {
1248+ posixLib .truncate (posixSupport , path .value , length );
1249+ } finally {
1250+ gil .acquire ();
1251+ }
1252+ return PNone .NONE ;
1253+ } catch (PosixException e ) {
1254+ throw constructAndRaiseNode .get (inliningTarget ).raiseOSErrorFromPosixException (frame , e , path .originalObject );
1255+ }
1256+ }
1257+
1258+ @ Specialization
1259+ static PNone ftruncate (VirtualFrame frame , PosixFd fd , long length ,
1260+ @ Bind ("this" ) Node inliningTarget ,
1261+ @ Bind ("getPosixSupport()" ) PosixSupport posixSupport ,
1262+ @ Shared @ CachedLibrary (limit = "1" ) PosixSupportLibrary posixLib ,
1263+ @ Shared @ Cached SysModuleBuiltins .AuditNode auditNode ,
1264+ @ Shared @ Cached GilNode gil ,
1265+ @ Cached InlinedBranchProfile errorProfile ,
1266+ @ Shared @ Cached PConstructAndRaiseNode .Lazy constructAndRaiseNode ) {
1267+ return FtruncateNode .ftruncate (frame , fd .fd , length , inliningTarget , posixSupport , posixLib , auditNode , gil , errorProfile , constructAndRaiseNode );
1268+ }
1269+ }
1270+
12241271 @ Builtin (name = "fsync" , minNumOfPositionalArgs = 1 , parameterNames = "fd" )
12251272 @ ArgumentClinic (name = "fd" , conversionClass = FileDescriptorConversionNode .class )
12261273 @ GenerateNodeFactory
0 commit comments