_winapi.c.h 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(_winapi_Overlapped_GetOverlappedResult__doc__,
  9. "GetOverlappedResult($self, wait, /)\n"
  10. "--\n"
  11. "\n");
  12. #define _WINAPI_OVERLAPPED_GETOVERLAPPEDRESULT_METHODDEF \
  13. {"GetOverlappedResult", (PyCFunction)_winapi_Overlapped_GetOverlappedResult, METH_O, _winapi_Overlapped_GetOverlappedResult__doc__},
  14. static PyObject *
  15. _winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait);
  16. static PyObject *
  17. _winapi_Overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *arg)
  18. {
  19. PyObject *return_value = NULL;
  20. int wait;
  21. wait = PyObject_IsTrue(arg);
  22. if (wait < 0) {
  23. goto exit;
  24. }
  25. return_value = _winapi_Overlapped_GetOverlappedResult_impl(self, wait);
  26. exit:
  27. return return_value;
  28. }
  29. PyDoc_STRVAR(_winapi_Overlapped_getbuffer__doc__,
  30. "getbuffer($self, /)\n"
  31. "--\n"
  32. "\n");
  33. #define _WINAPI_OVERLAPPED_GETBUFFER_METHODDEF \
  34. {"getbuffer", (PyCFunction)_winapi_Overlapped_getbuffer, METH_NOARGS, _winapi_Overlapped_getbuffer__doc__},
  35. static PyObject *
  36. _winapi_Overlapped_getbuffer_impl(OverlappedObject *self);
  37. static PyObject *
  38. _winapi_Overlapped_getbuffer(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
  39. {
  40. return _winapi_Overlapped_getbuffer_impl(self);
  41. }
  42. PyDoc_STRVAR(_winapi_Overlapped_cancel__doc__,
  43. "cancel($self, /)\n"
  44. "--\n"
  45. "\n");
  46. #define _WINAPI_OVERLAPPED_CANCEL_METHODDEF \
  47. {"cancel", (PyCFunction)_winapi_Overlapped_cancel, METH_NOARGS, _winapi_Overlapped_cancel__doc__},
  48. static PyObject *
  49. _winapi_Overlapped_cancel_impl(OverlappedObject *self);
  50. static PyObject *
  51. _winapi_Overlapped_cancel(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
  52. {
  53. return _winapi_Overlapped_cancel_impl(self);
  54. }
  55. PyDoc_STRVAR(_winapi_CloseHandle__doc__,
  56. "CloseHandle($module, handle, /)\n"
  57. "--\n"
  58. "\n"
  59. "Close handle.");
  60. #define _WINAPI_CLOSEHANDLE_METHODDEF \
  61. {"CloseHandle", (PyCFunction)_winapi_CloseHandle, METH_O, _winapi_CloseHandle__doc__},
  62. static PyObject *
  63. _winapi_CloseHandle_impl(PyObject *module, HANDLE handle);
  64. static PyObject *
  65. _winapi_CloseHandle(PyObject *module, PyObject *arg)
  66. {
  67. PyObject *return_value = NULL;
  68. HANDLE handle;
  69. if (!PyArg_Parse(arg, "" F_HANDLE ":CloseHandle", &handle)) {
  70. goto exit;
  71. }
  72. return_value = _winapi_CloseHandle_impl(module, handle);
  73. exit:
  74. return return_value;
  75. }
  76. PyDoc_STRVAR(_winapi_ConnectNamedPipe__doc__,
  77. "ConnectNamedPipe($module, /, handle, overlapped=False)\n"
  78. "--\n"
  79. "\n");
  80. #define _WINAPI_CONNECTNAMEDPIPE_METHODDEF \
  81. {"ConnectNamedPipe", _PyCFunction_CAST(_winapi_ConnectNamedPipe), METH_FASTCALL|METH_KEYWORDS, _winapi_ConnectNamedPipe__doc__},
  82. static PyObject *
  83. _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle,
  84. int use_overlapped);
  85. static PyObject *
  86. _winapi_ConnectNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  87. {
  88. PyObject *return_value = NULL;
  89. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  90. #define NUM_KEYWORDS 2
  91. static struct {
  92. PyGC_Head _this_is_not_used;
  93. PyObject_VAR_HEAD
  94. PyObject *ob_item[NUM_KEYWORDS];
  95. } _kwtuple = {
  96. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  97. .ob_item = { &_Py_ID(handle), &_Py_ID(overlapped), },
  98. };
  99. #undef NUM_KEYWORDS
  100. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  101. #else // !Py_BUILD_CORE
  102. # define KWTUPLE NULL
  103. #endif // !Py_BUILD_CORE
  104. static const char * const _keywords[] = {"handle", "overlapped", NULL};
  105. static _PyArg_Parser _parser = {
  106. .keywords = _keywords,
  107. .format = "" F_HANDLE "|p:ConnectNamedPipe",
  108. .kwtuple = KWTUPLE,
  109. };
  110. #undef KWTUPLE
  111. HANDLE handle;
  112. int use_overlapped = 0;
  113. if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
  114. &handle, &use_overlapped)) {
  115. goto exit;
  116. }
  117. return_value = _winapi_ConnectNamedPipe_impl(module, handle, use_overlapped);
  118. exit:
  119. return return_value;
  120. }
  121. PyDoc_STRVAR(_winapi_CreateFile__doc__,
  122. "CreateFile($module, file_name, desired_access, share_mode,\n"
  123. " security_attributes, creation_disposition,\n"
  124. " flags_and_attributes, template_file, /)\n"
  125. "--\n"
  126. "\n");
  127. #define _WINAPI_CREATEFILE_METHODDEF \
  128. {"CreateFile", _PyCFunction_CAST(_winapi_CreateFile), METH_FASTCALL, _winapi_CreateFile__doc__},
  129. static HANDLE
  130. _winapi_CreateFile_impl(PyObject *module, LPCWSTR file_name,
  131. DWORD desired_access, DWORD share_mode,
  132. LPSECURITY_ATTRIBUTES security_attributes,
  133. DWORD creation_disposition,
  134. DWORD flags_and_attributes, HANDLE template_file);
  135. static PyObject *
  136. _winapi_CreateFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  137. {
  138. PyObject *return_value = NULL;
  139. LPCWSTR file_name = NULL;
  140. DWORD desired_access;
  141. DWORD share_mode;
  142. LPSECURITY_ATTRIBUTES security_attributes;
  143. DWORD creation_disposition;
  144. DWORD flags_and_attributes;
  145. HANDLE template_file;
  146. HANDLE _return_value;
  147. if (!_PyArg_ParseStack(args, nargs, "O&kk" F_POINTER "kk" F_HANDLE ":CreateFile",
  148. _PyUnicode_WideCharString_Converter, &file_name, &desired_access, &share_mode, &security_attributes, &creation_disposition, &flags_and_attributes, &template_file)) {
  149. goto exit;
  150. }
  151. _return_value = _winapi_CreateFile_impl(module, file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file);
  152. if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
  153. goto exit;
  154. }
  155. if (_return_value == NULL) {
  156. Py_RETURN_NONE;
  157. }
  158. return_value = HANDLE_TO_PYNUM(_return_value);
  159. exit:
  160. /* Cleanup for file_name */
  161. PyMem_Free((void *)file_name);
  162. return return_value;
  163. }
  164. PyDoc_STRVAR(_winapi_CreateFileMapping__doc__,
  165. "CreateFileMapping($module, file_handle, security_attributes, protect,\n"
  166. " max_size_high, max_size_low, name, /)\n"
  167. "--\n"
  168. "\n");
  169. #define _WINAPI_CREATEFILEMAPPING_METHODDEF \
  170. {"CreateFileMapping", _PyCFunction_CAST(_winapi_CreateFileMapping), METH_FASTCALL, _winapi_CreateFileMapping__doc__},
  171. static HANDLE
  172. _winapi_CreateFileMapping_impl(PyObject *module, HANDLE file_handle,
  173. LPSECURITY_ATTRIBUTES security_attributes,
  174. DWORD protect, DWORD max_size_high,
  175. DWORD max_size_low, LPCWSTR name);
  176. static PyObject *
  177. _winapi_CreateFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  178. {
  179. PyObject *return_value = NULL;
  180. HANDLE file_handle;
  181. LPSECURITY_ATTRIBUTES security_attributes;
  182. DWORD protect;
  183. DWORD max_size_high;
  184. DWORD max_size_low;
  185. LPCWSTR name = NULL;
  186. HANDLE _return_value;
  187. if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_POINTER "kkkO&:CreateFileMapping",
  188. &file_handle, &security_attributes, &protect, &max_size_high, &max_size_low, _PyUnicode_WideCharString_Converter, &name)) {
  189. goto exit;
  190. }
  191. _return_value = _winapi_CreateFileMapping_impl(module, file_handle, security_attributes, protect, max_size_high, max_size_low, name);
  192. if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
  193. goto exit;
  194. }
  195. if (_return_value == NULL) {
  196. Py_RETURN_NONE;
  197. }
  198. return_value = HANDLE_TO_PYNUM(_return_value);
  199. exit:
  200. /* Cleanup for name */
  201. PyMem_Free((void *)name);
  202. return return_value;
  203. }
  204. PyDoc_STRVAR(_winapi_CreateJunction__doc__,
  205. "CreateJunction($module, src_path, dst_path, /)\n"
  206. "--\n"
  207. "\n");
  208. #define _WINAPI_CREATEJUNCTION_METHODDEF \
  209. {"CreateJunction", _PyCFunction_CAST(_winapi_CreateJunction), METH_FASTCALL, _winapi_CreateJunction__doc__},
  210. static PyObject *
  211. _winapi_CreateJunction_impl(PyObject *module, LPCWSTR src_path,
  212. LPCWSTR dst_path);
  213. static PyObject *
  214. _winapi_CreateJunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  215. {
  216. PyObject *return_value = NULL;
  217. LPCWSTR src_path = NULL;
  218. LPCWSTR dst_path = NULL;
  219. if (!_PyArg_CheckPositional("CreateJunction", nargs, 2, 2)) {
  220. goto exit;
  221. }
  222. if (!PyUnicode_Check(args[0])) {
  223. _PyArg_BadArgument("CreateJunction", "argument 1", "str", args[0]);
  224. goto exit;
  225. }
  226. src_path = PyUnicode_AsWideCharString(args[0], NULL);
  227. if (src_path == NULL) {
  228. goto exit;
  229. }
  230. if (!PyUnicode_Check(args[1])) {
  231. _PyArg_BadArgument("CreateJunction", "argument 2", "str", args[1]);
  232. goto exit;
  233. }
  234. dst_path = PyUnicode_AsWideCharString(args[1], NULL);
  235. if (dst_path == NULL) {
  236. goto exit;
  237. }
  238. return_value = _winapi_CreateJunction_impl(module, src_path, dst_path);
  239. exit:
  240. /* Cleanup for src_path */
  241. PyMem_Free((void *)src_path);
  242. /* Cleanup for dst_path */
  243. PyMem_Free((void *)dst_path);
  244. return return_value;
  245. }
  246. PyDoc_STRVAR(_winapi_CreateNamedPipe__doc__,
  247. "CreateNamedPipe($module, name, open_mode, pipe_mode, max_instances,\n"
  248. " out_buffer_size, in_buffer_size, default_timeout,\n"
  249. " security_attributes, /)\n"
  250. "--\n"
  251. "\n");
  252. #define _WINAPI_CREATENAMEDPIPE_METHODDEF \
  253. {"CreateNamedPipe", _PyCFunction_CAST(_winapi_CreateNamedPipe), METH_FASTCALL, _winapi_CreateNamedPipe__doc__},
  254. static HANDLE
  255. _winapi_CreateNamedPipe_impl(PyObject *module, LPCWSTR name, DWORD open_mode,
  256. DWORD pipe_mode, DWORD max_instances,
  257. DWORD out_buffer_size, DWORD in_buffer_size,
  258. DWORD default_timeout,
  259. LPSECURITY_ATTRIBUTES security_attributes);
  260. static PyObject *
  261. _winapi_CreateNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  262. {
  263. PyObject *return_value = NULL;
  264. LPCWSTR name = NULL;
  265. DWORD open_mode;
  266. DWORD pipe_mode;
  267. DWORD max_instances;
  268. DWORD out_buffer_size;
  269. DWORD in_buffer_size;
  270. DWORD default_timeout;
  271. LPSECURITY_ATTRIBUTES security_attributes;
  272. HANDLE _return_value;
  273. if (!_PyArg_ParseStack(args, nargs, "O&kkkkkk" F_POINTER ":CreateNamedPipe",
  274. _PyUnicode_WideCharString_Converter, &name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) {
  275. goto exit;
  276. }
  277. _return_value = _winapi_CreateNamedPipe_impl(module, name, open_mode, pipe_mode, max_instances, out_buffer_size, in_buffer_size, default_timeout, security_attributes);
  278. if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
  279. goto exit;
  280. }
  281. if (_return_value == NULL) {
  282. Py_RETURN_NONE;
  283. }
  284. return_value = HANDLE_TO_PYNUM(_return_value);
  285. exit:
  286. /* Cleanup for name */
  287. PyMem_Free((void *)name);
  288. return return_value;
  289. }
  290. PyDoc_STRVAR(_winapi_CreatePipe__doc__,
  291. "CreatePipe($module, pipe_attrs, size, /)\n"
  292. "--\n"
  293. "\n"
  294. "Create an anonymous pipe.\n"
  295. "\n"
  296. " pipe_attrs\n"
  297. " Ignored internally, can be None.\n"
  298. "\n"
  299. "Returns a 2-tuple of handles, to the read and write ends of the pipe.");
  300. #define _WINAPI_CREATEPIPE_METHODDEF \
  301. {"CreatePipe", _PyCFunction_CAST(_winapi_CreatePipe), METH_FASTCALL, _winapi_CreatePipe__doc__},
  302. static PyObject *
  303. _winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size);
  304. static PyObject *
  305. _winapi_CreatePipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  306. {
  307. PyObject *return_value = NULL;
  308. PyObject *pipe_attrs;
  309. DWORD size;
  310. if (!_PyArg_ParseStack(args, nargs, "Ok:CreatePipe",
  311. &pipe_attrs, &size)) {
  312. goto exit;
  313. }
  314. return_value = _winapi_CreatePipe_impl(module, pipe_attrs, size);
  315. exit:
  316. return return_value;
  317. }
  318. PyDoc_STRVAR(_winapi_CreateProcess__doc__,
  319. "CreateProcess($module, application_name, command_line, proc_attrs,\n"
  320. " thread_attrs, inherit_handles, creation_flags,\n"
  321. " env_mapping, current_directory, startup_info, /)\n"
  322. "--\n"
  323. "\n"
  324. "Create a new process and its primary thread.\n"
  325. "\n"
  326. " command_line\n"
  327. " Can be str or None\n"
  328. " proc_attrs\n"
  329. " Ignored internally, can be None.\n"
  330. " thread_attrs\n"
  331. " Ignored internally, can be None.\n"
  332. "\n"
  333. "The return value is a tuple of the process handle, thread handle,\n"
  334. "process ID, and thread ID.");
  335. #define _WINAPI_CREATEPROCESS_METHODDEF \
  336. {"CreateProcess", _PyCFunction_CAST(_winapi_CreateProcess), METH_FASTCALL, _winapi_CreateProcess__doc__},
  337. static PyObject *
  338. _winapi_CreateProcess_impl(PyObject *module,
  339. const Py_UNICODE *application_name,
  340. PyObject *command_line, PyObject *proc_attrs,
  341. PyObject *thread_attrs, BOOL inherit_handles,
  342. DWORD creation_flags, PyObject *env_mapping,
  343. const Py_UNICODE *current_directory,
  344. PyObject *startup_info);
  345. static PyObject *
  346. _winapi_CreateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  347. {
  348. PyObject *return_value = NULL;
  349. const Py_UNICODE *application_name = NULL;
  350. PyObject *command_line;
  351. PyObject *proc_attrs;
  352. PyObject *thread_attrs;
  353. BOOL inherit_handles;
  354. DWORD creation_flags;
  355. PyObject *env_mapping;
  356. const Py_UNICODE *current_directory = NULL;
  357. PyObject *startup_info;
  358. if (!_PyArg_ParseStack(args, nargs, "O&OOOikOO&O:CreateProcess",
  359. _PyUnicode_WideCharString_Opt_Converter, &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, _PyUnicode_WideCharString_Opt_Converter, &current_directory, &startup_info)) {
  360. goto exit;
  361. }
  362. return_value = _winapi_CreateProcess_impl(module, application_name, command_line, proc_attrs, thread_attrs, inherit_handles, creation_flags, env_mapping, current_directory, startup_info);
  363. exit:
  364. /* Cleanup for application_name */
  365. PyMem_Free((void *)application_name);
  366. /* Cleanup for current_directory */
  367. PyMem_Free((void *)current_directory);
  368. return return_value;
  369. }
  370. PyDoc_STRVAR(_winapi_DuplicateHandle__doc__,
  371. "DuplicateHandle($module, source_process_handle, source_handle,\n"
  372. " target_process_handle, desired_access, inherit_handle,\n"
  373. " options=0, /)\n"
  374. "--\n"
  375. "\n"
  376. "Return a duplicate handle object.\n"
  377. "\n"
  378. "The duplicate handle refers to the same object as the original\n"
  379. "handle. Therefore, any changes to the object are reflected\n"
  380. "through both handles.");
  381. #define _WINAPI_DUPLICATEHANDLE_METHODDEF \
  382. {"DuplicateHandle", _PyCFunction_CAST(_winapi_DuplicateHandle), METH_FASTCALL, _winapi_DuplicateHandle__doc__},
  383. static HANDLE
  384. _winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle,
  385. HANDLE source_handle,
  386. HANDLE target_process_handle,
  387. DWORD desired_access, BOOL inherit_handle,
  388. DWORD options);
  389. static PyObject *
  390. _winapi_DuplicateHandle(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  391. {
  392. PyObject *return_value = NULL;
  393. HANDLE source_process_handle;
  394. HANDLE source_handle;
  395. HANDLE target_process_handle;
  396. DWORD desired_access;
  397. BOOL inherit_handle;
  398. DWORD options = 0;
  399. HANDLE _return_value;
  400. if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle",
  401. &source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) {
  402. goto exit;
  403. }
  404. _return_value = _winapi_DuplicateHandle_impl(module, source_process_handle, source_handle, target_process_handle, desired_access, inherit_handle, options);
  405. if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
  406. goto exit;
  407. }
  408. if (_return_value == NULL) {
  409. Py_RETURN_NONE;
  410. }
  411. return_value = HANDLE_TO_PYNUM(_return_value);
  412. exit:
  413. return return_value;
  414. }
  415. PyDoc_STRVAR(_winapi_ExitProcess__doc__,
  416. "ExitProcess($module, ExitCode, /)\n"
  417. "--\n"
  418. "\n");
  419. #define _WINAPI_EXITPROCESS_METHODDEF \
  420. {"ExitProcess", (PyCFunction)_winapi_ExitProcess, METH_O, _winapi_ExitProcess__doc__},
  421. static PyObject *
  422. _winapi_ExitProcess_impl(PyObject *module, UINT ExitCode);
  423. static PyObject *
  424. _winapi_ExitProcess(PyObject *module, PyObject *arg)
  425. {
  426. PyObject *return_value = NULL;
  427. UINT ExitCode;
  428. if (!PyArg_Parse(arg, "I:ExitProcess", &ExitCode)) {
  429. goto exit;
  430. }
  431. return_value = _winapi_ExitProcess_impl(module, ExitCode);
  432. exit:
  433. return return_value;
  434. }
  435. PyDoc_STRVAR(_winapi_GetCurrentProcess__doc__,
  436. "GetCurrentProcess($module, /)\n"
  437. "--\n"
  438. "\n"
  439. "Return a handle object for the current process.");
  440. #define _WINAPI_GETCURRENTPROCESS_METHODDEF \
  441. {"GetCurrentProcess", (PyCFunction)_winapi_GetCurrentProcess, METH_NOARGS, _winapi_GetCurrentProcess__doc__},
  442. static HANDLE
  443. _winapi_GetCurrentProcess_impl(PyObject *module);
  444. static PyObject *
  445. _winapi_GetCurrentProcess(PyObject *module, PyObject *Py_UNUSED(ignored))
  446. {
  447. PyObject *return_value = NULL;
  448. HANDLE _return_value;
  449. _return_value = _winapi_GetCurrentProcess_impl(module);
  450. if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
  451. goto exit;
  452. }
  453. if (_return_value == NULL) {
  454. Py_RETURN_NONE;
  455. }
  456. return_value = HANDLE_TO_PYNUM(_return_value);
  457. exit:
  458. return return_value;
  459. }
  460. PyDoc_STRVAR(_winapi_GetExitCodeProcess__doc__,
  461. "GetExitCodeProcess($module, process, /)\n"
  462. "--\n"
  463. "\n"
  464. "Return the termination status of the specified process.");
  465. #define _WINAPI_GETEXITCODEPROCESS_METHODDEF \
  466. {"GetExitCodeProcess", (PyCFunction)_winapi_GetExitCodeProcess, METH_O, _winapi_GetExitCodeProcess__doc__},
  467. static DWORD
  468. _winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process);
  469. static PyObject *
  470. _winapi_GetExitCodeProcess(PyObject *module, PyObject *arg)
  471. {
  472. PyObject *return_value = NULL;
  473. HANDLE process;
  474. DWORD _return_value;
  475. if (!PyArg_Parse(arg, "" F_HANDLE ":GetExitCodeProcess", &process)) {
  476. goto exit;
  477. }
  478. _return_value = _winapi_GetExitCodeProcess_impl(module, process);
  479. if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
  480. goto exit;
  481. }
  482. return_value = Py_BuildValue("k", _return_value);
  483. exit:
  484. return return_value;
  485. }
  486. PyDoc_STRVAR(_winapi_GetLastError__doc__,
  487. "GetLastError($module, /)\n"
  488. "--\n"
  489. "\n");
  490. #define _WINAPI_GETLASTERROR_METHODDEF \
  491. {"GetLastError", (PyCFunction)_winapi_GetLastError, METH_NOARGS, _winapi_GetLastError__doc__},
  492. static DWORD
  493. _winapi_GetLastError_impl(PyObject *module);
  494. static PyObject *
  495. _winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored))
  496. {
  497. PyObject *return_value = NULL;
  498. DWORD _return_value;
  499. _return_value = _winapi_GetLastError_impl(module);
  500. if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
  501. goto exit;
  502. }
  503. return_value = Py_BuildValue("k", _return_value);
  504. exit:
  505. return return_value;
  506. }
  507. PyDoc_STRVAR(_winapi_GetLongPathName__doc__,
  508. "GetLongPathName($module, /, path)\n"
  509. "--\n"
  510. "\n"
  511. "Return the long version of the provided path.\n"
  512. "\n"
  513. "If the path is already in its long form, returns the same value.\n"
  514. "\n"
  515. "The path must already be a \'str\'. If the type is not known, use\n"
  516. "os.fsdecode before calling this function.");
  517. #define _WINAPI_GETLONGPATHNAME_METHODDEF \
  518. {"GetLongPathName", _PyCFunction_CAST(_winapi_GetLongPathName), METH_FASTCALL|METH_KEYWORDS, _winapi_GetLongPathName__doc__},
  519. static PyObject *
  520. _winapi_GetLongPathName_impl(PyObject *module, LPCWSTR path);
  521. static PyObject *
  522. _winapi_GetLongPathName(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  523. {
  524. PyObject *return_value = NULL;
  525. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  526. #define NUM_KEYWORDS 1
  527. static struct {
  528. PyGC_Head _this_is_not_used;
  529. PyObject_VAR_HEAD
  530. PyObject *ob_item[NUM_KEYWORDS];
  531. } _kwtuple = {
  532. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  533. .ob_item = { &_Py_ID(path), },
  534. };
  535. #undef NUM_KEYWORDS
  536. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  537. #else // !Py_BUILD_CORE
  538. # define KWTUPLE NULL
  539. #endif // !Py_BUILD_CORE
  540. static const char * const _keywords[] = {"path", NULL};
  541. static _PyArg_Parser _parser = {
  542. .keywords = _keywords,
  543. .fname = "GetLongPathName",
  544. .kwtuple = KWTUPLE,
  545. };
  546. #undef KWTUPLE
  547. PyObject *argsbuf[1];
  548. LPCWSTR path = NULL;
  549. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  550. if (!args) {
  551. goto exit;
  552. }
  553. if (!PyUnicode_Check(args[0])) {
  554. _PyArg_BadArgument("GetLongPathName", "argument 'path'", "str", args[0]);
  555. goto exit;
  556. }
  557. path = PyUnicode_AsWideCharString(args[0], NULL);
  558. if (path == NULL) {
  559. goto exit;
  560. }
  561. return_value = _winapi_GetLongPathName_impl(module, path);
  562. exit:
  563. /* Cleanup for path */
  564. PyMem_Free((void *)path);
  565. return return_value;
  566. }
  567. PyDoc_STRVAR(_winapi_GetModuleFileName__doc__,
  568. "GetModuleFileName($module, module_handle, /)\n"
  569. "--\n"
  570. "\n"
  571. "Return the fully-qualified path for the file that contains module.\n"
  572. "\n"
  573. "The module must have been loaded by the current process.\n"
  574. "\n"
  575. "The module parameter should be a handle to the loaded module\n"
  576. "whose path is being requested. If this parameter is 0,\n"
  577. "GetModuleFileName retrieves the path of the executable file\n"
  578. "of the current process.");
  579. #define _WINAPI_GETMODULEFILENAME_METHODDEF \
  580. {"GetModuleFileName", (PyCFunction)_winapi_GetModuleFileName, METH_O, _winapi_GetModuleFileName__doc__},
  581. static PyObject *
  582. _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle);
  583. static PyObject *
  584. _winapi_GetModuleFileName(PyObject *module, PyObject *arg)
  585. {
  586. PyObject *return_value = NULL;
  587. HMODULE module_handle;
  588. if (!PyArg_Parse(arg, "" F_HANDLE ":GetModuleFileName", &module_handle)) {
  589. goto exit;
  590. }
  591. return_value = _winapi_GetModuleFileName_impl(module, module_handle);
  592. exit:
  593. return return_value;
  594. }
  595. PyDoc_STRVAR(_winapi_GetShortPathName__doc__,
  596. "GetShortPathName($module, /, path)\n"
  597. "--\n"
  598. "\n"
  599. "Return the short version of the provided path.\n"
  600. "\n"
  601. "If the path is already in its short form, returns the same value.\n"
  602. "\n"
  603. "The path must already be a \'str\'. If the type is not known, use\n"
  604. "os.fsdecode before calling this function.");
  605. #define _WINAPI_GETSHORTPATHNAME_METHODDEF \
  606. {"GetShortPathName", _PyCFunction_CAST(_winapi_GetShortPathName), METH_FASTCALL|METH_KEYWORDS, _winapi_GetShortPathName__doc__},
  607. static PyObject *
  608. _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path);
  609. static PyObject *
  610. _winapi_GetShortPathName(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  611. {
  612. PyObject *return_value = NULL;
  613. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  614. #define NUM_KEYWORDS 1
  615. static struct {
  616. PyGC_Head _this_is_not_used;
  617. PyObject_VAR_HEAD
  618. PyObject *ob_item[NUM_KEYWORDS];
  619. } _kwtuple = {
  620. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  621. .ob_item = { &_Py_ID(path), },
  622. };
  623. #undef NUM_KEYWORDS
  624. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  625. #else // !Py_BUILD_CORE
  626. # define KWTUPLE NULL
  627. #endif // !Py_BUILD_CORE
  628. static const char * const _keywords[] = {"path", NULL};
  629. static _PyArg_Parser _parser = {
  630. .keywords = _keywords,
  631. .fname = "GetShortPathName",
  632. .kwtuple = KWTUPLE,
  633. };
  634. #undef KWTUPLE
  635. PyObject *argsbuf[1];
  636. LPCWSTR path = NULL;
  637. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  638. if (!args) {
  639. goto exit;
  640. }
  641. if (!PyUnicode_Check(args[0])) {
  642. _PyArg_BadArgument("GetShortPathName", "argument 'path'", "str", args[0]);
  643. goto exit;
  644. }
  645. path = PyUnicode_AsWideCharString(args[0], NULL);
  646. if (path == NULL) {
  647. goto exit;
  648. }
  649. return_value = _winapi_GetShortPathName_impl(module, path);
  650. exit:
  651. /* Cleanup for path */
  652. PyMem_Free((void *)path);
  653. return return_value;
  654. }
  655. PyDoc_STRVAR(_winapi_GetStdHandle__doc__,
  656. "GetStdHandle($module, std_handle, /)\n"
  657. "--\n"
  658. "\n"
  659. "Return a handle to the specified standard device.\n"
  660. "\n"
  661. " std_handle\n"
  662. " One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.\n"
  663. "\n"
  664. "The integer associated with the handle object is returned.");
  665. #define _WINAPI_GETSTDHANDLE_METHODDEF \
  666. {"GetStdHandle", (PyCFunction)_winapi_GetStdHandle, METH_O, _winapi_GetStdHandle__doc__},
  667. static HANDLE
  668. _winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle);
  669. static PyObject *
  670. _winapi_GetStdHandle(PyObject *module, PyObject *arg)
  671. {
  672. PyObject *return_value = NULL;
  673. DWORD std_handle;
  674. HANDLE _return_value;
  675. if (!PyArg_Parse(arg, "k:GetStdHandle", &std_handle)) {
  676. goto exit;
  677. }
  678. _return_value = _winapi_GetStdHandle_impl(module, std_handle);
  679. if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
  680. goto exit;
  681. }
  682. if (_return_value == NULL) {
  683. Py_RETURN_NONE;
  684. }
  685. return_value = HANDLE_TO_PYNUM(_return_value);
  686. exit:
  687. return return_value;
  688. }
  689. PyDoc_STRVAR(_winapi_GetVersion__doc__,
  690. "GetVersion($module, /)\n"
  691. "--\n"
  692. "\n"
  693. "Return the version number of the current operating system.");
  694. #define _WINAPI_GETVERSION_METHODDEF \
  695. {"GetVersion", (PyCFunction)_winapi_GetVersion, METH_NOARGS, _winapi_GetVersion__doc__},
  696. static long
  697. _winapi_GetVersion_impl(PyObject *module);
  698. static PyObject *
  699. _winapi_GetVersion(PyObject *module, PyObject *Py_UNUSED(ignored))
  700. {
  701. PyObject *return_value = NULL;
  702. long _return_value;
  703. _return_value = _winapi_GetVersion_impl(module);
  704. if ((_return_value == -1) && PyErr_Occurred()) {
  705. goto exit;
  706. }
  707. return_value = PyLong_FromLong(_return_value);
  708. exit:
  709. return return_value;
  710. }
  711. PyDoc_STRVAR(_winapi_MapViewOfFile__doc__,
  712. "MapViewOfFile($module, file_map, desired_access, file_offset_high,\n"
  713. " file_offset_low, number_bytes, /)\n"
  714. "--\n"
  715. "\n");
  716. #define _WINAPI_MAPVIEWOFFILE_METHODDEF \
  717. {"MapViewOfFile", _PyCFunction_CAST(_winapi_MapViewOfFile), METH_FASTCALL, _winapi_MapViewOfFile__doc__},
  718. static LPVOID
  719. _winapi_MapViewOfFile_impl(PyObject *module, HANDLE file_map,
  720. DWORD desired_access, DWORD file_offset_high,
  721. DWORD file_offset_low, size_t number_bytes);
  722. static PyObject *
  723. _winapi_MapViewOfFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  724. {
  725. PyObject *return_value = NULL;
  726. HANDLE file_map;
  727. DWORD desired_access;
  728. DWORD file_offset_high;
  729. DWORD file_offset_low;
  730. size_t number_bytes;
  731. LPVOID _return_value;
  732. if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "kkkO&:MapViewOfFile",
  733. &file_map, &desired_access, &file_offset_high, &file_offset_low, _PyLong_Size_t_Converter, &number_bytes)) {
  734. goto exit;
  735. }
  736. _return_value = _winapi_MapViewOfFile_impl(module, file_map, desired_access, file_offset_high, file_offset_low, number_bytes);
  737. if ((_return_value == NULL) && PyErr_Occurred()) {
  738. goto exit;
  739. }
  740. return_value = HANDLE_TO_PYNUM(_return_value);
  741. exit:
  742. return return_value;
  743. }
  744. PyDoc_STRVAR(_winapi_UnmapViewOfFile__doc__,
  745. "UnmapViewOfFile($module, address, /)\n"
  746. "--\n"
  747. "\n");
  748. #define _WINAPI_UNMAPVIEWOFFILE_METHODDEF \
  749. {"UnmapViewOfFile", (PyCFunction)_winapi_UnmapViewOfFile, METH_O, _winapi_UnmapViewOfFile__doc__},
  750. static PyObject *
  751. _winapi_UnmapViewOfFile_impl(PyObject *module, LPCVOID address);
  752. static PyObject *
  753. _winapi_UnmapViewOfFile(PyObject *module, PyObject *arg)
  754. {
  755. PyObject *return_value = NULL;
  756. LPCVOID address;
  757. if (!PyArg_Parse(arg, "" F_POINTER ":UnmapViewOfFile", &address)) {
  758. goto exit;
  759. }
  760. return_value = _winapi_UnmapViewOfFile_impl(module, address);
  761. exit:
  762. return return_value;
  763. }
  764. PyDoc_STRVAR(_winapi_OpenFileMapping__doc__,
  765. "OpenFileMapping($module, desired_access, inherit_handle, name, /)\n"
  766. "--\n"
  767. "\n");
  768. #define _WINAPI_OPENFILEMAPPING_METHODDEF \
  769. {"OpenFileMapping", _PyCFunction_CAST(_winapi_OpenFileMapping), METH_FASTCALL, _winapi_OpenFileMapping__doc__},
  770. static HANDLE
  771. _winapi_OpenFileMapping_impl(PyObject *module, DWORD desired_access,
  772. BOOL inherit_handle, LPCWSTR name);
  773. static PyObject *
  774. _winapi_OpenFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  775. {
  776. PyObject *return_value = NULL;
  777. DWORD desired_access;
  778. BOOL inherit_handle;
  779. LPCWSTR name = NULL;
  780. HANDLE _return_value;
  781. if (!_PyArg_ParseStack(args, nargs, "kiO&:OpenFileMapping",
  782. &desired_access, &inherit_handle, _PyUnicode_WideCharString_Converter, &name)) {
  783. goto exit;
  784. }
  785. _return_value = _winapi_OpenFileMapping_impl(module, desired_access, inherit_handle, name);
  786. if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
  787. goto exit;
  788. }
  789. if (_return_value == NULL) {
  790. Py_RETURN_NONE;
  791. }
  792. return_value = HANDLE_TO_PYNUM(_return_value);
  793. exit:
  794. /* Cleanup for name */
  795. PyMem_Free((void *)name);
  796. return return_value;
  797. }
  798. PyDoc_STRVAR(_winapi_OpenProcess__doc__,
  799. "OpenProcess($module, desired_access, inherit_handle, process_id, /)\n"
  800. "--\n"
  801. "\n");
  802. #define _WINAPI_OPENPROCESS_METHODDEF \
  803. {"OpenProcess", _PyCFunction_CAST(_winapi_OpenProcess), METH_FASTCALL, _winapi_OpenProcess__doc__},
  804. static HANDLE
  805. _winapi_OpenProcess_impl(PyObject *module, DWORD desired_access,
  806. BOOL inherit_handle, DWORD process_id);
  807. static PyObject *
  808. _winapi_OpenProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  809. {
  810. PyObject *return_value = NULL;
  811. DWORD desired_access;
  812. BOOL inherit_handle;
  813. DWORD process_id;
  814. HANDLE _return_value;
  815. if (!_PyArg_ParseStack(args, nargs, "kik:OpenProcess",
  816. &desired_access, &inherit_handle, &process_id)) {
  817. goto exit;
  818. }
  819. _return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id);
  820. if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
  821. goto exit;
  822. }
  823. if (_return_value == NULL) {
  824. Py_RETURN_NONE;
  825. }
  826. return_value = HANDLE_TO_PYNUM(_return_value);
  827. exit:
  828. return return_value;
  829. }
  830. PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__,
  831. "PeekNamedPipe($module, handle, size=0, /)\n"
  832. "--\n"
  833. "\n");
  834. #define _WINAPI_PEEKNAMEDPIPE_METHODDEF \
  835. {"PeekNamedPipe", _PyCFunction_CAST(_winapi_PeekNamedPipe), METH_FASTCALL, _winapi_PeekNamedPipe__doc__},
  836. static PyObject *
  837. _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size);
  838. static PyObject *
  839. _winapi_PeekNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  840. {
  841. PyObject *return_value = NULL;
  842. HANDLE handle;
  843. int size = 0;
  844. if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "|i:PeekNamedPipe",
  845. &handle, &size)) {
  846. goto exit;
  847. }
  848. return_value = _winapi_PeekNamedPipe_impl(module, handle, size);
  849. exit:
  850. return return_value;
  851. }
  852. PyDoc_STRVAR(_winapi_LCMapStringEx__doc__,
  853. "LCMapStringEx($module, /, locale, flags, src)\n"
  854. "--\n"
  855. "\n");
  856. #define _WINAPI_LCMAPSTRINGEX_METHODDEF \
  857. {"LCMapStringEx", _PyCFunction_CAST(_winapi_LCMapStringEx), METH_FASTCALL|METH_KEYWORDS, _winapi_LCMapStringEx__doc__},
  858. static PyObject *
  859. _winapi_LCMapStringEx_impl(PyObject *module, LPCWSTR locale, DWORD flags,
  860. PyObject *src);
  861. static PyObject *
  862. _winapi_LCMapStringEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  863. {
  864. PyObject *return_value = NULL;
  865. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  866. #define NUM_KEYWORDS 3
  867. static struct {
  868. PyGC_Head _this_is_not_used;
  869. PyObject_VAR_HEAD
  870. PyObject *ob_item[NUM_KEYWORDS];
  871. } _kwtuple = {
  872. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  873. .ob_item = { &_Py_ID(locale), &_Py_ID(flags), &_Py_ID(src), },
  874. };
  875. #undef NUM_KEYWORDS
  876. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  877. #else // !Py_BUILD_CORE
  878. # define KWTUPLE NULL
  879. #endif // !Py_BUILD_CORE
  880. static const char * const _keywords[] = {"locale", "flags", "src", NULL};
  881. static _PyArg_Parser _parser = {
  882. .keywords = _keywords,
  883. .format = "O&kU:LCMapStringEx",
  884. .kwtuple = KWTUPLE,
  885. };
  886. #undef KWTUPLE
  887. LPCWSTR locale = NULL;
  888. DWORD flags;
  889. PyObject *src;
  890. if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
  891. _PyUnicode_WideCharString_Converter, &locale, &flags, &src)) {
  892. goto exit;
  893. }
  894. return_value = _winapi_LCMapStringEx_impl(module, locale, flags, src);
  895. exit:
  896. /* Cleanup for locale */
  897. PyMem_Free((void *)locale);
  898. return return_value;
  899. }
  900. PyDoc_STRVAR(_winapi_ReadFile__doc__,
  901. "ReadFile($module, /, handle, size, overlapped=False)\n"
  902. "--\n"
  903. "\n");
  904. #define _WINAPI_READFILE_METHODDEF \
  905. {"ReadFile", _PyCFunction_CAST(_winapi_ReadFile), METH_FASTCALL|METH_KEYWORDS, _winapi_ReadFile__doc__},
  906. static PyObject *
  907. _winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size,
  908. int use_overlapped);
  909. static PyObject *
  910. _winapi_ReadFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  911. {
  912. PyObject *return_value = NULL;
  913. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  914. #define NUM_KEYWORDS 3
  915. static struct {
  916. PyGC_Head _this_is_not_used;
  917. PyObject_VAR_HEAD
  918. PyObject *ob_item[NUM_KEYWORDS];
  919. } _kwtuple = {
  920. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  921. .ob_item = { &_Py_ID(handle), &_Py_ID(size), &_Py_ID(overlapped), },
  922. };
  923. #undef NUM_KEYWORDS
  924. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  925. #else // !Py_BUILD_CORE
  926. # define KWTUPLE NULL
  927. #endif // !Py_BUILD_CORE
  928. static const char * const _keywords[] = {"handle", "size", "overlapped", NULL};
  929. static _PyArg_Parser _parser = {
  930. .keywords = _keywords,
  931. .format = "" F_HANDLE "k|p:ReadFile",
  932. .kwtuple = KWTUPLE,
  933. };
  934. #undef KWTUPLE
  935. HANDLE handle;
  936. DWORD size;
  937. int use_overlapped = 0;
  938. if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
  939. &handle, &size, &use_overlapped)) {
  940. goto exit;
  941. }
  942. return_value = _winapi_ReadFile_impl(module, handle, size, use_overlapped);
  943. exit:
  944. return return_value;
  945. }
  946. PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__,
  947. "SetNamedPipeHandleState($module, named_pipe, mode,\n"
  948. " max_collection_count, collect_data_timeout, /)\n"
  949. "--\n"
  950. "\n");
  951. #define _WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF \
  952. {"SetNamedPipeHandleState", _PyCFunction_CAST(_winapi_SetNamedPipeHandleState), METH_FASTCALL, _winapi_SetNamedPipeHandleState__doc__},
  953. static PyObject *
  954. _winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe,
  955. PyObject *mode,
  956. PyObject *max_collection_count,
  957. PyObject *collect_data_timeout);
  958. static PyObject *
  959. _winapi_SetNamedPipeHandleState(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  960. {
  961. PyObject *return_value = NULL;
  962. HANDLE named_pipe;
  963. PyObject *mode;
  964. PyObject *max_collection_count;
  965. PyObject *collect_data_timeout;
  966. if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "OOO:SetNamedPipeHandleState",
  967. &named_pipe, &mode, &max_collection_count, &collect_data_timeout)) {
  968. goto exit;
  969. }
  970. return_value = _winapi_SetNamedPipeHandleState_impl(module, named_pipe, mode, max_collection_count, collect_data_timeout);
  971. exit:
  972. return return_value;
  973. }
  974. PyDoc_STRVAR(_winapi_TerminateProcess__doc__,
  975. "TerminateProcess($module, handle, exit_code, /)\n"
  976. "--\n"
  977. "\n"
  978. "Terminate the specified process and all of its threads.");
  979. #define _WINAPI_TERMINATEPROCESS_METHODDEF \
  980. {"TerminateProcess", _PyCFunction_CAST(_winapi_TerminateProcess), METH_FASTCALL, _winapi_TerminateProcess__doc__},
  981. static PyObject *
  982. _winapi_TerminateProcess_impl(PyObject *module, HANDLE handle,
  983. UINT exit_code);
  984. static PyObject *
  985. _winapi_TerminateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  986. {
  987. PyObject *return_value = NULL;
  988. HANDLE handle;
  989. UINT exit_code;
  990. if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "I:TerminateProcess",
  991. &handle, &exit_code)) {
  992. goto exit;
  993. }
  994. return_value = _winapi_TerminateProcess_impl(module, handle, exit_code);
  995. exit:
  996. return return_value;
  997. }
  998. PyDoc_STRVAR(_winapi_VirtualQuerySize__doc__,
  999. "VirtualQuerySize($module, address, /)\n"
  1000. "--\n"
  1001. "\n");
  1002. #define _WINAPI_VIRTUALQUERYSIZE_METHODDEF \
  1003. {"VirtualQuerySize", (PyCFunction)_winapi_VirtualQuerySize, METH_O, _winapi_VirtualQuerySize__doc__},
  1004. static size_t
  1005. _winapi_VirtualQuerySize_impl(PyObject *module, LPCVOID address);
  1006. static PyObject *
  1007. _winapi_VirtualQuerySize(PyObject *module, PyObject *arg)
  1008. {
  1009. PyObject *return_value = NULL;
  1010. LPCVOID address;
  1011. size_t _return_value;
  1012. if (!PyArg_Parse(arg, "" F_POINTER ":VirtualQuerySize", &address)) {
  1013. goto exit;
  1014. }
  1015. _return_value = _winapi_VirtualQuerySize_impl(module, address);
  1016. if ((_return_value == (size_t)-1) && PyErr_Occurred()) {
  1017. goto exit;
  1018. }
  1019. return_value = PyLong_FromSize_t(_return_value);
  1020. exit:
  1021. return return_value;
  1022. }
  1023. PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__,
  1024. "WaitNamedPipe($module, name, timeout, /)\n"
  1025. "--\n"
  1026. "\n");
  1027. #define _WINAPI_WAITNAMEDPIPE_METHODDEF \
  1028. {"WaitNamedPipe", _PyCFunction_CAST(_winapi_WaitNamedPipe), METH_FASTCALL, _winapi_WaitNamedPipe__doc__},
  1029. static PyObject *
  1030. _winapi_WaitNamedPipe_impl(PyObject *module, LPCWSTR name, DWORD timeout);
  1031. static PyObject *
  1032. _winapi_WaitNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  1033. {
  1034. PyObject *return_value = NULL;
  1035. LPCWSTR name = NULL;
  1036. DWORD timeout;
  1037. if (!_PyArg_ParseStack(args, nargs, "O&k:WaitNamedPipe",
  1038. _PyUnicode_WideCharString_Converter, &name, &timeout)) {
  1039. goto exit;
  1040. }
  1041. return_value = _winapi_WaitNamedPipe_impl(module, name, timeout);
  1042. exit:
  1043. /* Cleanup for name */
  1044. PyMem_Free((void *)name);
  1045. return return_value;
  1046. }
  1047. PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__,
  1048. "WaitForMultipleObjects($module, handle_seq, wait_flag,\n"
  1049. " milliseconds=_winapi.INFINITE, /)\n"
  1050. "--\n"
  1051. "\n");
  1052. #define _WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF \
  1053. {"WaitForMultipleObjects", _PyCFunction_CAST(_winapi_WaitForMultipleObjects), METH_FASTCALL, _winapi_WaitForMultipleObjects__doc__},
  1054. static PyObject *
  1055. _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq,
  1056. BOOL wait_flag, DWORD milliseconds);
  1057. static PyObject *
  1058. _winapi_WaitForMultipleObjects(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  1059. {
  1060. PyObject *return_value = NULL;
  1061. PyObject *handle_seq;
  1062. BOOL wait_flag;
  1063. DWORD milliseconds = INFINITE;
  1064. if (!_PyArg_ParseStack(args, nargs, "Oi|k:WaitForMultipleObjects",
  1065. &handle_seq, &wait_flag, &milliseconds)) {
  1066. goto exit;
  1067. }
  1068. return_value = _winapi_WaitForMultipleObjects_impl(module, handle_seq, wait_flag, milliseconds);
  1069. exit:
  1070. return return_value;
  1071. }
  1072. PyDoc_STRVAR(_winapi_WaitForSingleObject__doc__,
  1073. "WaitForSingleObject($module, handle, milliseconds, /)\n"
  1074. "--\n"
  1075. "\n"
  1076. "Wait for a single object.\n"
  1077. "\n"
  1078. "Wait until the specified object is in the signaled state or\n"
  1079. "the time-out interval elapses. The timeout value is specified\n"
  1080. "in milliseconds.");
  1081. #define _WINAPI_WAITFORSINGLEOBJECT_METHODDEF \
  1082. {"WaitForSingleObject", _PyCFunction_CAST(_winapi_WaitForSingleObject), METH_FASTCALL, _winapi_WaitForSingleObject__doc__},
  1083. static long
  1084. _winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle,
  1085. DWORD milliseconds);
  1086. static PyObject *
  1087. _winapi_WaitForSingleObject(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  1088. {
  1089. PyObject *return_value = NULL;
  1090. HANDLE handle;
  1091. DWORD milliseconds;
  1092. long _return_value;
  1093. if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "k:WaitForSingleObject",
  1094. &handle, &milliseconds)) {
  1095. goto exit;
  1096. }
  1097. _return_value = _winapi_WaitForSingleObject_impl(module, handle, milliseconds);
  1098. if ((_return_value == -1) && PyErr_Occurred()) {
  1099. goto exit;
  1100. }
  1101. return_value = PyLong_FromLong(_return_value);
  1102. exit:
  1103. return return_value;
  1104. }
  1105. PyDoc_STRVAR(_winapi_WriteFile__doc__,
  1106. "WriteFile($module, /, handle, buffer, overlapped=False)\n"
  1107. "--\n"
  1108. "\n");
  1109. #define _WINAPI_WRITEFILE_METHODDEF \
  1110. {"WriteFile", _PyCFunction_CAST(_winapi_WriteFile), METH_FASTCALL|METH_KEYWORDS, _winapi_WriteFile__doc__},
  1111. static PyObject *
  1112. _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer,
  1113. int use_overlapped);
  1114. static PyObject *
  1115. _winapi_WriteFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1116. {
  1117. PyObject *return_value = NULL;
  1118. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1119. #define NUM_KEYWORDS 3
  1120. static struct {
  1121. PyGC_Head _this_is_not_used;
  1122. PyObject_VAR_HEAD
  1123. PyObject *ob_item[NUM_KEYWORDS];
  1124. } _kwtuple = {
  1125. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1126. .ob_item = { &_Py_ID(handle), &_Py_ID(buffer), &_Py_ID(overlapped), },
  1127. };
  1128. #undef NUM_KEYWORDS
  1129. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1130. #else // !Py_BUILD_CORE
  1131. # define KWTUPLE NULL
  1132. #endif // !Py_BUILD_CORE
  1133. static const char * const _keywords[] = {"handle", "buffer", "overlapped", NULL};
  1134. static _PyArg_Parser _parser = {
  1135. .keywords = _keywords,
  1136. .format = "" F_HANDLE "O|p:WriteFile",
  1137. .kwtuple = KWTUPLE,
  1138. };
  1139. #undef KWTUPLE
  1140. HANDLE handle;
  1141. PyObject *buffer;
  1142. int use_overlapped = 0;
  1143. if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
  1144. &handle, &buffer, &use_overlapped)) {
  1145. goto exit;
  1146. }
  1147. return_value = _winapi_WriteFile_impl(module, handle, buffer, use_overlapped);
  1148. exit:
  1149. return return_value;
  1150. }
  1151. PyDoc_STRVAR(_winapi_GetACP__doc__,
  1152. "GetACP($module, /)\n"
  1153. "--\n"
  1154. "\n"
  1155. "Get the current Windows ANSI code page identifier.");
  1156. #define _WINAPI_GETACP_METHODDEF \
  1157. {"GetACP", (PyCFunction)_winapi_GetACP, METH_NOARGS, _winapi_GetACP__doc__},
  1158. static PyObject *
  1159. _winapi_GetACP_impl(PyObject *module);
  1160. static PyObject *
  1161. _winapi_GetACP(PyObject *module, PyObject *Py_UNUSED(ignored))
  1162. {
  1163. return _winapi_GetACP_impl(module);
  1164. }
  1165. PyDoc_STRVAR(_winapi_GetFileType__doc__,
  1166. "GetFileType($module, /, handle)\n"
  1167. "--\n"
  1168. "\n");
  1169. #define _WINAPI_GETFILETYPE_METHODDEF \
  1170. {"GetFileType", _PyCFunction_CAST(_winapi_GetFileType), METH_FASTCALL|METH_KEYWORDS, _winapi_GetFileType__doc__},
  1171. static DWORD
  1172. _winapi_GetFileType_impl(PyObject *module, HANDLE handle);
  1173. static PyObject *
  1174. _winapi_GetFileType(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1175. {
  1176. PyObject *return_value = NULL;
  1177. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1178. #define NUM_KEYWORDS 1
  1179. static struct {
  1180. PyGC_Head _this_is_not_used;
  1181. PyObject_VAR_HEAD
  1182. PyObject *ob_item[NUM_KEYWORDS];
  1183. } _kwtuple = {
  1184. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1185. .ob_item = { &_Py_ID(handle), },
  1186. };
  1187. #undef NUM_KEYWORDS
  1188. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1189. #else // !Py_BUILD_CORE
  1190. # define KWTUPLE NULL
  1191. #endif // !Py_BUILD_CORE
  1192. static const char * const _keywords[] = {"handle", NULL};
  1193. static _PyArg_Parser _parser = {
  1194. .keywords = _keywords,
  1195. .format = "" F_HANDLE ":GetFileType",
  1196. .kwtuple = KWTUPLE,
  1197. };
  1198. #undef KWTUPLE
  1199. HANDLE handle;
  1200. DWORD _return_value;
  1201. if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
  1202. &handle)) {
  1203. goto exit;
  1204. }
  1205. _return_value = _winapi_GetFileType_impl(module, handle);
  1206. if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
  1207. goto exit;
  1208. }
  1209. return_value = Py_BuildValue("k", _return_value);
  1210. exit:
  1211. return return_value;
  1212. }
  1213. PyDoc_STRVAR(_winapi__mimetypes_read_windows_registry__doc__,
  1214. "_mimetypes_read_windows_registry($module, /, on_type_read)\n"
  1215. "--\n"
  1216. "\n"
  1217. "Optimized function for reading all known MIME types from the registry.\n"
  1218. "\n"
  1219. "*on_type_read* is a callable taking *type* and *ext* arguments, as for\n"
  1220. "MimeTypes.add_type.");
  1221. #define _WINAPI__MIMETYPES_READ_WINDOWS_REGISTRY_METHODDEF \
  1222. {"_mimetypes_read_windows_registry", _PyCFunction_CAST(_winapi__mimetypes_read_windows_registry), METH_FASTCALL|METH_KEYWORDS, _winapi__mimetypes_read_windows_registry__doc__},
  1223. static PyObject *
  1224. _winapi__mimetypes_read_windows_registry_impl(PyObject *module,
  1225. PyObject *on_type_read);
  1226. static PyObject *
  1227. _winapi__mimetypes_read_windows_registry(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1228. {
  1229. PyObject *return_value = NULL;
  1230. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1231. #define NUM_KEYWORDS 1
  1232. static struct {
  1233. PyGC_Head _this_is_not_used;
  1234. PyObject_VAR_HEAD
  1235. PyObject *ob_item[NUM_KEYWORDS];
  1236. } _kwtuple = {
  1237. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1238. .ob_item = { &_Py_ID(on_type_read), },
  1239. };
  1240. #undef NUM_KEYWORDS
  1241. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1242. #else // !Py_BUILD_CORE
  1243. # define KWTUPLE NULL
  1244. #endif // !Py_BUILD_CORE
  1245. static const char * const _keywords[] = {"on_type_read", NULL};
  1246. static _PyArg_Parser _parser = {
  1247. .keywords = _keywords,
  1248. .fname = "_mimetypes_read_windows_registry",
  1249. .kwtuple = KWTUPLE,
  1250. };
  1251. #undef KWTUPLE
  1252. PyObject *argsbuf[1];
  1253. PyObject *on_type_read;
  1254. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1255. if (!args) {
  1256. goto exit;
  1257. }
  1258. on_type_read = args[0];
  1259. return_value = _winapi__mimetypes_read_windows_registry_impl(module, on_type_read);
  1260. exit:
  1261. return return_value;
  1262. }
  1263. PyDoc_STRVAR(_winapi_NeedCurrentDirectoryForExePath__doc__,
  1264. "NeedCurrentDirectoryForExePath($module, exe_name, /)\n"
  1265. "--\n"
  1266. "\n");
  1267. #define _WINAPI_NEEDCURRENTDIRECTORYFOREXEPATH_METHODDEF \
  1268. {"NeedCurrentDirectoryForExePath", (PyCFunction)_winapi_NeedCurrentDirectoryForExePath, METH_O, _winapi_NeedCurrentDirectoryForExePath__doc__},
  1269. static int
  1270. _winapi_NeedCurrentDirectoryForExePath_impl(PyObject *module,
  1271. LPCWSTR exe_name);
  1272. static PyObject *
  1273. _winapi_NeedCurrentDirectoryForExePath(PyObject *module, PyObject *arg)
  1274. {
  1275. PyObject *return_value = NULL;
  1276. LPCWSTR exe_name = NULL;
  1277. int _return_value;
  1278. if (!PyUnicode_Check(arg)) {
  1279. _PyArg_BadArgument("NeedCurrentDirectoryForExePath", "argument", "str", arg);
  1280. goto exit;
  1281. }
  1282. exe_name = PyUnicode_AsWideCharString(arg, NULL);
  1283. if (exe_name == NULL) {
  1284. goto exit;
  1285. }
  1286. _return_value = _winapi_NeedCurrentDirectoryForExePath_impl(module, exe_name);
  1287. if ((_return_value == -1) && PyErr_Occurred()) {
  1288. goto exit;
  1289. }
  1290. return_value = PyBool_FromLong((long)_return_value);
  1291. exit:
  1292. /* Cleanup for exe_name */
  1293. PyMem_Free((void *)exe_name);
  1294. return return_value;
  1295. }
  1296. PyDoc_STRVAR(_winapi_CopyFile2__doc__,
  1297. "CopyFile2($module, /, existing_file_name, new_file_name, flags,\n"
  1298. " progress_routine=None)\n"
  1299. "--\n"
  1300. "\n"
  1301. "Copies a file from one name to a new name.\n"
  1302. "\n"
  1303. "This is implemented using the CopyFile2 API, which preserves all stat\n"
  1304. "and metadata information apart from security attributes.\n"
  1305. "\n"
  1306. "progress_routine is reserved for future use, but is currently not\n"
  1307. "implemented. Its value is ignored.");
  1308. #define _WINAPI_COPYFILE2_METHODDEF \
  1309. {"CopyFile2", _PyCFunction_CAST(_winapi_CopyFile2), METH_FASTCALL|METH_KEYWORDS, _winapi_CopyFile2__doc__},
  1310. static PyObject *
  1311. _winapi_CopyFile2_impl(PyObject *module, LPCWSTR existing_file_name,
  1312. LPCWSTR new_file_name, DWORD flags,
  1313. PyObject *progress_routine);
  1314. static PyObject *
  1315. _winapi_CopyFile2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1316. {
  1317. PyObject *return_value = NULL;
  1318. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1319. #define NUM_KEYWORDS 4
  1320. static struct {
  1321. PyGC_Head _this_is_not_used;
  1322. PyObject_VAR_HEAD
  1323. PyObject *ob_item[NUM_KEYWORDS];
  1324. } _kwtuple = {
  1325. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1326. .ob_item = { &_Py_ID(existing_file_name), &_Py_ID(new_file_name), &_Py_ID(flags), &_Py_ID(progress_routine), },
  1327. };
  1328. #undef NUM_KEYWORDS
  1329. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1330. #else // !Py_BUILD_CORE
  1331. # define KWTUPLE NULL
  1332. #endif // !Py_BUILD_CORE
  1333. static const char * const _keywords[] = {"existing_file_name", "new_file_name", "flags", "progress_routine", NULL};
  1334. static _PyArg_Parser _parser = {
  1335. .keywords = _keywords,
  1336. .format = "O&O&k|O:CopyFile2",
  1337. .kwtuple = KWTUPLE,
  1338. };
  1339. #undef KWTUPLE
  1340. LPCWSTR existing_file_name = NULL;
  1341. LPCWSTR new_file_name = NULL;
  1342. DWORD flags;
  1343. PyObject *progress_routine = Py_None;
  1344. if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
  1345. _PyUnicode_WideCharString_Converter, &existing_file_name, _PyUnicode_WideCharString_Converter, &new_file_name, &flags, &progress_routine)) {
  1346. goto exit;
  1347. }
  1348. return_value = _winapi_CopyFile2_impl(module, existing_file_name, new_file_name, flags, progress_routine);
  1349. exit:
  1350. /* Cleanup for existing_file_name */
  1351. PyMem_Free((void *)existing_file_name);
  1352. /* Cleanup for new_file_name */
  1353. PyMem_Free((void *)new_file_name);
  1354. return return_value;
  1355. }
  1356. /*[clinic end generated code: output=91b39b70024fa232 input=a9049054013a1b77]*/