this repo has no description
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com)
2#include "api-handle.h"
3#include "runtime.h"
4
5namespace py {
6
7PY_EXPORT PyObject* PyClassMethod_New(PyObject* callable) {
8 DCHECK(callable != nullptr, "uninitialized staticmethod object");
9 Thread* thread = Thread::current();
10 HandleScope scope(thread);
11 Runtime* runtime = thread->runtime();
12 Object callable_obj(&scope, ApiHandle::asObject(ApiHandle::fromPyObject(callable)));
13 ClassMethod result(&scope, runtime->newClassMethod());
14 result.setFunction(*callable_obj);
15 return ApiHandle::newReferenceWithManaged(runtime, *result);
16}
17
18PY_EXPORT PyObject* PyStaticMethod_New(PyObject* callable) {
19 DCHECK(callable != nullptr, "uninitialized classmethod object");
20 Thread* thread = Thread::current();
21 HandleScope scope(thread);
22 Runtime* runtime = thread->runtime();
23 Object callable_obj(&scope, ApiHandle::asObject(ApiHandle::fromPyObject(callable)));
24 StaticMethod result(&scope, runtime->newStaticMethod());
25 result.setFunction(*callable_obj);
26 return ApiHandle::newReferenceWithManaged(runtime, *result);
27}
28
29PY_EXPORT PyTypeObject* PyClassMethod_Type_Ptr() {
30 Runtime* runtime = Thread::current()->runtime();
31 return reinterpret_cast<PyTypeObject*>(ApiHandle::borrowedReference(
32 runtime, runtime->typeAt(LayoutId::kClassMethod)));
33}
34
35PY_EXPORT PyTypeObject* PyFunction_Type_Ptr() {
36 Runtime* runtime = Thread::current()->runtime();
37 return reinterpret_cast<PyTypeObject*>(ApiHandle::borrowedReference(
38 runtime, runtime->typeAt(LayoutId::kFunction)));
39}
40
41PY_EXPORT PyTypeObject* PyStaticMethod_Type_Ptr() {
42 Runtime* runtime = Thread::current()->runtime();
43 return reinterpret_cast<PyTypeObject*>(ApiHandle::borrowedReference(
44 runtime, runtime->typeAt(LayoutId::kStaticMethod)));
45}
46
47PY_EXPORT PyObject* _PyCFunction_FastCallDict(PyObject* /* c */,
48 PyObject* const* /* s */,
49 Py_ssize_t /* s */,
50 PyObject* /* s */) {
51 UNIMPLEMENTED("_PyCFunction_FastCallDict");
52}
53
54PY_EXPORT PyObject* _PyCFunction_FastCallKeywords(PyObject* /* c */,
55 PyObject* const* /* s */,
56 Py_ssize_t /* s */,
57 PyObject* /* s */) {
58 UNIMPLEMENTED("_PyCFunction_FastCallKeywords");
59}
60
61PY_EXPORT PyObject* _PyFunction_FastCallDict(PyObject* /* c */,
62 PyObject* const* /* s */,
63 Py_ssize_t /* s */,
64 PyObject* /* s */) {
65 UNIMPLEMENTED("_PyFunction_FastCallDict");
66}
67
68PY_EXPORT PyObject* _PyFunction_FastCallKeywords(PyObject* /* c */,
69 PyObject* const* /* k */,
70 Py_ssize_t /* s */,
71 PyObject* /* s */) {
72 UNIMPLEMENTED("_PyFunction_FastCallKeywords");
73}
74
75} // namespace py