<commit_before>// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package al

/*
#cgo LDFLAGS: -llog

#include <android/log.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <jni.h>
#include <limits.h>
#include <AL/al.h>
#include <AL/alc.h>

#define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, "Go/OpenAL", __VA_ARGS__)
#define LOG_FATAL(...) __android_log_print(ANDROID_LOG_FATAL, "Go/OpenAL", __VA_ARGS__)

void* al_init(void* vm, void* context) {
  JavaVM* current_vm = (JavaVM*)(vm);
  JNIEnv* env;

  int attached = 0;
  switch ((*current_vm)->GetEnv(current_vm, (void**)&env, JNI_VERSION_1_6)) {
  case JNI_OK:
    break;
  case JNI_EDETACHED:
    if ((*current_vm)->AttachCurrentThread(current_vm, &env, 0) != 0) {
      LOG_FATAL("cannot attach JVM");
    }
    attached = 1;
    break;
  case JNI_EVERSION:
    LOG_FATAL("bad JNI version");
  }

  jclass android_content_Context = (*env)->FindClass(env, "android/content/Context");
  jmethodID get_package_name = (*env)->GetMethodID(env, android_content_Context, "getPackageName", "()Ljava/lang/String;");
  jstring package_name = (*env)->CallObjectMethod(env, context, get_package_name);
  const char *cpackage_name = (*env)->GetStringUTFChars(env, package_name, 0);

  char lib_path[PATH_MAX] = "/data/data/";
  strcat(lib_path, cpackage_name);
  strcat(lib_path, "/lib/libopenal.so");
  void* handle = dlopen(lib_path, RTLD_LAZY);
  (*env)->ReleaseStringUTFChars(env, package_name, cpackage_name);
  if (!handle) {
    LOG_FATAL("cannot load libopenal.so");
  }
  if (attached) {
    (*current_vm)->DetachCurrentThread(current_vm);
  }
  return handle;
}

void call_alEnable(LPALENABLE fn, ALenum capability) {
  fn(capability);
}

void call_alDisable(LPALDISABLE fn, ALenum capability) {
  fn(capability);
}<commit_msg>audio/al: replace strcat with strlcat<commit_after>// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package al

/*
#cgo LDFLAGS: -llog

#include <android/log.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <jni.h>
#include <limits.h>
#include <AL/al.h>
#include <AL/alc.h>

#define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, "Go/OpenAL", __VA_ARGS__)
#define LOG_FATAL(...) __android_log_print(ANDROID_LOG_FATAL, "Go/OpenAL", __VA_ARGS__)

void* al_init(void* vm, void* context) {
  JavaVM* current_vm = (JavaVM*)(vm);
  JNIEnv* env;

  int attached = 0;
  switch ((*current_vm)->GetEnv(current_vm, (void**)&env, JNI_VERSION_1_6)) {
  case JNI_OK:
    break;
  case JNI_EDETACHED:
    if ((*current_vm)->AttachCurrentThread(current_vm, &env, 0) != 0) {
      LOG_FATAL("cannot attach JVM");
    }
    attached = 1;
    break;
  case JNI_EVERSION:
    LOG_FATAL("bad JNI version");
  }

  jclass android_content_Context = (*env)->FindClass(env, "android/content/Context");
  jmethodID get_package_name = (*env)->GetMethodID(env, android_content_Context, "getPackageName", "()Ljava/lang/String;");
  jstring package_name = (*env)->CallObjectMethod(env, context, get_package_name);
  const char *cpackage_name = (*env)->GetStringUTFChars(env, package_name, 0);

  char lib_path[PATH_MAX] = "/data/data/";
  strlcat(lib_path, cpackage_name, sizeof(lib_path));
  strlcat(lib_path, "/lib/libopenal.so", sizeof(lib_path));
  void* handle = dlopen(lib_path, RTLD_LAZY);
  (*env)->ReleaseStringUTFChars(env, package_name, cpackage_name);
  if (!handle) {
    LOG_FATAL("cannot load libopenal.so");
  }
  if (attached) {
    (*current_vm)->DetachCurrentThread(current_vm);
  }
  return handle;
}

void call_alEnable(LPALENABLE fn, ALenum capability) {
  fn(capability);
}

void call_alDisable(LPALDISABLE fn, ALenum capability) {
  fn(capability);
}
{'fraction_non_alphanumeric': 0.14837712519319937, 'fraction_numerical': 0.005667181865018032, 'mean_word_length': 4.910197869101979, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6236360', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1445, 'n_words': 312}