pg_query 4.2.3 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (528) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +6 -8
  4. data/Rakefile +3 -4
  5. data/ext/pg_query/extconf.rb +14 -6
  6. data/ext/pg_query/include/pg_query.h +27 -3
  7. data/ext/pg_query/include/pg_query_enum_defs.c +311 -149
  8. data/ext/pg_query/include/pg_query_fingerprint_conds.c +545 -489
  9. data/ext/pg_query/include/pg_query_fingerprint_defs.c +5092 -4432
  10. data/ext/pg_query/include/pg_query_outfuncs_conds.c +385 -343
  11. data/ext/pg_query/include/pg_query_outfuncs_defs.c +1294 -1161
  12. data/ext/pg_query/include/pg_query_readfuncs_conds.c +137 -123
  13. data/ext/pg_query/include/pg_query_readfuncs_defs.c +1657 -1496
  14. data/ext/pg_query/include/{access → postgres/access}/amapi.h +3 -1
  15. data/ext/pg_query/include/{access → postgres/access}/attmap.h +5 -3
  16. data/ext/pg_query/include/{access → postgres/access}/attnum.h +1 -1
  17. data/ext/pg_query/include/{access → postgres/access}/clog.h +1 -1
  18. data/ext/pg_query/include/{access → postgres/access}/commit_ts.h +1 -1
  19. data/ext/pg_query/include/{access → postgres/access}/detoast.h +1 -1
  20. data/ext/pg_query/include/{access → postgres/access}/genam.h +7 -5
  21. data/ext/pg_query/include/{access → postgres/access}/gin.h +16 -3
  22. data/ext/pg_query/include/{access → postgres/access}/htup.h +1 -1
  23. data/ext/pg_query/include/{access → postgres/access}/htup_details.h +6 -2
  24. data/ext/pg_query/include/{access → postgres/access}/itup.h +61 -58
  25. data/ext/pg_query/include/{access → postgres/access}/parallel.h +2 -2
  26. data/ext/pg_query/include/{access → postgres/access}/printtup.h +1 -1
  27. data/ext/pg_query/include/{access → postgres/access}/relation.h +1 -1
  28. data/ext/pg_query/include/{access → postgres/access}/relscan.h +1 -1
  29. data/ext/pg_query/include/{access → postgres/access}/rmgrlist.h +2 -2
  30. data/ext/pg_query/include/{access → postgres/access}/sdir.h +12 -3
  31. data/ext/pg_query/include/{access → postgres/access}/skey.h +1 -1
  32. data/ext/pg_query/include/{access → postgres/access}/stratnum.h +1 -1
  33. data/ext/pg_query/include/{access → postgres/access}/sysattr.h +1 -1
  34. data/ext/pg_query/include/{access → postgres/access}/table.h +1 -1
  35. data/ext/pg_query/include/{access → postgres/access}/tableam.h +68 -45
  36. data/ext/pg_query/include/{access → postgres/access}/toast_compression.h +1 -1
  37. data/ext/pg_query/include/{access → postgres/access}/transam.h +1 -1
  38. data/ext/pg_query/include/postgres/access/tsmapi.h +82 -0
  39. data/ext/pg_query/include/{access → postgres/access}/tupconvert.h +5 -2
  40. data/ext/pg_query/include/{access → postgres/access}/tupdesc.h +2 -2
  41. data/ext/pg_query/include/{access → postgres/access}/tupmacs.h +58 -98
  42. data/ext/pg_query/include/{access → postgres/access}/twophase.h +2 -2
  43. data/ext/pg_query/include/{access → postgres/access}/xact.h +25 -18
  44. data/ext/pg_query/include/{access → postgres/access}/xlog.h +15 -16
  45. data/ext/pg_query/include/{access → postgres/access}/xlog_internal.h +100 -62
  46. data/ext/pg_query/include/postgres/access/xlogbackup.h +41 -0
  47. data/ext/pg_query/include/{access → postgres/access}/xlogdefs.h +6 -25
  48. data/ext/pg_query/include/{access → postgres/access}/xlogprefetcher.h +1 -1
  49. data/ext/pg_query/include/{access → postgres/access}/xlogreader.h +7 -6
  50. data/ext/pg_query/include/{access → postgres/access}/xlogrecord.h +17 -5
  51. data/ext/pg_query/include/{access → postgres/access}/xlogrecovery.h +4 -3
  52. data/ext/pg_query/include/postgres/archive/archive_module.h +59 -0
  53. data/ext/pg_query/include/{c.h → postgres/c.h} +144 -156
  54. data/ext/pg_query/include/{catalog → postgres/catalog}/catalog.h +4 -3
  55. data/ext/pg_query/include/{catalog → postgres/catalog}/catversion.h +6 -2
  56. data/ext/pg_query/include/{catalog → postgres/catalog}/dependency.h +5 -4
  57. data/ext/pg_query/include/{catalog → postgres/catalog}/genbki.h +7 -6
  58. data/ext/pg_query/include/{catalog → postgres/catalog}/index.h +4 -4
  59. data/ext/pg_query/include/{catalog → postgres/catalog}/indexing.h +1 -1
  60. data/ext/pg_query/include/{catalog → postgres/catalog}/namespace.h +2 -2
  61. data/ext/pg_query/include/{catalog → postgres/catalog}/objectaccess.h +10 -8
  62. data/ext/pg_query/include/{catalog → postgres/catalog}/objectaddress.h +3 -3
  63. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_aggregate.h +1 -1
  64. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_aggregate_d.h +1 -1
  65. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_am.h +1 -1
  66. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_am_d.h +1 -1
  67. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_attribute.h +19 -17
  68. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_attribute_d.h +19 -19
  69. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_authid.h +1 -1
  70. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_authid_d.h +3 -1
  71. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_class.h +1 -1
  72. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_class_d.h +1 -1
  73. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_collation.h +3 -1
  74. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_collation_d.h +4 -3
  75. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_constraint.h +2 -2
  76. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_constraint_d.h +1 -1
  77. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_control.h +9 -1
  78. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_conversion.h +2 -2
  79. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_conversion_d.h +1 -1
  80. data/ext/pg_query/include/postgres/catalog/pg_database.h +124 -0
  81. data/ext/pg_query/include/postgres/catalog/pg_database_d.h +52 -0
  82. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_depend.h +1 -1
  83. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_depend_d.h +1 -1
  84. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_event_trigger.h +1 -1
  85. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_event_trigger_d.h +1 -1
  86. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_index.h +1 -1
  87. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_index_d.h +1 -1
  88. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_language.h +1 -1
  89. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_language_d.h +1 -1
  90. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_namespace.h +1 -1
  91. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_namespace_d.h +1 -1
  92. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_opclass.h +1 -1
  93. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_opclass_d.h +1 -1
  94. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_operator.h +1 -1
  95. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_operator_d.h +1 -1
  96. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_opfamily.h +3 -2
  97. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_opfamily_d.h +4 -2
  98. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_partitioned_table.h +1 -1
  99. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_partitioned_table_d.h +1 -1
  100. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_proc.h +1 -1
  101. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_proc_d.h +1 -1
  102. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_publication.h +2 -5
  103. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_publication_d.h +1 -1
  104. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_replication_origin.h +1 -1
  105. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_replication_origin_d.h +1 -1
  106. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_statistic.h +1 -1
  107. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_statistic_d.h +1 -1
  108. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_statistic_ext.h +1 -1
  109. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_statistic_ext_d.h +1 -1
  110. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_transform.h +1 -1
  111. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_transform_d.h +1 -1
  112. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_trigger.h +1 -1
  113. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_trigger_d.h +1 -1
  114. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_config.h +1 -1
  115. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_config_d.h +1 -1
  116. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_dict.h +1 -1
  117. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_dict_d.h +1 -1
  118. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_parser.h +1 -1
  119. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_parser_d.h +1 -1
  120. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_template.h +1 -1
  121. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_ts_template_d.h +1 -1
  122. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_type.h +1 -1
  123. data/ext/pg_query/include/{catalog → postgres/catalog}/pg_type_d.h +1 -1
  124. data/ext/pg_query/include/{catalog → postgres/catalog}/storage.h +6 -6
  125. data/ext/pg_query/include/{commands → postgres/commands}/async.h +1 -1
  126. data/ext/pg_query/include/{commands → postgres/commands}/dbcommands.h +2 -1
  127. data/ext/pg_query/include/{commands → postgres/commands}/defrem.h +2 -1
  128. data/ext/pg_query/include/{commands → postgres/commands}/event_trigger.h +1 -1
  129. data/ext/pg_query/include/{commands → postgres/commands}/explain.h +3 -1
  130. data/ext/pg_query/include/{commands → postgres/commands}/prepare.h +1 -1
  131. data/ext/pg_query/include/{commands → postgres/commands}/tablespace.h +4 -4
  132. data/ext/pg_query/include/{commands → postgres/commands}/trigger.h +15 -14
  133. data/ext/pg_query/include/{commands → postgres/commands}/user.h +9 -3
  134. data/ext/pg_query/include/{commands → postgres/commands}/vacuum.h +60 -14
  135. data/ext/pg_query/include/postgres/common/cryptohash.h +39 -0
  136. data/ext/pg_query/include/{common → postgres/common}/file_perm.h +1 -1
  137. data/ext/pg_query/include/{common → postgres/common}/hashfn.h +1 -1
  138. data/ext/pg_query/include/postgres/common/int.h +437 -0
  139. data/ext/pg_query/include/{common → postgres/common}/keywords.h +1 -1
  140. data/ext/pg_query/include/{common → postgres/common}/kwlookup.h +2 -2
  141. data/ext/pg_query/include/{common → postgres/common}/pg_prng.h +3 -2
  142. data/ext/pg_query/include/{common → postgres/common}/relpath.h +20 -13
  143. data/ext/pg_query/include/postgres/common/scram-common.h +70 -0
  144. data/ext/pg_query/include/postgres/common/sha2.h +32 -0
  145. data/ext/pg_query/include/{common → postgres/common}/string.h +5 -3
  146. data/ext/pg_query/include/{common → postgres/common}/unicode_east_asian_fw_table.h +10 -10
  147. data/ext/pg_query/include/{common/unicode_combining_table.h → postgres/common/unicode_nonspacing_table.h} +31 -13
  148. data/ext/pg_query/include/postgres/copyfuncs.funcs.c +5013 -0
  149. data/ext/pg_query/include/postgres/copyfuncs.switch.c +938 -0
  150. data/ext/pg_query/include/{datatype → postgres/datatype}/timestamp.h +11 -4
  151. data/ext/pg_query/include/postgres/equalfuncs.funcs.c +3097 -0
  152. data/ext/pg_query/include/postgres/equalfuncs.switch.c +785 -0
  153. data/ext/pg_query/include/{executor → postgres/executor}/execdesc.h +1 -1
  154. data/ext/pg_query/include/{executor → postgres/executor}/executor.h +34 -17
  155. data/ext/pg_query/include/{executor → postgres/executor}/functions.h +1 -1
  156. data/ext/pg_query/include/{executor → postgres/executor}/instrument.h +1 -1
  157. data/ext/pg_query/include/{executor → postgres/executor}/spi.h +2 -2
  158. data/ext/pg_query/include/{executor → postgres/executor}/tablefunc.h +1 -1
  159. data/ext/pg_query/include/{executor → postgres/executor}/tuptable.h +18 -11
  160. data/ext/pg_query/include/{fmgr.h → postgres/fmgr.h} +21 -2
  161. data/ext/pg_query/include/postgres/foreign/fdwapi.h +294 -0
  162. data/ext/pg_query/include/{funcapi.h → postgres/funcapi.h} +12 -12
  163. data/ext/pg_query/include/postgres/gram.h +1127 -0
  164. data/ext/pg_query/include/{parser → postgres}/gramparse.h +4 -4
  165. data/ext/pg_query/include/{jit → postgres/jit}/jit.h +2 -2
  166. data/ext/pg_query/include/postgres/kwlist_d.h +1119 -0
  167. data/ext/pg_query/include/{lib → postgres/lib}/dshash.h +4 -1
  168. data/ext/pg_query/include/{lib → postgres/lib}/ilist.h +435 -22
  169. data/ext/pg_query/include/{lib → postgres/lib}/pairingheap.h +1 -1
  170. data/ext/pg_query/include/{lib → postgres/lib}/simplehash.h +9 -9
  171. data/ext/pg_query/include/{lib → postgres/lib}/sort_template.h +1 -1
  172. data/ext/pg_query/include/{lib → postgres/lib}/stringinfo.h +3 -3
  173. data/ext/pg_query/include/{libpq → postgres/libpq}/auth.h +8 -2
  174. data/ext/pg_query/include/{libpq → postgres/libpq}/crypt.h +1 -1
  175. data/ext/pg_query/include/{libpq → postgres/libpq}/hba.h +24 -17
  176. data/ext/pg_query/include/{libpq → postgres/libpq}/libpq-be.h +36 -25
  177. data/ext/pg_query/include/{libpq → postgres/libpq}/libpq.h +1 -1
  178. data/ext/pg_query/include/{libpq → postgres/libpq}/pqcomm.h +10 -41
  179. data/ext/pg_query/include/{libpq → postgres/libpq}/pqformat.h +2 -2
  180. data/ext/pg_query/include/{libpq → postgres/libpq}/pqsignal.h +22 -10
  181. data/ext/pg_query/include/postgres/libpq/sasl.h +136 -0
  182. data/ext/pg_query/include/postgres/libpq/scram.h +37 -0
  183. data/ext/pg_query/include/{mb → postgres/mb}/pg_wchar.h +35 -18
  184. data/ext/pg_query/include/{mb → postgres/mb}/stringinfo_mb.h +1 -1
  185. data/ext/pg_query/include/{miscadmin.h → postgres/miscadmin.h} +27 -15
  186. data/ext/pg_query/include/{nodes → postgres/nodes}/bitmapset.h +11 -7
  187. data/ext/pg_query/include/{nodes → postgres/nodes}/execnodes.h +83 -30
  188. data/ext/pg_query/include/{nodes → postgres/nodes}/extensible.h +5 -3
  189. data/ext/pg_query/include/{nodes → postgres/nodes}/lockoptions.h +1 -1
  190. data/ext/pg_query/include/{nodes → postgres/nodes}/makefuncs.h +14 -2
  191. data/ext/pg_query/include/{nodes → postgres/nodes}/memnodes.h +7 -4
  192. data/ext/pg_query/include/postgres/nodes/miscnodes.h +56 -0
  193. data/ext/pg_query/include/{nodes → postgres/nodes}/nodeFuncs.h +89 -29
  194. data/ext/pg_query/include/{nodes → postgres/nodes}/nodes.h +96 -511
  195. data/ext/pg_query/include/postgres/nodes/nodetags.h +471 -0
  196. data/ext/pg_query/include/{nodes → postgres/nodes}/params.h +3 -3
  197. data/ext/pg_query/include/{nodes → postgres/nodes}/parsenodes.h +377 -139
  198. data/ext/pg_query/include/{nodes → postgres/nodes}/pathnodes.h +1090 -440
  199. data/ext/pg_query/include/{nodes → postgres/nodes}/pg_list.h +30 -7
  200. data/ext/pg_query/include/{nodes → postgres/nodes}/plannodes.h +367 -124
  201. data/ext/pg_query/include/{nodes → postgres/nodes}/primnodes.h +670 -222
  202. data/ext/pg_query/include/{nodes → postgres/nodes}/print.h +1 -1
  203. data/ext/pg_query/include/{utils → postgres/nodes}/queryjumble.h +5 -7
  204. data/ext/pg_query/include/postgres/nodes/replnodes.h +111 -0
  205. data/ext/pg_query/include/postgres/nodes/supportnodes.h +346 -0
  206. data/ext/pg_query/include/{nodes → postgres/nodes}/tidbitmap.h +1 -1
  207. data/ext/pg_query/include/{nodes → postgres/nodes}/value.h +12 -2
  208. data/ext/pg_query/include/{optimizer → postgres/optimizer}/cost.h +6 -4
  209. data/ext/pg_query/include/{optimizer → postgres/optimizer}/geqo.h +1 -1
  210. data/ext/pg_query/include/{optimizer → postgres/optimizer}/geqo_gene.h +1 -1
  211. data/ext/pg_query/include/{optimizer → postgres/optimizer}/optimizer.h +8 -8
  212. data/ext/pg_query/include/{optimizer → postgres/optimizer}/paths.h +16 -7
  213. data/ext/pg_query/include/{optimizer → postgres/optimizer}/planmain.h +3 -6
  214. data/ext/pg_query/include/{parser → postgres/parser}/analyze.h +4 -3
  215. data/ext/pg_query/include/{parser → postgres/parser}/kwlist.h +12 -1
  216. data/ext/pg_query/include/{parser → postgres/parser}/parse_agg.h +4 -2
  217. data/ext/pg_query/include/{parser → postgres/parser}/parse_coerce.h +3 -1
  218. data/ext/pg_query/include/{parser → postgres/parser}/parse_expr.h +1 -1
  219. data/ext/pg_query/include/{parser → postgres/parser}/parse_func.h +1 -1
  220. data/ext/pg_query/include/{parser → postgres/parser}/parse_node.h +22 -4
  221. data/ext/pg_query/include/{parser → postgres/parser}/parse_oper.h +3 -3
  222. data/ext/pg_query/include/{parser → postgres/parser}/parse_relation.h +8 -3
  223. data/ext/pg_query/include/{parser → postgres/parser}/parse_type.h +4 -3
  224. data/ext/pg_query/include/{parser → postgres/parser}/parser.h +4 -4
  225. data/ext/pg_query/include/{parser → postgres/parser}/parsetree.h +1 -1
  226. data/ext/pg_query/include/{parser → postgres/parser}/scanner.h +2 -2
  227. data/ext/pg_query/include/{parser → postgres/parser}/scansup.h +1 -1
  228. data/ext/pg_query/include/{partitioning → postgres/partitioning}/partdefs.h +1 -1
  229. data/ext/pg_query/include/{pg_config.h → postgres/pg_config.h} +156 -217
  230. data/ext/pg_query/include/{pg_config_manual.h → postgres/pg_config_manual.h} +8 -46
  231. data/ext/pg_query/include/postgres/pg_config_os.h +8 -0
  232. data/ext/pg_query/include/{pg_getopt.h → postgres/pg_getopt.h} +1 -1
  233. data/ext/pg_query/include/{pg_trace.h → postgres/pg_trace.h} +1 -1
  234. data/ext/pg_query/include/{pgstat.h → postgres/pgstat.h} +173 -94
  235. data/ext/pg_query/include/{pgtime.h → postgres/pgtime.h} +3 -3
  236. data/ext/pg_query/include/{pl_gram.h → postgres/pl_gram.h} +66 -64
  237. data/ext/pg_query/include/{pl_reserved_kwlist.h → postgres/pl_reserved_kwlist.h} +1 -1
  238. data/ext/pg_query/include/{pl_reserved_kwlist_d.h → postgres/pl_reserved_kwlist_d.h} +1 -1
  239. data/ext/pg_query/include/{pl_unreserved_kwlist.h → postgres/pl_unreserved_kwlist.h} +2 -1
  240. data/ext/pg_query/include/{pl_unreserved_kwlist_d.h → postgres/pl_unreserved_kwlist_d.h} +48 -46
  241. data/ext/pg_query/include/{plpgsql.h → postgres/plpgsql.h} +28 -33
  242. data/ext/pg_query/include/{port → postgres/port}/atomics/arch-arm.h +3 -3
  243. data/ext/pg_query/include/postgres/port/atomics/arch-hppa.h +17 -0
  244. data/ext/pg_query/include/{port → postgres/port}/atomics/arch-ppc.h +21 -21
  245. data/ext/pg_query/include/{port → postgres/port}/atomics/arch-x86.h +2 -2
  246. data/ext/pg_query/include/{port → postgres/port}/atomics/fallback.h +3 -3
  247. data/ext/pg_query/include/{port → postgres/port}/atomics/generic-gcc.h +1 -1
  248. data/ext/pg_query/include/postgres/port/atomics/generic-msvc.h +101 -0
  249. data/ext/pg_query/include/postgres/port/atomics/generic-sunpro.h +106 -0
  250. data/ext/pg_query/include/{port → postgres/port}/atomics/generic.h +1 -1
  251. data/ext/pg_query/include/{port → postgres/port}/atomics.h +2 -7
  252. data/ext/pg_query/include/{port → postgres/port}/pg_bitutils.h +62 -25
  253. data/ext/pg_query/include/{port → postgres/port}/pg_bswap.h +1 -1
  254. data/ext/pg_query/include/{port → postgres/port}/pg_crc32c.h +1 -1
  255. data/ext/pg_query/include/postgres/port/simd.h +375 -0
  256. data/ext/pg_query/include/postgres/port/win32/arpa/inet.h +3 -0
  257. data/ext/pg_query/include/postgres/port/win32/dlfcn.h +1 -0
  258. data/ext/pg_query/include/postgres/port/win32/grp.h +1 -0
  259. data/ext/pg_query/include/postgres/port/win32/netdb.h +7 -0
  260. data/ext/pg_query/include/postgres/port/win32/netinet/in.h +3 -0
  261. data/ext/pg_query/include/postgres/port/win32/netinet/tcp.h +7 -0
  262. data/ext/pg_query/include/postgres/port/win32/pwd.h +3 -0
  263. data/ext/pg_query/include/postgres/port/win32/sys/resource.h +20 -0
  264. data/ext/pg_query/include/postgres/port/win32/sys/select.h +3 -0
  265. data/ext/pg_query/include/postgres/port/win32/sys/socket.h +26 -0
  266. data/ext/pg_query/include/postgres/port/win32/sys/un.h +17 -0
  267. data/ext/pg_query/include/postgres/port/win32/sys/wait.h +3 -0
  268. data/ext/pg_query/include/postgres/port/win32.h +59 -0
  269. data/ext/pg_query/include/postgres/port/win32_msvc/dirent.h +34 -0
  270. data/ext/pg_query/include/postgres/port/win32_msvc/sys/file.h +1 -0
  271. data/ext/pg_query/include/postgres/port/win32_msvc/sys/param.h +1 -0
  272. data/ext/pg_query/include/postgres/port/win32_msvc/sys/time.h +1 -0
  273. data/ext/pg_query/include/postgres/port/win32_msvc/unistd.h +9 -0
  274. data/ext/pg_query/include/postgres/port/win32_msvc/utime.h +3 -0
  275. data/ext/pg_query/include/postgres/port/win32_port.h +594 -0
  276. data/ext/pg_query/include/{port.h → postgres/port.h} +42 -75
  277. data/ext/pg_query/include/postgres/portability/instr_time.h +197 -0
  278. data/ext/pg_query/include/postgres/postgres.h +579 -0
  279. data/ext/pg_query/include/{postgres_ext.h → postgres/postgres_ext.h} +0 -1
  280. data/ext/pg_query/include/{postmaster → postgres/postmaster}/autovacuum.h +1 -4
  281. data/ext/pg_query/include/{postmaster → postgres/postmaster}/bgworker.h +2 -2
  282. data/ext/pg_query/include/{postmaster → postgres/postmaster}/bgworker_internals.h +1 -1
  283. data/ext/pg_query/include/{postmaster → postgres/postmaster}/bgwriter.h +2 -2
  284. data/ext/pg_query/include/{postmaster → postgres/postmaster}/interrupt.h +1 -1
  285. data/ext/pg_query/include/postgres/postmaster/pgarch.h +36 -0
  286. data/ext/pg_query/include/{postmaster → postgres/postmaster}/postmaster.h +6 -3
  287. data/ext/pg_query/include/{postmaster → postgres/postmaster}/startup.h +3 -1
  288. data/ext/pg_query/include/{postmaster → postgres/postmaster}/syslogger.h +2 -2
  289. data/ext/pg_query/include/{postmaster → postgres/postmaster}/walwriter.h +3 -1
  290. data/ext/pg_query/include/{regex → postgres/regex}/regex.h +9 -6
  291. data/ext/pg_query/include/{replication → postgres/replication}/logicallauncher.h +6 -1
  292. data/ext/pg_query/include/{replication → postgres/replication}/logicalproto.h +30 -10
  293. data/ext/pg_query/include/postgres/replication/logicalworker.h +32 -0
  294. data/ext/pg_query/include/{replication → postgres/replication}/origin.h +4 -4
  295. data/ext/pg_query/include/{replication → postgres/replication}/reorderbuffer.h +113 -45
  296. data/ext/pg_query/include/{replication → postgres/replication}/slot.h +25 -6
  297. data/ext/pg_query/include/{replication → postgres/replication}/syncrep.h +2 -8
  298. data/ext/pg_query/include/{replication → postgres/replication}/walreceiver.h +15 -9
  299. data/ext/pg_query/include/{replication → postgres/replication}/walsender.h +13 -13
  300. data/ext/pg_query/include/{rewrite → postgres/rewrite}/prs2lock.h +1 -1
  301. data/ext/pg_query/include/{rewrite → postgres/rewrite}/rewriteHandler.h +1 -4
  302. data/ext/pg_query/include/{rewrite → postgres/rewrite}/rewriteManip.h +11 -2
  303. data/ext/pg_query/include/{rewrite → postgres/rewrite}/rewriteSupport.h +1 -1
  304. data/ext/pg_query/include/{storage → postgres/storage}/backendid.h +1 -1
  305. data/ext/pg_query/include/{storage → postgres/storage}/block.h +24 -31
  306. data/ext/pg_query/include/{storage → postgres/storage}/buf.h +1 -1
  307. data/ext/pg_query/include/{storage → postgres/storage}/bufmgr.h +183 -87
  308. data/ext/pg_query/include/{storage → postgres/storage}/bufpage.h +146 -93
  309. data/ext/pg_query/include/{storage → postgres/storage}/condition_variable.h +2 -2
  310. data/ext/pg_query/include/{storage → postgres/storage}/dsm.h +3 -6
  311. data/ext/pg_query/include/{storage → postgres/storage}/dsm_impl.h +4 -1
  312. data/ext/pg_query/include/{storage → postgres/storage}/fd.h +24 -20
  313. data/ext/pg_query/include/{storage → postgres/storage}/fileset.h +1 -1
  314. data/ext/pg_query/include/{storage → postgres/storage}/ipc.h +2 -2
  315. data/ext/pg_query/include/{storage → postgres/storage}/item.h +1 -1
  316. data/ext/pg_query/include/{storage → postgres/storage}/itemid.h +1 -1
  317. data/ext/pg_query/include/{storage → postgres/storage}/itemptr.h +94 -57
  318. data/ext/pg_query/include/{storage → postgres/storage}/large_object.h +1 -1
  319. data/ext/pg_query/include/{storage → postgres/storage}/latch.h +9 -1
  320. data/ext/pg_query/include/{storage → postgres/storage}/lmgr.h +6 -1
  321. data/ext/pg_query/include/{storage → postgres/storage}/lock.h +21 -13
  322. data/ext/pg_query/include/{storage → postgres/storage}/lockdefs.h +3 -3
  323. data/ext/pg_query/include/{storage → postgres/storage}/lwlock.h +16 -2
  324. data/ext/pg_query/include/{storage → postgres/storage}/off.h +1 -1
  325. data/ext/pg_query/include/{storage → postgres/storage}/pg_sema.h +1 -1
  326. data/ext/pg_query/include/{storage → postgres/storage}/pg_shmem.h +1 -1
  327. data/ext/pg_query/include/{storage → postgres/storage}/pmsignal.h +1 -1
  328. data/ext/pg_query/include/{storage → postgres/storage}/predicate.h +2 -2
  329. data/ext/pg_query/include/{storage → postgres/storage}/proc.h +22 -17
  330. data/ext/pg_query/include/{storage → postgres/storage}/procarray.h +3 -2
  331. data/ext/pg_query/include/{storage → postgres/storage}/proclist_types.h +1 -1
  332. data/ext/pg_query/include/{storage → postgres/storage}/procsignal.h +3 -1
  333. data/ext/pg_query/include/postgres/storage/relfilelocator.h +99 -0
  334. data/ext/pg_query/include/{storage → postgres/storage}/s_lock.h +66 -309
  335. data/ext/pg_query/include/{storage → postgres/storage}/sharedfileset.h +1 -1
  336. data/ext/pg_query/include/{storage → postgres/storage}/shm_mq.h +1 -1
  337. data/ext/pg_query/include/{storage → postgres/storage}/shm_toc.h +1 -1
  338. data/ext/pg_query/include/{storage → postgres/storage}/shmem.h +1 -23
  339. data/ext/pg_query/include/{storage → postgres/storage}/sinval.h +3 -3
  340. data/ext/pg_query/include/{storage → postgres/storage}/sinvaladt.h +4 -2
  341. data/ext/pg_query/include/{storage → postgres/storage}/smgr.h +12 -10
  342. data/ext/pg_query/include/{storage → postgres/storage}/spin.h +1 -1
  343. data/ext/pg_query/include/{storage → postgres/storage}/standby.h +9 -8
  344. data/ext/pg_query/include/{storage → postgres/storage}/standbydefs.h +1 -1
  345. data/ext/pg_query/include/{storage → postgres/storage}/sync.h +3 -3
  346. data/ext/pg_query/include/{tcop → postgres/tcop}/cmdtag.h +7 -2
  347. data/ext/pg_query/include/{tcop → postgres/tcop}/cmdtaglist.h +1 -1
  348. data/ext/pg_query/include/{tcop → postgres/tcop}/deparse_utility.h +1 -1
  349. data/ext/pg_query/include/{tcop → postgres/tcop}/dest.h +1 -3
  350. data/ext/pg_query/include/{tcop → postgres/tcop}/fastpath.h +1 -1
  351. data/ext/pg_query/include/{tcop → postgres/tcop}/pquery.h +1 -1
  352. data/ext/pg_query/include/{tcop → postgres/tcop}/tcopprot.h +3 -6
  353. data/ext/pg_query/include/{tcop → postgres/tcop}/utility.h +1 -1
  354. data/ext/pg_query/include/{tsearch → postgres/tsearch}/ts_cache.h +2 -4
  355. data/ext/pg_query/include/{utils → postgres/utils}/acl.h +26 -81
  356. data/ext/pg_query/include/{utils → postgres/utils}/aclchk_internal.h +1 -1
  357. data/ext/pg_query/include/{utils → postgres/utils}/array.h +19 -1
  358. data/ext/pg_query/include/{utils → postgres/utils}/backend_progress.h +2 -1
  359. data/ext/pg_query/include/{utils → postgres/utils}/backend_status.h +24 -3
  360. data/ext/pg_query/include/{utils → postgres/utils}/builtins.h +15 -6
  361. data/ext/pg_query/include/{utils → postgres/utils}/bytea.h +1 -1
  362. data/ext/pg_query/include/{utils → postgres/utils}/catcache.h +1 -1
  363. data/ext/pg_query/include/{utils → postgres/utils}/date.h +37 -9
  364. data/ext/pg_query/include/{utils → postgres/utils}/datetime.h +41 -21
  365. data/ext/pg_query/include/{utils → postgres/utils}/datum.h +1 -1
  366. data/ext/pg_query/include/{utils → postgres/utils}/dsa.h +5 -1
  367. data/ext/pg_query/include/{utils → postgres/utils}/elog.h +104 -29
  368. data/ext/pg_query/include/{utils → postgres/utils}/expandeddatum.h +14 -3
  369. data/ext/pg_query/include/{utils → postgres/utils}/expandedrecord.h +14 -4
  370. data/ext/pg_query/include/{utils → postgres/utils}/float.h +7 -6
  371. data/ext/pg_query/include/{utils → postgres/utils}/fmgroids.h +54 -1
  372. data/ext/pg_query/include/{utils → postgres/utils}/fmgrprotos.h +45 -3
  373. data/ext/pg_query/include/{utils → postgres/utils}/fmgrtab.h +1 -1
  374. data/ext/pg_query/include/{utils → postgres/utils}/guc.h +59 -86
  375. data/ext/pg_query/include/postgres/utils/guc_hooks.h +163 -0
  376. data/ext/pg_query/include/{utils → postgres/utils}/guc_tables.h +49 -3
  377. data/ext/pg_query/include/{utils → postgres/utils}/hsearch.h +1 -1
  378. data/ext/pg_query/include/{utils → postgres/utils}/inval.h +3 -3
  379. data/ext/pg_query/include/postgres/utils/logtape.h +77 -0
  380. data/ext/pg_query/include/{utils → postgres/utils}/lsyscache.h +5 -1
  381. data/ext/pg_query/include/{utils → postgres/utils}/memdebug.h +1 -1
  382. data/ext/pg_query/include/{utils → postgres/utils}/memutils.h +7 -51
  383. data/ext/pg_query/include/postgres/utils/memutils_internal.h +136 -0
  384. data/ext/pg_query/include/postgres/utils/memutils_memorychunk.h +237 -0
  385. data/ext/pg_query/include/{utils → postgres/utils}/numeric.h +20 -5
  386. data/ext/pg_query/include/{utils → postgres/utils}/palloc.h +9 -2
  387. data/ext/pg_query/include/{utils → postgres/utils}/partcache.h +3 -2
  388. data/ext/pg_query/include/{utils → postgres/utils}/pg_locale.h +22 -14
  389. data/ext/pg_query/include/{utils → postgres/utils}/pgstat_internal.h +37 -7
  390. data/ext/pg_query/include/{utils → postgres/utils}/plancache.h +1 -1
  391. data/ext/pg_query/include/{utils → postgres/utils}/portal.h +1 -1
  392. data/ext/pg_query/include/{utils → postgres/utils}/probes.h +6 -6
  393. data/ext/pg_query/include/postgres/utils/ps_status.h +47 -0
  394. data/ext/pg_query/include/{utils → postgres/utils}/queryenvironment.h +1 -1
  395. data/ext/pg_query/include/{utils → postgres/utils}/regproc.h +3 -3
  396. data/ext/pg_query/include/{utils → postgres/utils}/rel.h +60 -43
  397. data/ext/pg_query/include/{utils → postgres/utils}/relcache.h +13 -8
  398. data/ext/pg_query/include/{utils → postgres/utils}/reltrigger.h +1 -1
  399. data/ext/pg_query/include/{utils → postgres/utils}/resowner.h +1 -1
  400. data/ext/pg_query/include/{utils → postgres/utils}/ruleutils.h +6 -1
  401. data/ext/pg_query/include/{utils → postgres/utils}/sharedtuplestore.h +1 -1
  402. data/ext/pg_query/include/{utils → postgres/utils}/snapmgr.h +4 -2
  403. data/ext/pg_query/include/{utils → postgres/utils}/snapshot.h +1 -1
  404. data/ext/pg_query/include/{utils → postgres/utils}/sortsupport.h +2 -2
  405. data/ext/pg_query/include/{utils → postgres/utils}/syscache.h +4 -1
  406. data/ext/pg_query/include/{utils → postgres/utils}/timeout.h +1 -1
  407. data/ext/pg_query/include/{utils → postgres/utils}/timestamp.h +41 -11
  408. data/ext/pg_query/include/{utils → postgres/utils}/tuplesort.h +189 -35
  409. data/ext/pg_query/include/{utils → postgres/utils}/tuplestore.h +1 -1
  410. data/ext/pg_query/include/{utils → postgres/utils}/typcache.h +1 -1
  411. data/ext/pg_query/include/{utils → postgres/utils}/varlena.h +13 -1
  412. data/ext/pg_query/include/{utils → postgres/utils}/wait_event.h +9 -4
  413. data/ext/pg_query/include/{utils → postgres/utils}/xml.h +15 -5
  414. data/ext/pg_query/include/{postgres.h → postgres/varatt.h} +7 -457
  415. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +6186 -5585
  416. data/ext/pg_query/include/protobuf/pg_query.pb.h +112443 -91222
  417. data/ext/pg_query/pg_query.c +10 -1
  418. data/ext/pg_query/pg_query.pb-c.c +19755 -17757
  419. data/ext/pg_query/pg_query_fingerprint.c +12 -8
  420. data/ext/pg_query/pg_query_fingerprint.h +1 -1
  421. data/ext/pg_query/pg_query_internal.h +1 -1
  422. data/ext/pg_query/pg_query_json_plpgsql.c +1 -0
  423. data/ext/pg_query/pg_query_normalize.c +1 -1
  424. data/ext/pg_query/pg_query_outfuncs_json.c +6 -0
  425. data/ext/pg_query/pg_query_outfuncs_protobuf.c +3 -2
  426. data/ext/pg_query/pg_query_parse.c +47 -5
  427. data/ext/pg_query/pg_query_parse_plpgsql.c +7 -5
  428. data/ext/pg_query/pg_query_readfuncs_protobuf.c +1 -0
  429. data/ext/pg_query/pg_query_ruby.c +5 -0
  430. data/ext/pg_query/pg_query_scan.c +1 -1
  431. data/ext/pg_query/pg_query_split.c +3 -3
  432. data/ext/pg_query/postgres_deparse.c +503 -105
  433. data/ext/pg_query/src_backend_catalog_namespace.c +7 -2
  434. data/ext/pg_query/src_backend_catalog_pg_proc.c +1 -1
  435. data/ext/pg_query/src_backend_commands_define.c +1 -1
  436. data/ext/pg_query/src_backend_nodes_bitmapset.c +11 -70
  437. data/ext/pg_query/src_backend_nodes_copyfuncs.c +96 -6202
  438. data/ext/pg_query/src_backend_nodes_equalfuncs.c +95 -4068
  439. data/ext/pg_query/src_backend_nodes_extensible.c +6 -29
  440. data/ext/pg_query/src_backend_nodes_list.c +14 -2
  441. data/ext/pg_query/src_backend_nodes_makefuncs.c +95 -1
  442. data/ext/pg_query/src_backend_nodes_nodeFuncs.c +283 -132
  443. data/ext/pg_query/src_backend_nodes_nodes.c +38 -0
  444. data/ext/pg_query/src_backend_nodes_value.c +1 -1
  445. data/ext/pg_query/src_backend_parser_gram.c +33208 -31806
  446. data/ext/pg_query/src_backend_parser_parser.c +28 -2
  447. data/ext/pg_query/src_backend_parser_scan.c +4318 -3329
  448. data/ext/pg_query/src_backend_parser_scansup.c +1 -1
  449. data/ext/pg_query/src_backend_storage_ipc_ipc.c +1 -1
  450. data/ext/pg_query/src_backend_tcop_postgres.c +66 -87
  451. data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +1 -1
  452. data/ext/pg_query/src_backend_utils_adt_datum.c +5 -7
  453. data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +1 -1
  454. data/ext/pg_query/src_backend_utils_adt_format_type.c +1 -1
  455. data/ext/pg_query/src_backend_utils_adt_numutils.c +489 -0
  456. data/ext/pg_query/src_backend_utils_adt_ruleutils.c +79 -5
  457. data/ext/pg_query/src_backend_utils_error_assert.c +4 -7
  458. data/ext/pg_query/src_backend_utils_error_elog.c +371 -249
  459. data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +33 -1
  460. data/ext/pg_query/src_backend_utils_init_globals.c +6 -3
  461. data/ext/pg_query/src_backend_utils_mb_mbutils.c +21 -67
  462. data/ext/pg_query/src_backend_utils_misc_guc_tables.c +492 -0
  463. data/ext/pg_query/src_backend_utils_mmgr_alignedalloc.c +163 -0
  464. data/ext/pg_query/src_backend_utils_mmgr_aset.c +449 -312
  465. data/ext/pg_query/src_backend_utils_mmgr_generation.c +1039 -0
  466. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +398 -49
  467. data/ext/pg_query/src_backend_utils_mmgr_slab.c +1021 -0
  468. data/ext/pg_query/src_common_encnames.c +4 -1
  469. data/ext/pg_query/src_common_hashfn.c +1 -1
  470. data/ext/pg_query/src_common_keywords.c +1 -1
  471. data/ext/pg_query/src_common_kwlist_d.h +534 -510
  472. data/ext/pg_query/src_common_kwlookup.c +1 -1
  473. data/ext/pg_query/src_common_psprintf.c +1 -1
  474. data/ext/pg_query/src_common_stringinfo.c +4 -4
  475. data/ext/pg_query/src_common_wchar.c +9 -8
  476. data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +1 -1
  477. data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +3 -1
  478. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +661 -694
  479. data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +1 -1
  480. data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +1 -1
  481. data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +1 -1
  482. data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +48 -46
  483. data/ext/pg_query/src_port_pg_bitutils.c +79 -5
  484. data/ext/pg_query/src_port_pgstrcasecmp.c +29 -1
  485. data/ext/pg_query/src_port_snprintf.c +6 -10
  486. data/ext/pg_query/src_port_strerror.c +1 -1
  487. data/ext/pg_query/src_port_strlcpy.c +79 -0
  488. data/lib/pg_query/fingerprint.rb +2 -3
  489. data/lib/pg_query/node.rb +16 -11
  490. data/lib/pg_query/parse.rb +1 -1
  491. data/lib/pg_query/pg_query_pb.rb +166 -3191
  492. data/lib/pg_query/treewalker.rb +23 -5
  493. data/lib/pg_query/version.rb +1 -1
  494. metadata +432 -383
  495. data/ext/pg_query/guc-file.c +0 -0
  496. data/ext/pg_query/include/catalog/pg_parameter_acl.h +0 -60
  497. data/ext/pg_query/include/catalog/pg_parameter_acl_d.h +0 -34
  498. data/ext/pg_query/include/commands/variable.h +0 -38
  499. data/ext/pg_query/include/common/ip.h +0 -31
  500. data/ext/pg_query/include/getaddrinfo.h +0 -162
  501. data/ext/pg_query/include/kwlist_d.h +0 -1095
  502. data/ext/pg_query/include/parser/gram.h +0 -1101
  503. data/ext/pg_query/include/pg_config_os.h +0 -8
  504. data/ext/pg_query/include/portability/instr_time.h +0 -256
  505. data/ext/pg_query/include/postmaster/auxprocess.h +0 -20
  506. data/ext/pg_query/include/postmaster/fork_process.h +0 -17
  507. data/ext/pg_query/include/postmaster/pgarch.h +0 -73
  508. data/ext/pg_query/include/replication/logicalworker.h +0 -19
  509. data/ext/pg_query/include/storage/relfilenode.h +0 -99
  510. data/ext/pg_query/include/utils/dynahash.h +0 -20
  511. data/ext/pg_query/include/utils/pg_lsn.h +0 -29
  512. data/ext/pg_query/include/utils/pidfile.h +0 -56
  513. data/ext/pg_query/include/utils/ps_status.h +0 -25
  514. data/ext/pg_query/include/utils/rls.h +0 -50
  515. data/ext/pg_query/include/utils/tzparser.h +0 -39
  516. data/ext/pg_query/src_backend_postmaster_postmaster.c +0 -2201
  517. data/ext/pg_query/src_backend_storage_lmgr_s_lock.c +0 -371
  518. data/ext/pg_query/src_backend_utils_hash_dynahash.c +0 -1116
  519. data/ext/pg_query/src_backend_utils_misc_guc.c +0 -1993
  520. data/ext/pg_query/src_common_pg_prng.c +0 -152
  521. data/ext/pg_query/src_common_string.c +0 -92
  522. data/ext/pg_query/src_port_pgsleep.c +0 -69
  523. data/ext/pg_query/src_port_strnlen.c +0 -39
  524. /data/ext/pg_query/include/{access → postgres/access}/rmgr.h +0 -0
  525. /data/ext/pg_query/include/{pg_config_ext.h → postgres/pg_config_ext.h} +0 -0
  526. /data/ext/pg_query/include/{plerrcodes.h → postgres/plerrcodes.h} +0 -0
  527. /data/ext/pg_query/include/{storage → postgres/storage}/lwlocknames.h +0 -0
  528. /data/ext/pg_query/include/{utils → postgres/utils}/errcodes.h +0 -0
