generated from Pseudo-Lab/Jupyter-Book-Template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1cea97
commit c049703
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
``` | ||
- 구조체 |