<commit_before>"""Mesh wrappers"""
from _renderlib import ffi
from _renderlib import lib
from renderlib.animation import Animation
from matlib.mat import Mat

class Mesh:
    def __init__(self, vertices=None, indices=None, normals=None, uvs=None,
            joint_ids=None, joint_weights=None, ptr=None):
        if not ptr:
            # check constraints
            if not vertices or not indices:
                raise RuntimeError('vertex and index data is required')
            if len(vertices) < 3 or len(indices) % 3:
                raise RuntimeError('invalid vertex and/or index data')
            if normals and len(normals) != len(vertices):
                raise RuntimeError('invalid index data')
            if uvs and len(uvs) != len(vertices):
                raise RuntimeError('invalid UV data')
            if any([joint_ids, joint_weights]):
                if not all([joint_ids, joint_weights]) or \
                        len(joint_ids) != len(joint_weights):
                    raise RuntimeError('inconsistent joint data')

            vdata = ffi.new('float[][3]', vertices)
            idata = ffi.new('uint32_t[]', indices)
            udata = ffi.new('float[][2]', uvs) if uvs else ffi.NULL
            ndata = ffi.new('float[][3]', normals) if normals else ffi.NULL
            jidata = ffi.new('uint8_t[][4]', joint_ids) if joint_ids else ffi.NULL
            jwdata = ffi.new('uint8_t[][4]', joint_weights) if joint_weights else ffi.NULL

            ptr = lib.mesh_new(
                vdata,
                ndata,
                udata,
                jidata,
                jwdata,
                len(vertices),
                idata,
                len(indices))
            if not ptr:
                raise RuntimeError('failed to create mesh')

        self._ptr = ptr
        self._animations = [
            Animation(animptr=ffi.addressof(self._ptr.animations, i))
            for i in range(self._ptr.anim_count)
        ]
        self._transform = Mat(ptr=ffi.addressof(self._ptr, 'transform'))

    def __del__(self):
        lib.mesh_free(self._ptr)<commit_msg>Fix exception handling in Mesh constructor<commit_after>"""Mesh wrappers"""
from _renderlib import ffi
from _renderlib import lib
from renderlib.animation import Animation
from matlib.mat import Mat

class Mesh:
    def __init__(self, vertices=None, indices=None, normals=None, uvs=None,
            joint_ids=None, joint_weights=None, ptr=None):
        self._ptr = None
        if not ptr:
            # check constraints
            if not vertices or not indices:
                raise RuntimeError('vertex and index data is required')
            if len(vertices) < 3 or len(indices) % 3:
                raise RuntimeError('invalid vertex and/or index data')
            if normals and len(normals) != len(vertices):
                raise RuntimeError('invalid index data')
            if uvs and len(uvs) != len(vertices):
                raise RuntimeError('invalid UV data')
            if any([joint_ids, joint_weights]):
                if not all([joint_ids, joint_weights]) or \
                        len(joint_ids) != len(joint_weights):
                    raise RuntimeError('inconsistent joint data')

            vdata = ffi.new('float[][3]', vertices)
            idata = ffi.new('uint32_t[]', indices)
            udata = ffi.new('float[][2]', uvs) if uvs else ffi.NULL
            ndata = ffi.new('float[][3]', normals) if normals else ffi.NULL
            jidata = ffi.new('uint8_t[][4]', joint_ids) if joint_ids else ffi.NULL
            jwdata = ffi.new('uint8_t[][4]', joint_weights) if joint_weights else ffi.NULL

            ptr = lib.mesh_new(
                vdata,
                ndata,
                udata,
                jidata,
                jwdata,
                len(vertices),
                idata,
                len(indices))
            if not ptr:
                raise RuntimeError('failed to create mesh')

        self._ptr = ptr
        self._animations = [
            Animation(animptr=ffi.addressof(self._ptr.animations, i))
            for i in range(self._ptr.anim_count)
        ]
        self._transform = Mat(ptr=ffi.addressof(self._ptr, 'transform'))

    def __del__(self):
        lib.mesh_free(self._ptr or ffi.NULL)
{'fraction_non_alphanumeric': 0.10251046025104603, 'fraction_numerical': 0.005113900511390051, 'mean_word_length': 1.8821165438713998, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7122699', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1205, 'n_words': 324}