<commit_before>// Copyright 2017 ibelie, <NAME>, Joungtao. All rights reserved.
// Use of this source code is governed by The MIT License
// that can be found in the LICENSE file.

#include "typy.h"

#ifdef TYPY_PROPERTY_HANDLER

bool TypyComposite_AddOwner(TypyComposite* child, TypyComposite* parent, FieldType type, PropertyFlag flag) {
	if (!child) {
		return true;
	} else if (child->owners_length) {
		register size_t i;
		for (i = 0; i < child->owners_length && child->owners_list[i].prop_owner != parent; i++);
		if (i < child->owners_length) { return true; }
	}
	if (child->owners_length + 1 > child->owners_capacity) {
		register size_t capacity = Ibl_Max(2 * child->owners_capacity + 1, MIN_OWNER_CAPACITY);
		register TypyPropertyOwner buffer = (TypyPropertyOwner)calloc(capacity, sizeof(struct _TypyPropertyOwner));
		if (!buffer) { return false; }
		child->owners_capacity = capacity;
		if (child->owners_list) {
			memcpy(buffer, child->owners_list, child->owners_length * sizeof(struct _TypyPropertyOwner));
			free(child->owners_list);
		}
		child->owners_list = buffer;
	}
	register TypyPropertyOwner owner = &child->owners_list[child->owners_length];
	owner->owner_type = type;
	owner->prop_owner = parent;
	owner->prop_flag  = flag;
	child->owners_length++;
	return true;
}

void TypyComposite_DelOwner(TypyComposite* child, TypyComposite* parent) {
	if (child && child->owners_length) {
		register size_t i;
		for (i = 0; i < child->owners_length && child->owners_list[i].prop_owner != parent; i++);
		for (; i < child->owners_length - 1; i++) {
			memcpy(&child->owners_list[i], &child->owners_list[i + 1], sizeof(struct _TypyPropertyOwner));
		}
		if (i < child->owners_length) {
			memset(&child->owners_list[i], 0, sizeof(struct _TypyPropertyOwner));
			child->owners_length--;
		}
	}
}

void TypyComposite_Notify(TypyComposite* composite, FieldType type, PropertyFlag f, FieldType ft, TypyType tt, TypyField o, TypyField n) {
	register size_t i;
	switch (type) {
	case FIELD_TYPE_OBJECT:
		TypyProperty_Changed((TypyObject*)composite, f, ft, tt, o, n);
	case FIELD_TYPE_VARIANT:
		for (i = 0; i < composite->owners_length; i++) {
			register TypyPropertyOwner owner = &composite->owners_list[i];
			TypyComposite_Notify(owner->prop_owner, owner->owner_type, owner->prop_flag + f, ft, tt, o, n);
		}
		break;
	case FIELD_TYPE_LIST:
	case FIELD_TYPE_DICT:
		for (i = 0; i < composite->owners_length; i++) {
			register TypyPropertyOwner owner = &composite->owners_list[i];
			TypyComposite_Notify(owner->prop_owner, owner->owner_type, 0, ft, tt, o, n);
		}
		break;
	}
}

#endif

//=============================================================================

static PyObject* TypyInt32_GetPyObject  (TypyType t, int32* v)  { return PyInt_FromLong(*v); }
static PyObject* TypyUint32_GetPyObject (TypyType t, uint32* v) { return PyInt_FromSize_t(*v); }
static PyObject* TypyBool_GetPyObject   (TypyType t, bool* v)   { return PyBool_FromLong(*v); }
static PyObject* TypyFloat_GetPyObject  (TypyType t, float* v)  { return PyFloat_FromDouble(*v); }
<commit_msg>notify list/dict bug<commit_after>// Copyright 2017 ibelie, <NAME>, Joungtao. All rights reserved.
// Use of this source code is governed by The MIT License
// that can be found in the LICENSE file.

#include "typy.h"

#ifdef TYPY_PROPERTY_HANDLER

bool TypyComposite_AddOwner(TypyComposite* child, TypyComposite* parent, FieldType type, PropertyFlag flag) {
	if (!child) {
		return true;
	} else if (child->owners_length) {
		register size_t i;
		for (i = 0; i < child->owners_length && child->owners_list[i].prop_owner != parent; i++);
		if (i < child->owners_length) { return true; }
	}
	if (child->owners_length + 1 > child->owners_capacity) {
		register size_t capacity = Ibl_Max(2 * child->owners_capacity + 1, MIN_OWNER_CAPACITY);
		register TypyPropertyOwner buffer = (TypyPropertyOwner)calloc(capacity, sizeof(struct _TypyPropertyOwner));
		if (!buffer) { return false; }
		child->owners_capacity = capacity;
		if (child->owners_list) {
			memcpy(buffer, child->owners_list, child->owners_length * sizeof(struct _TypyPropertyOwner));
			free(child->owners_list);
		}
		child->owners_list = buffer;
	}
	register TypyPropertyOwner owner = &child->owners_list[child->owners_length];
	owner->owner_type = type;
	owner->prop_owner = parent;
	owner->prop_flag  = flag;
	child->owners_length++;
	return true;
}

void TypyComposite_DelOwner(TypyComposite* child, TypyComposite* parent) {
	if (child && child->owners_length) {
		register size_t i;
		for (i = 0; i < child->owners_length && child->owners_list[i].prop_owner != parent; i++);
		for (; i < child->owners_length - 1; i++) {
			memcpy(&child->owners_list[i], &child->owners_list[i + 1], sizeof(struct _TypyPropertyOwner));
		}
		if (i < child->owners_length) {
			memset(&child->owners_list[i], 0, sizeof(struct _TypyPropertyOwner));
			child->owners_length--;
		}
	}
}

void TypyComposite_Notify(TypyComposite* composite, FieldType type, PropertyFlag f, FieldType ft, TypyType tt, TypyField o, TypyField n) {
	register size_t i;
	switch (type) {
	case FIELD_TYPE_OBJECT:
		TypyProperty_Changed((TypyObject*)composite, f, ft, tt, o, n);
	case FIELD_TYPE_VARIANT:
		for (i = 0; i < composite->owners_length; i++) {
			register TypyPropertyOwner owner = &composite->owners_list[i];
			TypyComposite_Notify(owner->prop_owner, owner->owner_type, owner->prop_flag + f, ft, tt, o, n);
		}
		break;
	case FIELD_TYPE_LIST:
	case FIELD_TYPE_DICT:
		for (i = 0; i < composite->owners_length; i++) {
			register TypyPropertyOwner owner = &composite->owners_list[i];
			TypyComposite_Notify(owner->prop_owner, owner->owner_type, owner->prop_flag, ft, tt, o, n);
		}
		break;
	}
}

#endif

//=============================================================================

static PyObject* TypyInt32_GetPyObject  (TypyType t, int32* v)  { return PyInt_FromLong(*v); }
static PyObject* TypyUint32_GetPyObject (TypyType t, uint32* v) { return PyInt_FromSize_t(*v); }
static PyObject* TypyBool_GetPyObject   (TypyType t, bool* v)   { return PyBool_FromLong(*v); }
static PyObject* TypyFloat_GetPyObject  (TypyType t, float* v)  { return PyFloat_FromDouble(*v); }

{'fraction_non_alphanumeric': 0.15460420032310176, 'fraction_numerical': 0.007269789983844911, 'mean_word_length': 5.197197197197197, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 82, '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': '2055159', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2126, 'n_words': 512}