Skip to content

Commit 6517ec8

Browse files
committed
---
yaml --- r: 56635 b: refs/heads/auto c: a64aa28 h: refs/heads/master i: 56633: 07819c9 56631: cb38dcf v: v3
1 parent ac5d465 commit 6517ec8

File tree

10 files changed

+898
-24
lines changed

10 files changed

+898
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: d6697e702774c422871499826e7d346320610242
17+
refs/heads/auto: a64aa28efed2b8be4bc7878b83978e788f5b1716
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/mk/rt.mk

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,14 @@ endif
163163
ifdef CFG_WINDOWSY_$(1)
164164
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
165165
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
166-
CFLAGS="$$(CFG_GCCISH_CFLAGS)" \
167-
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS)" \
168166
builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
169167
OS=mingw \
170168
V=$$(VERBOSE)
171169
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
172170
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
173171
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
174-
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
175-
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
172+
CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
173+
LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
176174
CC="$$(CC_$(1))" \
177175
CXX="$$(CXX_$(1))" \
178176
AR="$$(AR_$(1))" \
@@ -183,8 +181,8 @@ $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
183181
else
184182
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
185183
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
186-
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
187-
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
184+
CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
185+
LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
188186
CC="$$(CC_$(1))" \
189187
CXX="$$(CXX_$(1))" \
190188
AR="$$(AR_$(1))" \
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env python
2+
# xfail-license
3+
4+
# This creates the tables used for distributions implemented using the
5+
# ziggurat algorithm in `core::rand::distributions;`. They are
6+
# (basically) the tables as used in the ZIGNOR variant (Doornik 2005).
7+
# They are changed rarely, so the generated file should be checked in
8+
# to git.
9+
#
10+
# It creates 3 tables: X as in the paper, F which is f(x_i), and
11+
# F_DIFF which is f(x_i) - f(x_{i-1}). The latter two are just cached
12+
# values which is not done in that paper (but is done in other
13+
# variants). Note that the adZigR table is unnecessary because of
14+
# algebra.
15+
#
16+
# It is designed to be compatible with Python 2 and 3.
17+
18+
from math import exp, sqrt, log, floor
19+
import random
20+
21+
# The order should match the return value of `tables`
22+
TABLE_NAMES = ['X', 'F', 'F_DIFF']
23+
24+
# The actual length of the table is 1 more, to stop
25+
# index-out-of-bounds errors. This should match the bitwise operation
26+
# to find `i` in `zigurrat` in `libstd/rand/mod.rs`. Also the *_R and
27+
# *_V constants below depend on this value.
28+
TABLE_LEN = 256
29+
30+
# equivalent to `zigNorInit` in Doornik2005, but generalised to any
31+
# distribution. r = dR, v = dV, f = probability density function,
32+
# f_inv = inverse of f
33+
def tables(r, v, f, f_inv):
34+
# compute the x_i
35+
xvec = [0]*(TABLE_LEN+1)
36+
37+
xvec[0] = v / f(r)
38+
xvec[1] = r
39+
40+
for i in range(2, TABLE_LEN):
41+
last = xvec[i-1]
42+
xvec[i] = f_inv(v / last + f(last))
43+
44+
# cache the f's
45+
fvec = [0]*(TABLE_LEN+1)
46+
fdiff = [0]*(TABLE_LEN+1)
47+
for i in range(TABLE_LEN+1):
48+
fvec[i] = f(xvec[i])
49+
if i > 0:
50+
fdiff[i] = fvec[i] - fvec[i-1]
51+
52+
return xvec, fvec, fdiff
53+
54+
# Distributions
55+
# N(0, 1)
56+
def norm_f(x):
57+
return exp(-x*x/2.0)
58+
def norm_f_inv(y):
59+
return sqrt(-2.0*log(y))
60+
61+
NORM_R = 3.6541528853610088
62+
NORM_V = 0.00492867323399
63+
64+
NORM = tables(NORM_R, NORM_V,
65+
norm_f, norm_f_inv)
66+
67+
# Exp(1)
68+
def exp_f(x):
69+
return exp(-x)
70+
def exp_f_inv(y):
71+
return -log(y)
72+
73+
EXP_R = 7.69711747013104972
74+
EXP_V = 0.0039496598225815571993
75+
76+
EXP = tables(EXP_R, EXP_V,
77+
exp_f, exp_f_inv)
78+
79+
80+
# Output the tables/constants/types
81+
82+
def render_static(name, type, value):
83+
# no space or
84+
return 'pub static %s: %s =%s;\n' % (name, type, value)
85+
86+
# static `name`: [`type`, .. `len(values)`] =
87+
# [values[0], ..., values[3],
88+
# values[4], ..., values[7],
89+
# ... ];
90+
def render_table(name, values):
91+
rows = []
92+
# 4 values on each row
93+
for i in range(0, len(values), 4):
94+
row = values[i:i+4]
95+
rows.append(', '.join('%.18f' % f for f in row))
96+
97+
rendered = '\n [%s]' % ',\n '.join(rows)
98+
return render_static(name, '[f64, .. %d]' % len(values), rendered)
99+
100+
101+
with open('ziggurat_tables.rs', 'w') as f:
102+
f.write('''// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
103+
// file at the top-level directory of this distribution and at
104+
// http://rust-lang.org/COPYRIGHT.
105+
//
106+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
107+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
108+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
109+
// option. This file may not be copied, modified, or distributed
110+
// except according to those terms.
111+
112+
// Tables for distributions which are sampled using the ziggurat
113+
// algorithm. Autogenerated by `ziggurat_tables.py`.
114+
115+
pub type ZigTable = &\'static [f64, .. %d];
116+
''' % (TABLE_LEN + 1))
117+
for name, tables, r in [('NORM', NORM, NORM_R),
118+
('EXP', EXP, EXP_R)]:
119+
f.write(render_static('ZIG_%s_R' % name, 'f64', ' %.18f' % r))
120+
for (tabname, table) in zip(TABLE_NAMES, tables):
121+
f.write(render_table('ZIG_%s_%s' % (name, tabname), table))

