<commit_before>#include "perl_xmmsclient.h"

SV *
perl_xmmsclient_new_sv_from_ptr (void *ptr, const char *class) {
	SV *obj;
	SV *sv;
	HV *stash;

	obj = (SV *)newHV ();
	sv_magic (obj, 0, PERL_MAGIC_ext, (const char *)ptr, 0);
	sv = newRV_noinc (obj);
	stash = gv_stashpv (class, 0);
	sv_bless (sv, stash);

	return sv;
}

void *
perl_xmmsclient_get_ptr_from_sv (SV *sv, const char *class) {
	MAGIC *mg;

	if (!(mg = perl_xmmsclient_get_magic_from_sv (sv, class))) {
		return NULL;
	}

	return (void *)mg->mg_ptr;
}

MAGIC *
perl_xmmsclient_get_magic_from_sv (SV *sv, const char *class) {
	MAGIC *mg;

	if (!sv || !SvOK (sv) || !SvROK (sv) || !sv_derived_from (sv, class) || !(mg = mg_find (SvRV (sv), PERL_MAGIC_ext))) {
		return NULL;
	}

	return mg;
}

void
_perl_xmmsclient_call_xs (pTHX_ void (*subaddr) (pTHX_ CV *), CV *cv, SV **mark) {
	dSP;
	PUSHMARK (mark);
	(*subaddr) (aTHX_ cv);
	PUTBACK;
}

PerlXMMSClientCallback *
perl_xmmsclient_callback_new (SV *func, SV *data, SV *wrapper, int n_params, PerlXMMSClientCallbackParamType param_types[]) {<commit_msg>OTHER: croak when the object to be converted isn't derived by the class we expect.<commit_after>#include "perl_xmmsclient.h"

SV *
perl_xmmsclient_new_sv_from_ptr (void *ptr, const char *class) {
	SV *obj;
	SV *sv;
	HV *stash;

	obj = (SV *)newHV ();
	sv_magic (obj, 0, PERL_MAGIC_ext, (const char *)ptr, 0);
	sv = newRV_noinc (obj);
	stash = gv_stashpv (class, 0);
	sv_bless (sv, stash);

	return sv;
}

void *
perl_xmmsclient_get_ptr_from_sv (SV *sv, const char *class) {
	MAGIC *mg;

	if (!(mg = perl_xmmsclient_get_magic_from_sv (sv, class))) {
		return NULL;
	}

	return (void *)mg->mg_ptr;
}

MAGIC *
perl_xmmsclient_get_magic_from_sv (SV *sv, const char *class) {
	MAGIC *mg;

	if (!sv || !SvOK (sv) || !SvROK (sv)) {
		return NULL;
	}

	if (!sv_derived_from (sv, class)) {
		croak ("object isn't a %s", class);
	}

	if (!(mg = mg_find (SvRV (sv), PERL_MAGIC_ext))) {
		return NULL;
	}

	return mg;
}

void
_perl_xmmsclient_call_xs (pTHX_ void (*subaddr) (pTHX_ CV *), CV *cv, SV **mark) {
	dSP;
	PUSHMARK (mark);
	(*subaddr) (aTHX_ cv);
	PUTBACK;
}

PerlXMMSClientCallback *
perl_xmmsclient_callback_new (SV *func, SV *data, SV *wrapper, int n_params, PerlXMMSClientCallbackParamType param_types[]) {
{'fraction_non_alphanumeric': 0.15026362038664323, 'fraction_numerical': 0.0026362038664323375, 'mean_word_length': 4.75, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2874035', 'n_tokens_mistral': 1048, 'n_tokens_neox': 997, 'n_words': 252}