void add_function(boost::python::object& object, FunctionT function, const std::string& name, const std::string& docstring = "") { boost::python::object func_obj = boost::python::make_function(function); boost::python::setattr(func_obj, "__doc__", boost::python::str(docstring.c_str())); // TODO: weak ref here doesn't work for some reasons generic_setattr(object, name.c_str(), boost::python::import("types").attr("MethodType")(func_obj, object)); }
/* * note this function is deprecated, the new truncate sequence should be * used instead -- see eg. simple_setsize, generic_setattr. */ int inode_setattr(struct inode *inode, const struct iattr *attr) { unsigned int ia_valid = attr->ia_valid; if (ia_valid & ATTR_SIZE && attr->ia_size != i_size_read(inode)) { int error; error = vmtruncate(inode, attr->ia_size); if (error) return error; } generic_setattr(inode, attr); mark_inode_dirty(inode); return 0; }
int sysfs_setattr(struct dentry *dentry, struct iattr *iattr) { struct inode *inode = dentry->d_inode; struct sysfs_dirent *sd = dentry->d_fsdata; int error; if (!sd) return -EINVAL; mutex_lock(&sysfs_mutex); error = inode_change_ok(inode, iattr); if (error) goto out; /* this ignores size changes */ generic_setattr(inode, iattr); error = sysfs_sd_setattr(sd, iattr); out: mutex_unlock(&sysfs_mutex); return error; }