Example #1
0
static void caml_ba_finalize(value v)
{
  struct caml_ba_array * b = Caml_ba_array_val(v);

  switch (b->flags & CAML_BA_MANAGED_MASK) {
  case CAML_BA_EXTERNAL:
    break;
  case CAML_BA_MANAGED:
    if (b->proxy == NULL) {
      free(b->data);
    } else {
      if (-- b->proxy->refcount == 0) {
        free(b->proxy->data);
        caml_stat_free(b->proxy);
      }
    }
    break;
  case CAML_BA_MAPPED_FILE:
    if (b->proxy == NULL) {
      caml_ba_unmap_file(b->data, caml_ba_byte_size(b));
    } else {
      if (-- b->proxy->refcount == 0) {
        caml_ba_unmap_file(b->proxy->data, b->proxy->size);
        caml_stat_free(b->proxy);
      }
    }
    break;
  }
}
Example #2
0
static void caml_ba_update_proxy(struct caml_ba_array * b1,
                                 struct caml_ba_array * b2)
{
  struct caml_ba_proxy * proxy;
  /* Nothing to do for un-managed arrays */
  if ((b1->flags & CAML_BA_MANAGED_MASK) == CAML_BA_EXTERNAL) return;
  if (b1->proxy != NULL) {
    /* If b1 is already a proxy for a larger array, increment refcount of
       proxy */
    b2->proxy = b1->proxy;
    ++ b1->proxy->refcount;
  } else {
    /* Otherwise, create proxy and attach it to both b1 and b2 */
    proxy = caml_stat_alloc(sizeof(struct caml_ba_proxy));
    proxy->refcount = 2;      /* original array + sub array */
    proxy->data = b1->data;
    proxy->size =
      b1->flags & CAML_BA_MAPPED_FILE ? caml_ba_byte_size(b1) : 0;
    b1->proxy = proxy;
    b2->proxy = proxy;
  }
}
Example #3
0
void core_bigstring_destroy(struct caml_ba_array *b, int flags)
{
  int i;
  switch (b->flags & CAML_BA_MANAGED_MASK) {
    case CAML_BA_EXTERNAL :
      if ((flags & CORE_BIGSTRING_DESTROY_ALLOW_EXTERNAL)
           != CORE_BIGSTRING_DESTROY_ALLOW_EXTERNAL)
        caml_failwith("bigstring_destroy: bigstring is external or already deallocated");
      break;
    case CAML_BA_MANAGED :
      check_bigstring_proxy(b);
      free(b->data);
      break;
    case CAML_BA_MAPPED_FILE :
      check_bigstring_proxy(b);
      if ((flags & CORE_BIGSTRING_DESTROY_DO_NOT_UNMAP)
           != CORE_BIGSTRING_DESTROY_DO_NOT_UNMAP)
        caml_ba_unmap_file(b->data, caml_ba_byte_size(b));
      break;
  }
  b->data = NULL;
  b->flags = CAML_BA_EXTERNAL;
  for (i = 0; i < b->num_dims; ++i) b->dim[i] = 0;
}
Example #4
0
CAMLextern_C value
caml_sfSoundBuffer_loadFromMemory(value data)
{
    sf::SoundBuffer *sbf = new sf::SoundBuffer;
    bool r = sbf->loadFromMemory(String_val(data), caml_string_length(data));
    if (!r) caml_failwith("SFSoundBuffer.loadFromMemory");
    return Val_sfSoundBuffer(sbf);
}

CAMLextern_C value
caml_sfSoundBuffer_loadFromSamples(
        value samples, value channelCount, value sampleRate)
{
    sf::Int16* _samples = static_cast<sf::Int16*>Caml_ba_data_val(samples);
    std::size_t sampleCount = caml_ba_byte_size(Caml_ba_array_val(samples)) / 2;
#if defined(_OCAML_SFML_DEBUG)
    std::cout << "# SFSoundBuffer.loadFromSamples: "
              << sampleCount
              << std::endl << std::flush;  // DEBUG
#endif
    sf::SoundBuffer *sbf = new sf::SoundBuffer;
    bool r = sbf->loadFromSamples(
            _samples, sampleCount,
            UInt_val(channelCount), UInt_val(sampleRate));
    if (!r) caml_failwith("SFSoundBuffer.loadFromSamples");
    return Val_sfSoundBuffer(sbf);
}

CAMLextern_C value
caml_sfSoundBuffer_destroy(value soundBuffer)