<commit_before>
#![crate_type = "rlib"]
#![feature(phase)]
#![allow(dead_code)]

extern crate rustrt;
extern crate native;
#[phase(plugin, link)]
extern crate log;
extern crate time;

use native::io::file::open;
use rustrt::rtio::{Open, Read, RtioFileStream};
use std::fmt;
use std::mem::transmute;
use std::num::FromPrimitive;
use std::os::{MapReadable, MapFd, MemoryMap};
use std::slice::raw;
use std::str::from_utf8;

#[cfg(test)]
mod test;

pub struct File {
    map: MemoryMap,
    data: *const u8,
    header: *const Header,
    nodetable: *const NodeData,
    stringtable: *const u64,
}

impl File {
    #[inline]
    pub fn open(path: &Path) -> Result<File, &'static str> {
        unsafe { ::std::rt::stack::record_sp_limit(0); }
        let mut file = match open(&path.to_c_str(), Open, Read) {
            Ok(file) => file,
            Err(_) => return Err("Failed to open file"),
        };
        let stat = match file.fstat() {
            Ok(stat) => stat,
            Err(_) => return Err("Failed to get file size"),
        };
        let map = match MemoryMap::new(stat.size as uint, [MapReadable, MapFd(file.fd())]) {
            Ok(map) => map,
            Err(_) => return Err("Failed to map file"),
        };
        let data = map.data as *const u8;
        let header: *const Header = unsafe { transmute(data) };
        if unsafe { (*header).magic } != 0x34474B50 {
            return Err("Not a valid NX PKG4 file");
        }
        let nodetable: *const NodeData = unsafe {
            transmute(data.offset((*header).nodeoffset as int))
        };
        let stringtable: *const u64 = unsafe {
            transmute(data.offset((*header).stringoffset as int))
        };
        Ok(File {
            map: map,
            data: data,
            header: header,
            nodetable: nodetable,
            stringtable: stringtable,
        })<commit_msg>Update to latest rust.<commit_after>
#![crate_type = "rlib"]
#![feature(phase)]
#![allow(dead_code)]

extern crate rustrt;
extern crate native;
#[phase(plugin, link)]
extern crate log;
extern crate time;

use native::io::file::open;
use rustrt::rtio::{Open, Read, RtioFileStream};
use std::fmt;
use std::mem::transmute;
use std::num::FromPrimitive;
use std::os::{MapReadable, MapFd, MemoryMap};
use std::slice::raw;
use std::str::from_utf8;

#[cfg(test)]
mod test;

pub struct File {
    map: MemoryMap,
    data: *const u8,
    header: *const Header,
    nodetable: *const NodeData,
    stringtable: *const u64,
}

impl File {
    #[inline]
    pub fn open(path: &Path) -> Result<File, &'static str> {
        unsafe { ::std::rt::stack::record_sp_limit(0); }
        let mut file = match open(&path.to_c_str(), Open, Read) {
            Ok(file) => file,
            Err(_) => return Err("Failed to open file"),
        };
        let stat = match file.fstat() {
            Ok(stat) => stat,
            Err(_) => return Err("Failed to get file size"),
        };
        let map = match MemoryMap::new(stat.size as uint, [MapReadable, MapFd(file.fd())]) {
            Ok(map) => map,
            Err(_) => return Err("Failed to map file"),
        };
        let data = map.data() as *const u8;
        let header: *const Header = unsafe { transmute(data) };
        if unsafe { (*header).magic } != 0x34474B50 {
            return Err("Not a valid NX PKG4 file");
        }
        let nodetable: *const NodeData = unsafe {
            transmute(data.offset((*header).nodeoffset as int))
        };
        let stringtable: *const u64 = unsafe {
            transmute(data.offset((*header).stringoffset as int))
        };
        Ok(File {
            map: map,
            data: data,
            header: header,
            nodetable: nodetable,
            stringtable: stringtable,
        })
{'fraction_non_alphanumeric': 0.1490371933526774, 'fraction_numerical': 0.008968609865470852, 'mean_word_length': 2.4192966636609556, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '1935540', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1206, 'n_words': 333}