标签: trampolines

在没有蹦床的情况下跟踪通知点击(Android 12 中禁止)

Android 12 禁止所谓的通知蹦床: https://developer.android.com/about/versions/12/behavior-changes-12#notification-trampolines

目前,我正在通过分析工具跟踪通知点击事件,但使用“trampoline”,这是一个广播接收器,它在实际通知意图打开特定活动之前发送事件。

在这里和那里阅读时,我发现该方法的替代方案(也可以避免蹦床)包括使用发送分析事件所需的信息填充 Intent extras。但在这里我看到两个问题:

  1. 此逻辑应在所有涉及的活动上复制,因此很难使其可靠以避免错误/错误
  2. AFAIK,在活动重新创建时清理 Intent 额外内容是不可能的,这意味着,即使您删除了发送事件所需的 Intent 额外内容,如果重新创建相同的活动(即使用“不保留活动”开发选项),使用原始 Intent 附加功能,导致单个实际通知点击产生多个事件。

这是我用来消耗额外意图的函数:

fun consumeClickEventIfAny(intent: Intent) {
    intent.extras?.let { extras ->
        if (extras.containsKey(EXTRA_ANALYTICS_FOR_CLICK)) {
            ... trigger analytics event here
            extras.remove(EXTRA_ANALYTICS_FOR_CLICK)
            intent.replaceExtras(extras)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您是否遇到过相同或类似的问题?你是怎么解决的?任何帮助将不胜感激。谢谢你!

android analytics trampolines android-12

8
推荐指数
0
解决办法
963
查看次数

"运行时蹦床"在MonoTouch 6.0.8发行说明中的​​含义是什么?

MonoTouch 6.0.8发行说明说:

运行时Trampolines:不再需要在Mono运行时手动管理trampolines,现在动态处理trampolines.

这是什么意思?你怎么手动管理蹦床呢?
当你知道你可能会用完蹦床时,你还需要添加编译器标志吗?

c# trampolines xamarin.ios xamarin

7
推荐指数
1
解决办法
1294
查看次数

为什么return/redo在调用上下文中评估结果函数,但是不计算块结果?

昨晚我return从一个函数中了解了/ redo选项.它允许您返回另一个函数,然后在调用站点调用该函数并从同一位置重新调用求值程序

>> foo: func [a] [(print a) (return/redo (func [b] [print b + 10]))] 

>> foo "Hello" 10
Hello
20
Run Code Online (Sandbox Code Playgroud)

即使foo是只接受一个参数的函数,它现在就像一个带有两个参数的函数.这样的事情会要求调用者知道你正在返回一个函数,并且调用者必须手动使用do它上面的求值程序.

因此,没有return/redo,你会得到:

>> foo: func [a] [(print a) (return (func [b] [print b + 10]))] 

>> foo "Hello" 10
Hello
== 10
Run Code Online (Sandbox Code Playgroud)

foo使用了它的一个参数并按值返回了一个函数(没有被调用,因此解释器继续运行).然后表达式评估为10.如果return/redo不存在,你必须写:

>> do foo "Hello" 10
Hello
20
Run Code Online (Sandbox Code Playgroud)

这使得调用者不必知道(或关心)您是否已选择返回要执行的函数.并且非常酷,因为您可以执行尾部调用优化或为返回功能本身编写包装器等操作.这是一个return打印消息的变体,但仍然退出该函数并提供结果:

>> myreturn: func [] [(print "Leaving...") (return/redo :return)]

>> foo: func …
Run Code Online (Sandbox Code Playgroud)

return rebol trampolines tail-call-optimization rebol3

7
推荐指数
1
解决办法
345
查看次数

使用Lambda/Template/SFINAE自动化蹦床功能的try/catch-safeguarding

我有100个左右的蹦床功能.我想知道是否可以在try/catch块中自动包装每个.

请提前通知,这不是一个简单的问题.我将从描述(简化)代码的问题开始,然后尝试在下面尽可能地回答它,以便读者可以看到我在哪里.

Foo有一个函数指针表:

编辑:这是一个C函数指针表.所以它可以接受static W::w.
签名在这里:http://svn.python.org/projects/python/trunk/Include/object.h

编辑:我在这里试过一个测试用例:

class Foo {
    Table table;
    Foo() {
        // Each slot has a default lambda.
        :
        table->fp_53 = [](S s, A a, B b)      -> int   {cout<<"load me!";};
        table->fp_54 = [](S s, C c, D d, E e) -> float {cout<<"load me!";};
        // ^ Note: slots MAY have different signatures
        //         only the first parameter 'S s' is guaranteed
    }

    // Foo also has …
Run Code Online (Sandbox Code Playgroud)

c++ lambda trampolines template-meta-programming c++11

6
推荐指数
1
解决办法
575
查看次数

这个(类似蹦床的)构造是否有名字?

我想在创建类似于功能建议方法组合的系统时避免吹掉堆栈.这涉及树遍历(在我的实现中),条件递归等.可用于将递归转换为循环的极少数方法之一是蹦床.我试过这个然后发现我需要实现例如.短路布尔表达式评估.简而言之,我已经实现了蹦床与延续的组合,现在我试图找出这种结构是否存在以及它的名称是什么 - 因为我一直无法找到任何这样的现有结构.

我的实现 - 手动堆栈处理的反弹评估:

function immediate($bounce, $args)
{
    $stack = array($bounce->run($args));

    while ($stack[0] instanceof Bounce) {
        $current = array_pop($stack);
        if ($current instanceof Bounce) {
            $stack[] = $current;
            $stack[] = $current->current();
        } else {
            $next = array_pop($stack);
            $stack[] = $next->next($current);
        }
    }

    return $stack[0];
}
Run Code Online (Sandbox Code Playgroud)

Bounce类:

class Bounce
{
    protected $current;
    protected $next;

    public function __construct($current, $next)
    {
        $this->current = $current;
        $this->next = $next;
    }

    public function current()
    {
        $fn = $this->current;
        return $fn();
    } …
Run Code Online (Sandbox Code Playgroud)

php recursion functional-programming trampolines

5
推荐指数
0
解决办法
145
查看次数

How to adapt trampolines to Continuation Passing Style?

Here is a naive implementation of a right fold:

const foldr = f => acc => ([x, ...xs]) =>
  x === undefined
    ? acc 
    : f(x) (foldkr(f) (acc) (xs));
Run Code Online (Sandbox Code Playgroud)

This is non-tail recursion and hence we cannot apply a trampoline. One approach would be to make the algorithm iterative and use a stack to mimick the function call stack.

Another approch would be to transform the recursion into CPS:

const Cont = k => ({runCont: k});

const foldkr = f …
Run Code Online (Sandbox Code Playgroud)

javascript continuations functional-programming trampolines continuation-passing

5
推荐指数
2
解决办法
139
查看次数

如何跳出Lisp中的函数?

在(Common)Lisp中是否可以跳转到另一个函数而不是调用另一个函数?我的意思是,当前函数被打破而另一个被调用,没有跳过数千个函数,就好像我决定自己是否完成尾调用优化,即使它不是尾部.我不确定"(从fn x返回)"是否,我想要什么.

例:

(defun fn (x)
  (when x
    (princ x)
    (jump 'fn (cdr x)))
  (rest))
Run Code Online (Sandbox Code Playgroud)

'jump'应该像调用下面的函数而不保存这个函数的位置,而是返回原来的funcall所在的位置,这样就不会有堆栈溢出.只有x为零才能执行'rest'.

lisp return common-lisp trampolines tail-call-optimization

3
推荐指数
1
解决办法
331
查看次数

Groovy 的 trampoline() 使递归执行速度慢得多 - 为什么?

我正在试验递归:

def fac
//fac = { int curr, res = 1G -> 1 >= curr ? res : fac( curr - 1, res * curr ) }
fac = { int curr, res = 1G -> 1 >= curr ? res : fac.trampoline( curr - 1, res * curr ) }
fac = fac.trampoline()

def rnd = new Random()

long s = System.currentTimeMillis()

100000.times{ fac rnd.nextInt( 40 ) }

println "done in ${System.currentTimeMillis() - s} ms / ${fac(40)}"
Run Code Online (Sandbox Code Playgroud)

如果我像这样使用它,我会得到这个:

在 …

recursion groovy trampolines

3
推荐指数
1
解决办法
267
查看次数

如何将 Hook 和 Trampoline 函数合二为一以进行 WinAPI 挂钩

因此,我一直在学习挂钩和使用蹦床的概念,以便绕过/执行 WinAPI 挂钩函数中的数据(在不同的可执行文件中,使用 DLL 注入)。到目前为止,我知道如何使用汇编和 C 的混合来制作它(蹦床和钩子),但我似乎无法仅使用 C 来做到这一点,因为我似乎遗漏了一些东西。如果有人能告诉我我做错了什么以及如何解决它,我将不胜感激。

现在我的代码:

#include <Windows.h>

unsigned char* address = 0;

__declspec(naked) int __stdcall MessageBoxAHookTrampoline(HWND Window, char* Message, char* Title, int Type) {
    __asm
    {
        push ebp
        mov ebp, esp
        mov eax, address
        add eax, 5
        jmp eax
    }
}

int __stdcall MessageBoxAHook(HWND Window, char* Message, char* Title, int Type) {
    wchar_t* WMessage = L"Hooked!";
    wchar_t* WTitle = L"Success!";
    MessageBoxW(0, WMessage, WTitle, 0);
    return MessageBoxAHookTrampoline(Window, Message, Title, Type);
}

unsigned long __stdcall Thread(void* Context) …
Run Code Online (Sandbox Code Playgroud)

c assembly hook winapi trampolines

2
推荐指数
1
解决办法
3623
查看次数