@@ -10,10 +10,21 @@
10
10
  * - MemoryContextCallResetCallbacks
11
11
  * - MemoryContextResetOnly
12
12
  * - repalloc
13
+ * - GetMemoryChunkContext
13
14
  * - MemoryContextStats
14
15
  * - MemoryContextStatsDetail
15
16
  * - MemoryContextStatsInternal
16
17
  * - MemoryContextStatsPrint
18
+ * - mcxt_methods
19
+ * - GetMemoryChunkSpace
20
+ * - MemoryContextAllocAligned
21
+ * - MemoryContextAllocExtended
22
+ * - BogusFree
23
+ * - GetMemoryChunkHeader
24
+ * - BogusRealloc
25
+ * - BogusGetChunkContext
26
+ * - BogusGetChunkSpace
27
+ * - GetMemoryChunkMethodID
17
28
  * - pfree
18
29
  * - pstrdup
19
30
  * - MemoryContextStrdup
@@ -43,7 +54,7 @@
43
54
  * context's MemoryContextMethods struct.
44
55
  *
45
56
  *
46
- * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
57
+ * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
47
58
  * Portions Copyright (c) 1994, Regents of the University of California
48
59
  *
49
60
  *
@@ -63,12 +74,105 @@
63
74
  #include "utils/fmgrprotos.h"
