<commit_before>// Copyright 2013-2015, The Rust-GNOME Project Developers.
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

use std::slice;
use ffi;
use glib::translate::{FromGlibPtr, ToGlibPtr};

pub struct TreePath {
    pointer:   *mut ffi::C_GtkTreePath
}

impl TreePath {
    pub fn new() -> Option<TreePath> {
        let tmp = unsafe { ffi::gtk_tree_path_new() };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    pub fn new_from_string(path: &str) -> Option<TreePath> {
        let tmp = unsafe {
            ffi::gtk_tree_path_new_from_string(path.borrow_to_glib().0)
        };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    #[cfg(feature = "gtk_3_12")]
    pub fn new_from_indicesv(indices: &mut [i32]) -> Option<TreePath> {
        let tmp = unsafe { ffi::gtk_tree_path_new_from_indicesv(indices.as_mut_ptr(), indices.len() as ::libc::c_ulong) };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    pub fn new_first() -> Option<TreePath> {
        let tmp = unsafe { ffi::gtk_tree_path_new_first() };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    #[allow(unused_variables)]
    pub fn to_string(&self) -> Option<String> {
        unsafe {
            FromGlibPtr::take(
                ffi::gtk_tree_path_to_string(self.pointer))
        }
    }

    pub fn append_index(&self, index_: i32) {
        unsafe { ffi::gtk_tree_path_append_index(self.pointer, index_) }
    }

    pub fn prepend_index(&self, index_: i32) {
        unsafe { ffi::gtk_tree_path_prepend_index(self.pointer, index_) }
    }

    pub fn get_depth(&self) -> i32 {
        unsafe { ffi::gtk_tree_path_get_depth(self.pointer) }
    }

    pub fn get_indices(&self) -> Vec<i32> {
        let tmp = unsafe { ffi::gtk_tree_path_get_indices(self.pointer) };
        let depth = self.get_depth();

        unsafe {
            Vec::from(
                slice::from_raw_parts(tmp as *const i32, depth as usize))
        }
    }

    pub fn copy(&self) -> Option<TreePath> {
        let tmp = unsafe { ffi::gtk_tree_path_copy(self.pointer) };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    pub fn compare(&self, other: &TreePath) -> i32 {
        unsafe { ffi::gtk_tree_path_compare(self.pointer as *const ffi::C_GtkTreePath, other.pointer as *const ffi::C_GtkTreePath) }
    }

    pub fn next(&self) {
        unsafe { ffi::gtk_tree_path_next(self.pointer) }
    }

    pub fn prev(&self) {
        unsafe { ffi::gtk_tree_path_prev(self.pointer) }
    }

    pub fn path_up(&self) -> bool {
        match unsafe { ffi::gtk_tree_path_up(self.pointer) } {
            0 => false,
            _ => true
        }
    }

    pub fn path_down(&self) {
        unsafe { ffi::gtk_tree_path_down(self.pointer) }
    }

    pub fn is_ancestor(&self, descendant: &TreePath) -> bool {
        match unsafe { ffi::gtk_tree_path_is_ancestor(self.pointer, descendant.pointer) } {
            0 => false,
            _ => true
        }
    }

    pub fn is_descendant(&self, ancestor: &TreePath) -> bool {
        match unsafe { ffi::gtk_tree_path_is_descendant(self.pointer, ancestor.pointer) } {
            0 => false,
            _ => true
        }
    }

    pub fn drop(&mut self) {
        unsafe { ffi::gtk_tree_path_free(self.pointer as *mut ffi::C_GtkTreePath) }
        self.pointer = ::std::ptr::null_mut();
    }

    #[doc(hidden)]
    pub fn unwrap_pointer(&self) -> *mut ffi::C_GtkTreePath {
        self.pointer
    }

    #[doc(hidden)]
    pub fn wrap_pointer(c_treepath: *mut ffi::C_GtkTreePath) -> TreePath {
        unsafe{
            ::glib::ffi::g_object_ref(c_treepath as *mut ::libc::c_void);
        }

        TreePath {
            pointer: c_treepath
        }
    }
}<commit_msg>Revert "Increase the refcount when wrapping a TreePath"<commit_after>// Copyright 2013-2015, The Rust-GNOME Project Developers.
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

use std::slice;
use ffi;
use glib::translate::{FromGlibPtr, ToGlibPtr};

pub struct TreePath {
    pointer:   *mut ffi::C_GtkTreePath
}

impl TreePath {
    pub fn new() -> Option<TreePath> {
        let tmp = unsafe { ffi::gtk_tree_path_new() };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    pub fn new_from_string(path: &str) -> Option<TreePath> {
        let tmp = unsafe {
            ffi::gtk_tree_path_new_from_string(path.borrow_to_glib().0)
        };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    #[cfg(feature = "gtk_3_12")]
    pub fn new_from_indicesv(indices: &mut [i32]) -> Option<TreePath> {
        let tmp = unsafe { ffi::gtk_tree_path_new_from_indicesv(indices.as_mut_ptr(), indices.len() as ::libc::c_ulong) };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    pub fn new_first() -> Option<TreePath> {
        let tmp = unsafe { ffi::gtk_tree_path_new_first() };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    #[allow(unused_variables)]
    pub fn to_string(&self) -> Option<String> {
        unsafe {
            FromGlibPtr::take(
                ffi::gtk_tree_path_to_string(self.pointer))
        }
    }

    pub fn append_index(&self, index_: i32) {
        unsafe { ffi::gtk_tree_path_append_index(self.pointer, index_) }
    }

    pub fn prepend_index(&self, index_: i32) {
        unsafe { ffi::gtk_tree_path_prepend_index(self.pointer, index_) }
    }

    pub fn get_depth(&self) -> i32 {
        unsafe { ffi::gtk_tree_path_get_depth(self.pointer) }
    }

    pub fn get_indices(&self) -> Vec<i32> {
        let tmp = unsafe { ffi::gtk_tree_path_get_indices(self.pointer) };
        let depth = self.get_depth();

        unsafe {
            Vec::from(
                slice::from_raw_parts(tmp as *const i32, depth as usize))
        }
    }

    pub fn copy(&self) -> Option<TreePath> {
        let tmp = unsafe { ffi::gtk_tree_path_copy(self.pointer) };

        if tmp.is_null() {
            None
        } else {
            Some(TreePath {
                pointer: tmp
            })
        }
    }

    pub fn compare(&self, other: &TreePath) -> i32 {
        unsafe { ffi::gtk_tree_path_compare(self.pointer as *const ffi::C_GtkTreePath, other.pointer as *const ffi::C_GtkTreePath) }
    }

    pub fn next(&self) {
        unsafe { ffi::gtk_tree_path_next(self.pointer) }
    }

    pub fn prev(&self) {
        unsafe { ffi::gtk_tree_path_prev(self.pointer) }
    }

    pub fn path_up(&self) -> bool {
        match unsafe { ffi::gtk_tree_path_up(self.pointer) } {
            0 => false,
            _ => true
        }
    }

    pub fn path_down(&self) {
        unsafe { ffi::gtk_tree_path_down(self.pointer) }
    }

    pub fn is_ancestor(&self, descendant: &TreePath) -> bool {
        match unsafe { ffi::gtk_tree_path_is_ancestor(self.pointer, descendant.pointer) } {
            0 => false,
            _ => true
        }
    }

    pub fn is_descendant(&self, ancestor: &TreePath) -> bool {
        match unsafe { ffi::gtk_tree_path_is_descendant(self.pointer, ancestor.pointer) } {
            0 => false,
            _ => true
        }
    }

    pub fn drop(&mut self) {
        unsafe { ffi::gtk_tree_path_free(self.pointer as *mut ffi::C_GtkTreePath) }
        self.pointer = ::std::ptr::null_mut();
    }

    #[doc(hidden)]
    pub fn unwrap_pointer(&self) -> *mut ffi::C_GtkTreePath {
        self.pointer
    }

    #[doc(hidden)]
    pub fn wrap_pointer(c_treepath: *mut ffi::C_GtkTreePath) -> TreePath {
        TreePath {
            pointer: c_treepath
        }
    }
}
{'fraction_non_alphanumeric': 0.12129661903102126, 'fraction_numerical': 0.006738701057278959, 'mean_word_length': 1.8953918600739994, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7427638', 'n_tokens_mistral': 2930, 'n_tokens_neox': 2792, 'n_words': 554}