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