branches/auto/src/libcore/libc.rs

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub use libc::funcs::posix88::unistd::*;
104104

105105
pub use libc::funcs::posix01::stat_::*;
106106
pub use libc::funcs::posix01::unistd::*;
107+
pub use libc::funcs::posix01::glob::*;
107108
pub use libc::funcs::posix08::unistd::*;
108109

109110
pub use libc::funcs::bsd44::*;
@@ -210,7 +211,21 @@ pub mod types {
210211
#[cfg(target_os = "android")]
211212
pub mod os {
212213
pub mod common {
213-
pub mod posix01 {}
214+
pub mod posix01 {
215+
use libc::types::common::c95::{c_void};
216+
use libc::types::os::arch::c95::{c_char, size_t};
217+
pub struct glob_t {
218+
gl_pathc: size_t,
219+
gl_pathv: **c_char,
220+
gl_offs: size_t,
221+
222+
__unused1: *c_void,
223+
__unused2: *c_void,
224+
__unused3: *c_void,
225+
__unused4: *c_void,
226+
__unused5: *c_void,
227+
}
228+
}
214229
}
215230

216231
#[cfg(target_arch = "x86")]
@@ -369,7 +384,25 @@ pub mod types {
369384
#[cfg(target_os = "freebsd")]
370385
pub mod os {
371386
pub mod common {
372-
pub mod posix01 {}
387+
pub mod posix01 {
388+
use libc::types::common::c95::{c_void};
389+
use libc::types::os::arch::c95::{c_char, c_int, size_t};
390+
pub struct glob_t {
391+
gl_pathc: size_t,
392+
__unused1: size_t,
393+
gl_offs: size_t,
394+
__unused2: c_int,
395+
gl_pathv: **c_char,
396+
397+
__unused3: *c_void,
398+
399+
__unused4: *c_void,
400+
__unused5: *c_void,
401+
__unused6: *c_void,
402+
__unused7: *c_void,
403+
__unused8: *c_void,
404+
}
405+
}
373406
}
374407

375408
#[cfg(target_arch = "x86_64")]
@@ -571,6 +604,23 @@ pub mod types {
571604
pub mod os {
572605
pub mod common {
573606
pub mod posix01 {
607+
use libc::types::common::c95::{c_void};
608+
use libc::types::os::arch::c95::{c_char, c_int, size_t};
609+
pub struct glob_t {
610+
gl_pathc: size_t,
611+
__unused1: c_int,
612+
gl_offs: size_t,
613+
__unused2: c_int,
614+
gl_pathv: **c_char,
615+
616+
__unused3: *c_void,
617+
618+
__unused4: *c_void,
619+
__unused5: *c_void,
620+
__unused6: *c_void,
621+
__unused7: *c_void,
622+
__unused8: *c_void,
623+
}
574624
}
575625
}
576626

@@ -877,6 +927,18 @@ pub mod consts {
877927
}
878928
pub mod posix01 {
879929
pub static SIGTRAP : int = 5;
930+
931+
pub static GLOB_ERR : int = 1 << 0;
932+
pub static GLOB_MARK : int = 1 << 1;
933+
pub static GLOB_NOSORT : int = 1 << 2;
934+
pub static GLOB_DOOFFS : int = 1 << 3;
935+
pub static GLOB_NOCHECK : int = 1 << 4;
936+
pub static GLOB_APPEND : int = 1 << 5;
937+
pub static GLOB_NOESCAPE : int = 1 << 6;
938+
939+
pub static GLOB_NOSPACE : int = 1;
940+
pub static GLOB_ABORTED : int = 2;
941+
pub static GLOB_NOMATCH : int = 3;
880942
}
881943
pub mod posix08 {
882944
}
@@ -956,6 +1018,18 @@ pub mod consts {
9561018
}
9571019
pub mod posix01 {
9581020
pub static SIGTRAP : int = 5;
1021+
1022+
pub static GLOB_APPEND : int = 0x0001;
1023+
pub static GLOB_DOOFFS : int = 0x0002;
1024+
pub static GLOB_ERR : int = 0x0004;
1025+
pub static GLOB_MARK : int = 0x0008;
1026+
pub static GLOB_NOCHECK : int = 0x0010;
1027+
pub static GLOB_NOSORT : int = 0x0020;
1028+
pub static GLOB_NOESCAPE : int = 0x2000;
1029+
1030+
pub static GLOB_NOSPACE : int = -1;
1031+
pub static GLOB_ABORTED : int = -2;
1032+
pub static GLOB_NOMATCH : int = -3;
9591033
}
9601034
pub mod posix08 {
9611035
}
@@ -1036,6 +1110,18 @@ pub mod consts {
10361110
}
10371111
pub mod posix01 {
10381112
pub static SIGTRAP : int = 5;
1113+
1114+
pub static GLOB_APPEND : int = 0x0001;
1115+
pub static GLOB_DOOFFS : int = 0x0002;
1116+
pub static GLOB_ERR : int = 0x0004;
1117+
pub static GLOB_MARK : int = 0x0008;
1118+
pub static GLOB_NOCHECK : int = 0x0010;
1119+
pub static GLOB_NOSORT : int = 0x0020;
1120+
pub static GLOB_NOESCAPE : int = 0x2000;
1121+
1122+
pub static GLOB_NOSPACE : int = -1;
1123+
pub static GLOB_ABORTED : int = -2;
1124+
pub static GLOB_NOMATCH : int = -3;
10391125
}
10401126
pub mod posix08 {
10411127
}
@@ -1606,6 +1692,21 @@ pub mod funcs {
16061692
-> pid_t;
16071693
}
16081694
}
1695+
1696+
#[nolink]
1697+
#[abi = "cdecl"]
1698+
pub mod glob {
1699+
use libc::types::common::c95::{c_void};
1700+
use libc::types::os::arch::c95::{c_char, c_int};
1701+
use libc::types::os::common::posix01::{glob_t};
1702+
1703+
pub extern {
1704+
unsafe fn glob(pattern: *c_char, flags: c_int,
1705+
errfunc: *c_void, // XXX callback
1706+
pglob: *mut glob_t);
1707+
unsafe fn globfree(pglob: *mut glob_t);
1708+
}
1709+
}
16091710
}
16101711

16111712
#[cfg(target_os = "win32")]
@@ -1615,6 +1716,9 @@ pub mod funcs {
16151716

16161717
pub mod unistd {
16171718
}
1719+
1720+
pub mod glob {
1721+
}
16181722
}
16191723

16201724

0 commit comments

Comments
 (0)