Show newer

喜闻乐见 libcxx vector 移动所用的函数模板

// 普通类
template <class _Ptr>
_LIBCPP_INLINE_VISIBILITY
static
void
__construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
{
    static_assert(__is_cpp17_move_insertable<allocator_type>::value,
      "The specified type does not meet the requirements of Cpp17MoveInsertable");
    // __end2 目的
    // __begin1, __end1 源
    while (__end1 != __begin1) // 遍历 vector 扩张前所有元素
    {
        // 在 (__end2 - 1) 位置上移动构造 *(--end1)
        construct(__a, _VSTD::__to_address(__end2 - 1),
#ifdef _LIBCPP_NO_EXCEPTIONS
            _VSTD::move(*--__end1)
#else
            _VSTD::move_if_noexcept(*--__end1)
#endif
        );
        --__end2;
    }
}

// 可平凡移动构造的类
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
static
typename enable_if
<
    (__is_default_allocator<allocator_type>::value
        || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
     is_trivially_move_constructible<_Tp>::value, // 平凡移动构造约束
    void
>::type
__construct_backward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
{
    ptrdiff_t _Np = __end1 - __begin1; // 需要移动的元素个数
    __end2 -= _Np; // 目的地址

    // memcpy
    if (_Np > 0)
        _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
}

语 料 库: lib/libc/gen/errlst.c

const char __uprefix[] = "Unknown error";

const char *const sys_errlist[] = {
	"No error: 0",				/*  0 - ENOERROR */
	"Operation not permitted",		/*  1 - EPERM */
	"No such file or directory",		/*  2 - ENOENT */
	"No such process",			/*  3 - ESRCH */
	"Interrupted system call",		/*  4 - EINTR */
	"Input/output error",			/*  5 - EIO */
	"Device not configured",		/*  6 - ENXIO */
	"Argument list too long",		/*  7 - E2BIG */
	"Exec format error",			/*  8 - ENOEXEC */
	"Bad file descriptor",			/*  9 - EBADF */
	"No child processes",			/* 10 - ECHILD */
	"Resource deadlock avoided",		/* 11 - EDEADLK */
	"Cannot allocate memory",		/* 12 - ENOMEM */
	"Permission denied",			/* 13 - EACCES */
	"Bad address",				/* 14 - EFAULT */
	"Block device required",		/* 15 - ENOTBLK */
	"Device busy",				/* 16 - EBUSY */
	"File exists",				/* 17 - EEXIST */
	"Cross-device link",			/* 18 - EXDEV */
	"Operation not supported by device",	/* 19 - ENODEV */
	"Not a directory",			/* 20 - ENOTDIR */
	"Is a directory",			/* 21 - EISDIR */
	"Invalid argument",			/* 22 - EINVAL */
	"Too many open files in system",	/* 23 - ENFILE */
	"Too many open files",			/* 24 - EMFILE */
	"Inappropriate ioctl for device",	/* 25 - ENOTTY */
	"Text file busy",			/* 26 - ETXTBSY */
	"File too large",			/* 27 - EFBIG */
	"No space left on device",		/* 28 - ENOSPC */
	"Illegal seek",				/* 29 - ESPIPE */
	"Read-only file system",		/* 30 - EROFS */
	"Too many links",			/* 31 - EMLINK */
	"Broken pipe",				/* 32 - EPIPE */

/* math software */
	"Numerical argument out of domain",	/* 33 - EDOM */
	"Result too large",			/* 34 - ERANGE */

/* non-blocking and interrupt i/o */
	"Resource temporarily unavailable",	/* 35 - EAGAIN */
						/* 35 - EWOULDBLOCK */
	"Operation now in progress",		/* 36 - EINPROGRESS */
	"Operation already in progress",	/* 37 - EALREADY */

/* ipc/network software -- argument errors */
	"Socket operation on non-socket",	/* 38 - ENOTSOCK */
	"Destination address required",		/* 39 - EDESTADDRREQ */
	"Message too long",			/* 40 - EMSGSIZE */
	"Protocol wrong type for socket",	/* 41 - EPROTOTYPE */
	"Protocol not available",		/* 42 - ENOPROTOOPT */
	"Protocol not supported",		/* 43 - EPROTONOSUPPORT */
	"Socket type not supported",		/* 44 - ESOCKTNOSUPPORT */
	"Operation not supported",		/* 45 - EOPNOTSUPP */
	"Protocol family not supported",	/* 46 - EPFNOSUPPORT */
						/* 47 - EAFNOSUPPORT */
	"Address family not supported by protocol family",
	"Address already in use",		/* 48 - EADDRINUSE */
	"Can't assign requested address",	/* 49 - EADDRNOTAVAIL */

/* ipc/network software -- operational errors */
	"Network is down",			/* 50 - ENETDOWN */
	"Network is unreachable",		/* 51 - ENETUNREACH */
	"Network dropped connection on reset",	/* 52 - ENETRESET */
	"Software caused connection abort",	/* 53 - ECONNABORTED */
	"Connection reset by peer",		/* 54 - ECONNRESET */
	"No buffer space available",		/* 55 - ENOBUFS */
	"Socket is already connected",		/* 56 - EISCONN */
	"Socket is not connected",		/* 57 - ENOTCONN */
	"Can't send after socket shutdown",	/* 58 - ESHUTDOWN */
	"Too many references: can't splice",	/* 59 - ETOOMANYREFS */
	"Operation timed out",			/* 60 - ETIMEDOUT */
	"Connection refused",			/* 61 - ECONNREFUSED */

	"Too many levels of symbolic links",	/* 62 - ELOOP */
	"File name too long",			/* 63 - ENAMETOOLONG */

/* should be rearranged */
	"Host is down",				/* 64 - EHOSTDOWN */
	"No route to host",			/* 65 - EHOSTUNREACH */
	"Directory not empty",			/* 66 - ENOTEMPTY */

/* quotas & mush */
	"Too many processes",			/* 67 - EPROCLIM */
	"Too many users",			/* 68 - EUSERS */
	"Disc quota exceeded",			/* 69 - EDQUOT */

/* Network File System */
	"Stale NFS file handle",		/* 70 - ESTALE */
	"Too many levels of remote in path",	/* 71 - EREMOTE */
	"RPC struct is bad",			/* 72 - EBADRPC */
	"RPC version wrong",			/* 73 - ERPCMISMATCH */
	"RPC prog. not avail",			/* 74 - EPROGUNAVAIL */
	"Program version wrong",		/* 75 - EPROGMISMATCH */
	"Bad procedure for program",		/* 76 - EPROCUNAVAIL */

	"No locks available",			/* 77 - ENOLCK */
	"Function not implemented",		/* 78 - ENOSYS */
	"Inappropriate file type or format",	/* 79 - EFTYPE */
	"Authentication error",			/* 80 - EAUTH */
	"Need authenticator",			/* 81 - ENEEDAUTH */
	"Identifier removed",			/* 82 - EIDRM */
	"No message of desired type",		/* 83 - ENOMSG */
	"Value too large to be stored in data type", /* 84 - EOVERFLOW */
	"Operation canceled",			/* 85 - ECANCELED */
	"Illegal byte sequence",		/* 86 - EILSEQ */
	"Attribute not found",			/* 87 - ENOATTR */

/* General */
	"Programming error",			/* 88 - EDOOFUS */

	"Bad message",				/* 89 - EBADMSG */
	"Multihop attempted",			/* 90 - EMULTIHOP */
	"Link has been severed",		/* 91 - ENOLINK */
	"Protocol error",			/* 92 - EPROTO */
	"Capabilities insufficient",		/* 93 - ENOTCAPABLE */
	"Not permitted in capability mode",	/* 94 - ECAPMODE */
	"State not recoverable",		/* 95 - ENOTRECOVERABLE */
	"Previous owner died",			/* 96 - EOWNERDEAD */

/*
 * Reserved space in sys_errlist, take the next slot for a next error code.
 * Reserve prevents the array size from changing for some time.
 */
	__uprefix,				/* 97 */
	__uprefix,				/* 98 */
	__uprefix,				/* 99 */
	__uprefix,				/* 100 */
	__uprefix,				/* 101 */
	__uprefix,				/* 102 */
	__uprefix,				/* 103 */
	__uprefix,				/* 104 */
	__uprefix,				/* 105 */
	__uprefix,				/* 106 */
	__uprefix,				/* 107 */
	__uprefix,				/* 108 */
	__uprefix,				/* 109 */
	__uprefix,				/* 110 */
	__uprefix,				/* 111 */
	__uprefix,				/* 112 */
	__uprefix,				/* 113 */
	__uprefix,				/* 114 */
	__uprefix,				/* 115 */
	__uprefix,				/* 116 */
	__uprefix,				/* 117 */
	__uprefix,				/* 118 */
	__uprefix,				/* 119 */
	__uprefix,				/* 120 */
	__uprefix,				/* 121 */
	__uprefix,				/* 122 */
	__uprefix,				/* 123 */
	__uprefix,				/* 124 */
	__uprefix,				/* 125 */
	__uprefix,				/* 126 */
	__uprefix,				/* 127 */
	__uprefix,				/* 128 */
	__uprefix,				/* 129 */
	__uprefix,				/* 130 */
	__uprefix,				/* 131 */
	__uprefix,				/* 132 */
	__uprefix,				/* 133 */
	__uprefix,				/* 134 */
	__uprefix,				/* 135 */
	__uprefix,				/* 136 */
	__uprefix,				/* 137 */
	__uprefix,				/* 138 */
	__uprefix,				/* 139 */
	__uprefix,				/* 140 */
	__uprefix,				/* 141 */
	__uprefix,				/* 142 */
	__uprefix,				/* 143 */
	__uprefix,				/* 144 */
	__uprefix,				/* 145 */
	__uprefix,				/* 146 */
	__uprefix,				/* 147 */
	__uprefix,				/* 148 */
	__uprefix,				/* 149 */
	__uprefix,				/* 150 */
};

来点plan9让大家开心一下:
/sys/include/9p.h

struct Fid
{
	ulong	fid;
	char		omode;	/* -1 = not open */
	File*		file;
	char*	uid;
	Qid		qid;
	void*	aux;

/* below is implementation-specific; don't use */
	Readdir*	rdir;
	Ref		ref;
	Fidpool*	pool;
	vlong	diroffset;
	long		dirindex;
};

这周除了一门python,都最后一节课了,然后院领导现在开会,说给我们又搞了一个月的课
据说是华为的老师,一直带到6.24
绷不住了

括号匹配(雾

#include <stdio.h>
#include <ctype.h>
#include <stack>
#include <stdlib.h>

int error()
{
    printf("match failed\n");
    return EXIT_FAILURE;
}

int main()
{
    std::stack<int> st;
    int ch;
    while((ch = getchar()) != EOF)
    {
        switch(ch)
        {
        case '{': st.push('}'); break; 
        case '[': st.push(']'); break;
        case '(': st.push(')'); break;
        case '}':
        case ']':
        case ')':
            if(st.empty() || ch != st.top())
                return error();
            st.pop();
            break;
        case '\r':
        case '\n':
        case '\x1a':
            break;
        default:
            return error();
        }
    }

    if(!st.empty()) return error();

    printf("success\n");
    return EXIT_SUCCESS;
}

暴躁警告 

又往我电脑上滴水嗷,他妈的,有完没完。

FreeBSD kernel doxygen 太难看了,还不如直接啃源码(雾,图要紧,图要紧)

做了人类想成仙,生在地上要上天
笑死我了

没大内存都不好意思FUZZ别人
(卡死了,直接强制关虚拟机)

高端的文档,往往只需要最朴素的学习方式(翻译)(好吧,我是废物,自己练一练再总结一遍)
上面是初稿,下面是用人话再写一遍。

arch linux 上测试 tput 的输入是 capname,我自闭了。

Show older
小森林

每个人都有属于自己的一片森林,也许我们从来不曾走过,但它一直在那里,总会在那里。迷失的人迷失了,相逢的人会再相逢。愿这里,成为属于你的小森林。