<commit_before>/**************************************************************************//**
 * RMagick declarations and definitions.
 *
 * Copyright &copy; 2002 - 2009 by <NAME>
 *
 * Changes since Nov. 2009 copyright &copy; by <NAME> and <NAME>
 *
 * @file     rmagick.h
 * @version  $Id: rmagick.h,v 1.282 2010/02/16 06:50:28 baror Exp $
 * @author   <NAME>
 ******************************************************************************/

#ifndef _RMAGICK_H_
#define _RMAGICK_H_

//! Suppress warnings about deprecated functions on Windows
#define _CRT_SECURE_NO_DEPRECATE 1

#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <sys/types.h>
#include "ruby.h"
#include "ruby/io.h"

#if defined(__MINGW32__)
    // Ruby defines wrong format specifiers for MinGW. So this defines original macro in here.
    #if SIZEOF_SIZE_T == SIZEOF_LONG
        #define RMIuSIZE  "lu"
        #define RMIdSIZE  "ld"
        #define RMIsVALUE "li\v"
    #elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
        #define RMIuSIZE  "I64u"
        #define RMIdSIZE  "I64d"
        #define RMIsVALUE "I64i\v"
    #endif
#else
    // Use constants defined in Ruby
    #define RMIuSIZE  PRIuSIZE
    #define RMIdSIZE  PRIdSIZE
    #define RMIsVALUE PRIsVALUE
#endif

#if defined(__GNUC__)
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
    #pragma GCC diagnostic ignored "-Wunknown-pragmas"

    #if __GNUC__ > 6
        #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
    #endif
#endif

// Undef Ruby's versions of these symbols
#undef PACKAGE_VERSION
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_BUGREPORT
#undef PACKAGE_TARNAME
#undef WORDS_BIGENDIAN

#include "extconf.h"

#if defined(IMAGEMAGICK_7)
    #include "MagickCore/MagickCore.h"
    #include "MagickCore/magick-config.h"
#else
    #include "magick/MagickCore.h"
    #include "magick/magick-config.h"
#endif

// Undef ImageMagick's versions of these symbols
#undef PACKAGE_STRING


//! For quoting preprocessor symbols
#define Q2(q) #q
//! For quoting preprocessor symbols
#define Q(q) Q2(q)

#ifdef __GNUC__
#define ATTRIBUTE_UNUSED   __attribute__((unused))
#define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
#else
#define ATTRIBUTE_UNUSED
#define ATTRIBUTE_NORETURN
#endif

//! Trace new image creation in bang methods
#define UPDATE_DATA_PTR(_obj_, _new_) \
    do { (void) rm_trace_creation(_new_);\
    DATA_PTR(_obj_) = (void *)(_new_);\
    } while(0)


// Handle Quantum <-> Ruby Numeric object conversion
#if (MAGICKCORE_QUANTUM_DEPTH == 8 || MAGICKCORE_QUANTUM_DEPTH == 16)
#define QUANTUM2NUM(q) INT2FIX((q)) /**< Quantum -> Ruby Numeric conversion */
#define NUM2QUANTUM(n) (Quantum)NUM2UINT((n)) /**< Quantum <- Ruby Numeric conversion */
#elif (MAGICKCORE_QUANTUM_DEPTH == 32)
#define QUANTUM2NUM(q) UINT2NUM((q)) /**< Quantum -> Ruby Numeric conversion */
#define NUM2QUANTUM(n) (Quantum)NUM2UINT((n)) /**< Quntum <- Ruby Numeric conversion */
#elif (MAGICKCORE_QUANTUM_DEPTH == 64)
#define QUANTUM2NUM(q) ULL2NUM((q)) /**< Quantum -> Ruby Numeric conversion */
#define NUM2QUANTUM(n) (Quantum)NUM2ULL((n)) /**< Quntum <- Ruby Numeric conversion */
#else
#error Specified MAGICKCORE_QUANTUM_DEPTH is not supported.
#endif
//! Convert user-supplied objects to Quantum
#define APP2QUANTUM(n) rm_app2quantum((n))

