_actions.c revision 2639
49N/A * CDDL HEADER START 49N/A * The contents of this file are subject to the terms of the 49N/A * Common Development and Distribution License (the "License"). 49N/A * You may not use this file except in compliance with the License. 49N/A * See the License for the specific language governing permissions 49N/A * and limitations under the License. 49N/A * When distributing Covered Code, include this CDDL HEADER in each 49N/A * If applicable, add the following below this CDDL HEADER, with the 49N/A * fields enclosed by brackets "[]" replaced with your own identifying 49N/A * information: Portions Copyright [yyyy] [name of copyright owner] 49N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. 49N/Astatic const char *
notident =
"hash attribute not identical to positional hash";
49N/A /* PyList_SET_ITEM steals references. */ 873N/A * If malformed() or invalid() are used, CLEANUP_REFS can only be used 873N/A * after. Likewise, PyMem_Free(str) should not be called before using 873N/A * malformed() or invalid(). Failure to order this properly will cause 873N/A * corruption of the exception messages. 873N/A * Positional arguments must be included in the keyword argument list in 591N/A * the order you want them to be assigned. (A subtle point missing from 591N/A * the Python documentation.) 1292N/A /* Assume data=None by default. */ 1292N/A * The action string is currently assumed to be a stream of bytes that 873N/A * are valid UTF-8. This method works regardless of whether the string 873N/A * object provided is a Unicode object, string object, or a character 873N/A * The comparisons here are ordered by frequency in which actions are 542N/A * most likely to be encountered in usage by the client grouped by 873N/A * length. Yes, a cheap hack to squeeze a tiny bit of additional 305N/A * Unable to build argument list for exception; so raise 305N/A * general type exception instead. 1500N/A * Pool attribute key to reduce memory usage and 1500N/A * potentially improve lookup performance. 1500N/A * "slashmap" is a list of the positions of the 1500N/A * backslashes that need to be removed from the * Terminate slashmap with an invalid * value so we don't think there's a * slash right at the beginning. * Keep slashmap properly terminated so * that a realloc()ed array doesn't give * us random slash positions. * Copy the attribute from str into * sattr, removing backslashes as * slashmap indicates we should. for (j = 0, o = 0; j <
attrlen; j++) {
if (
str[i] ==
' ' ||
str[i] ==
'\t') {
if (
str[i] !=
' ' &&
str[i] !=
'\t') {
* UQVAL is the most frequently encountered end-state, so check that * first to avoid unnecessary state comparisons. * Action parsing is done; now build the list of arguments to construct * Using the cached action class assigned earlier based on the type, * call the action constructor, set the hash attribute, and then return * Note that module initialization functions are void and may not return * a value. However, they should set an exception if appropriate. * We need to retrieve the MalformedActionError object from pkg.actions. * We can't import pkg.actions directly, because that would result in a * circular dependency. But the "sys" module has a dict called * "modules" which maps loaded module names to the corresponding module * objects. We can then grab the exception from those objects. /* No exception is set */ * Each reference is DECREF'd after retrieval as Python 2.x doesn't * guaranteed to stay around until the module is unloaded, DECREF'ing * them now ensures that garbage cleanup will work as expected during * process exit. This applies to the action type caching below as well. * Retrieve the list of action types and then store a reference to each * class for use during action construction. (This allows avoiding the * overhead of retrieving a new reference for each action constructed.) * cache_class borrows the references to the action type objects; this * is safe as they should remain valid as long as the module is loaded. * (PyDict_GetItem* doesn't return a new reference.) "Action type class missing: " name); \