--- a/UnixFileDescriptorHandle.st Wed Feb 12 13:54:54 2014 +0100
+++ b/UnixFileDescriptorHandle.st Wed Feb 12 13:55:06 2014 +0100
@@ -9,7 +9,6 @@
other person. No title to or ownership of the software is
hereby transferred.
"
-
"{ Package: 'stx:libbasic' }"
OSFileHandle subclass:#UnixFileDescriptorHandle
@@ -57,84 +56,90 @@
int nInstBytes, objSize;
if (! __bothSmallInteger(count, firstIndex)) {
- goto bad;
+ goto bad;
}
cnt = __smallIntegerVal(count);
offs = __smallIntegerVal(firstIndex) - 1;
if (fd < 0) {
- goto bad;
+ goto bad;
}
if (__isExternalBytesLike(aByteBuffer)) {
- OBJ sz;
+ OBJ sz;
- nInstBytes = 0;
- extPtr = (char *)(__externalBytesAddress(aByteBuffer));
- if (extPtr == NULL) goto bad;
- sz = __externalBytesSize(aByteBuffer);
- if (__isSmallInteger(sz)) {
- objSize = __smallIntegerVal(sz);
- } else {
- objSize = -1; /* unknown */
- }
+ nInstBytes = 0;
+ extPtr = (char *)(__externalBytesAddress(aByteBuffer));
+ if (extPtr == NULL) goto bad;
+ sz = __externalBytesSize(aByteBuffer);
+ if (__isSmallInteger(sz)) {
+ objSize = __smallIntegerVal(sz);
+ } else {
+ objSize = -1; /* unknown */
+ }
} else {
- OBJ oClass;
- int nInstVars;
+ OBJ oClass = __Class(aByteBuffer);
+ int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
- oClass = __Class(aByteBuffer);
- switch (__smallIntegerVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- case DOUBLEARRAY:
- break;
- default:
- goto bad;
- }
- extPtr = (char *)0;
- nInstVars = __smallIntegerVal(__ClassInstPtr(oClass)->c_ninstvars);
- nInstBytes = __OBJS2BYTES__(nInstVars);
- objSize = __Size(aByteBuffer) - OHDR_SIZE - nInstBytes;
+ nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+ switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ case DOUBLEARRAY:
+#ifdef __NEED_DOUBLE_ALIGN
+ nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
+#endif
+ break;
+ case LONGLONGARRAY:
+ case SLONGLONGARRAY:
+#ifdef __NEED_LONGLONG_ALIGN
+ nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
+#endif
+ default:
+ goto bad;
+ }
+ extPtr = (char *)0;
+ objSize = __Size(aByteBuffer) - OHDR_SIZE - nInstBytes;
}
if ((offs >= 0)
&& (cnt >= 0)
&& ((objSize == -1) || (objSize >= (cnt + offs)))) {
- nRead = 0;
+ nRead = 0;
- do {
- int n;
+ do {
+ int n;
- if (extPtr) {
- n = read(fd, extPtr+offs, cnt);
- } else {
- char *bp;
+ if (extPtr) {
+ n = read(fd, extPtr+offs, cnt);
+ } else {
+ char *bp;
- /*
- * on interrupt, anObject may be moved to another location.
- * So we recompute the byte-address here.
- */
- bp = __ByteArrayInstPtr(aByteBuffer)->ba_element + nInstBytes;
+ /*
+ * on interrupt, anObject may be moved to another location.
+ * So we recompute the byte-address here.
+ */
+ bp = __ByteArrayInstPtr(aByteBuffer)->ba_element + nInstBytes;
- n = read(fd, bp + offs, cnt);
- }
- if (n > 0) {
- cnt -= n;
- offs += n;
- nRead += n;
- } else {
- if (n < 0) {
- if (errno == EINTR) {
- continue;
- }
- break;
- }
- }
- } while (cnt > 0);
+ n = read(fd, bp + offs, cnt);
+ }
+ if (n > 0) {
+ cnt -= n;
+ offs += n;
+ nRead += n;
+ } else {
+ if (n < 0) {
+ if (errno == EINTR) {
+ continue;
+ }
+ break;
+ }
+ }
+ } while (cnt > 0);
- RETURN (__mkSmallInteger(nRead));
+ RETURN (__mkSmallInteger(nRead));
}
bad: ;
%}.
@@ -163,84 +168,90 @@
int nInstBytes, objSize;
if (! __bothSmallInteger(count, firstIndex)) {
- goto bad;
+ goto bad;
}
cnt = __smallIntegerVal(count);
offs = __smallIntegerVal(firstIndex) - 1;
if (fd < 0) {
- goto bad;
+ goto bad;
}
if (__isExternalBytesLike(aByteBuffer)) {
- OBJ sz;
+ OBJ sz;
- nInstBytes = 0;
- extPtr = (char *)(__externalBytesAddress(aByteBuffer));
- if (extPtr == NULL) goto bad;
- sz = __externalBytesSize(aByteBuffer);
- if (__isSmallInteger(sz)) {
- objSize = __smallIntegerVal(sz);
- } else {
- objSize = -1; /* unknown */
- }
+ nInstBytes = 0;
+ extPtr = (char *)(__externalBytesAddress(aByteBuffer));
+ if (extPtr == NULL) goto bad;
+ sz = __externalBytesSize(aByteBuffer);
+ if (__isSmallInteger(sz)) {
+ objSize = __smallIntegerVal(sz);
+ } else {
+ objSize = -1; /* unknown */
+ }
} else {
- OBJ oClass;
- int nInstVars;
+ OBJ oClass = __Class(aByteBuffer);
+ int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
- oClass = __Class(aByteBuffer);
- switch (__smallIntegerVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- case DOUBLEARRAY:
- break;
- default:
- goto bad;
- }
- extPtr = (char *)0;
- nInstVars = __smallIntegerVal(__ClassInstPtr(oClass)->c_ninstvars);
- nInstBytes = __OBJS2BYTES__(nInstVars);
- objSize = __Size(aByteBuffer) - OHDR_SIZE - nInstBytes;
+ nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+ switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ case DOUBLEARRAY:
+#ifdef __NEED_DOUBLE_ALIGN
+ nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
+#endif
+ break;
+ case LONGLONGARRAY:
+ case SLONGLONGARRAY:
+#ifdef __NEED_LONGLONG_ALIGN
+ nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
+#endif
+ default:
+ goto bad;
+ }
+ extPtr = (char *)0;
+ objSize = __Size(aByteBuffer) - OHDR_SIZE - nInstBytes;
}
if ((offs >= 0)
&& (cnt >= 0)
&& ((objSize == -1) || (objSize >= (cnt + offs)))) {
- nWritten = 0;
+ nWritten = 0;
- do {
- int n;
+ do {
+ int n;
- if (extPtr) {
- n = write(fd, extPtr+offs, cnt);
- } else {
- char *bp;
+ if (extPtr) {
+ n = write(fd, extPtr+offs, cnt);
+ } else {
+ char *bp;
- /*
- * on interrupt, anObject may be moved to another location.
- * So we recompute the byte-address here.
- */
- bp = __ByteArrayInstPtr(aByteBuffer)->ba_element + nInstBytes;
+ /*
+ * on interrupt, anObject may be moved to another location.
+ * So we recompute the byte-address here.
+ */
+ bp = __ByteArrayInstPtr(aByteBuffer)->ba_element + nInstBytes;
- n = write(fd, bp + offs, cnt);
- }
- if (n > 0) {
- cnt -= n;
- offs += n;
- nWritten += n;
- } else {
- if (n < 0) {
- if (errno == EINTR) {
- continue;
- }
- break;
- }
- }
- } while (cnt > 0);
+ n = write(fd, bp + offs, cnt);
+ }
+ if (n > 0) {
+ cnt -= n;
+ offs += n;
+ nWritten += n;
+ } else {
+ if (n < 0) {
+ if (errno == EINTR) {
+ continue;
+ }
+ break;
+ }
+ }
+ } while (cnt > 0);
- RETURN (__mkSmallInteger(nWritten));
+ RETURN (__mkSmallInteger(nWritten));
}
bad: ;
%}.
@@ -288,5 +299,6 @@
!UnixFileDescriptorHandle class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/UnixFileDescriptorHandle.st,v 1.9 2013-01-17 22:37:55 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/UnixFileDescriptorHandle.st,v 1.10 2014-02-12 12:55:06 stefan Exp $'
! !
+