<commit_before>#include "platform.h"

namespace opencl {

/* Platform API */
// extern CL_API_ENTRY cl_int CL_API_CALL
// clGetPlatformIDs(cl_uint          /* num_entries */,
//                  cl_platform_id * /* platforms */,
//                  cl_uint *        /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;
NAN_METHOD(GetPlatformIDs) {
  NanScope();

  cl_uint num_entries = 0;
  CHECK_ERR(::clGetPlatformIDs(0, NULL, &num_entries));

  unique_ptr<cl_platform_id[]> platforms(new cl_platform_id[num_entries]);
  CHECK_ERR(::clGetPlatformIDs(num_entries, platforms.get(), NULL));

  Local<Array> platformArray = Array::New(num_entries);
  for (uint32_t i=0; i<num_entries; i++) {
    platformArray->Set(i, Wrap(platforms[i]));
  }

  NanReturnValue(platformArray);
}

// extern CL_API_ENTRY cl_int CL_API_CALL
// clGetPlatformInfo(cl_platform_id   /* platform */,
//                   cl_platform_info /* param_name */,
//                   size_t           /* param_value_size */,
//                   void *           /* param_value */,
//                   size_t *         /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
NAN_METHOD(GetPlatformInfo) {
  NanScope();
  REQ_ARGS(2);

  if(!isOpenCLObj(args[0])) {
    return NanThrowError(JS_INT(CL_INVALID_PLATFORM));
  }

  cl_platform_id platform_id=Unwrap<cl_platform_id>(args[0]);
  cl_platform_info param_name = args[1]->Uint32Value();

  char param_value[1024];
  size_t param_value_size_ret=0;

  CHECK_ERR(::clGetPlatformInfo(platform_id, param_name, 1024, param_value, &param_value_size_ret));

  // NOTE: Adjust length because API returns NULL terminated string<commit_msg>[Implementation] Platform: throw errors instead of returning js_int<commit_after>#include "platform.h"

namespace opencl {

/* Platform API */
// extern CL_API_ENTRY cl_int CL_API_CALL
// clGetPlatformIDs(cl_uint          /* num_entries */,
//                  cl_platform_id * /* platforms */,
//                  cl_uint *        /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;
NAN_METHOD(GetPlatformIDs) {
  NanScope();

  cl_uint num_entries = 0;
  CHECK_ERR(::clGetPlatformIDs(0, NULL, &num_entries));

  unique_ptr<cl_platform_id[]> platforms(new cl_platform_id[num_entries]);
  CHECK_ERR(::clGetPlatformIDs(num_entries, platforms.get(), NULL));

  Local<Array> platformArray = Array::New(num_entries);
  for (uint32_t i=0; i<num_entries; i++) {
    platformArray->Set(i, Wrap(platforms[i]));
  }

  NanReturnValue(platformArray);
}

// extern CL_API_ENTRY cl_int CL_API_CALL
// clGetPlatformInfo(cl_platform_id   /* platform */,
//                   cl_platform_info /* param_name */,
//                   size_t           /* param_value_size */,
//                   void *           /* param_value */,
//                   size_t *         /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
NAN_METHOD(GetPlatformInfo) {
  NanScope();
  REQ_ARGS(2);

  if(!isOpenCLObj(args[0])) {
    THROW_ERR(CL_INVALID_PLATFORM);
  }

  cl_platform_id platform_id=Unwrap<cl_platform_id>(args[0]);
  cl_platform_info param_name = args[1]->Uint32Value();

  char param_value[1024];
  size_t param_value_size_ret=0;

  CHECK_ERR(::clGetPlatformInfo(platform_id, param_name, 1024, param_value, &param_value_size_ret));

  // NOTE: Adjust length because API returns NULL terminated string
{'fraction_non_alphanumeric': 0.1262368815592204, 'fraction_numerical': 0.0143928035982009, 'mean_word_length': 3.3156532988357053, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '6134986', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1094, 'n_words': 177}