Changeset 15383


Ignore:
Timestamp:
09/26/20 07:32:03 (2 years ago)
Author:
Mark Evenson
Message:

Fixes for allocation of arrays via :nio-buffer

Fix capacity allocation for (or (unsigned-byte 16) (unsigned-byte 32))
arrays created via an nio-buffer.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/BasicVector_CharBuffer.java

    r15359 r15383  
    7777    elements = buffer.asCharBuffer();
    7878    this.directAllocation = directAllocation;
    79     capacity = ((java.nio.Buffer)buffer).limit();
     79    capacity = ((java.nio.Buffer)buffer).limit() / 2;
    8080  }
    8181
  • trunk/abcl/src/org/armedbear/lisp/BasicVector_IntBuffer.java

    r15359 r15383  
    8080    this.directAllocation = directAllocation;
    8181    elements = buffer.asIntBuffer();
    82     capacity = ((java.nio.Buffer)buffer).limit();
     82    capacity = ((java.nio.Buffer)buffer).limit() / 4;
    8383  }
    8484
    8585  public BasicVector_IntBuffer(IntBuffer buffer) {
     86    this(buffer, false);
     87  }
     88
     89  public BasicVector_IntBuffer(IntBuffer buffer, boolean directAllocation) {
    8690    this.directAllocation = directAllocation;
    8791    elements = buffer;
  • trunk/abcl/src/org/armedbear/lisp/make_array.java

    r15352 r15383  
    193193                 && fillPointer == NIL && adjustable == NIL) {
    194194        if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
    195           v = new BasicVector_CharBuffer(size, directAllocation);
     195          if (!nioBuffer.equals(NIL)) {
     196            Object o = ((JavaObject)nioBuffer).getObject();
     197            if (o instanceof java.nio.CharBuffer) {
     198              v = new BasicVector_CharBuffer((java.nio.CharBuffer) o, directAllocation);
     199            } else if (o instanceof java.nio.ByteBuffer) {
     200              v = new BasicVector_CharBuffer((java.nio.ByteBuffer)o, directAllocation); // FIXME warn on coercion?
     201            } else {
     202              return type_error(nioBuffer, JavaObject.getInstance(java.nio.CharBuffer.class));
     203            }
     204          } else {
     205            v = new BasicVector_CharBuffer(size, directAllocation);
     206          }
    196207        } else { //if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY)) {
    197208          v = new BasicVector_UnsignedByte16(size);
     
    200211      } else if (upgradedType.equal(UNSIGNED_BYTE_32)) {
    201212        if (fillPointer != NIL || adjustable != NIL) {
    202           v = new ComplexVector_UnsignedByte32(size);
    203         } else {
    204213          if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
    205             v = new BasicVector_IntBuffer(size, directAllocation);
     214            v = new ComplexVector_IntBuffer(size);
     215          } else {
     216            v = new ComplexVector_UnsignedByte32(size);
     217          }
     218        } else {
     219          if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
     220            if (!nioBuffer.equals(NIL)) {
     221              Object o = ((JavaObject)nioBuffer).getObject();
     222              if (o instanceof java.nio.IntBuffer) {
     223                v = new BasicVector_IntBuffer((java.nio.IntBuffer)o, directAllocation);
     224              } else if (o instanceof java.nio.ByteBuffer) {
     225                v = new BasicVector_IntBuffer((java.nio.ByteBuffer)o, directAllocation);
     226              } else {
     227                return type_error(nioBuffer, JavaObject.getInstance(java.nio.IntBuffer.class));
     228              }
     229            } else {
     230              v = new BasicVector_IntBuffer(size, directAllocation);
     231            }
    206232          } else { //if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY)) {
    207233            v = new BasicVector_UnsignedByte32(size);
     
    220246        defaultInitialElement = NIL;
    221247      }
     248     
    222249      if (nioBuffer != NIL) {
    223         // v is fine

     250        // v should have been allocated with a nioBuffer reference

    224251        ;
    225252      } else if (initialElementProvided != NIL) {
Note: See TracChangeset for help on using the changeset viewer.