mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 17:41:33 +03:00
c5b2463de4
This reverts commit 8c87faf180e00c582b01f7c4e82b77b17933596a. The previous use-after-free fix appears to alleviate the crash "caused" by this code.
91 lines
2.3 KiB
C
91 lines
2.3 KiB
C
/* j/3/rub.c
|
|
**
|
|
** This file is in the public domain.
|
|
*/
|
|
#include "all.h"
|
|
#include "../pit.h"
|
|
|
|
/* functions
|
|
*/
|
|
u2_noun // produce
|
|
j2_mby(Pt5, rub)(u2_wire wir_r,
|
|
u2_atom a, // retain
|
|
u2_atom b) // retain
|
|
{
|
|
u2_atom c, d, e;
|
|
u2_atom w, x, y, z;
|
|
u2_atom p, q;
|
|
|
|
u2_atom m = j2_mbc(Pt1, add)(wir_r, a, u2_met(0, b));
|
|
|
|
// Compute c and d.
|
|
{
|
|
x = u2_rx(wir_r, a);
|
|
|
|
while ( _0 == j2_mbc(Pt3, cut)(wir_r, _0, x, _1, b) ) {
|
|
u2_atom y = j2_mbc(Pt1, inc)(wir_r, x);
|
|
|
|
// Sanity check: crash if decoding more bits than available
|
|
if ( u2_yes == j2_mbc(Pt1, gth)(wir_r, x, m)) {
|
|
// fprintf(stderr, "[%%rub-hard %d %d %d]\r\n", a, x, m);
|
|
return u2_bl_bail(wir_r, c3__exit);
|
|
}
|
|
|
|
u2_rz(wir_r, x);
|
|
x = y;
|
|
}
|
|
if ( u2_yes == u2_sing(x, a) ) {
|
|
u2_rz(wir_r, x);
|
|
return u2_bc(wir_r, _1, _0);
|
|
}
|
|
c = j2_mbc(Pt1, sub)(wir_r, x, a);
|
|
d = j2_mbc(Pt1, inc)(wir_r, x);
|
|
|
|
u2_rz(wir_r, x);
|
|
}
|
|
|
|
// Compute e, p, q.
|
|
{
|
|
x = j2_mbc(Pt1, dec)(wir_r, c);
|
|
y = j2_mbc(Pt3, bex)(wir_r, x);
|
|
z = j2_mbc(Pt3, cut)(wir_r, _0, d, x, b);
|
|
|
|
e = j2_mbc(Pt1, add)(wir_r, y, z);
|
|
u2_rz(wir_r, y); u2_rz(wir_r, z);
|
|
|
|
w = j2_mbc(Pt1, add)(wir_r, c, c);
|
|
y = j2_mbc(Pt1, add)(wir_r, w, e);
|
|
z = j2_mbc(Pt1, add)(wir_r, d, x);
|
|
|
|
p = j2_mbc(Pt1, add)(wir_r, w, e);
|
|
q = j2_mbc(Pt3, cut)(wir_r, _0, z, e, b);
|
|
|
|
u2_rz(wir_r, w); u2_rz(wir_r, x); u2_rz(wir_r, y); u2_rz(wir_r, z);
|
|
|
|
return u2_bc(wir_r, p, q);
|
|
}
|
|
}
|
|
u2_noun // transfer
|
|
j2_mb(Pt5, rub)(u2_wire wir_r,
|
|
u2_noun cor) // retain
|
|
{
|
|
u2_noun a, b;
|
|
|
|
if ( (u2_no == u2_mean(cor, u2_cv_sam_2, &a, u2_cv_sam_3, &b, 0)) ||
|
|
(u2_no == u2_stud(a)) ||
|
|
(u2_no == u2_stud(b)) )
|
|
{
|
|
return u2_bl_bail(wir_r, c3__fail);
|
|
} else {
|
|
return j2_mby(Pt5, rub)(wir_r, a, b);
|
|
}
|
|
}
|
|
|
|
/* structures
|
|
*/
|
|
u2_ho_jet
|
|
j2_mbj(Pt5, rub)[] = {
|
|
{ ".2", c3__hevy, j2_mb(Pt5, rub), Tier5, u2_none, u2_none },
|
|
{ }
|
|
};
|