@@ -141,6 +141,40 @@ msgid ""
141
141
" Py_ExitStatusException(status);\n"
142
142
"}"
143
143
msgstr ""
144
+ "#define PY_SSIZE_T_CLEAN\n"
145
+ "#include <Python.h>\n"
146
+ "\n"
147
+ "int\n"
148
+ "main(int argc, char *argv[])\n"
149
+ "{\n"
150
+ " PyStatus status;\n"
151
+ " PyConfig config;\n"
152
+ " PyConfig_InitPythonConfig(&config);\n"
153
+ "\n"
154
+ " /* 선택적이지만 권장됩니다 */\n"
155
+ " status = PyConfig_SetBytesString(&config, &config.program_name, "
156
+ "argv[0]);\n"
157
+ " if (PyStatus_Exception(status)) {\n"
158
+ " goto exception;\n"
159
+ " }\n"
160
+ "\n"
161
+ " status = Py_InitializeFromConfig(&config);\n"
162
+ " if (PyStatus_Exception(status)) {\n"
163
+ " goto exception;\n"
164
+ " }\n"
165
+ " PyConfig_Clear(&config);\n"
166
+ "\n"
167
+ " PyRun_SimpleString(\" from time import time,ctime\\ n\" \n"
168
+ " \" print('Today is', ctime(time()))\\ n\" );\n"
169
+ " if (Py_FinalizeEx() < 0) {\n"
170
+ " exit(120);\n"
171
+ " }\n"
172
+ " return 0;\n"
173
+ "\n"
174
+ " exception:\n"
175
+ " PyConfig_Clear(&config);\n"
176
+ " Py_ExitStatusException(status);\n"
177
+ "}"
144
178
145
179
#: ../../extending/embedding.rst:92
146
180
msgid ""
@@ -151,7 +185,6 @@ msgid ""
151
185
msgstr ""
152
186
153
187
#: ../../extending/embedding.rst:97
154
- #, fuzzy
155
188
msgid ""
156
189
"Setting :c:member:`PyConfig.program_name` should be called before "
157
190
":c:func:`Py_InitializeFromConfig` to inform the interpreter about paths "
@@ -165,8 +198,8 @@ msgid ""
165
198
"using the :c:func:`PyRun_SimpleFile` function, which saves you the "
166
199
"trouble of allocating memory space and loading the file contents."
167
200
msgstr ""
168
- ":c:func:`Py_SetProgramName` 함수는 파이썬 런타임 라이브러리에 대한 경로를 인터프리터에게 알리기 위해 "
169
- ":c:func:`Py_Initialize `\\ 보다 먼저 호출되어야 합니다. 다음으로, 파이썬 인터프리터는 "
201
+ ":c:member:`PyConfig.program_name` 설정은 파이썬 런타임 라이브러리에 대한 경로를 인터프리터에게 알리기 "
202
+ "위해 :c:func:`Py_InitializeFromConfig `\\ 보다 먼저 호출되어야 합니다. 다음으로, 파이썬 인터프리터는 "
170
203
":c:func:`Py_Initialize`\\ 로 초기화되고, 날짜와 시간을 인쇄하는 하드 코딩된 파이썬 스크립트가 실행됩니다. 그런"
171
204
" 다음, :c:func:`Py_FinalizeEx` 호출이 인터프리터를 종료하고 프로그램이 끝납니다. 실제 프로그램에서는 파이썬 "
172
205
"스크립트를 다른 소스(아마도 텍스트 편집기 루틴, 파일 또는 데이터베이스)에서 가져올 수 있습니다. 파일에서 파이썬 코드를 얻는 "
@@ -347,6 +380,79 @@ msgid ""
347
380
" return 0;\n"
348
381
"}\n"
349
382
msgstr ""
383
+ "#define PY_SSIZE_T_CLEAN\n"
384
+ "#include <Python.h>\n"
385
+ "\n"
386
+ "int\n"
387
+ "main(int argc, char *argv[])\n"
388
+ "{\n"
389
+ " PyObject *pName, *pModule, *pFunc;\n"
390
+ " PyObject *pArgs, *pValue;\n"
391
+ " int i;\n"
392
+ "\n"
393
+ " if (argc < 3) {\n"
394
+ " fprintf(stderr,\" Usage: call pythonfile funcname [args]\\ n\" );\n"
395
+ " return 1;\n"
396
+ " }\n"
397
+ "\n"
398
+ " Py_Initialize();\n"
399
+ " pName = PyUnicode_DecodeFSDefault(argv[1]);\n"
400
+ " /* pName의 에러 검사가 생략되었습니다 */\n"
401
+ "\n"
402
+ " pModule = PyImport_Import(pName);\n"
403
+ " Py_DECREF(pName);\n"
404
+ "\n"
405
+ " if (pModule != NULL) {\n"
406
+ " pFunc = PyObject_GetAttrString(pModule, argv[2]);\n"
407
+ " /* pFunc는 새로운 참조입니다 */\n"
408
+ "\n"
409
+ " if (pFunc && PyCallable_Check(pFunc)) {\n"
410
+ " pArgs = PyTuple_New(argc - 3);\n"
411
+ " for (i = 0; i < argc - 3; ++i) {\n"
412
+ " pValue = PyLong_FromLong(atoi(argv[i + 3]));\n"
413
+ " if (!pValue) {\n"
414
+ " Py_DECREF(pArgs);\n"
415
+ " Py_DECREF(pModule);\n"
416
+ " fprintf(stderr, \" Cannot convert argument\\ n\" );\n"
417
+ " return 1;\n"
418
+ " }\n"
419
+ " /* 여기에서 pValue 참조를 훔칩니다: */\n"
420
+ " PyTuple_SetItem(pArgs, i, pValue);\n"
421
+ " }\n"
422
+ " pValue = PyObject_CallObject(pFunc, pArgs);\n"
423
+ " Py_DECREF(pArgs);\n"
424
+ " if (pValue != NULL) {\n"
425
+ " printf(\" Result of call: %ld\\ n\" , "
426
+ "PyLong_AsLong(pValue));\n"
427
+ " Py_DECREF(pValue);\n"
428
+ " }\n"
429
+ " else {\n"
430
+ " Py_DECREF(pFunc);\n"
431
+ " Py_DECREF(pModule);\n"
432
+ " PyErr_Print();\n"
433
+ " fprintf(stderr,\" Call failed\\ n\" );\n"
434
+ " return 1;\n"
435
+ " }\n"
436
+ " }\n"
437
+ " else {\n"
438
+ " if (PyErr_Occurred())\n"
439
+ " PyErr_Print();\n"
440
+ " fprintf(stderr, \" Cannot find function \\\" %s\\\"\\ n\" , "
441
+ "argv[2]);\n"
442
+ " }\n"
443
+ " Py_XDECREF(pFunc);\n"
444
+ " Py_DECREF(pModule);\n"
445
+ " }\n"
446
+ " else {\n"
447
+ " PyErr_Print();\n"
448
+ " fprintf(stderr, \" Failed to load \\\" %s\\\"\\ n\" , argv[1]);\n"
449
+ " return 1;\n"
450
+ " }\n"
451
+ " if (Py_FinalizeEx() < 0) {\n"
452
+ " return 120;\n"
453
+ " }\n"
454
+ " return 0;\n"
455
+ "}\n"
350
456
351
457
#: ../../extending/embedding.rst:165
352
458
msgid ""
@@ -369,6 +475,12 @@ msgid ""
369
475
" c = c + b\n"
370
476
" return c"
371
477
msgstr ""
478
+ "def multiply(a,b):\n"
479
+ " print(\" Will compute\" , a, \" times\" , b)\n"
480
+ " c = 0\n"
481
+ " for i in range(0, a):\n"
482
+ " c = c + b\n"
483
+ " return c"
372
484
373
485
#: ../../extending/embedding.rst:180
374
486
msgid "then the result should be:"
@@ -380,6 +492,9 @@ msgid ""
380
492
"Will compute 3 times 2\n"
381
493
"Result of call: 6"
382
494
msgstr ""
495
+ "$ call multiply multiply 3 2\n"
496
+ "Will compute 3 times 2\n"
497
+ "Result of call: 6"
383
498
384
499
#: ../../extending/embedding.rst:188
385
500
msgid ""
@@ -398,17 +513,21 @@ msgid ""
398
513
"/* Error checking of pName left out */\n"
399
514
"pModule = PyImport_Import(pName);"
400
515
msgstr ""
516
+ "Py_Initialize();\n"
517
+ "pName = PyUnicode_DecodeFSDefault(argv[1]);\n"
518
+ "/* Error checking of pName left out */\n"
519
+ "pModule = PyImport_Import(pName);"
401
520
402
521
#: ../../extending/embedding.rst:197
403
- #, fuzzy
404
522
msgid ""
405
523
"After initializing the interpreter, the script is loaded using "
406
524
":c:func:`PyImport_Import`. This routine needs a Python string as its "
407
525
"argument, which is constructed using the "
408
526
":c:func:`PyUnicode_DecodeFSDefault` data conversion routine. ::"
409
527
msgstr ""
410
528
"인터프리터를 초기화한 후, 스크립트는 :c:func:`PyImport_Import`\\ 를 사용하여 로드됩니다. 이 루틴은 인자로 "
411
- "파이썬 문자열을 요구하는데, :c:func:`PyUnicode_FromString` 데이터 변환 루틴을 사용하여 구성됩니다. ::"
529
+ "파이썬 문자열을 요구하는데, :c:func:`PyUnicode_DecodeFSDefault` 데이터 변환 루틴을 사용하여 "
530
+ "구성됩니다. ::"
412
531
413
532
#: ../../extending/embedding.rst:202
414
533
#, python-brace-format
@@ -421,6 +540,13 @@ msgid ""
421
540
"}\n"
422
541
"Py_XDECREF(pFunc);"
423
542
msgstr ""
543
+ "pFunc = PyObject_GetAttrString(pModule, argv[2]);\n"
544
+ "/* pFunc는 새로운 참조입니다 */\n"
545
+ "\n"
546
+ "if (pFunc && PyCallable_Check(pFunc)) {\n"
547
+ " ...\n"
548
+ "}\n"
549
+ "Py_XDECREF(pFunc);"
424
550
425
551
#: ../../extending/embedding.rst:210
426
552
msgid ""
@@ -436,7 +562,7 @@ msgstr ""
436
562
437
563
#: ../../extending/embedding.rst:216
438
564
msgid "pValue = PyObject_CallObject(pFunc, pArgs);"
439
- msgstr ""
565
+ msgstr "pValue = PyObject_CallObject(pFunc, pArgs); "
440
566
441
567
#: ../../extending/embedding.rst:218
442
568
msgid ""
@@ -499,6 +625,33 @@ msgid ""
499
625
" return PyModule_Create(&EmbModule);\n"
500
626
"}"
501
627
msgstr ""
628
+ "static int numargs=0;\n"
629
+ "\n"
630
+ "/* 응용 프로그램 명령 줄의 인자 수를 반환합니다 */\n"
631
+ "static PyObject*\n"
632
+ "emb_numargs(PyObject *self, PyObject *args)\n"
633
+ "{\n"
634
+ " if(!PyArg_ParseTuple(args, \" :numargs\" ))\n"
635
+ " return NULL;\n"
636
+ " return PyLong_FromLong(numargs);\n"
637
+ "}\n"
638
+ "\n"
639
+ "static PyMethodDef EmbMethods[] = {\n"
640
+ " {\" numargs\" , emb_numargs, METH_VARARGS,\n"
641
+ " \" Return the number of arguments received by the process.\" },\n"
642
+ " {NULL, NULL, 0, NULL}\n"
643
+ "};\n"
644
+ "\n"
645
+ "static PyModuleDef EmbModule = {\n"
646
+ " PyModuleDef_HEAD_INIT, \" emb\" , NULL, -1, EmbMethods,\n"
647
+ " NULL, NULL, NULL, NULL\n"
648
+ "};\n"
649
+ "\n"
650
+ "static PyObject*\n"
651
+ "PyInit_emb(void)\n"
652
+ "{\n"
653
+ " return PyModule_Create(&EmbModule);\n"
654
+ "}"
502
655
503
656
#: ../../extending/embedding.rst:265
504
657
msgid ""
@@ -514,22 +667,25 @@ msgid ""
514
667
"numargs = argc;\n"
515
668
"PyImport_AppendInittab(\" emb\" , &PyInit_emb);"
516
669
msgstr ""
670
+ "numargs = argc;\n"
671
+ "PyImport_AppendInittab(\" emb\" , &PyInit_emb);"
517
672
518
673
#: ../../extending/embedding.rst:271
519
- #, fuzzy
520
674
msgid ""
521
675
"These two lines initialize the ``numargs`` variable, and make the "
522
676
":func:`!emb.numargs` function accessible to the embedded Python "
523
677
"interpreter. With these extensions, the Python script can do things like"
524
678
msgstr ""
525
- "이 두 줄은 ``numargs`` 변수를 초기화하고, :func:`emb.numargs` 함수를 내장된 파이썬 인터프리터가 액세스할 "
526
- " 수 있도록 만듭니다. 이러한 확장을 통해, 파이썬 스크립트는 다음과 같은 작업을 수행할 수 있습니다"
679
+ "이 두 줄은 ``numargs`` 변수를 초기화하고, :func:`! emb.numargs` 함수를 내장된 파이썬 인터프리터가 "
680
+ "액세스할 수 있도록 만듭니다. 이러한 확장을 통해, 파이썬 스크립트는 다음과 같은 작업을 수행할 수 있습니다"
527
681
528
682
#: ../../extending/embedding.rst:275
529
683
msgid ""
530
684
"import emb\n"
531
685
"print(\" Number of arguments\" , emb.numargs())"
532
686
msgstr ""
687
+ "import emb\n"
688
+ "print(\" Number of arguments\" , emb.numargs())"
533
689
534
690
#: ../../extending/embedding.rst:280
535
691
msgid ""
@@ -593,20 +749,25 @@ msgid ""
593
749
"-I/opt/include/python3.11 -I/opt/include/python3.11 -Wsign-compare "
594
750
"-DNDEBUG -g -fwrapv -O3 -Wall"
595
751
msgstr ""
752
+ "$ /opt/bin/python3.11-config --cflags\n"
753
+ "-I/opt/include/python3.11 -I/opt/include/python3.11 -Wsign-compare "
754
+ "-DNDEBUG -g -fwrapv -O3 -Wall"
596
755
597
756
#: ../../extending/embedding.rst:323
598
- #, fuzzy
599
757
msgid ""
600
758
"``pythonX.Y-config --ldflags --embed`` will give you the recommended "
601
759
"flags when linking:"
602
- msgstr "``pythonX.Y-config --ldflags``\\ 는 링크 할 때의 권장 플래그를 제공합니다:"
760
+ msgstr "``pythonX.Y-config --ldflags --embed ``\\ 는 링크 할 때의 권장 플래그를 제공합니다:"
603
761
604
762
#: ../../extending/embedding.rst:326
605
763
msgid ""
606
764
"$ /opt/bin/python3.11-config --ldflags --embed\n"
607
765
"-L/opt/lib/python3.11/config-3.11-x86_64-linux-gnu -L/opt/lib "
608
766
"-lpython3.11 -lpthread -ldl -lutil -lm"
609
767
msgstr ""
768
+ "$ /opt/bin/python3.11-config --ldflags --embed\n"
769
+ "-L/opt/lib/python3.11/config-3.11-x86_64-linux-gnu -L/opt/lib "
770
+ "-lpython3.11 -lpthread -ldl -lutil -lm"
610
771
611
772
#: ../../extending/embedding.rst:332
612
773
#, python-brace-format
@@ -644,4 +805,9 @@ msgid ""
644
805
">>> sysconfig.get_config_var('LINKFORSHARED')\n"
645
806
"'-Xlinker -export-dynamic'"
646
807
msgstr ""
808
+ ">>> import sysconfig\n"
809
+ ">>> sysconfig.get_config_var('LIBS')\n"
810
+ "'-lpthread -ldl -lutil'\n"
811
+ ">>> sysconfig.get_config_var('LINKFORSHARED')\n"
812
+ "'-Xlinker -export-dynamic'"
647
813
0 commit comments