From c049703ed92049953824dc653d66f340faaa9ec2 Mon Sep 17 00:00:00 2001 From: SeongBeomLEE <2712qwer@naver.com> Date: Sat, 6 Jul 2024 22:19:43 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=9D=B4=EC=84=B1=EB=B2=94]=2011=EC=A3=BC?= =?UTF-8?q?=EC=B0=A8=20=EB=AF=B8=EC=85=98=20=EC=A0=9C=EC=B6=9C=20(#125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../11\354\243\274\354\260\250.md" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "8th_members/\354\235\264\354\204\261\353\262\224/11\354\243\274\354\260\250.md" diff --git "a/8th_members/\354\235\264\354\204\261\353\262\224/11\354\243\274\354\260\250.md" "b/8th_members/\354\235\264\354\204\261\353\262\224/11\354\243\274\354\260\250.md" new file mode 100644 index 0000000..5a23a2b --- /dev/null +++ "b/8th_members/\354\235\264\354\204\261\353\262\224/11\354\243\274\354\260\250.md" @@ -0,0 +1,74 @@ +# 11주차 +## str type 분석 +```c +Objects/object.c + +INIT_TYPE(&PyUnicode_Type, "str"); +``` +- python의 str은 PyUnicode_Type 을 서용함 + +```c +Objects\unicodeobject.c + +PyTypeObject PyUnicode_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "str", /* tp_name */ + sizeof(PyUnicodeObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* Slots */ + (destructor)unicode_dealloc, /* tp_dealloc */ + 0, /* tp_vectorcall_offset */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_as_async */ + unicode_repr, /* tp_repr */ + &unicode_as_number, /* tp_as_number */ + &unicode_as_sequence, /* tp_as_sequence */ + &unicode_as_mapping, /* tp_as_mapping */ + (hashfunc) unicode_hash, /* tp_hash*/ + 0, /* tp_call*/ + (reprfunc) unicode_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_UNICODE_SUBCLASS, /* tp_flags */ + unicode_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + PyUnicode_RichCompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + unicode_iter, /* tp_iter */ + 0, /* tp_iternext */ + unicode_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &PyBaseObject_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + unicode_new, /* tp_new */ + PyObject_Del, /* tp_free */ +}; +``` +- type 정의 + +```c +/* Strings allocated through PyUnicode_FromUnicode(NULL, len) use the + PyUnicodeObject structure. The actual string data is initially in the wstr + block, and copied into the data block using _PyUnicode_Ready. */ +typedef struct { + PyCompactUnicodeObject _base; + union { + void *any; + Py_UCS1 *latin1; + Py_UCS2 *ucs2; + Py_UCS4 *ucs4; + } data; /* Canonical, smallest-form Unicode buffer */ +} PyUnicodeObject; + +``` +- 구조체 \ No newline at end of file