ObjFW  Diff

Differences From Artifact [2d4bdd05bf]:

To Artifact [cfbf6fbabe]:

  • File src/OFStream.m — part of check-in [3d16a30f41] at 2013-06-22 12:12:36 on branch trunk — Rework exceptions.

    This mostly removes the argument for the class in which the exception
    occurred. As backtraces were recently added for all platforms, the
    passed class does not give any extra information on where the exception
    occurred anymore.

    This also removes a few other arguments which were not too helpful. In
    the past, the idea was to pass as many arguments as possible so that it
    is easier to find the origin of the exception. However, as backtraces
    are a much better way to find the origin, those are not useful anymore
    and just make the exception more cumbersome to use. The rule is now to
    only pass arguments that might help in recovering from the exception or
    provide information that is otherwise not easily accessible. (user: js, size: 30357) [annotate] [blame] [check-ins using]


785
786
787
788
789
790
791
792

793
794
795
796
797
798
799
800
801
785
786
787
788
789
790
791

792


793
794
795
796
797
798
799







-
+
-
-







	OFString *ret;

	delimiterCString = [delimiter cStringWithEncoding: encoding];
	delimiterLength = [delimiter cStringLengthWithEncoding: encoding];
	j = 0;

	if (delimiterLength == 0)
		@throw [OFInvalidArgumentException
		@throw [OFInvalidArgumentException exception];
		    exceptionWithClass: [self class]
			      selector: _cmd];

	/* Look if there's something in our buffer */
	if (!_waitingForDelimiter && _readBuffer != NULL) {
		for (i = 0; i < _readBufferLength; i++) {
			if (_readBuffer[i] != delimiterCString[j++])
				j = 0;

1445
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458

1459
1460
1461
1462
1463
1464
1465
1466
1443
1444
1445
1446
1447
1448
1449

1450


1451
1452
1453

1454

1455
1456
1457
1458
1459
1460
1461







-
+
-
-



-
+
-







- (size_t)writeFormat: (OFConstantString*)format
	    arguments: (va_list)arguments
{
	char *UTF8String;
	int length;

	if (format == nil)
		@throw [OFInvalidArgumentException
		@throw [OFInvalidArgumentException exception];
		    exceptionWithClass: [self class]
			      selector: _cmd];

	if ((length = of_vasprintf(&UTF8String, [format UTF8String],
	    arguments)) == -1)
		@throw [OFInvalidFormatException
		@throw [OFInvalidFormatException exception];
		    exceptionWithClass: [self class]];

	@try {
		[self writeBuffer: UTF8String
			   length: length];
	} @finally {
		free(UTF8String);
	}
1488
1489
1490
1491
1492
1493
1494
1495
1496

1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507

1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521

1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532

1533
1534
1535
1536
1537

1538
1539

1540
1541
1542
1543
1544
1545
1546
1483
1484
1485
1486
1487
1488
1489


1490
1491
1492
1493
1494
1495
1496
1497
1498
1499


1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512


1513
1514
1515
1516
1517
1518
1519
1520
1521
1522


1523
1524
1525
1526
1527

1528


1529
1530
1531
1532
1533
1534
1535
1536







-
-
+









-
-
+












-
-
+









-
-
+




-
+
-
-
+








		readFlags = fcntl([self fileDescriptorForReading], F_GETFL);

		readImplemented = true;

		if (readFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];
			    exceptionWithStream: self];

		if (enable)
			readFlags &= ~O_NONBLOCK;
		else
			readFlags |= O_NONBLOCK;

		if (fcntl([self fileDescriptorForReading], F_SETFL,
		    readFlags) == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];
			    exceptionWithStream: self];
	} @catch (OFNotImplementedException *e) {
	}

	@try {
		int writeFlags;

		writeFlags = fcntl([self fileDescriptorForWriting], F_GETFL);

		writeImplemented = true;

		if (writeFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];
			    exceptionWithStream: self];

		if (enable)
			writeFlags &= ~O_NONBLOCK;
		else
			writeFlags |= O_NONBLOCK;

		if (fcntl([self fileDescriptorForWriting], F_SETFL,
		    writeFlags) == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];
			    exceptionWithStream: self];
	} @catch (OFNotImplementedException *e) {
	}

	if (!readImplemented && !writeImplemented)
		@throw [OFNotImplementedException
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
		    exceptionWithClass: [self class]
			      selector: _cmd];
								 object: self];

	_blocking = enable;
#else
	[self doesNotRecognizeSelector: _cmd];
	abort();
#endif
}