//! degrees to radians conversion
#undef DegreesToRadians     // defined in ImageMagick.h in 6.0.2
#define DegreesToRadians(x) ((x)*3.14159265358979323846/180.0)

//! pixel intensity calculation
#define PIXEL_INTENSITY(q) ((Quantum)(0.299*(q)->red + 0.587*(q)->green + 0.114*(q)->blue + 0.5))

//! find maximum of longs
#define LMAX(a, b) ((((long)(a))>((long)(b)))?((long)(a)):((long)(b)))
//! find maximum of floats
#define FMAX(a, b) ((((double)(a))>((double)(b)))?((double)(a)):((double)(b)))
//! find minimum of floats
#define FMIN(a, b) ((((double)(a))<=((double)(b)))?((double)(a)):((double)(b)))

#define RMAGICK_PI 3.14159265358979  /**< pi */

//! round to Quantum
#define ROUND_TO_QUANTUM(value) ((Quantum) ((value) > (Quantum)QuantumRange ? QuantumRange : (value) + 0.5))

//! Convert a C string to a Ruby symbol. Used in marshal_dump/marshal_load methods
#define CSTR2SYM(s) ID2SYM(rb_intern(s))
//! Convert a C string to a Ruby String, or nil if the ptr is NULL
#define MAGICK_STRING_TO_OBJ(f) (f) ? rb_str_new2(f) : Qnil
/**
 * Copy the C string in a Ruby String object to ImageMagick memory, or set the
 * pointer to NULL if the object is nil.
 */