64
75
  #include "utils/memdebug.h"
65
76
  #include "utils/memutils.h"
77
+ #include "utils/memutils_internal.h"
78
+ #include "utils/memutils_memorychunk.h"
79
+
66
80
 
81
+ static void BogusFree(void *pointer);
82
+ static void *BogusRealloc(void *pointer, Size size);
83
+ static MemoryContext BogusGetChunkContext(void *pointer);
84
+ static Size BogusGetChunkSpace(void *pointer);
67
85
 
68
86
  /*****************************************************************************
69
87
  * GLOBAL MEMORY *
70
88
  *****************************************************************************/
71
89
 
90
+ static const MemoryContextMethods mcxt_methods[] = {
91
+ /* aset.c */
92
+ [MCTX_ASET_ID].alloc = AllocSetAlloc,
93
+ [MCTX_ASET_ID].free_p = AllocSetFree,
94
+ [MCTX_ASET_ID].realloc = AllocSetRealloc,
95
+ [MCTX_ASET_ID].reset = AllocSetReset,
96
+ [MCTX_ASET_ID].delete_context = AllocSetDelete,
97
+ [MCTX_ASET_ID].get_chunk_context = AllocSetGetChunkContext,
98
+ [MCTX_ASET_ID].get_chunk_space = AllocSetGetChunkSpace,
99
+ [MCTX_ASET_ID].is_empty = AllocSetIsEmpty,
100
+ [MCTX_ASET_ID].stats = AllocSetStats,
101
+ #ifdef MEMORY_CONTEXT_CHECKING
102
+ [MCTX_ASET_ID].check = AllocSetCheck,
103
+ #endif
104
+
105
+ /* generation.c */
106
+ [MCTX_GENERATION_ID].alloc = GenerationAlloc,
107
+ [MCTX_GENERATION_ID].free_p = GenerationFree,
108
+ [MCTX_GENERATION_ID].realloc = GenerationRealloc,
109
+ [MCTX_GENERATION_ID].reset = GenerationReset,
110
+ [MCTX_GENERATION_ID].delete_context = GenerationDelete,
111
+ [MCTX_GENERATION_ID].get_chunk_context = GenerationGetChunkContext,
112
+ [MCTX_GENERATION_ID].get_chunk_space = GenerationGetChunkSpace,
113
+ [MCTX_GENERATION_ID].is_empty = GenerationIsEmpty,
114
+ [MCTX_GENERATION_ID].stats = GenerationStats,
115
+ #ifdef MEMORY_CONTEXT_CHECKING
116
+ [MCTX_GENERATION_ID].check = GenerationCheck,
117
+ #endif
118
+
119
+ /* slab.c */
120
+ [MCTX_SLAB_ID].alloc = SlabAlloc,
121
+ [MCTX_SLAB_ID].free_p = SlabFree,
122
+ [MCTX_SLAB_ID].realloc = SlabRealloc,
123
+ [MCTX_SLAB_ID].reset = SlabReset,
124
+ [MCTX_SLAB_ID].delete_context = SlabDelete,
125
+ [MCTX_SLAB_ID].get_chunk_context = SlabGetChunkContext,
126
+ [MCTX_SLAB_ID].get_chunk_space = SlabGetChunkSpace,
127
+ [MCTX_SLAB_ID].is_empty = SlabIsEmpty,
128
+ [MCTX_SLAB_ID].stats = SlabStats,
129
+ #ifdef MEMORY_CONTEXT_CHECKING
130
+ [MCTX_SLAB_ID].check = SlabCheck,
131
+ #endif
132
+
133
+ /* alignedalloc.c */
134
+ [MCTX_ALIGNED_REDIRECT_ID].alloc = NULL, /* not required */
135
+ [MCTX_ALIGNED_REDIRECT_ID].free_p = AlignedAllocFree,
136
+ [MCTX_ALIGNED_REDIRECT_ID].realloc = AlignedAllocRealloc,
137
+ [MCTX_ALIGNED_REDIRECT_ID].reset = NULL, /* not required */
138
+ [MCTX_ALIGNED_REDIRECT_ID].delete_context = NULL, /* not required */
139
+ [MCTX_ALIGNED_REDIRECT_ID].get_chunk_context = AlignedAllocGetChunkContext,
140
+ [MCTX_ALIGNED_REDIRECT_ID].get_chunk_space = AlignedAllocGetChunkSpace,
141
+ [MCTX_ALIGNED_REDIRECT_ID].is_empty = NULL, /* not required */
142
+ [MCTX_ALIGNED_REDIRECT_ID].stats = NULL, /* not required */
143
+ #ifdef MEMORY_CONTEXT_CHECKING
144
+ [MCTX_ALIGNED_REDIRECT_ID].check = NULL, /* not required */
145
+ #endif
146
+
147
+
148
+ /*
149
+ * Unused (as yet) IDs should have dummy entries here. This allows us to
150
+ * fail cleanly if a bogus pointer is passed to pfree or the like. It
151
+ * seems sufficient to provide routines for the methods that might get
152
+ * invoked from inspection of a chunk (see MCXT_METHOD calls below).
153
+ */
154
+
155
+ [MCTX_UNUSED1_ID].free_p = BogusFree,
156
+ [MCTX_UNUSED1_ID].realloc = BogusRealloc,
157
+ [MCTX_UNUSED1_ID].get_chunk_context = BogusGetChunkContext,
158
+ [MCTX_UNUSED1_ID].get_chunk_space = BogusGetChunkSpace,
159
+
160
+ [MCTX_UNUSED2_ID].free_p = BogusFree,
161
+ [MCTX_UNUSED2_ID].realloc = BogusRealloc,
162
+ [MCTX_UNUSED2_ID].get_chunk_context = BogusGetChunkContext,
163
+ [MCTX_UNUSED2_ID].get_chunk_space = BogusGetChunkSpace,
164
+
165
+ [MCTX_UNUSED3_ID].free_p = BogusFree,
166
+ [MCTX_UNUSED3_ID].realloc = BogusRealloc,
167
+ [MCTX_UNUSED3_ID].get_chunk_context = BogusGetChunkContext,
168
+ [MCTX_UNUSED3_ID].get_chunk_space = BogusGetChunkSpace,
169
+
170
+ [MCTX_UNUSED4_ID].free_p = BogusFree,
171
+ [MCTX_UNUSED4_ID].realloc = BogusRealloc,
172
+ [MCTX_UNUSED4_ID].get_chunk_context = BogusGetChunkContext,
173
+ [MCTX_UNUSED4_ID].get_chunk_space = BogusGetChunkSpace,
174
+ };
175
+
72
176
  /*
73
177
  * CurrentMemoryContext
74
178
  * Default memory context for allocations.
@@ -110,6 +214,100 @@ static void MemoryContextStatsPrint(MemoryContext context, void *passthru,
110
214
  #define AssertNotInCriticalSection(context) \
111
215
  Assert(CritSectionCount == 0 || (context)->allowInCritSection)
112
216
 
217
+ /*
218
+ * Call the given function in the MemoryContextMethods for the memory context
219
+ * type that 'pointer' belongs to.
220
+ */
221
+ #define MCXT_METHOD(pointer, method) \
222
+ mcxt_methods[GetMemoryChunkMethodID(pointer)].method
223
+
224
+ /*
225
+ * GetMemoryChunkMethodID
226
+ * Return the MemoryContextMethodID from the uint64 chunk header which
227
+ * directly precedes 'pointer'.
228
+ */
229
+ static inline MemoryContextMethodID
230
+ GetMemoryChunkMethodID(const void *pointer)
231
+ {
232
+ uint64 header;
233
+
234
+ /*
235
+ * Try to detect bogus pointers handed to us, poorly though we can.
236
+ * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
237
+ * allocated chunk.
238
+ */
239
+ Assert(pointer == (const void *) MAXALIGN(pointer));
240
+
241
+ /* Allow access to the uint64 header */
242
+ VALGRIND_MAKE_MEM_DEFINED((char *) pointer - sizeof(uint64), sizeof(uint64));
243
+
244
+ header = *((const uint64 *) ((const char *) pointer - sizeof(uint64)));
245
+
246
+ /* Disallow access to the uint64 header */
247
+ VALGRIND_MAKE_MEM_NOACCESS((char *) pointer - sizeof(uint64), sizeof(uint64));
248
+
249
+ return (MemoryContextMethodID) (header & MEMORY_CONTEXT_METHODID_MASK);
250
+ }
251
+
252
+ /*
253
+ * GetMemoryChunkHeader
254
+ * Return the uint64 chunk header which directly precedes 'pointer'.
255
+ *
256
+ * This is only used after GetMemoryChunkMethodID, so no need for error checks.
257
+ */
258
+ static inline uint64
259
+ GetMemoryChunkHeader(const void *pointer)
260
+ {
261
+ uint64 header;
262
+
263
+ /* Allow access to the uint64 header */
264
+ VALGRIND_MAKE_MEM_DEFINED((char *) pointer - sizeof(uint64), sizeof(uint64));
265
+
266
+ header = *((const uint64 *) ((const char *) pointer - sizeof(uint64)));
267
+
268
+ /* Disallow access to the uint64 header */
269
+ VALGRIND_MAKE_MEM_NOACCESS((char *) pointer - sizeof(uint64), sizeof(uint64));
270
+
271
+ return header;
272
+ }
273
+
274
+ /*
275
+ * Support routines to trap use of invalid memory context method IDs
276
+ * (from calling pfree or the like on a bogus pointer). As a possible
277
+ * aid in debugging, we report the header word along with the pointer
278
+ * address (if we got here, there must be an accessible header word).
279
+ */
280
+ static void
281
+ BogusFree(void *pointer)
282
+ {
283
+ elog(ERROR, "pfree called with invalid pointer %p (header 0x%016llx)",
284
+ pointer, (unsigned long long) GetMemoryChunkHeader(pointer));
285
+ }
286
+
287
+ static void *
288
+ BogusRealloc(void *pointer, Size size)
289
+ {
290
+ elog(ERROR, "repalloc called with invalid pointer %p (header 0x%016llx)",
291
+ pointer, (unsigned long long) GetMemoryChunkHeader(pointer));
292
+ return NULL; /* keep compiler quiet */
293
+ }
294
+
295
+ static MemoryContext
296
+ BogusGetChunkContext(void *pointer)
297
+ {
298
+ elog(ERROR, "GetMemoryChunkContext called with invalid pointer %p (header 0x%016llx)",
299
+ pointer, (unsigned long long) GetMemoryChunkHeader(pointer));
300
+ return NULL; /* keep compiler quiet */
301
+ }
302
+
303
+ static Size
304
+ BogusGetChunkSpace(void *pointer)
305
+ {
306
+ elog(ERROR, "GetMemoryChunkSpace called with invalid pointer %p (header 0x%016llx)",
307
+ pointer, (unsigned long long) GetMemoryChunkHeader(pointer));
308
+ return 0; /* keep compiler quiet */
309
+ }
310
+
113
311
 
