<commit_before>#include "CCallback.h"


void CCallbackHandler::Process()
{
	CCallback *callback = nullptr;
	while (m_Queue.pop(callback))
	{
		for (auto amx : m_AmxList) 
		{
			int cb_idx;
			if (amx_FindPublic(amx, callback->m_Name.c_str(), &cb_idx) == AMX_ERR_NONE) 
			{
				cell amx_address = -1;
				while(callback->m_Params.empty() == false) 
				{
					auto &param = callback->m_Params.top();
					if (param.type() == typeid(cell))
					{
						amx_Push(amx, boost::get<cell>(param));
					}
					else
					{
						cell tmp_addr;
						amx_PushString(amx, &tmp_addr, NULL, 
							boost::get<string>(param).c_str(), 0, 0);

						if (amx_address < NULL)
							amx_address = tmp_addr;
					}
					callback->m_Params.pop();
				}

				callback->CallPreExecute();

				amx_Exec(amx, NULL, cb_idx);
				if(amx_address >= NULL)
					amx_Release(amx, amx_address);

				callback->CallPostExecute();

				break;
			}
		}

		delete callback;
	}
}

CCallback *CCallbackHandler::Create(string name, string format, 
	AMX* amx, cell* params, const cell param_offset)
{
	if (amx == nullptr || params == nullptr || name.empty() || format.empty())
		return nullptr;

	if (static_cast<cell>(params[0]/sizeof(cell)) < param_offset)
		return nullptr;


	cell param_idx = 0;
	cell *address_ptr = nullptr;
	decltype(CCallback::m_Params) param_list;

	for (auto &c : format)
	{
		switch (c)
		{
		case 'd':
		case 'i':
		case 'f':
		case 'b':
			amx_GetAddr(amx, params[param_offset + param_idx], &address_ptr);
			param_list.push(*address_ptr);
			break;
		case 's':
			param_list.push(amx_GetCppString(amx, params[param_offset + param_idx]));
			break;
		default:
			logprintf(">> plugin.TSConnector: Error while creating callback structure: \
					  (#1) Unrecognized format specifier '%c'", c);
			return nullptr;
		}
		param_idx++;
	}

	return new CCallback(name, std::move(param_list));
}<commit_msg>bugfix: callbacks with empty format specifier didn't work<commit_after>#include "CCallback.h"


void CCallbackHandler::Process()
{
	CCallback *callback = nullptr;
	while (m_Queue.pop(callback))
	{
		for (auto amx : m_AmxList) 
		{
			int cb_idx;
			if (amx_FindPublic(amx, callback->m_Name.c_str(), &cb_idx) == AMX_ERR_NONE) 
			{
				cell amx_address = -1;
				while(callback->m_Params.empty() == false) 
				{
					auto &param = callback->m_Params.top();
					if (param.type() == typeid(cell))
					{
						amx_Push(amx, boost::get<cell>(param));
					}
					else
					{
						cell tmp_addr;
						amx_PushString(amx, &tmp_addr, NULL, 
							boost::get<string>(param).c_str(), 0, 0);

						if (amx_address < NULL)
							amx_address = tmp_addr;
					}
					callback->m_Params.pop();
				}

				callback->CallPreExecute();

				amx_Exec(amx, NULL, cb_idx);
				if(amx_address >= NULL)
					amx_Release(amx, amx_address);

				callback->CallPostExecute();

				break;
			}
		}

		delete callback;
	}
}

CCallback *CCallbackHandler::Create(string name, string format, 
	AMX* amx, cell* params, const cell param_offset)
{
	if (name.empty())
		return nullptr;


	decltype(CCallback::m_Params) param_list;
	if (format.empty() == false)
	{
		if (amx == nullptr || params == nullptr 
			|| static_cast<cell>(params[0] / sizeof(cell)) < param_offset)
			return nullptr;


		cell param_idx = 0;
		cell *address_ptr = nullptr;

		for (auto &c : format)
		{
			switch (c)
			{
			case 'd':
			case 'i':
			case 'f':
			case 'b':
				amx_GetAddr(amx, params[param_offset + param_idx], &address_ptr);
				param_list.push(*address_ptr);
				break;
			case 's':
				param_list.push(amx_GetCppString(amx, params[param_offset + param_idx]));
				break;
			default:
				logprintf(">> plugin.TSConnector: Error while creating callback structure: \
						  (#1) Unrecognized format specifier '%c'", c);
				return nullptr;
			}
			param_idx++;
		}
	}
	return new CCallback(name, std::move(param_list));
}
{'fraction_non_alphanumeric': 0.1468693635660912, 'fraction_numerical': 0.003091986601391394, 'mean_word_length': 3.303769401330377, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, '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': '2530346', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1426, 'n_words': 292}