Lines Matching refs:rec

105         auto rec = make_function_record();
108 if (sizeof(capture) <= sizeof(rec->data)) {
116 new ((capture *) &rec->data) capture { std::forward<Func>(f) };
121 rec->free_data = [](function_record *r) { ((capture *) &r->data)->~capture(); };
123 rec->data[0] = new capture { std::forward<Func>(f) };
124 rec->free_data = [](function_record *r) { delete ((capture *) r->data[0]); };
137 rec->impl = [](function_call &call) -> handle {
169 process_attributes<Extra...>::init(extra..., rec);
176 initialize_generic(rec, signature.text, types.data(), sizeof...(Args));
178 if (cast_in::has_args) rec->has_args = true;
179 if (cast_in::has_kwargs) rec->has_kwargs = true;
187 rec->is_stateless = true;
188 rec->data[1] = const_cast<void *>(reinterpret_cast<const void *>(&typeid(FunctionType)));
193 void initialize_generic(detail::function_record *rec, const char *text,
197 rec->name = strdup(rec->name ? rec->name : "");
198 if (rec->doc) rec->doc = strdup(rec->doc);
199 for (auto &a: rec->args) {
208 rec->is_constructor = !strcmp(rec->name, "__init__") || !strcmp(rec->name, "__setstate__");
211 if (rec->is_constructor && !rec->is_new_style_constructor) {
212 const auto class_name = std::string(((PyTypeObject *) rec->scope.ptr())->tp_name);
213 const auto func_name = std::string(rec->name);
235 if (arg_index < rec->args.size() && rec->args[arg_index].name) {
236 signature += rec->args[arg_index].name;
237 } else if (arg_index == 0 && rec->is_method) {
240 signature += "arg" + std::to_string(arg_index - (rec->is_method ? 1 : 0));
245 if (arg_index < rec->args.size() && rec->args[arg_index].descr) {
247 signature += rec->args[arg_index].descr;
259 } else if (rec->is_new_style_constructor && arg_index == 0) {
263 rec->scope.attr("__module__").cast<std::string>() + "." +
264 rec->scope.attr("__qualname__").cast<std::string>();
278 if (strcmp(rec->name, "__next__") == 0) {
279 std::free(rec->name);
280 rec->name = strdup("next");
281 } else if (strcmp(rec->name, "__bool__") == 0) {
282 std::free(rec->name);
283 rec->name = strdup("__nonzero__");
286 rec->signature = strdup(signature.c_str());
287 rec->args.shrink_to_fit();
288 rec->nargs = (std::uint16_t) args;
290 if (rec->sibling && PYBIND11_INSTANCE_METHOD_CHECK(rec->sibling.ptr()))
291 rec->sibling = PYBIND11_INSTANCE_METHOD_GET_FUNCTION(rec->sibling.ptr());
293 detail::function_record *chain = nullptr, *chain_start = rec;
294 if (rec->sibling) {
295 if (PyCFunction_Check(rec->sibling.ptr())) {
296 auto rec_capsule = reinterpret_borrow<capsule>(PyCFunction_GET_SELF(rec->sibling.ptr()));
300 if (!chain->scope.is(rec->scope))
304 else if (!rec->sibling.is_none() && rec->name[0] != '_')
305 pybind11_fail("Cannot overload existing non-function object \"" + std::string(rec->name) +
311 rec->def = new PyMethodDef();
312 std::memset(rec->def, 0, sizeof(PyMethodDef));
313 rec->def->ml_name = rec->name;
314 rec->def->ml_meth = reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) (void)>(*dispatcher));
315 rec->def->ml_flags = METH_VARARGS | METH_KEYWORDS;
317 capsule rec_capsule(rec, [](void *ptr) {
322 if (rec->scope) {
323 if (hasattr(rec->scope, "__module__")) {
324 scope_module = rec->scope.attr("__module__");
325 } else if (hasattr(rec->scope, "__name__")) {
326 scope_module = rec->scope.attr("__name__");
330 m_ptr = PyCFunction_NewEx(rec->def, rec_capsule.ptr(), scope_module.ptr());
335 m_ptr = rec->sibling.ptr();
338 if (chain->is_method != rec->is_method)
343 "error while attempting to bind " + std::string(rec->is_method ? "instance" : "static") + " method " +
344 std::string(pybind11::str(rec->scope.attr("__name__"))) + "." + std::string(rec->name) + signature
349 chain->next = rec;
354 /* Create a nice pydoc rec including all signatures and
358 signatures += rec->name;
369 signatures += rec->name;
392 if (rec->is_method) {
393 m_ptr = PYBIND11_INSTANCE_METHOD_NEW(m_ptr, rec->scope.ptr());
401 static void destruct(detail::function_record *rec) {
402 while (rec) {
403 detail::function_record *next = rec->next;
404 if (rec->free_data)
405 rec->free_data(rec);
406 std::free((char *) rec->name);
407 std::free((char *) rec->doc);
408 std::free((char *) rec->signature);
409 for (auto &arg: rec->args) {
414 if (rec->def) {
415 std::free(const_cast<char *>(rec->def->ml_doc));
416 delete rec->def;
418 delete rec;
419 rec = next;
892 void initialize(const type_record &rec) {
893 if (rec.scope && hasattr(rec.scope, rec.name))
894 pybind11_fail("generic_type: cannot initialize type \"" + std::string(rec.name) +
897 if (rec.module_local ? get_local_type_info(*rec.type) : get_global_type_info(*rec.type))
898 pybind11_fail("generic_type: type \"" + std::string(rec.name) +
901 m_ptr = make_new_python_type(rec);
906 tinfo->cpptype = rec.type;
907 tinfo->type_size = rec.type_size;
908 tinfo->type_align = rec.type_align;
909 tinfo->operator_new = rec.operator_new;
910 tinfo->holder_size_in_ptrs = size_in_ptrs(rec.holder_size);
911 tinfo->init_instance = rec.init_instance;
912 tinfo->dealloc = rec.dealloc;
915 tinfo->default_holder = rec.default_holder;
916 tinfo->module_local = rec.module_local;
919 auto tindex = std::type_index(*rec.type);
921 if (rec.module_local)
927 if (rec.bases.size() > 1 || rec.multiple_inheritance) {
931 else if (rec.bases.size() == 1) {
932 auto parent_tinfo = get_type_info((PyTypeObject *) rec.bases[0].ptr());
936 if (rec.module_local) {
1100 static void add_base(detail::type_record &rec) {
1101 rec.add_base(typeid(Base), [](void *src) -> void * {