114
312
  /*****************************************************************************
115
313
  * EXPORTED ROUTINES *
@@ -135,7 +333,7 @@ static void MemoryContextStatsPrint(MemoryContext context, void *passthru,
135
333
  void
136
334
  MemoryContextInit(void)
137
335
  {
138
- AssertState(TopMemoryContext == NULL);
336
+ Assert(TopMemoryContext == NULL);
139
337
 
140
338
  /*
141
339
  * First, initialize TopMemoryContext, which is the parent of all others.
@@ -179,7 +377,7 @@ MemoryContextInit(void)
179
377
  void
180
378
  MemoryContextReset(MemoryContext context)
181
379
  {
182
- AssertArg(MemoryContextIsValid(context));
380
+ Assert(MemoryContextIsValid(context));
183
381
 
184
382
  /* save a function call in common case where there are no children */
185
383
  if (context->firstchild != NULL)
@@ -198,7 +396,7 @@ MemoryContextReset(MemoryContext context)
198
396
  void
199
397
  MemoryContextResetOnly(MemoryContext context)
200
398
  {
201
- AssertArg(MemoryContextIsValid(context));
399
+ Assert(MemoryContextIsValid(context));
202
400
 
203
401
  /* Nothing to do if no pallocs since startup or last reset */
204
402
  if (!context->isReset)
@@ -209,10 +407,8 @@ MemoryContextResetOnly(MemoryContext context)
209
407
  * If context->ident points into the context's memory, it will become
210
408
  * a dangling pointer. We could prevent that by setting it to NULL
211
409
  * here, but that would break valid coding patterns that keep the
212
- * ident elsewhere, e.g. in a parent context. Another idea is to use
213
- * MemoryContextContains(), but we don't require ident strings to be
214
- * in separately-palloc'd chunks, so that risks false positives. So
215
- * for now we assume the programmer got it right.
410
+ * ident elsewhere, e.g. in a parent context. So for now we assume
411
+ * the programmer got it right.
216
412
  */
217
413
 
218
414
  context->methods->reset(context);
@@ -242,7 +438,7 @@ MemoryContextResetOnly(MemoryContext context)
242
438
  void
243
439
  MemoryContextDelete(MemoryContext context)
244
440
  {
245
- AssertArg(MemoryContextIsValid(context));
441
+ Assert(MemoryContextIsValid(context));
246
442
  /* We had better not be deleting TopMemoryContext ... */
247
443
  Assert(context != TopMemoryContext);
248
444
  /* And not CurrentMemoryContext, either */
@@ -287,7 +483,7 @@ MemoryContextDelete(MemoryContext context)
287
483
  void
288
484
  MemoryContextDeleteChildren(MemoryContext context)
289
485
  {
290
- AssertArg(MemoryContextIsValid(context));
486
+ Assert(MemoryContextIsValid(context));
291
487
 
292
488
  /*
293
489
  * MemoryContextDelete will delink the child from me, so just iterate as
@@ -369,8 +565,8 @@ MemoryContextCallResetCallbacks(MemoryContext context)
369
565
  void
370
566
  MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
371
567
  {
372
- AssertArg(MemoryContextIsValid(context));
373
- AssertArg(context != new_parent);
568
+ Assert(MemoryContextIsValid(context));
569
+ Assert(context != new_parent);
374
570
 
375
571
  /* Fast path if it's got correct parent already */
376
572
  if (new_parent == context->parent)
@@ -396,7 +592,7 @@ MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
396
592
  /* And relink */
397
593
  if (new_parent)
398
594
  {
399
- AssertArg(MemoryContextIsValid(new_parent));
595
+ Assert(MemoryContextIsValid(new_parent));
400
596
  context->parent = new_parent;
401
597
  context->prevchild = NULL;
402
598
  context->nextchild = new_parent->firstchild;
@@ -426,11 +622,22 @@ MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
426
622
  void
427
623
  MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
428
624
  {
429
- AssertArg(MemoryContextIsValid(context));
625
+ Assert(MemoryContextIsValid(context));
430
626
 
431
627
  context->allowInCritSection = allow;
432
628
  }
433
629
 
630
+ /*
631
+ * GetMemoryChunkContext
632
+ * Given a currently-allocated chunk, determine the MemoryContext that
633
+ * the chunk belongs to.
634
+ */
635
+ MemoryContext
636
+ GetMemoryChunkContext(void *pointer)
637
+ {
638
+ return MCXT_METHOD(pointer, get_chunk_context) (pointer);
639
+ }
640
+
434
641
  /*
435
642
  * GetMemoryChunkSpace
436
643
  * Given a currently-allocated chunk, determine the total space
@@ -439,7 +646,11 @@ MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
439
646
  * This is useful for measuring the total space occupied by a set of
440
647
  * allocated chunks.
441
648
  */
442
-
649
+ Size
650
+ GetMemoryChunkSpace(void *pointer)
651
+ {
652
+ return MCXT_METHOD(pointer, get_chunk_space) (pointer);
653
+ }
443
654
 
444
655
  /*
445
656
  * MemoryContextGetParent
@@ -505,10 +716,10 @@ MemoryContextStatsDetail(MemoryContext context, int max_children,
505
716
  * to the connected client.
506
717
  *
507
718
  * We don't buffer the information about all memory contexts in a
508
- * backend into StringInfo and log it as one message. Otherwise which
509
- * may require the buffer to be enlarged very much and lead to OOM
510
- * error since there can be a large number of memory contexts in a
511
- * backend. Instead, we log one message per memory context.
719
+ * backend into StringInfo and log it as one message. That would
720
+ * require the buffer to be enlarged, risking an OOM as there could be
721
+ * a large number of memory contexts in a backend. Instead, we log
722
+ * one message per memory context.
512
723
  */
513
724
  ereport(LOG_SERVER_ONLY,
514
725
  (errhidestmt(true),
@@ -536,7 +747,7 @@ MemoryContextStatsInternal(MemoryContext context, int level,
536
747
  MemoryContext child;
537
748
  int ichild;
538
749
 
539
- AssertArg(MemoryContextIsValid(context));
750
+ Assert(MemoryContextIsValid(context));
540
751
 
541
752
  /* Examine the context itself */
542
753
  context->methods->stats(context,
@@ -699,19 +910,6 @@ MemoryContextStatsPrint(MemoryContext context, void *passthru,
699
910
 
700
911
  #endif
701
912
 
702
- /*
703
- * MemoryContextContains
704
- * Detect whether an allocated chunk of memory belongs to a given
705
- * context or not.
706
- *
707
- * Caution: this test is reliable as long as 'pointer' does point to
708
- * a chunk of memory allocated from *some* context. If 'pointer' points
709
- * at memory obtained in some other way, there is a small chance of a
710
- * false-positive result, since the bits right before it might look like
711
- * a valid chunk header by chance.
712
- */
713
-
714
-
715
913
  /*
716
914
  * MemoryContextCreate
717
915
  * Context-type-independent part of context creation.
@@ -737,7 +935,7 @@ MemoryContextStatsPrint(MemoryContext context, void *passthru,
737
935
  *
738
936
  * node: the as-yet-uninitialized common part of the context header node.
739
937
  * tag: NodeTag code identifying the memory context type.
740
- * methods: context-type-specific methods (usually statically allocated).
938
+ * method_id: MemoryContextMethodID of the context-type being created.
741
939
  * parent: parent context, or NULL if this will be a top-level context.
742
940
  * name: name of context (must be statically allocated).
743
941
  *
@@ -747,7 +945,7 @@ MemoryContextStatsPrint(MemoryContext context, void *passthru,
747
945
  void
748
946
  MemoryContextCreate(MemoryContext node,
749
947
  NodeTag tag,
750
- const MemoryContextMethods *methods,
948
+ MemoryContextMethodID method_id,
751
949
  MemoryContext parent,
752
950
  const char *name)
753
951
  {
@@ -757,7 +955,7 @@ MemoryContextCreate(MemoryContext node,
757
955
  /* Initialize all standard fields of memory context header */
758
956
  node->type = tag;
759
957
  node->isReset = true;
760
- node->methods = methods;
958
+ node->methods = &mcxt_methods[method_id];
761
959
  node->parent = parent;
762
960
  node->firstchild = NULL;
763
961
  node->mem_allocated = 0;
@@ -797,7 +995,7 @@ MemoryContextAlloc(MemoryContext context, Size size)
797
995
  {
798
996
  void *ret;
799
997
 
800
- AssertArg(MemoryContextIsValid(context));
998
+ Assert(MemoryContextIsValid(context));
801
999
  AssertNotInCriticalSection(context);
802
1000
 
803
1001
  if (!AllocSizeIsValid(size))
@@ -840,7 +1038,7 @@ MemoryContextAllocZero(MemoryContext context, Size size)
840
1038
  {
841
1039
  void *ret;
842
1040
 
843
- AssertArg(MemoryContextIsValid(context));
1041
+ Assert(MemoryContextIsValid(context));
844
1042
  AssertNotInCriticalSection(context);
845
1043
 
846
1044
  if (!AllocSizeIsValid(size))
@@ -878,7 +1076,7 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size)
878
1076
  {
879
1077
  void *ret;
880
1078
 
881
- AssertArg(MemoryContextIsValid(context));
1079
+ Assert(MemoryContextIsValid(context));
882
1080
  AssertNotInCriticalSection(context);
883
1081
 
884
1082
  if (!AllocSizeIsValid(size))
@@ -913,11 +1111,11 @@ MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
913
1111
  {
914
1112
  void *ret;
915
1113
 
916
- AssertArg(MemoryContextIsValid(context));
1114
+ Assert(MemoryContextIsValid(context));
917
1115
  AssertNotInCriticalSection(context);
918
1116
 
919
- if (((flags & MCXT_ALLOC_HUGE) != 0 && !AllocHugeSizeIsValid(size)) ||
920
- ((flags & MCXT_ALLOC_HUGE) == 0 && !AllocSizeIsValid(size)))
1117
+ if (!((flags & MCXT_ALLOC_HUGE) != 0 ? AllocHugeSizeIsValid(size) :
1118
+ AllocSizeIsValid(size)))
921
1119
  elog(ERROR, "invalid memory alloc request size %zu", size);
922
1120
 
923
1121
  context->isReset = false;
@@ -973,7 +1171,7 @@ palloc(Size size)
973
1171
  void *ret;
974
1172
  MemoryContext context = CurrentMemoryContext;
975
1173
 
976
- AssertArg(MemoryContextIsValid(context));
1174
+ Assert(MemoryContextIsValid(context));
977
1175
  AssertNotInCriticalSection(context);
978
1176
 
979
1177
  if (!AllocSizeIsValid(size))
@@ -1004,7 +1202,7 @@ palloc0(Size size)
1004
1202
  void *ret;
1005
1203
  MemoryContext context = CurrentMemoryContext;
1006
1204
 
1007
- AssertArg(MemoryContextIsValid(context));
1205
+ Assert(MemoryContextIsValid(context));
1008
1206
  AssertNotInCriticalSection(context);
1009
1207
 
1010
1208
  if (!AllocSizeIsValid(size))
@@ -1032,6 +1230,125 @@ palloc0(Size size)
1032
1230
 
1033
1231
 
1034
1232
 
1233
+ /*
1234
+ * MemoryContextAllocAligned
1235
+ * Allocate 'size' bytes of memory in 'context' aligned to 'alignto'
1236
+ * bytes.
1237
+ *
1238
+ * Currently, we align addresses by requesting additional bytes from the
1239
+ * MemoryContext's standard allocator function and then aligning the returned
1240
+ * address by the required alignment. This means that the given MemoryContext
1241
+ * must support providing us with a chunk of memory that's larger than 'size'.
1242
+ * For allocators such as Slab, that's not going to work, as slab only allows
1243
+ * chunks of the size that's specified when the context is created.
1244
+ *
1245
+ * 'alignto' must be a power of 2.
1246
+ * 'flags' may be 0 or set the same as MemoryContextAllocExtended().
1247
+ */
1248
+ void *
1249
+ MemoryContextAllocAligned(MemoryContext context,
1250
+ Size size, Size alignto, int flags)
1251
+ {
1252
+ MemoryChunk *alignedchunk;
1253
+ Size alloc_size;
1254
+ void *unaligned;
1255
+ void *aligned;
1256
+
1257
+ /* wouldn't make much sense to waste that much space */
1258
+ Assert(alignto < (128 * 1024 * 1024));
1259
+
1260
+ /* ensure alignto is a power of 2 */
1261
+ Assert((alignto & (alignto - 1)) == 0);
1262
+
1263
+ /*
1264
+ * If the alignment requirements are less than what we already guarantee
1265
+ * then just use the standard allocation function.
1266
+ */
1267
+ if (unlikely(alignto <= MAXIMUM_ALIGNOF))
1268
+ return MemoryContextAllocExtended(context, size, flags);
1269
+
1270
+ /*
1271
+ * We implement aligned pointers by simply allocating enough memory for
1272
+ * the requested size plus the alignment and an additional "redirection"
1273
+ * MemoryChunk. This additional MemoryChunk is required for operations
1274
+ * such as pfree when used on the pointer returned by this function. We
1275
+ * use this redirection MemoryChunk in order to find the pointer to the
1276
+ * memory that was returned by the MemoryContextAllocExtended call below.
1277
+ * We do that by "borrowing" the block offset field and instead of using
1278
+ * that to find the offset into the owning block, we use it to find the
1279
+ * original allocated address.
1280
+ *
1281
+ * Here we must allocate enough extra memory so that we can still align
1282
+ * the pointer returned by MemoryContextAllocExtended and also have enough
1283
+ * space for the redirection MemoryChunk. Since allocations will already
1284
+ * be at least aligned by MAXIMUM_ALIGNOF, we can subtract that amount
1285
+ * from the allocation size to save a little memory.
1286
+ */
1287
+ alloc_size = size + PallocAlignedExtraBytes(alignto);
1288
+
1289
+ #ifdef MEMORY_CONTEXT_CHECKING
1290
+ /* ensure there's space for a sentinel byte */
1291
+ alloc_size += 1;
1292
+ #endif
1293
+
1294
+ /* perform the actual allocation */
1295
+ unaligned = MemoryContextAllocExtended(context, alloc_size, flags);
1296
+
1297
+ /* set the aligned pointer */
1298
+ aligned = (void *) TYPEALIGN(alignto, (char *) unaligned +
1299
+ sizeof(MemoryChunk));
1300
+
1301
+ alignedchunk = PointerGetMemoryChunk(aligned);
1302
+
1303
+ /*
1304
+ * We set the redirect MemoryChunk so that the block offset calculation is
1305
+ * used to point back to the 'unaligned' allocated chunk. This allows us
1306
+ * to use MemoryChunkGetBlock() to find the unaligned chunk when we need
1307
+ * to perform operations such as pfree() and repalloc().
1308
+ *
1309
+ * We store 'alignto' in the MemoryChunk's 'value' so that we know what
1310
+ * the alignment was set to should we ever be asked to realloc this
1311
+ * pointer.
1312
+ */
1313
+ MemoryChunkSetHdrMask(alignedchunk, unaligned, alignto,
1314
+ MCTX_ALIGNED_REDIRECT_ID);
1315
+
1316
+ /* double check we produced a correctly aligned pointer */
1317
+ Assert((void *) TYPEALIGN(alignto, aligned) == aligned);
1318
+
1319
+ #ifdef MEMORY_CONTEXT_CHECKING
1320
+ alignedchunk->requested_size = size;
1321
+ /* set mark to catch clobber of "unused" space */
1322
+ set_sentinel(aligned, size);
1323
+ #endif
1324
+
1325
+ /* Mark the bytes before the redirection header as noaccess */
1326
+ VALGRIND_MAKE_MEM_NOACCESS(unaligned,
1327
+ (char *) alignedchunk - (char *) unaligned);
1328
+
1329
+ /* Disallow access to the redirection chunk header. */
1330
+ VALGRIND_MAKE_MEM_NOACCESS(alignedchunk, sizeof(MemoryChunk));
1331
+
1332
+ return aligned;
1333
+ }
1334
+
1335
+ /*
1336
+ * palloc_aligned
1337
+ * Allocate 'size' bytes returning a pointer that's aligned to the
1338
+ * 'alignto' boundary.
1339
+ *
1340
+ * Currently, we align addresses by requesting additional bytes from the
1341
+ * MemoryContext's standard allocator function and then aligning the returned
1342
+ * address by the required alignment. This means that the given MemoryContext
1343
+ * must support providing us with a chunk of memory that's larger than 'size'.
1344
+ * For allocators such as Slab, that's not going to work, as slab only allows
1345
+ * chunks of the size that's specified when the context is created.
1346
+ *
1347
+ * 'alignto' must be a power of 2.
1348
+ * 'flags' may be 0 or set the same as MemoryContextAllocExtended().
1349
+ */
1350
+
1351
+
1035
1352
  /*
1036
1353
  * pfree
1037
1354
  * Release an allocated chunk.
@@ -1039,10 +1356,17 @@ palloc0(Size size)
1039
1356
  void
1040
1357
  pfree(void *pointer)
1041
1358
  {
1359
+ #ifdef USE_VALGRIND
1360
+ MemoryContextMethodID method = GetMemoryChunkMethodID(pointer);
1042
1361
  MemoryContext context = GetMemoryChunkContext(pointer);
1362
+ #endif
1363
+
1364
+ MCXT_METHOD(pointer, free_p) (pointer);
1043
1365
 
1044
- context->methods->free_p(context, pointer);
1045
- VALGRIND_MEMPOOL_FREE(context, pointer);
1366
+ #ifdef USE_VALGRIND
1367
+ if (method != MCTX_ALIGNED_REDIRECT_ID)
1368
+ VALGRIND_MEMPOOL_FREE(context, pointer);
1369
+ #endif
1046
1370
  }
1047
1371
 
1048
1372
  /*
@@ -1052,7 +1376,12 @@ pfree(void *pointer)
1052
1376
  void *
1053
1377
  repalloc(void *pointer, Size size)
1054
1378
  {
1379
+ #ifdef USE_VALGRIND
1380
+ MemoryContextMethodID method = GetMemoryChunkMethodID(pointer);
1381
+ #endif
1382
+ #if defined(USE_ASSERT_CHECKING) || defined(USE_VALGRIND)
1055
1383
  MemoryContext context = GetMemoryChunkContext(pointer);
1384
+ #endif
1056
1385
  void *ret;
1057
1386
 
1058
1387
  if (!AllocSizeIsValid(size))
@@ -1063,22 +1392,42 @@ repalloc(void *pointer, Size size)
1063
1392
  /* isReset must be false already */
1064
1393
  Assert(!context->isReset);
1065
1394
 
1066
- ret = context->methods->realloc(context, pointer, size);
1395
+ ret = MCXT_METHOD(pointer, realloc) (pointer, size);
1067
1396
  if (unlikely(ret == NULL))
1068
1397
  {
1398
+ MemoryContext cxt = GetMemoryChunkContext(pointer);
1399
+
1069
1400
  MemoryContextStats(TopMemoryContext);
1070
1401
  ereport(ERROR,
1071
1402
  (errcode(ERRCODE_OUT_OF_MEMORY),
1072
1403
  errmsg("out of memory"),
1073
1404
  errdetail("Failed on request of size %zu in memory context \"%s\".",
1074
- size, context->name)));
1405
+ size, cxt->name)));
1075
1406
  }
1076
1407
 
1077
- VALGRIND_MEMPOOL_CHANGE(context, pointer, ret, size);
1408
+ #ifdef USE_VALGRIND
1409
+ if (method != MCTX_ALIGNED_REDIRECT_ID)
1410
+ VALGRIND_MEMPOOL_CHANGE(context, pointer, ret, size);
1411
+ #endif
1078
1412
 
1079
1413
  return ret;
1080
1414
  }
1081
1415
 
1416
+ /*
1417
+ * repalloc_extended
1418
+ * Adjust the size of a previously allocated chunk,
1419
+ * with HUGE and NO_OOM options.
1420
+ */
1421
+ #if defined(USE_ASSERT_CHECKING) || defined(USE_VALGRIND)
1422
+ #endif
1423
+
1424
+ /*
1425
+ * repalloc0
1426
+ * Adjust the size of a previously allocated chunk and zero out the added
1427
+ * space.
1428
+ */
1429
+
1430
+
1082
1431
  /*
1083
1432
  * MemoryContextAllocHuge
1084
1433
  * Allocate (possibly-expansive) space within the specified context.