* Create a new PLyProcedure structure */
| 130 | * Create a new PLyProcedure structure |
| 131 | */ |
| 132 | static PLyProcedure * |
| 133 | PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger) |
| 134 | { |
| 135 | char procName[NAMEDATALEN + 256]; |
| 136 | Form_pg_proc procStruct; |
| 137 | PLyProcedure *volatile proc; |
| 138 | MemoryContext cxt; |
| 139 | MemoryContext oldcxt; |
| 140 | int rv; |
| 141 | char *ptr; |
| 142 | |
| 143 | procStruct = (Form_pg_proc) GETSTRUCT(procTup); |
| 144 | rv = snprintf(procName, sizeof(procName), |
| 145 | "__plpython_procedure_%s_%u", |
| 146 | NameStr(procStruct->proname), |
| 147 | fn_oid); |
| 148 | if (rv >= sizeof(procName) || rv < 0) |
| 149 | elog(ERROR, "procedure name would overrun buffer"); |
| 150 | |
| 151 | /* Replace any not-legal-in-Python-names characters with '_' */ |
| 152 | for (ptr = procName; *ptr; ptr++) |
| 153 | { |
| 154 | if (!((*ptr >= 'A' && *ptr <= 'Z') || |
| 155 | (*ptr >= 'a' && *ptr <= 'z') || |
| 156 | (*ptr >= '0' && *ptr <= '9'))) |
| 157 | *ptr = '_'; |
| 158 | } |
| 159 | |
| 160 | /* Create long-lived context that all procedure info will live in */ |
| 161 | cxt = AllocSetContextCreate(TopMemoryContext, |
| 162 | "PL/Python function", |
| 163 | ALLOCSET_DEFAULT_SIZES); |
| 164 | |
| 165 | oldcxt = MemoryContextSwitchTo(cxt); |
| 166 | |
| 167 | proc = (PLyProcedure *) palloc0(sizeof(PLyProcedure)); |
| 168 | proc->mcxt = cxt; |
| 169 | |
| 170 | PG_TRY(); |
| 171 | { |
| 172 | Datum protrftypes_datum; |
| 173 | Datum prosrcdatum; |
| 174 | bool isnull; |
| 175 | char *procSource; |
| 176 | int i; |
| 177 | |
| 178 | proc->proname = pstrdup(NameStr(procStruct->proname)); |
| 179 | MemoryContextSetIdentifier(cxt, proc->proname); |
| 180 | proc->pyname = pstrdup(procName); |
| 181 | proc->fn_xmin = HeapTupleHeaderGetRawXmin(procTup->t_data); |
| 182 | proc->fn_tid = procTup->t_self; |
| 183 | proc->fn_readonly = (procStruct->provolatile != PROVOLATILE_VOLATILE); |
| 184 | proc->is_setof = procStruct->proretset; |
| 185 | proc->is_procedure = (procStruct->prokind == PROKIND_PROCEDURE); |
| 186 | proc->is_trigger = is_trigger; |
| 187 | proc->src = NULL; |
| 188 | proc->argnames = NULL; |
| 189 | proc->args = NULL; |
no test coverage detected