#define OBJ_TO_MAGICK_STRING(f, obj) \
    if ((obj) != Qnil)\
        magick_clone_string(&f, RSTRING_PTR(obj));\<commit_msg>Use StringValueCStr() to get null-terminated C-lang string (#1158)<commit_after>/**************************************************************************//**
 * RMagick declarations and definitions.
 *
 * Copyright &copy; 2002 - 2009 by <NAME>
 *
 * Changes since Nov. 2009 copyright &copy; by <NAME> and <NAME>
 *
 * @file     rmagick.h
 * @version  $Id: rmagick.h,v 1.282 2010/02/16 06:50:28 baror Exp $
 * @author   <NAME>
 ******************************************************************************/

#ifndef _RMAGICK_H_
#define _RMAGICK_H_

//! Suppress warnings about deprecated functions on Windows
#define _CRT_SECURE_NO_DEPRECATE 1

#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <sys/types.h>
#include "ruby.h"
#include "ruby/io.h"

#if defined(__MINGW32__)
    // Ruby defines wrong format specifiers for MinGW. So this defines original macro in here.
    #if SIZEOF_SIZE_T == SIZEOF_LONG
        #define RMIuSIZE  "lu"
        #define RMIdSIZE  "ld"
        #define RMIsVALUE "li\v"
    #elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
        #define RMIuSIZE  "I64u"
        #define RMIdSIZE  "I64d"
        #define RMIsVALUE "I64i\v"
    #endif
#else
    // Use constants defined in Ruby
    #define RMIuSIZE  PRIuSIZE
    #define RMIdSIZE  PRIdSIZE
    #define RMIsVALUE PRIsVALUE
#endif

#if defined(__GNUC__)
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
    #pragma GCC diagnostic ignored "-Wunknown-pragmas"

    #if __GNUC__ > 6
        #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
    #endif
#endif

// Undef Ruby's versions of these symbols
#undef PACKAGE_VERSION
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_BUGREPORT
#undef PACKAGE_TARNAME
#undef WORDS_BIGENDIAN

#include "extconf.h"

#if defined(IMAGEMAGICK_7)
    #include "MagickCore/MagickCore.h"
    #include "MagickCore/magick-config.h"
#else
    #include "magick/MagickCore.h"
    #include "magick/magick-config.h"
#endif

// Undef ImageMagick's versions of these symbols
#undef PACKAGE_STRING


//! For quoting preprocessor symbols
#define Q2(q) #q
//! For quoting preprocessor symbols
#define Q(q) Q2(q)

#ifdef __GNUC__
#define ATTRIBUTE_UNUSED   __attribute__((unused))
#define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
#else
#define ATTRIBUTE_UNUSED
#define ATTRIBUTE_NORETURN
#endif

//! Trace new image creation in bang methods
#define UPDATE_DATA_PTR(_obj_, _new_) \
    do { (void) rm_trace_creation(_new_);\
    DATA_PTR(_obj_) = (void *)(_new_);\
    } while(0)


// Handle Quantum <-> Ruby Numeric object conversion
#if (MAGICKCORE_QUANTUM_DEPTH == 8 || MAGICKCORE_QUANTUM_DEPTH == 16)
#define QUANTUM2NUM(q) INT2FIX((q)) /**< Quantum -> Ruby Numeric conversion */
#define NUM2QUANTUM(n) (Quantum)NUM2UINT((n)) /**< Quantum <- Ruby Numeric conversion */
#elif (MAGICKCORE_QUANTUM_DEPTH == 32)
#define QUANTUM2NUM(q) UINT2NUM((q)) /**< Quantum -> Ruby Numeric conversion */
#define NUM2QUANTUM(n) (Quantum)NUM2UINT((n)) /**< Quntum <- Ruby Numeric conversion */
#elif (MAGICKCORE_QUANTUM_DEPTH == 64)
#define QUANTUM2NUM(q) ULL2NUM((q)) /**< Quantum -> Ruby Numeric conversion */
#define NUM2QUANTUM(n) (Quantum)NUM2ULL((n)) /**< Quntum <- Ruby Numeric conversion */
#else
#error Specified MAGICKCORE_QUANTUM_DEPTH is not supported.
#endif
//! Convert user-supplied objects to Quantum
#define APP2QUANTUM(n) rm_app2quantum((n))

//! degrees to radians conversion
#undef DegreesToRadians     // defined in ImageMagick.h in 6.0.2
#define DegreesToRadians(x) ((x)*3.14159265358979323846/180.0)

//! pixel intensity calculation
#define PIXEL_INTENSITY(q) ((Quantum)(0.299*(q)->red + 0.587*(q)->green + 0.114*(q)->blue + 0.5))

//! find maximum of longs
#define LMAX(a, b) ((((long)(a))>((long)(b)))?((long)(a)):((long)(b)))
//! find maximum of floats
#define FMAX(a, b) ((((double)(a))>((double)(b)))?((double)(a)):((double)(b)))
//! find minimum of floats
#define FMIN(a, b) ((((double)(a))<=((double)(b)))?((double)(a)):((double)(b)))

#define RMAGICK_PI 3.14159265358979  /**< pi */

//! round to Quantum
#define ROUND_TO_QUANTUM(value) ((Quantum) ((value) > (Quantum)QuantumRange ? QuantumRange : (value) + 0.5))

//! Convert a C string to a Ruby symbol. Used in marshal_dump/marshal_load methods
#define CSTR2SYM(s) ID2SYM(rb_intern(s))
//! Convert a C string to a Ruby String, or nil if the ptr is NULL
#define MAGICK_STRING_TO_OBJ(f) (f) ? rb_str_new2(f) : Qnil
/**
 * Copy the C string in a Ruby String object to ImageMagick memory, or set the
 * pointer to NULL if the object is nil.
 */
#define OBJ_TO_MAGICK_STRING(f, obj) \
    if ((obj) != Qnil)\
    {\
        VALUE str = rb_String(obj);\
        magick_clone_string(&f, StringValueCStr(str));\
    }\
{'fraction_non_alphanumeric': 0.1694450305971724, 'fraction_numerical': 0.027220932686220722, 'mean_word_length': 4.488708743485813, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 45, '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': '5733125', 'n_tokens_mistral': 3614, 'n_tokens_neox': 3272, 'n_words': 877}