<commit_before>/*
  Copyright (C) 2015-2016  Brazil
  Copyright (C) 2021-2022  <NAME> <<EMAIL>>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License version 2.1 as published by the Free Software Foundation.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "grn_ctx_impl.h"
#include "grn_config.h"

#include <string.h>

grn_rc
grn_config_set(grn_ctx *ctx,
               const char *key, int32_t key_size,
               const char *value, int32_t value_size)
{
  grn_obj *db;
  grn_hash *config;
  grn_id id;

  GRN_API_ENTER;

  if (!ctx || !ctx->impl || !(db = ctx->impl->db)) {
    ERR(GRN_INVALID_ARGUMENT, "[config][set] DB isn't initialized");
    GRN_API_RETURN(ctx->rc);
  }

  uint32_t real_key_size;
  if (key_size < 0) {
    real_key_size = (uint32_t)strlen(key);
  } else {
    real_key_size = (uint32_t)key_size;
  }
  if (real_key_size > GRN_CONFIG_MAX_KEY_SIZE) {
    ERR(GRN_INVALID_ARGUMENT,
        "[config][set] too large key: max=<%u>: <%u>",
        GRN_CONFIG_MAX_KEY_SIZE, real_key_size);
    GRN_API_RETURN(ctx->rc);
  }

  uint32_t real_value_size;
  if (value_size < 0) {
    real_value_size = (uint32_t)strlen(value);
  } else {
    real_value_size = (uint32_t)value_size;
  }
  if ((size_t)value_size > GRN_CONFIG_MAX_VALUE_SIZE) {
    ERR(GRN_INVALID_ARGUMENT,
        "[config][set] too large value: max=<%" GRN_FMT_SIZE ">: <%u>",
        GRN_CONFIG_MAX_VALUE_SIZE, real_value_size);
    GRN_API_RETURN(ctx->rc);<commit_msg>grn_config_set: fix a bug that negative value_size is always failed<commit_after>/*
  Copyright (C) 2015-2016  Brazil
  Copyright (C) 2021-2022  <NAME> <<EMAIL>>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License version 2.1 as published by the Free Software Foundation.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "grn_ctx_impl.h"
#include "grn_config.h"

#include <string.h>

grn_rc
grn_config_set(grn_ctx *ctx,
               const char *key, int32_t key_size,
               const char *value, int32_t value_size)
{
  grn_obj *db;
  grn_hash *config;
  grn_id id;

  GRN_API_ENTER;

  if (!ctx || !ctx->impl || !(db = ctx->impl->db)) {
    ERR(GRN_INVALID_ARGUMENT, "[config][set] DB isn't initialized");
    GRN_API_RETURN(ctx->rc);
  }

  uint32_t real_key_size;
  if (key_size < 0) {
    real_key_size = (uint32_t)strlen(key);
  } else {
    real_key_size = (uint32_t)key_size;
  }
  if (real_key_size > GRN_CONFIG_MAX_KEY_SIZE) {
    ERR(GRN_INVALID_ARGUMENT,
        "[config][set] too large key: max=<%u>: <%u>",
        GRN_CONFIG_MAX_KEY_SIZE, real_key_size);
    GRN_API_RETURN(ctx->rc);
  }

  uint32_t real_value_size;
  if (value_size < 0) {
    real_value_size = (uint32_t)strlen(value);
  } else {
    real_value_size = (uint32_t)value_size;
  }
  if (real_value_size > GRN_CONFIG_MAX_VALUE_SIZE) {
    ERR(GRN_INVALID_ARGUMENT,
        "[config][set] too large value: max=<%" GRN_FMT_SIZE ">: <%u>",
        GRN_CONFIG_MAX_VALUE_SIZE, real_value_size);
    GRN_API_RETURN(ctx->rc);
{'fraction_non_alphanumeric': 0.10037546933667084, 'fraction_numerical': 0.023529411764705882, 'mean_word_length': 3.7011764705882353, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 35, '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': '1243948', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1403, 'n_words': 406}