-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy path_bytecodetools.java
More file actions
66 lines (55 loc) · 1.86 KB
/
_bytecodetools.java
File metadata and controls
66 lines (55 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.python.modules;
import org.python.core.BytecodeNotification;
import org.python.core.PyObject;
import org.python.core.Py;
/**
* BytecodeTools provides tools for generated JVM bytecode.
* <p>
* This module supports registering a python callback function
* to be notified when new bytecode is loaded.
* see also core/BytecodeNotification.java
*/
public class _bytecodetools {
public static final String __doc__ =
"Provides utilities for generated bytecode.\n";
public static final String __name__ = "BytecodeTools";
static class _Callback implements BytecodeNotification.Callback {
PyObject callback;
public _Callback(PyObject callback) {
this.callback = callback;
}
public void notify(String name, byte[] bytes, Class c) {
callback.__call__(Py.java2py(name), Py.java2py(bytes), Py.java2py(c));
}
public int hashCode() {
return callback.hashCode();
}
public boolean equals(Object other) {
if (!(other instanceof _Callback)) return false;
_Callback that = (_Callback) other;
return callback.equals(that.callback);
}
}
/**
* Registers a python callback function that will be notified on bytecode loading.
*
* @param callback a Python callback function
*/
public static void register(final PyObject callback) {
BytecodeNotification.register(new _Callback(callback));
}
/**
* Unregisters a python callback function.
*
* @param callback a Python callback function
*/
public static boolean unregister(final PyObject callback) {
return BytecodeNotification.unregister(new _Callback(callback));
}
/**
* Clears all the registered callbacks.
*/
public static void clear() {
BytecodeNotification.clear();
}
}