repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | FILE_TIME_to_time_t_nsec | static void
FILE_TIME_to_time_t_nsec(FILETIME *in_ptr, time_t *time_out, int* nsec_out)
{
/* XXX endianness. Shouldn't matter, as all Windows implementations are little-endian */
/* Cannot simply cast and dereference in_ptr,
since it might not be aligned properly */
__int64 in;
memcpy(&in, in_ptr, sizeof(in));
*nsec_out = (int)(in % 10000000) * 100; /* FILETIME is in units of 100 nsec. */
*time_out = Py_SAFE_DOWNCAST((in / 10000000) - secs_between_epochs, __int64, time_t);
} | /* Seconds between 1.1.1601 and 1.1.1970 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/posixmodule.c#L1007-L1017 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | cmp_constdefs | static int
cmp_constdefs(const void *v1, const void *v2)
{
const struct constdef *c1 =
(const struct constdef *) v1;
const struct constdef *c2 =
(const struct constdef *) v2;
return strcmp(c1->name, c2->name);
} | /* This code is used to ensure that the tables of configuration value names
* are in sorted order as required by conv_confname(), and also to build the
* the exported dictionaries that are used to publish information about the
* names available on the host platform.
*
* Sorting the table at runtime ensures that the table is properly ordered
* when used, even for platforms we're not able to test on. It also makes
* it easier to add additional entries to the tables.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/posixmodule.c#L8516-L8525 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | setup_confname_tables | static int
setup_confname_tables(PyObject *module)
{
#if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
if (setup_confname_table(posix_constants_pathconf,
sizeof(posix_constants_pathconf)
/ sizeof(struct constdef),
"pathconf_names", module))
return -1;
#endif
#ifdef HAVE_CONFSTR
if (setup_confname_table(posix_constants_confstr,
sizeof(posix_constants_confstr)
/ sizeof(struct constdef),
"confstr_names", module))
return -1;
#endif
#ifdef HAVE_SYSCONF
if (setup_confname_table(posix_constants_sysconf,
sizeof(posix_constants_sysconf)
/ sizeof(struct constdef),
"sysconf_names", module))
return -1;
#endif
return 0;
} | /* Return -1 on failure, 0 on success. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/posixmodule.c#L8552-L8577 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | insertvalues | static int insertvalues(PyObject *module)
{
APIRET rc;
ULONG values[QSV_MAX+1];
PyObject *v;
char *ver, tmp[50];
Py_BEGIN_ALLOW_THREADS
rc = DosQuerySysInfo(1L, QSV_MAX, &values[1], sizeof(ULONG) * QSV_MAX);
Py_END_ALLOW_THREADS
if (rc != NO_ERROR) {
os2_error(rc);
return -1;
}
if (ins(module, "meminstalled", values[QSV_TOTPHYSMEM])) return -1;
if (ins(module, "memkernel", values[QSV_TOTRESMEM])) return -1;
if (ins(module, "memvirtual", values[QSV_TOTAVAILMEM])) return -1;
if (ins(module, "maxpathlen", values[QSV_MAX_PATH_LENGTH])) return -1;
if (ins(module, "maxnamelen", values[QSV_MAX_COMP_LENGTH])) return -1;
if (ins(module, "revision", values[QSV_VERSION_REVISION])) return -1;
if (ins(module, "timeslice", values[QSV_MIN_SLICE])) return -1;
switch (values[QSV_VERSION_MINOR]) {
case 0: ver = "2.00"; break;
case 10: ver = "2.10"; break;
case 11: ver = "2.11"; break;
case 30: ver = "3.00"; break;
case 40: ver = "4.00"; break;
case 50: ver = "5.00"; break;
default:
PyOS_snprintf(tmp, sizeof(tmp),
"%d-%d", values[QSV_VERSION_MAJOR],
values[QSV_VERSION_MINOR]);
ver = &tmp[0];
}
/* Add Indicator of the Version of the Operating System */
if (PyModule_AddStringConstant(module, "version", tmp) < 0)
return -1;
/* Add Indicator of Which Drive was Used to Boot the System */
tmp[0] = 'A' + values[QSV_BOOT_DRIVE] - 1;
tmp[1] = ':';
tmp[2] = '\0';
return PyModule_AddStringConstant(module, "bootdrive", tmp);
} | /* Insert Platform-Specific Constant Values (Strings & Numbers) of Common Use */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/posixmodule.c#L9130-L9178 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | set_error_attr | static int
set_error_attr(PyObject *err, char *name, int value)
{
PyObject *v = PyInt_FromLong(value);
if (v == NULL || PyObject_SetAttrString(err, name, v) == -1) {
Py_XDECREF(v);
return 0;
}
Py_DECREF(v);
return 1;
} | /* Set an integer attribute on the error object; return true on success,
* false on an exception.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/pyexpat.c#L104-L115 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | error_external_entity_ref_handler | static int
error_external_entity_ref_handler(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId)
{
return 0;
} | /* This handler is used when an error has been detected, in the hope
that actual parsing can be terminated early. This will only help
if an external entity reference is encountered. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/pyexpat.c#L231-L239 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | noop_character_data_handler | static void
noop_character_data_handler(void *userData, const XML_Char *data, int len)
{
/* Do nothing. */
} | /* Dummy character data handler used when an error (exception) has
been detected, and the actual parsing can be terminated early.
This is needed since character data handler can't be safely removed
from within the character data handler, but can be replaced. It is
used only from the character data handler trampoline, and must be
used right after `flag_error()` is called. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/pyexpat.c#L247-L251 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | call_character_handler | static int
call_character_handler(xmlparseobject *self, const XML_Char *buffer, int len)
{
PyObject *args;
PyObject *temp;
if (!have_handler(self, CharacterData))
return -1;
args = PyTuple_New(1);
if (args == NULL)
return -1;
#ifdef Py_USING_UNICODE
temp = (self->returns_unicode
? conv_string_len_to_unicode(buffer, len)
: conv_string_len_to_utf8(buffer, len));
#else
temp = conv_string_len_to_utf8(buffer, len);
#endif
if (temp == NULL) {
Py_DECREF(args);
flag_error(self);
XML_SetCharacterDataHandler(self->itself,
noop_character_data_handler);
return -1;
}
PyTuple_SET_ITEM(args, 0, temp);
/* temp is now a borrowed reference; consider it unused. */
self->in_callback = 1;
temp = call_with_frame(getcode(CharacterData, "CharacterData", __LINE__),
self->handlers[CharacterData], args, self);
/* temp is an owned reference again, or NULL */
self->in_callback = 0;
Py_DECREF(args);
if (temp == NULL) {
flag_error(self);
XML_SetCharacterDataHandler(self->itself,
noop_character_data_handler);
return -1;
}
Py_DECREF(temp);
return 0;
} | /* Return 0 on success, -1 on exception.
* flag_error() will be called before return if needed.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/pyexpat.c#L412-L454 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | MODULE_INITFUNC | PyMODINIT_FUNC
MODULE_INITFUNC(void)
{
PyObject *m, *d;
PyObject *errmod_name = PyString_FromString(MODULE_NAME ".errors");
PyObject *errors_module;
PyObject *modelmod_name;
PyObject *model_module;
PyObject *sys_modules;
PyObject *version;
static struct PyExpat_CAPI capi;
PyObject* capi_object;
if (errmod_name == NULL)
return;
modelmod_name = PyString_FromString(MODULE_NAME ".model");
if (modelmod_name == NULL)
return;
Py_TYPE(&Xmlparsetype) = &PyType_Type;
/* Create the module and add the functions */
m = Py_InitModule3(MODULE_NAME, pyexpat_methods,
pyexpat_module_documentation);
if (m == NULL)
return;
/* Add some symbolic constants to the module */
if (ErrorObject == NULL) {
ErrorObject = PyErr_NewException("xml.parsers.expat.ExpatError",
NULL, NULL);
if (ErrorObject == NULL)
return;
}
Py_INCREF(ErrorObject);
PyModule_AddObject(m, "error", ErrorObject);
Py_INCREF(ErrorObject);
PyModule_AddObject(m, "ExpatError", ErrorObject);
Py_INCREF(&Xmlparsetype);
PyModule_AddObject(m, "XMLParserType", (PyObject *) &Xmlparsetype);
version = PyString_FromString(PY_VERSION);
if (!version)
return;
PyModule_AddObject(m, "__version__", version);
PyModule_AddStringConstant(m, "EXPAT_VERSION",
(char *) XML_ExpatVersion());
{
XML_Expat_Version info = XML_ExpatVersionInfo();
PyModule_AddObject(m, "version_info",
Py_BuildValue("(iii)", info.major,
info.minor, info.micro));
}
#ifdef Py_USING_UNICODE
init_template_buffer();
#endif
/* XXX When Expat supports some way of figuring out how it was
compiled, this should check and set native_encoding
appropriately.
*/
PyModule_AddStringConstant(m, "native_encoding", "UTF-8");
sys_modules = PySys_GetObject("modules");
d = PyModule_GetDict(m);
errors_module = PyDict_GetItem(d, errmod_name);
if (errors_module == NULL) {
errors_module = PyModule_New(MODULE_NAME ".errors");
if (errors_module != NULL) {
PyDict_SetItem(sys_modules, errmod_name, errors_module);
/* gives away the reference to errors_module */
PyModule_AddObject(m, "errors", errors_module);
}
}
Py_DECREF(errmod_name);
model_module = PyDict_GetItem(d, modelmod_name);
if (model_module == NULL) {
model_module = PyModule_New(MODULE_NAME ".model");
if (model_module != NULL) {
PyDict_SetItem(sys_modules, modelmod_name, model_module);
/* gives away the reference to model_module */
PyModule_AddObject(m, "model", model_module);
}
}
Py_DECREF(modelmod_name);
if (errors_module == NULL || model_module == NULL)
/* Don't core dump later! */
return;
#if XML_COMBINED_VERSION > 19505
{
const XML_Feature *features = XML_GetFeatureList();
PyObject *list = PyList_New(0);
if (list == NULL)
/* just ignore it */
PyErr_Clear();
else {
int i = 0;
for (; features[i].feature != XML_FEATURE_END; ++i) {
int ok;
PyObject *item = Py_BuildValue("si", features[i].name,
features[i].value);
if (item == NULL) {
Py_DECREF(list);
list = NULL;
break;
}
ok = PyList_Append(list, item);
Py_DECREF(item);
if (ok < 0) {
PyErr_Clear();
break;
}
}
if (list != NULL)
PyModule_AddObject(m, "features", list);
}
}
#endif
#define MYCONST(name) \
PyModule_AddStringConstant(errors_module, #name, \
(char*)XML_ErrorString(name))
MYCONST(XML_ERROR_NO_MEMORY);
MYCONST(XML_ERROR_SYNTAX);
MYCONST(XML_ERROR_NO_ELEMENTS);
MYCONST(XML_ERROR_INVALID_TOKEN);
MYCONST(XML_ERROR_UNCLOSED_TOKEN);
MYCONST(XML_ERROR_PARTIAL_CHAR);
MYCONST(XML_ERROR_TAG_MISMATCH);
MYCONST(XML_ERROR_DUPLICATE_ATTRIBUTE);
MYCONST(XML_ERROR_JUNK_AFTER_DOC_ELEMENT);
MYCONST(XML_ERROR_PARAM_ENTITY_REF);
MYCONST(XML_ERROR_UNDEFINED_ENTITY);
MYCONST(XML_ERROR_RECURSIVE_ENTITY_REF);
MYCONST(XML_ERROR_ASYNC_ENTITY);
MYCONST(XML_ERROR_BAD_CHAR_REF);
MYCONST(XML_ERROR_BINARY_ENTITY_REF);
MYCONST(XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF);
MYCONST(XML_ERROR_MISPLACED_XML_PI);
MYCONST(XML_ERROR_UNKNOWN_ENCODING);
MYCONST(XML_ERROR_INCORRECT_ENCODING);
MYCONST(XML_ERROR_UNCLOSED_CDATA_SECTION);
MYCONST(XML_ERROR_EXTERNAL_ENTITY_HANDLING);
MYCONST(XML_ERROR_NOT_STANDALONE);
MYCONST(XML_ERROR_UNEXPECTED_STATE);
MYCONST(XML_ERROR_ENTITY_DECLARED_IN_PE);
MYCONST(XML_ERROR_FEATURE_REQUIRES_XML_DTD);
MYCONST(XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING);
/* Added in Expat 1.95.7. */
MYCONST(XML_ERROR_UNBOUND_PREFIX);
/* Added in Expat 1.95.8. */
MYCONST(XML_ERROR_UNDECLARING_PREFIX);
MYCONST(XML_ERROR_INCOMPLETE_PE);
MYCONST(XML_ERROR_XML_DECL);
MYCONST(XML_ERROR_TEXT_DECL);
MYCONST(XML_ERROR_PUBLICID);
MYCONST(XML_ERROR_SUSPENDED);
MYCONST(XML_ERROR_NOT_SUSPENDED);
MYCONST(XML_ERROR_ABORTED);
MYCONST(XML_ERROR_FINISHED);
MYCONST(XML_ERROR_SUSPEND_PE);
PyModule_AddStringConstant(errors_module, "__doc__",
"Constants used to describe error conditions.");
#undef MYCONST
#define MYCONST(c) PyModule_AddIntConstant(m, #c, c)
MYCONST(XML_PARAM_ENTITY_PARSING_NEVER);
MYCONST(XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE);
MYCONST(XML_PARAM_ENTITY_PARSING_ALWAYS);
#undef MYCONST
#define MYCONST(c) PyModule_AddIntConstant(model_module, #c, c)
PyModule_AddStringConstant(model_module, "__doc__",
"Constants used to interpret content model information.");
MYCONST(XML_CTYPE_EMPTY);
MYCONST(XML_CTYPE_ANY);
MYCONST(XML_CTYPE_MIXED);
MYCONST(XML_CTYPE_NAME);
MYCONST(XML_CTYPE_CHOICE);
MYCONST(XML_CTYPE_SEQ);
MYCONST(XML_CQUANT_NONE);
MYCONST(XML_CQUANT_OPT);
MYCONST(XML_CQUANT_REP);
MYCONST(XML_CQUANT_PLUS);
#undef MYCONST
/* initialize pyexpat dispatch table */
capi.size = sizeof(capi);
capi.magic = PyExpat_CAPI_MAGIC;
capi.MAJOR_VERSION = XML_MAJOR_VERSION;
capi.MINOR_VERSION = XML_MINOR_VERSION;
capi.MICRO_VERSION = XML_MICRO_VERSION;
capi.ErrorString = XML_ErrorString;
capi.GetErrorCode = XML_GetErrorCode;
capi.GetErrorColumnNumber = XML_GetErrorColumnNumber;
capi.GetErrorLineNumber = XML_GetErrorLineNumber;
capi.Parse = XML_Parse;
capi.ParserCreate_MM = XML_ParserCreate_MM;
capi.ParserFree = XML_ParserFree;
capi.SetCharacterDataHandler = XML_SetCharacterDataHandler;
capi.SetCommentHandler = XML_SetCommentHandler;
capi.SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand;
capi.SetElementHandler = XML_SetElementHandler;
capi.SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler;
capi.SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler;
capi.SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler;
capi.SetUserData = XML_SetUserData;
/* export using capsule */
capi_object = PyCapsule_New(&capi, PyExpat_CAPSULE_NAME, NULL);
if (capi_object)
PyModule_AddObject(m, "expat_CAPI", capi_object);
} | /* avoid compiler warnings */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/pyexpat.c#L1835-L2052 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _py_free_history_entry | static void
_py_free_history_entry(HIST_ENTRY *entry)
{
histdata_t data = free_history_entry(entry);
free(data);
} | /* Readline version >= 5.0 introduced a timestamp field into the history entry
structure; this needs to be freed to avoid a memory leak. This version of
readline also introduced the handy 'free_history_entry' function, which
takes care of the timestamp. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/readline.c#L381-L386 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _py_free_history_entry | static void
_py_free_history_entry(HIST_ENTRY *entry)
{
if (entry->line)
free((void *)entry->line);
if (entry->data)
free(entry->data);
free(entry);
} | /* No free_history_entry function; free everything manually. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/readline.c#L392-L400 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _py_get_history_length | static int
_py_get_history_length(void)
{
HISTORY_STATE *hist_st = history_get_history_state();
int length = hist_st->length;
/* the history docs don't say so, but the address of hist_st changes each
time history_get_history_state is called which makes me think it's
freshly malloc'd memory... on the other hand, the address of the last
line stays the same as long as history isn't extended, so it appears to
be malloc'd but managed by the history package... */
free(hist_st);
return length;
} | /* Private function to get current length of history. XXX It may be
* possible to replace this with a direct use of history_length instead,
* but it's not clear whether BSD's libedit keeps history_length up to date.
* See issue #8065.*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/readline.c#L533-L545 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | on_hook | static int
on_hook(PyObject *func)
{
int result = 0;
if (func != NULL) {
PyObject *r;
#ifdef WITH_THREAD
PyGILState_STATE gilstate = PyGILState_Ensure();
#endif
r = PyObject_CallFunction(func, NULL);
if (r == NULL)
goto error;
if (r == Py_None)
result = 0;
else {
result = PyInt_AsLong(r);
if (result == -1 && PyErr_Occurred())
goto error;
}
Py_DECREF(r);
goto done;
error:
PyErr_Clear();
Py_XDECREF(r);
done:
#ifdef WITH_THREAD
PyGILState_Release(gilstate);
#endif
return result;
}
return result;
} | /* C function to call the Python hooks. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/readline.c#L718-L749 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | onintr | static void
onintr(int sig)
{
longjmp(jbuf, 1);
} | /* ARGSUSED */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/readline.c#L1032-L1036 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | initresource | PyMODINIT_FUNC
initresource(void)
{
PyObject *m, *v;
/* Create the module and add the functions */
m = Py_InitModule("resource", resource_methods);
if (m == NULL)
return;
/* Add some symbolic constants to the module */
if (ResourceError == NULL) {
ResourceError = PyErr_NewException("resource.error",
NULL, NULL);
}
Py_INCREF(ResourceError);
PyModule_AddObject(m, "error", ResourceError);
if (!initialized)
PyStructSequence_InitType(&StructRUsageType,
&struct_rusage_desc);
Py_INCREF(&StructRUsageType);
PyModule_AddObject(m, "struct_rusage",
(PyObject*) &StructRUsageType);
/* insert constants */
#ifdef RLIMIT_CPU
PyModule_AddIntConstant(m, "RLIMIT_CPU", RLIMIT_CPU);
#endif
#ifdef RLIMIT_FSIZE
PyModule_AddIntConstant(m, "RLIMIT_FSIZE", RLIMIT_FSIZE);
#endif
#ifdef RLIMIT_DATA
PyModule_AddIntConstant(m, "RLIMIT_DATA", RLIMIT_DATA);
#endif
#ifdef RLIMIT_STACK
PyModule_AddIntConstant(m, "RLIMIT_STACK", RLIMIT_STACK);
#endif
#ifdef RLIMIT_CORE
PyModule_AddIntConstant(m, "RLIMIT_CORE", RLIMIT_CORE);
#endif
#ifdef RLIMIT_NOFILE
PyModule_AddIntConstant(m, "RLIMIT_NOFILE", RLIMIT_NOFILE);
#endif
#ifdef RLIMIT_OFILE
PyModule_AddIntConstant(m, "RLIMIT_OFILE", RLIMIT_OFILE);
#endif
#ifdef RLIMIT_VMEM
PyModule_AddIntConstant(m, "RLIMIT_VMEM", RLIMIT_VMEM);
#endif
#ifdef RLIMIT_AS
PyModule_AddIntConstant(m, "RLIMIT_AS", RLIMIT_AS);
#endif
#ifdef RLIMIT_RSS
PyModule_AddIntConstant(m, "RLIMIT_RSS", RLIMIT_RSS);
#endif
#ifdef RLIMIT_NPROC
PyModule_AddIntConstant(m, "RLIMIT_NPROC", RLIMIT_NPROC);
#endif
#ifdef RLIMIT_MEMLOCK
PyModule_AddIntConstant(m, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK);
#endif
#ifdef RLIMIT_SBSIZE
PyModule_AddIntConstant(m, "RLIMIT_SBSIZE", RLIMIT_SBSIZE);
#endif
#ifdef RUSAGE_SELF
PyModule_AddIntConstant(m, "RUSAGE_SELF", RUSAGE_SELF);
#endif
#ifdef RUSAGE_CHILDREN
PyModule_AddIntConstant(m, "RUSAGE_CHILDREN", RUSAGE_CHILDREN);
#endif
#ifdef RUSAGE_BOTH
PyModule_AddIntConstant(m, "RUSAGE_BOTH", RUSAGE_BOTH);
#endif
#if defined(HAVE_LONG_LONG)
if (sizeof(RLIM_INFINITY) > sizeof(long)) {
v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY);
} else
#endif
{
v = PyInt_FromLong((long) RLIM_INFINITY);
}
if (v) {
PyModule_AddObject(m, "RLIM_INFINITY", v);
}
initialized = 1;
} | /* Module initialization */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/resource.c#L245-L346 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RotatingTree_Add | void
RotatingTree_Add(rotating_node_t **root, rotating_node_t *node)
{
while (*root != NULL) {
if (KEY_LOWER_THAN(node->key, (*root)->key))
root = &((*root)->left);
else
root = &((*root)->right);
}
node->left = NULL;
node->right = NULL;
*root = node;
} | /* Insert a new node into the tree.
(*root) is modified to point to the new root. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/rotatingtree.c#L30-L42 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RotatingTree_Enum | int
RotatingTree_Enum(rotating_node_t *root, rotating_tree_enum_fn enumfn,
void *arg)
{
int result;
rotating_node_t *node;
while (root != NULL) {
result = RotatingTree_Enum(root->left, enumfn, arg);
if (result != 0) return result;
node = root->right;
result = enumfn(root, arg);
if (result != 0) return result;
root = node;
}
return 0;
} | /* Enumerate all nodes in the tree. The callback enumfn() should return
zero to continue the enumeration, or non-zero to interrupt it.
A non-zero value is directly returned by RotatingTree_Enum(). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/rotatingtree.c#L106-L121 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | seq2set | static int
seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
{
int i;
int max = -1;
int index = 0;
PyObject* fast_seq = NULL;
PyObject* o = NULL;
fd2obj[0].obj = (PyObject*)0; /* set list to zero size */
FD_ZERO(set);
fast_seq = PySequence_Fast(seq, "arguments 1-3 must be sequences");
if (!fast_seq)
return -1;
for (i = 0; i < PySequence_Fast_GET_SIZE(fast_seq); i++) {
SOCKET v;
/* any intervening fileno() calls could decr this refcnt */
if (!(o = PySequence_Fast_GET_ITEM(fast_seq, i)))
return -1;
Py_INCREF(o);
v = PyObject_AsFileDescriptor( o );
if (v == -1) goto finally;
#if defined(_MSC_VER)
max = 0; /* not used for Win32 */
#else /* !_MSC_VER */
if (!_PyIsSelectable_fd(v)) {
PyErr_SetString(PyExc_ValueError,
"filedescriptor out of range in select()");
goto finally;
}
if (v > max)
max = v;
#endif /* _MSC_VER */
FD_SET(v, set);
/* add object and its file descriptor to the list */
if (index >= FD_SETSIZE) {
PyErr_SetString(PyExc_ValueError,
"too many file descriptors in select()");
goto finally;
}
fd2obj[index].obj = o;
fd2obj[index].fd = v;
fd2obj[index].sentinel = 0;
fd2obj[++index].sentinel = -1;
}
Py_DECREF(fast_seq);
return max+1;
finally:
Py_XDECREF(o);
Py_DECREF(fast_seq);
return -1;
} | /* returns -1 and sets the Python exception if an error occurred, otherwise
returns a number >= 0
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/selectmodule.c#L83-L141 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | update_ufd_array | static int
update_ufd_array(pollObject *self)
{
Py_ssize_t i, pos;
PyObject *key, *value;
struct pollfd *old_ufds = self->ufds;
self->ufd_len = PyDict_Size(self->dict);
PyMem_RESIZE(self->ufds, struct pollfd, self->ufd_len);
if (self->ufds == NULL) {
self->ufds = old_ufds;
PyErr_NoMemory();
return 0;
}
i = pos = 0;
while (PyDict_Next(self->dict, &pos, &key, &value)) {
assert(i < self->ufd_len);
/* Never overflow */
self->ufds[i].fd = (int)PyInt_AsLong(key);
self->ufds[i].events = (short)(unsigned short)PyInt_AsLong(value);
i++;
}
assert(i == self->ufd_len);
self->ufd_uptodate = 1;
return 1;
} | /* Update the malloc'ed array of pollfds to match the dictionary
contained within a pollObject. Return 1 on success, 0 on an error.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/selectmodule.c#L329-L355 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | select_have_broken_poll | static int select_have_broken_poll(void)
{
int poll_test;
int filedes[2];
struct pollfd poll_struct = { 0, POLLIN|POLLPRI|POLLOUT, 0 };
/* Create a file descriptor to make invalid */
if (pipe(filedes) < 0) {
return 1;
}
poll_struct.fd = filedes[0];
close(filedes[0]);
close(filedes[1]);
poll_test = poll(&poll_struct, 1, 0);
if (poll_test < 0) {
return 1;
} else if (poll_test == 0 && poll_struct.revents != POLLNVAL) {
return 1;
}
return 0;
} | /*
* On some systems poll() sets errno on invalid file descriptors. We test
* for this at runtime because this bug may be fixed or introduced between
* OS releases.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/selectmodule.c#L690-L711 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | longReverse | static void longReverse(SHA_INT32 *buffer, int byteCount, int Endianness)
{
SHA_INT32 value;
if ( Endianness == PCT_BIG_ENDIAN )
return;
byteCount /= sizeof(*buffer);
while (byteCount--) {
value = *buffer;
value = ( ( value & 0xFF00FF00L ) >> 8 ) | \
( ( value & 0x00FF00FFL ) << 8 );
*buffer++ = ( value << 16 ) | ( value >> 16 );
}
} | /* When run on a little-endian CPU we need to perform byte reversal on an
array of longwords. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha256module.c#L60-L74 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha_init | static void
sha_init(SHAobject *sha_info)
{
TestEndianness(sha_info->Endianness)
sha_info->digest[0] = 0x6A09E667L;
sha_info->digest[1] = 0xBB67AE85L;
sha_info->digest[2] = 0x3C6EF372L;
sha_info->digest[3] = 0xA54FF53AL;
sha_info->digest[4] = 0x510E527FL;
sha_info->digest[5] = 0x9B05688CL;
sha_info->digest[6] = 0x1F83D9ABL;
sha_info->digest[7] = 0x5BE0CD19L;
sha_info->count_lo = 0L;
sha_info->count_hi = 0L;
sha_info->local = 0;
sha_info->digestsize = 32;
} | /* initialize the SHA digest */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha256module.c#L227-L243 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha_update | static void
sha_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
{
int i;
SHA_INT32 clo;
clo = sha_info->count_lo + ((SHA_INT32) count << 3);
if (clo < sha_info->count_lo) {
++sha_info->count_hi;
}
sha_info->count_lo = clo;
sha_info->count_hi += (SHA_INT32) count >> 29;
if (sha_info->local) {
i = SHA_BLOCKSIZE - sha_info->local;
if (i > count) {
i = count;
}
memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local, buffer, i);
count -= i;
buffer += i;
sha_info->local += i;
if (sha_info->local == SHA_BLOCKSIZE) {
sha_transform(sha_info);
}
else {
return;
}
}
while (count >= SHA_BLOCKSIZE) {
memcpy(sha_info->data, buffer, SHA_BLOCKSIZE);
buffer += SHA_BLOCKSIZE;
count -= SHA_BLOCKSIZE;
sha_transform(sha_info);
}
memcpy(sha_info->data, buffer, count);
sha_info->local = count;
} | /* update the SHA digest */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha256module.c#L266-L302 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha_final | static void
sha_final(unsigned char digest[SHA_DIGESTSIZE], SHAobject *sha_info)
{
int count;
SHA_INT32 lo_bit_count, hi_bit_count;
lo_bit_count = sha_info->count_lo;
hi_bit_count = sha_info->count_hi;
count = (int) ((lo_bit_count >> 3) & 0x3f);
((SHA_BYTE *) sha_info->data)[count++] = 0x80;
if (count > SHA_BLOCKSIZE - 8) {
memset(((SHA_BYTE *) sha_info->data) + count, 0,
SHA_BLOCKSIZE - count);
sha_transform(sha_info);
memset((SHA_BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 8);
}
else {
memset(((SHA_BYTE *) sha_info->data) + count, 0,
SHA_BLOCKSIZE - 8 - count);
}
/* GJS: note that we add the hi/lo in big-endian. sha_transform will
swap these values into host-order. */
sha_info->data[56] = (hi_bit_count >> 24) & 0xff;
sha_info->data[57] = (hi_bit_count >> 16) & 0xff;
sha_info->data[58] = (hi_bit_count >> 8) & 0xff;
sha_info->data[59] = (hi_bit_count >> 0) & 0xff;
sha_info->data[60] = (lo_bit_count >> 24) & 0xff;
sha_info->data[61] = (lo_bit_count >> 16) & 0xff;
sha_info->data[62] = (lo_bit_count >> 8) & 0xff;
sha_info->data[63] = (lo_bit_count >> 0) & 0xff;
sha_transform(sha_info);
digest[ 0] = (unsigned char) ((sha_info->digest[0] >> 24) & 0xff);
digest[ 1] = (unsigned char) ((sha_info->digest[0] >> 16) & 0xff);
digest[ 2] = (unsigned char) ((sha_info->digest[0] >> 8) & 0xff);
digest[ 3] = (unsigned char) ((sha_info->digest[0] ) & 0xff);
digest[ 4] = (unsigned char) ((sha_info->digest[1] >> 24) & 0xff);
digest[ 5] = (unsigned char) ((sha_info->digest[1] >> 16) & 0xff);
digest[ 6] = (unsigned char) ((sha_info->digest[1] >> 8) & 0xff);
digest[ 7] = (unsigned char) ((sha_info->digest[1] ) & 0xff);
digest[ 8] = (unsigned char) ((sha_info->digest[2] >> 24) & 0xff);
digest[ 9] = (unsigned char) ((sha_info->digest[2] >> 16) & 0xff);
digest[10] = (unsigned char) ((sha_info->digest[2] >> 8) & 0xff);
digest[11] = (unsigned char) ((sha_info->digest[2] ) & 0xff);
digest[12] = (unsigned char) ((sha_info->digest[3] >> 24) & 0xff);
digest[13] = (unsigned char) ((sha_info->digest[3] >> 16) & 0xff);
digest[14] = (unsigned char) ((sha_info->digest[3] >> 8) & 0xff);
digest[15] = (unsigned char) ((sha_info->digest[3] ) & 0xff);
digest[16] = (unsigned char) ((sha_info->digest[4] >> 24) & 0xff);
digest[17] = (unsigned char) ((sha_info->digest[4] >> 16) & 0xff);
digest[18] = (unsigned char) ((sha_info->digest[4] >> 8) & 0xff);
digest[19] = (unsigned char) ((sha_info->digest[4] ) & 0xff);
digest[20] = (unsigned char) ((sha_info->digest[5] >> 24) & 0xff);
digest[21] = (unsigned char) ((sha_info->digest[5] >> 16) & 0xff);
digest[22] = (unsigned char) ((sha_info->digest[5] >> 8) & 0xff);
digest[23] = (unsigned char) ((sha_info->digest[5] ) & 0xff);
digest[24] = (unsigned char) ((sha_info->digest[6] >> 24) & 0xff);
digest[25] = (unsigned char) ((sha_info->digest[6] >> 16) & 0xff);
digest[26] = (unsigned char) ((sha_info->digest[6] >> 8) & 0xff);
digest[27] = (unsigned char) ((sha_info->digest[6] ) & 0xff);
digest[28] = (unsigned char) ((sha_info->digest[7] >> 24) & 0xff);
digest[29] = (unsigned char) ((sha_info->digest[7] >> 16) & 0xff);
digest[30] = (unsigned char) ((sha_info->digest[7] >> 8) & 0xff);
digest[31] = (unsigned char) ((sha_info->digest[7] ) & 0xff);
} | /* finish computing the SHA digest */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha256module.c#L306-L370 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SHA_dealloc | static void
SHA_dealloc(PyObject *ptr)
{
PyObject_Del(ptr);
} | /* Internal methods for a hash object */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha256module.c#L396-L400 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | longReverse | static void longReverse(SHA_INT64 *buffer, int byteCount, int Endianness)
{
SHA_INT64 value;
if ( Endianness == PCT_BIG_ENDIAN )
return;
byteCount /= sizeof(*buffer);
while (byteCount--) {
value = *buffer;
((unsigned char*)buffer)[0] = (unsigned char)(value >> 56) & 0xff;
((unsigned char*)buffer)[1] = (unsigned char)(value >> 48) & 0xff;
((unsigned char*)buffer)[2] = (unsigned char)(value >> 40) & 0xff;
((unsigned char*)buffer)[3] = (unsigned char)(value >> 32) & 0xff;
((unsigned char*)buffer)[4] = (unsigned char)(value >> 24) & 0xff;
((unsigned char*)buffer)[5] = (unsigned char)(value >> 16) & 0xff;
((unsigned char*)buffer)[6] = (unsigned char)(value >> 8) & 0xff;
((unsigned char*)buffer)[7] = (unsigned char)(value ) & 0xff;
buffer++;
}
} | /* When run on a little-endian CPU we need to perform byte reversal on an
array of longwords. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha512module.c#L62-L84 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha512_init | static void
sha512_init(SHAobject *sha_info)
{
TestEndianness(sha_info->Endianness)
sha_info->digest[0] = Py_ULL(0x6a09e667f3bcc908);
sha_info->digest[1] = Py_ULL(0xbb67ae8584caa73b);
sha_info->digest[2] = Py_ULL(0x3c6ef372fe94f82b);
sha_info->digest[3] = Py_ULL(0xa54ff53a5f1d36f1);
sha_info->digest[4] = Py_ULL(0x510e527fade682d1);
sha_info->digest[5] = Py_ULL(0x9b05688c2b3e6c1f);
sha_info->digest[6] = Py_ULL(0x1f83d9abfb41bd6b);
sha_info->digest[7] = Py_ULL(0x5be0cd19137e2179);
sha_info->count_lo = 0L;
sha_info->count_hi = 0L;
sha_info->local = 0;
sha_info->digestsize = 64;
} | /* initialize the SHA digest */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha512module.c#L253-L269 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha512_update | static void
sha512_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
{
int i;
SHA_INT32 clo;
clo = sha_info->count_lo + ((SHA_INT32) count << 3);
if (clo < sha_info->count_lo) {
++sha_info->count_hi;
}
sha_info->count_lo = clo;
sha_info->count_hi += (SHA_INT32) count >> 29;
if (sha_info->local) {
i = SHA_BLOCKSIZE - sha_info->local;
if (i > count) {
i = count;
}
memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local, buffer, i);
count -= i;
buffer += i;
sha_info->local += i;
if (sha_info->local == SHA_BLOCKSIZE) {
sha512_transform(sha_info);
}
else {
return;
}
}
while (count >= SHA_BLOCKSIZE) {
memcpy(sha_info->data, buffer, SHA_BLOCKSIZE);
buffer += SHA_BLOCKSIZE;
count -= SHA_BLOCKSIZE;
sha512_transform(sha_info);
}
memcpy(sha_info->data, buffer, count);
sha_info->local = count;
} | /* update the SHA digest */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha512module.c#L292-L328 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha512_final | static void
sha512_final(unsigned char digest[SHA_DIGESTSIZE], SHAobject *sha_info)
{
int count;
SHA_INT32 lo_bit_count, hi_bit_count;
lo_bit_count = sha_info->count_lo;
hi_bit_count = sha_info->count_hi;
count = (int) ((lo_bit_count >> 3) & 0x7f);
((SHA_BYTE *) sha_info->data)[count++] = 0x80;
if (count > SHA_BLOCKSIZE - 16) {
memset(((SHA_BYTE *) sha_info->data) + count, 0,
SHA_BLOCKSIZE - count);
sha512_transform(sha_info);
memset((SHA_BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 16);
}
else {
memset(((SHA_BYTE *) sha_info->data) + count, 0,
SHA_BLOCKSIZE - 16 - count);
}
/* GJS: note that we add the hi/lo in big-endian. sha512_transform will
swap these values into host-order. */
sha_info->data[112] = 0;
sha_info->data[113] = 0;
sha_info->data[114] = 0;
sha_info->data[115] = 0;
sha_info->data[116] = 0;
sha_info->data[117] = 0;
sha_info->data[118] = 0;
sha_info->data[119] = 0;
sha_info->data[120] = (hi_bit_count >> 24) & 0xff;
sha_info->data[121] = (hi_bit_count >> 16) & 0xff;
sha_info->data[122] = (hi_bit_count >> 8) & 0xff;
sha_info->data[123] = (hi_bit_count >> 0) & 0xff;
sha_info->data[124] = (lo_bit_count >> 24) & 0xff;
sha_info->data[125] = (lo_bit_count >> 16) & 0xff;
sha_info->data[126] = (lo_bit_count >> 8) & 0xff;
sha_info->data[127] = (lo_bit_count >> 0) & 0xff;
sha512_transform(sha_info);
digest[ 0] = (unsigned char) ((sha_info->digest[0] >> 56) & 0xff);
digest[ 1] = (unsigned char) ((sha_info->digest[0] >> 48) & 0xff);
digest[ 2] = (unsigned char) ((sha_info->digest[0] >> 40) & 0xff);
digest[ 3] = (unsigned char) ((sha_info->digest[0] >> 32) & 0xff);
digest[ 4] = (unsigned char) ((sha_info->digest[0] >> 24) & 0xff);
digest[ 5] = (unsigned char) ((sha_info->digest[0] >> 16) & 0xff);
digest[ 6] = (unsigned char) ((sha_info->digest[0] >> 8) & 0xff);
digest[ 7] = (unsigned char) ((sha_info->digest[0] ) & 0xff);
digest[ 8] = (unsigned char) ((sha_info->digest[1] >> 56) & 0xff);
digest[ 9] = (unsigned char) ((sha_info->digest[1] >> 48) & 0xff);
digest[10] = (unsigned char) ((sha_info->digest[1] >> 40) & 0xff);
digest[11] = (unsigned char) ((sha_info->digest[1] >> 32) & 0xff);
digest[12] = (unsigned char) ((sha_info->digest[1] >> 24) & 0xff);
digest[13] = (unsigned char) ((sha_info->digest[1] >> 16) & 0xff);
digest[14] = (unsigned char) ((sha_info->digest[1] >> 8) & 0xff);
digest[15] = (unsigned char) ((sha_info->digest[1] ) & 0xff);
digest[16] = (unsigned char) ((sha_info->digest[2] >> 56) & 0xff);
digest[17] = (unsigned char) ((sha_info->digest[2] >> 48) & 0xff);
digest[18] = (unsigned char) ((sha_info->digest[2] >> 40) & 0xff);
digest[19] = (unsigned char) ((sha_info->digest[2] >> 32) & 0xff);
digest[20] = (unsigned char) ((sha_info->digest[2] >> 24) & 0xff);
digest[21] = (unsigned char) ((sha_info->digest[2] >> 16) & 0xff);
digest[22] = (unsigned char) ((sha_info->digest[2] >> 8) & 0xff);
digest[23] = (unsigned char) ((sha_info->digest[2] ) & 0xff);
digest[24] = (unsigned char) ((sha_info->digest[3] >> 56) & 0xff);
digest[25] = (unsigned char) ((sha_info->digest[3] >> 48) & 0xff);
digest[26] = (unsigned char) ((sha_info->digest[3] >> 40) & 0xff);
digest[27] = (unsigned char) ((sha_info->digest[3] >> 32) & 0xff);
digest[28] = (unsigned char) ((sha_info->digest[3] >> 24) & 0xff);
digest[29] = (unsigned char) ((sha_info->digest[3] >> 16) & 0xff);
digest[30] = (unsigned char) ((sha_info->digest[3] >> 8) & 0xff);
digest[31] = (unsigned char) ((sha_info->digest[3] ) & 0xff);
digest[32] = (unsigned char) ((sha_info->digest[4] >> 56) & 0xff);
digest[33] = (unsigned char) ((sha_info->digest[4] >> 48) & 0xff);
digest[34] = (unsigned char) ((sha_info->digest[4] >> 40) & 0xff);
digest[35] = (unsigned char) ((sha_info->digest[4] >> 32) & 0xff);
digest[36] = (unsigned char) ((sha_info->digest[4] >> 24) & 0xff);
digest[37] = (unsigned char) ((sha_info->digest[4] >> 16) & 0xff);
digest[38] = (unsigned char) ((sha_info->digest[4] >> 8) & 0xff);
digest[39] = (unsigned char) ((sha_info->digest[4] ) & 0xff);
digest[40] = (unsigned char) ((sha_info->digest[5] >> 56) & 0xff);
digest[41] = (unsigned char) ((sha_info->digest[5] >> 48) & 0xff);
digest[42] = (unsigned char) ((sha_info->digest[5] >> 40) & 0xff);
digest[43] = (unsigned char) ((sha_info->digest[5] >> 32) & 0xff);
digest[44] = (unsigned char) ((sha_info->digest[5] >> 24) & 0xff);
digest[45] = (unsigned char) ((sha_info->digest[5] >> 16) & 0xff);
digest[46] = (unsigned char) ((sha_info->digest[5] >> 8) & 0xff);
digest[47] = (unsigned char) ((sha_info->digest[5] ) & 0xff);
digest[48] = (unsigned char) ((sha_info->digest[6] >> 56) & 0xff);
digest[49] = (unsigned char) ((sha_info->digest[6] >> 48) & 0xff);
digest[50] = (unsigned char) ((sha_info->digest[6] >> 40) & 0xff);
digest[51] = (unsigned char) ((sha_info->digest[6] >> 32) & 0xff);
digest[52] = (unsigned char) ((sha_info->digest[6] >> 24) & 0xff);
digest[53] = (unsigned char) ((sha_info->digest[6] >> 16) & 0xff);
digest[54] = (unsigned char) ((sha_info->digest[6] >> 8) & 0xff);
digest[55] = (unsigned char) ((sha_info->digest[6] ) & 0xff);
digest[56] = (unsigned char) ((sha_info->digest[7] >> 56) & 0xff);
digest[57] = (unsigned char) ((sha_info->digest[7] >> 48) & 0xff);
digest[58] = (unsigned char) ((sha_info->digest[7] >> 40) & 0xff);
digest[59] = (unsigned char) ((sha_info->digest[7] >> 32) & 0xff);
digest[60] = (unsigned char) ((sha_info->digest[7] >> 24) & 0xff);
digest[61] = (unsigned char) ((sha_info->digest[7] >> 16) & 0xff);
digest[62] = (unsigned char) ((sha_info->digest[7] >> 8) & 0xff);
digest[63] = (unsigned char) ((sha_info->digest[7] ) & 0xff);
} | /* finish computing the SHA digest */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha512module.c#L332-L436 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SHA512_dealloc | static void
SHA512_dealloc(PyObject *ptr)
{
PyObject_Del(ptr);
} | /* Internal methods for a hash object */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sha512module.c#L462-L466 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | longReverse | static void longReverse(SHA_INT32 *buffer, int byteCount, int Endianness)
{
SHA_INT32 value;
if ( Endianness == PCT_BIG_ENDIAN )
return;
byteCount /= sizeof(*buffer);
while (byteCount--) {
value = *buffer;
value = ( ( value & 0xFF00FF00L ) >> 8 ) | \
( ( value & 0x00FF00FFL ) << 8 );
*buffer++ = ( value << 16 ) | ( value >> 16 );
}
} | /* When run on a little-endian CPU we need to perform byte reversal on an
array of longwords. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/shamodule.c#L58-L72 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha_transform | static void
sha_transform(SHAobject *sha_info)
{
int i;
SHA_INT32 T, A, B, C, D, E, W[80], *WP;
memcpy(W, sha_info->data, sizeof(sha_info->data));
longReverse(W, (int)sizeof(sha_info->data), sha_info->Endianness);
for (i = 16; i < 80; ++i) {
W[i] = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16];
/* extra rotation fix */
W[i] = R32(W[i], 1);
}
A = sha_info->digest[0];
B = sha_info->digest[1];
C = sha_info->digest[2];
D = sha_info->digest[3];
E = sha_info->digest[4];
WP = W;
#ifdef UNRAVEL
FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1); FC(1); FD(1);
FE(1); FT(1); FA(1); FB(1); FC(1); FD(1); FE(1); FT(1); FA(1); FB(1);
FC(2); FD(2); FE(2); FT(2); FA(2); FB(2); FC(2); FD(2); FE(2); FT(2);
FA(2); FB(2); FC(2); FD(2); FE(2); FT(2); FA(2); FB(2); FC(2); FD(2);
FE(3); FT(3); FA(3); FB(3); FC(3); FD(3); FE(3); FT(3); FA(3); FB(3);
FC(3); FD(3); FE(3); FT(3); FA(3); FB(3); FC(3); FD(3); FE(3); FT(3);
FA(4); FB(4); FC(4); FD(4); FE(4); FT(4); FA(4); FB(4); FC(4); FD(4);
FE(4); FT(4); FA(4); FB(4); FC(4); FD(4); FE(4); FT(4); FA(4); FB(4);
sha_info->digest[0] += E;
sha_info->digest[1] += T;
sha_info->digest[2] += A;
sha_info->digest[3] += B;
sha_info->digest[4] += C;
#else /* !UNRAVEL */
#ifdef UNROLL_LOOPS
FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1);
FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1); FG(1);
FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2);
FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2); FG(2);
FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3);
FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3); FG(3);
FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4);
FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4); FG(4);
#else /* !UNROLL_LOOPS */
for (i = 0; i < 20; ++i) { FG(1); }
for (i = 20; i < 40; ++i) { FG(2); }
for (i = 40; i < 60; ++i) { FG(3); }
for (i = 60; i < 80; ++i) { FG(4); }
#endif /* !UNROLL_LOOPS */
sha_info->digest[0] += A;
sha_info->digest[1] += B;
sha_info->digest[2] += C;
sha_info->digest[3] += D;
sha_info->digest[4] += E;
#endif /* !UNRAVEL */
} | /* do SHA transformation */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/shamodule.c#L160-L217 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha_init | static void
sha_init(SHAobject *sha_info)
{
TestEndianness(sha_info->Endianness)
sha_info->digest[0] = 0x67452301L;
sha_info->digest[1] = 0xefcdab89L;
sha_info->digest[2] = 0x98badcfeL;
sha_info->digest[3] = 0x10325476L;
sha_info->digest[4] = 0xc3d2e1f0L;
sha_info->count_lo = 0L;
sha_info->count_hi = 0L;
sha_info->local = 0;
} | /* initialize the SHA digest */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/shamodule.c#L221-L234 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha_update | static void
sha_update(SHAobject *sha_info, SHA_BYTE *buffer, unsigned int count)
{
unsigned int i;
SHA_INT32 clo;
clo = sha_info->count_lo + ((SHA_INT32) count << 3);
if (clo < sha_info->count_lo) {
++sha_info->count_hi;
}
sha_info->count_lo = clo;
sha_info->count_hi += (SHA_INT32) count >> 29;
if (sha_info->local) {
i = SHA_BLOCKSIZE - sha_info->local;
if (i > count) {
i = count;
}
memcpy(((SHA_BYTE *) sha_info->data) + sha_info->local, buffer, i);
count -= i;
buffer += i;
sha_info->local += i;
if (sha_info->local == SHA_BLOCKSIZE) {
sha_transform(sha_info);
}
else {
return;
}
}
while (count >= SHA_BLOCKSIZE) {
memcpy(sha_info->data, buffer, SHA_BLOCKSIZE);
buffer += SHA_BLOCKSIZE;
count -= SHA_BLOCKSIZE;
sha_transform(sha_info);
}
memcpy(sha_info->data, buffer, count);
sha_info->local = count;
} | /* update the SHA digest */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/shamodule.c#L238-L274 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha_final | static void
sha_final(unsigned char digest[20], SHAobject *sha_info)
{
int count;
SHA_INT32 lo_bit_count, hi_bit_count;
lo_bit_count = sha_info->count_lo;
hi_bit_count = sha_info->count_hi;
count = (int) ((lo_bit_count >> 3) & 0x3f);
((SHA_BYTE *) sha_info->data)[count++] = 0x80;
if (count > SHA_BLOCKSIZE - 8) {
memset(((SHA_BYTE *) sha_info->data) + count, 0,
SHA_BLOCKSIZE - count);
sha_transform(sha_info);
memset((SHA_BYTE *) sha_info->data, 0, SHA_BLOCKSIZE - 8);
}
else {
memset(((SHA_BYTE *) sha_info->data) + count, 0,
SHA_BLOCKSIZE - 8 - count);
}
/* GJS: note that we add the hi/lo in big-endian. sha_transform will
swap these values into host-order. */
sha_info->data[56] = (hi_bit_count >> 24) & 0xff;
sha_info->data[57] = (hi_bit_count >> 16) & 0xff;
sha_info->data[58] = (hi_bit_count >> 8) & 0xff;
sha_info->data[59] = (hi_bit_count >> 0) & 0xff;
sha_info->data[60] = (lo_bit_count >> 24) & 0xff;
sha_info->data[61] = (lo_bit_count >> 16) & 0xff;
sha_info->data[62] = (lo_bit_count >> 8) & 0xff;
sha_info->data[63] = (lo_bit_count >> 0) & 0xff;
sha_transform(sha_info);
digest[ 0] = (unsigned char) ((sha_info->digest[0] >> 24) & 0xff);
digest[ 1] = (unsigned char) ((sha_info->digest[0] >> 16) & 0xff);
digest[ 2] = (unsigned char) ((sha_info->digest[0] >> 8) & 0xff);
digest[ 3] = (unsigned char) ((sha_info->digest[0] ) & 0xff);
digest[ 4] = (unsigned char) ((sha_info->digest[1] >> 24) & 0xff);
digest[ 5] = (unsigned char) ((sha_info->digest[1] >> 16) & 0xff);
digest[ 6] = (unsigned char) ((sha_info->digest[1] >> 8) & 0xff);
digest[ 7] = (unsigned char) ((sha_info->digest[1] ) & 0xff);
digest[ 8] = (unsigned char) ((sha_info->digest[2] >> 24) & 0xff);
digest[ 9] = (unsigned char) ((sha_info->digest[2] >> 16) & 0xff);
digest[10] = (unsigned char) ((sha_info->digest[2] >> 8) & 0xff);
digest[11] = (unsigned char) ((sha_info->digest[2] ) & 0xff);
digest[12] = (unsigned char) ((sha_info->digest[3] >> 24) & 0xff);
digest[13] = (unsigned char) ((sha_info->digest[3] >> 16) & 0xff);
digest[14] = (unsigned char) ((sha_info->digest[3] >> 8) & 0xff);
digest[15] = (unsigned char) ((sha_info->digest[3] ) & 0xff);
digest[16] = (unsigned char) ((sha_info->digest[4] >> 24) & 0xff);
digest[17] = (unsigned char) ((sha_info->digest[4] >> 16) & 0xff);
digest[18] = (unsigned char) ((sha_info->digest[4] >> 8) & 0xff);
digest[19] = (unsigned char) ((sha_info->digest[4] ) & 0xff);
} | /* finish computing the SHA digest */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/shamodule.c#L278-L330 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SHA_dealloc | static void
SHA_dealloc(PyObject *ptr)
{
PyObject_Del(ptr);
} | /* Internal methods for a hashing object */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/shamodule.c#L349-L353 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | timeval_from_double | static void
timeval_from_double(double d, struct timeval *tv)
{
tv->tv_sec = floor(d);
tv->tv_usec = fmod(d, 1.0) * 1000000.0;
} | /* auxiliary functions for setitimer/getitimer */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/signalmodule.c#L109-L114 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PySignal_SetWakeupFd | int
PySignal_SetWakeupFd(int fd)
{
int old_fd = wakeup_fd;
if (fd < 0)
fd = -1;
wakeup_fd = fd;
return old_fd;
} | /* C API for the same, without all the error checking */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/signalmodule.c#L437-L445 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyErr_CheckSignals | int
PyErr_CheckSignals(void)
{
int i;
PyObject *f;
if (!is_tripped)
return 0;
#ifdef WITH_THREAD
if (PyThread_get_thread_ident() != main_thread)
return 0;
#endif
/*
* The is_tripped variable is meant to speed up the calls to
* PyErr_CheckSignals (both directly or via pending calls) when no
* signal has arrived. This variable is set to 1 when a signal arrives
* and it is set to 0 here, when we know some signals arrived. This way
* we can run the registered handlers with no signals blocked.
*
* NOTE: with this approach we can have a situation where is_tripped is
* 1 but we have no more signals to handle (Handlers[i].tripped
* is 0 for every signal i). This won't do us any harm (except
* we're gonna spent some cycles for nothing). This happens when
* we receive a signal i after we zero is_tripped and before we
* check Handlers[i].tripped.
*/
is_tripped = 0;
if (!(f = (PyObject *)PyEval_GetFrame()))
f = Py_None;
for (i = 1; i < NSIG; i++) {
if (Handlers[i].tripped) {
PyObject *result = NULL;
PyObject *arglist = Py_BuildValue("(iO)", i, f);
Handlers[i].tripped = 0;
if (arglist) {
result = PyEval_CallObject(Handlers[i].func,
arglist);
Py_DECREF(arglist);
}
if (!result)
return -1;
Py_DECREF(result);
}
}
return 0;
} | /* Declared in pyerrors.h */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/signalmodule.c#L892-L944 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyErr_SetInterrupt | void
PyErr_SetInterrupt(void)
{
trip_signal(SIGINT);
} | /* Replacements for intrcheck.c functionality
* Declared in pyerrors.h
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/signalmodule.c#L950-L954 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sendsegmented | static int
sendsegmented(int sock_fd, char *buf, int len, int flags)
{
int n = 0;
int remaining = len;
while (remaining > 0) {
unsigned int segment;
segment = (remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : remaining);
n = send(sock_fd, buf, segment, flags);
if (n < 0) {
return n;
}
remaining -= segment;
buf += segment;
} /* end while */
return len;
} | /* Function to send in segments */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/socketmodule.c#L600-L619 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | setbdaddr | static int
setbdaddr(char *name, bdaddr_t *bdaddr)
{
unsigned int b0, b1, b2, b3, b4, b5;
char ch;
int n;
n = sscanf(name, "%X:%X:%X:%X:%X:%X%c",
&b5, &b4, &b3, &b2, &b1, &b0, &ch);
if (n == 6 && (b0 | b1 | b2 | b3 | b4 | b5) < 256) {
bdaddr->b[0] = b0;
bdaddr->b[1] = b1;
bdaddr->b[2] = b2;
bdaddr->b[3] = b3;
bdaddr->b[4] = b4;
bdaddr->b[5] = b5;
return 6;
} else {
PyErr_SetString(socket_error, "bad bluetooth address");
return -1;
}
} | /* Convert a string representation of a Bluetooth address into a numeric
address. Returns the length (6), or raises an exception and returns -1 if
an error occurred. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/socketmodule.c#L979-L1000 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | os_cleanup | static void
os_cleanup(void)
{
WSACleanup();
} | /* Additional initialization and cleanup for Windows */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/socketmodule.c#L4467-L4471 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | os_init | static int
os_init(void)
{
#ifndef PYCC_GCC
char reason[64];
int rc = sock_init();
if (rc == 0) {
return 1; /* Success */
}
PyOS_snprintf(reason, sizeof(reason),
"OS/2 TCP/IP Error# %d", sock_errno());
PyErr_SetString(PyExc_ImportError, reason);
return 0; /* Failure */
#else
/* No need to initialize sockets with GCC/EMX */
return 1; /* Success */
#endif
} | /* Additional initialization for OS/2 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/socketmodule.c#L4511-L4531 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | inet_pton | int
inet_pton(int af, const char *src, void *dst)
{
if (af == AF_INET) {
#if (SIZEOF_INT != 4)
#error "Not sure if in_addr_t exists and int is not 32-bits."
#endif
unsigned int packed_addr;
packed_addr = inet_addr(src);
if (packed_addr == INADDR_NONE)
return 0;
memcpy(dst, &packed_addr, 4);
return 1;
}
/* Should set errno to EAFNOSUPPORT */
return -1;
} | /* Simplistic emulation code for inet_pton that only works for IPv4 */
/* These are not exposed because they do not set errno properly */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/socketmodule.c#L5519-L5535 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | mymemfind | static Py_ssize_t
mymemfind(const char *mem, Py_ssize_t len, const char *pat, Py_ssize_t pat_len)
{
register Py_ssize_t ii;
/* pattern can not occur in the last pat_len-1 chars */
len -= pat_len;
for (ii = 0; ii <= len; ii++) {
if (mem[ii] == pat[0] &&
(pat_len == 1 ||
memcmp(&mem[ii+1], &pat[1], pat_len-1) == 0)) {
return ii;
}
}
return -1;
} | /* What follows is used for implementing replace(). Perry Stoll. */
/*
mymemfind
strstr replacement for arbitrary blocks of memory.
Locates the first occurrence in the memory pointed to by MEM of the
contents of memory pointed to by PAT. Returns the index into MEM if
found, or -1 if not found. If len of PAT is greater than length of
MEM, the function returns -1.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/stropmodule.c#L1027-L1043 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | mymemcnt | static Py_ssize_t
mymemcnt(const char *mem, Py_ssize_t len, const char *pat, Py_ssize_t pat_len)
{
register Py_ssize_t offset = 0;
Py_ssize_t nfound = 0;
while (len >= 0) {
offset = mymemfind(mem, len, pat, pat_len);
if (offset == -1)
break;
mem += offset + pat_len;
len -= offset + pat_len;
nfound++;
}
return nfound;
} | /*
mymemcnt
Return the number of distinct times PAT is found in MEM.
meaning mem=1111 and pat==11 returns 2.
mem=11111 and pat==11 also return 2.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/stropmodule.c#L1052-L1067 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sad_dealloc | static void
sad_dealloc(sadobject *xp)
{
close(xp->x_fd);
PyObject_Del(xp);
} | /* Sad methods */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/sunaudiodev.c#L122-L127 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | initsyslog | PyMODINIT_FUNC
initsyslog(void)
{
PyObject *m;
/* Create the module and add the functions */
m = Py_InitModule("syslog", syslog_methods);
if (m == NULL)
return;
/* Add some symbolic constants to the module */
/* Priorities */
PyModule_AddIntConstant(m, "LOG_EMERG", LOG_EMERG);
PyModule_AddIntConstant(m, "LOG_ALERT", LOG_ALERT);
PyModule_AddIntConstant(m, "LOG_CRIT", LOG_CRIT);
PyModule_AddIntConstant(m, "LOG_ERR", LOG_ERR);
PyModule_AddIntConstant(m, "LOG_WARNING", LOG_WARNING);
PyModule_AddIntConstant(m, "LOG_NOTICE", LOG_NOTICE);
PyModule_AddIntConstant(m, "LOG_INFO", LOG_INFO);
PyModule_AddIntConstant(m, "LOG_DEBUG", LOG_DEBUG);
/* openlog() option flags */
PyModule_AddIntConstant(m, "LOG_PID", LOG_PID);
PyModule_AddIntConstant(m, "LOG_CONS", LOG_CONS);
PyModule_AddIntConstant(m, "LOG_NDELAY", LOG_NDELAY);
#ifdef LOG_NOWAIT
PyModule_AddIntConstant(m, "LOG_NOWAIT", LOG_NOWAIT);
#endif
#ifdef LOG_PERROR
PyModule_AddIntConstant(m, "LOG_PERROR", LOG_PERROR);
#endif
/* Facilities */
PyModule_AddIntConstant(m, "LOG_KERN", LOG_KERN);
PyModule_AddIntConstant(m, "LOG_USER", LOG_USER);
PyModule_AddIntConstant(m, "LOG_MAIL", LOG_MAIL);
PyModule_AddIntConstant(m, "LOG_DAEMON", LOG_DAEMON);
PyModule_AddIntConstant(m, "LOG_AUTH", LOG_AUTH);
PyModule_AddIntConstant(m, "LOG_LPR", LOG_LPR);
PyModule_AddIntConstant(m, "LOG_LOCAL0", LOG_LOCAL0);
PyModule_AddIntConstant(m, "LOG_LOCAL1", LOG_LOCAL1);
PyModule_AddIntConstant(m, "LOG_LOCAL2", LOG_LOCAL2);
PyModule_AddIntConstant(m, "LOG_LOCAL3", LOG_LOCAL3);
PyModule_AddIntConstant(m, "LOG_LOCAL4", LOG_LOCAL4);
PyModule_AddIntConstant(m, "LOG_LOCAL5", LOG_LOCAL5);
PyModule_AddIntConstant(m, "LOG_LOCAL6", LOG_LOCAL6);
PyModule_AddIntConstant(m, "LOG_LOCAL7", LOG_LOCAL7);
#ifndef LOG_SYSLOG
#define LOG_SYSLOG LOG_DAEMON
#endif
#ifndef LOG_NEWS
#define LOG_NEWS LOG_MAIL
#endif
#ifndef LOG_UUCP
#define LOG_UUCP LOG_MAIL
#endif
#ifndef LOG_CRON
#define LOG_CRON LOG_DAEMON
#endif
PyModule_AddIntConstant(m, "LOG_SYSLOG", LOG_SYSLOG);
PyModule_AddIntConstant(m, "LOG_CRON", LOG_CRON);
PyModule_AddIntConstant(m, "LOG_UUCP", LOG_UUCP);
PyModule_AddIntConstant(m, "LOG_NEWS", LOG_NEWS);
} | /* Initialization function for the module */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/syslogmodule.c#L240-L306 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _PyTime_DoubleToTimet | time_t
_PyTime_DoubleToTimet(double x)
{
time_t result;
double diff;
result = (time_t)x;
/* How much info did we lose? time_t may be an integral or
* floating type, and we don't know which. If it's integral,
* we don't know whether C truncates, rounds, returns the floor,
* etc. If we lost a second or more, the C rounding is
* unreasonable, or the input just doesn't fit in a time_t;
* call it an error regardless. Note that the original cast to
* time_t can cause a C error too, but nothing we can do to
* worm around that.
*/
diff = x - (double)result;
if (diff <= -1.0 || diff >= 1.0) {
PyErr_SetString(PyExc_ValueError,
"timestamp out of range for platform time_t");
result = (time_t)-1;
}
return result;
} | /* Exposed in timefuncs.h. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/timemodule.c#L110-L133 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | parse_time_double_args | static int
parse_time_double_args(PyObject *args, char *format, double *pwhen)
{
PyObject *ot = NULL;
if (!PyArg_ParseTuple(args, format, &ot))
return 0;
if (ot == NULL || ot == Py_None)
*pwhen = floattime();
else {
double when = PyFloat_AsDouble(ot);
if (PyErr_Occurred())
return 0;
*pwhen = when;
}
return 1;
} | /* Parse arg tuple that can contain an optional float-or-None value;
format needs to be "|O:name".
Returns non-zero on success (parallels PyArg_ParseTuple).
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/timemodule.c#L306-L322 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | inittimezone | static void
inittimezone(PyObject *m) {
/* This code moved from inittime wholesale to allow calling it from
time_tzset. In the future, some parts of it can be moved back
(for platforms that don't HAVE_WORKING_TZSET, when we know what they
are), and the extraneous calls to tzset(3) should be removed.
I haven't done this yet, as I don't want to change this code as
little as possible when introducing the time.tzset and time.tzsetwall
methods. This should simply be a method of doing the following once,
at the top of this function and removing the call to tzset() from
time_tzset():
#ifdef HAVE_TZSET
tzset()
#endif
And I'm lazy and hate C so nyer.
*/
#if defined(HAVE_TZNAME) && !defined(__GLIBC__) && !defined(__CYGWIN__) && !defined(MS_WINDOWS)
tzset();
#ifdef PYOS_OS2
PyModule_AddIntConstant(m, "timezone", _timezone);
#else /* !PYOS_OS2 */
PyModule_AddIntConstant(m, "timezone", timezone);
#endif /* PYOS_OS2 */
#ifdef HAVE_ALTZONE
PyModule_AddIntConstant(m, "altzone", altzone);
#else
#ifdef PYOS_OS2
PyModule_AddIntConstant(m, "altzone", _timezone-3600);
#else /* !PYOS_OS2 */
PyModule_AddIntConstant(m, "altzone", timezone-3600);
#endif /* PYOS_OS2 */
#endif
PyModule_AddIntConstant(m, "daylight", daylight);
PyModule_AddObject(m, "tzname",
Py_BuildValue("(zz)", tzname[0], tzname[1]));
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
#ifdef HAVE_STRUCT_TM_TM_ZONE
{
#define YEAR ((time_t)((365 * 24 + 6) * 3600))
time_t t;
struct tm *p;
long janzone, julyzone;
char janname[10], julyname[10];
t = (time((time_t *)0) / YEAR) * YEAR;
p = localtime(&t);
janzone = -p->tm_gmtoff;
strncpy(janname, p->tm_zone ? p->tm_zone : " ", 9);
janname[9] = '\0';
t += YEAR/2;
p = localtime(&t);
julyzone = -p->tm_gmtoff;
strncpy(julyname, p->tm_zone ? p->tm_zone : " ", 9);
julyname[9] = '\0';
if( janzone < julyzone ) {
/* DST is reversed in the southern hemisphere */
PyModule_AddIntConstant(m, "timezone", julyzone);
PyModule_AddIntConstant(m, "altzone", janzone);
PyModule_AddIntConstant(m, "daylight",
janzone != julyzone);
PyModule_AddObject(m, "tzname",
Py_BuildValue("(zz)",
julyname, janname));
} else {
PyModule_AddIntConstant(m, "timezone", janzone);
PyModule_AddIntConstant(m, "altzone", julyzone);
PyModule_AddIntConstant(m, "daylight",
janzone != julyzone);
PyModule_AddObject(m, "tzname",
Py_BuildValue("(zz)",
janname, julyname));
}
}
#else
#endif /* HAVE_STRUCT_TM_TM_ZONE */
#if defined(__CYGWIN__) || defined(MS_WINDOWS)
tzset();
PyModule_AddIntConstant(m, "timezone", _timezone);
PyModule_AddIntConstant(m, "altzone", _timezone-3600);
PyModule_AddIntConstant(m, "daylight", _daylight);
PyModule_AddObject(m, "tzname",
Py_BuildValue("(zz)", _tzname[0], _tzname[1]));
#endif /* __CYGWIN__ || MS_WINDOWS */
#endif /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
} | /* HAVE_WORKING_TZSET */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/timemodule.c#L698-L784 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | floattime | static double
floattime(void)
{
/* There are three ways to get the time:
(1) gettimeofday() -- resolution in microseconds
(2) ftime() -- resolution in milliseconds
(3) time() -- resolution in seconds
In all cases the return value is a float in seconds.
Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
fail, so we fall back on ftime() or time().
Note: clock resolution does not imply clock accuracy! */
#ifdef HAVE_GETTIMEOFDAY
{
struct timeval t;
#ifdef GETTIMEOFDAY_NO_TZ
if (gettimeofday(&t) == 0)
return (double)t.tv_sec + t.tv_usec*0.000001;
#else /* !GETTIMEOFDAY_NO_TZ */
if (gettimeofday(&t, (struct timezone *)NULL) == 0)
return (double)t.tv_sec + t.tv_usec*0.000001;
#endif /* !GETTIMEOFDAY_NO_TZ */
}
#endif /* !HAVE_GETTIMEOFDAY */
{
#if defined(HAVE_FTIME)
struct timeb t;
ftime(&t);
return (double)t.time + (double)t.millitm * (double)0.001;
#else /* !HAVE_FTIME */
time_t secs;
time(&secs);
return (double)secs;
#endif /* !HAVE_FTIME */
}
} | /* Implement floattime() for various platforms */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/timemodule.c#L902-L937 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | if | Py_BEGIN_ALLOW_THREADS
if (DosSleep(secs * 1000) != NO_ERROR) {
Py_BLOCK_THREADS
PyErr_SetFromErrno(PyExc_IOError);
return -1;
} | /* This Sleep *IS* Interruptable by Exceptions */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/timemodule.c#L1010-L1015 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | if | Py_BEGIN_ALLOW_THREADS
if(sleep((long)millisecs) < 0){
Py_BLOCK_THREADS
PyErr_SetFromErrno(PyExc_IOError);
return -1;
} | /* This sleep *CAN BE* interrupted. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/timemodule.c#L1049-L1054 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | Xxo_dealloc | static void
Xxo_dealloc(XxoObject *self)
{
Py_XDECREF(self->x_attr);
PyObject_Del(self);
} | /* Xxo methods */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/xxmodule.c#L43-L48 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | initxx | PyMODINIT_FUNC
initxx(void)
{
PyObject *m;
/* Due to cross platform compiler issues the slots must be filled
* here. It's required for portability to Windows without requiring
* C++. */
Null_Type.tp_base = &PyBaseObject_Type;
Null_Type.tp_new = PyType_GenericNew;
Str_Type.tp_base = &PyUnicode_Type;
/* Finalize the type object including setting type of the new type
* object; doing it here is required for portability, too. */
if (PyType_Ready(&Xxo_Type) < 0)
return;
/* Create the module and add the functions */
m = Py_InitModule3("xx", xx_methods, module_doc);
if (m == NULL)
return;
/* Add some symbolic constants to the module */
if (ErrorObject == NULL) {
ErrorObject = PyErr_NewException("xx.error", NULL, NULL);
if (ErrorObject == NULL)
return;
}
Py_INCREF(ErrorObject);
PyModule_AddObject(m, "error", ErrorObject);
/* Add Str */
if (PyType_Ready(&Str_Type) < 0)
return;
PyModule_AddObject(m, "Str", (PyObject *)&Str_Type);
/* Add Null */
if (PyType_Ready(&Null_Type) < 0)
return;
PyModule_AddObject(m, "Null", (PyObject *)&Null_Type);
} | /* Initialization function for the module (*must* be called initxx) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/xxmodule.c#L339-L379 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | zipimporter_init | static int
zipimporter_init(ZipImporter *self, PyObject *args, PyObject *kwds)
{
char *path, *p, *prefix, buf[MAXPATHLEN+2];
size_t len;
if (!_PyArg_NoKeywords("zipimporter()", kwds))
return -1;
if (!PyArg_ParseTuple(args, "s:zipimporter",
&path))
return -1;
len = strlen(path);
if (len == 0) {
PyErr_SetString(ZipImportError, "archive path is empty");
return -1;
}
if (len >= MAXPATHLEN) {
PyErr_SetString(ZipImportError,
"archive path too long");
return -1;
}
strcpy(buf, path);
#ifdef ALTSEP
for (p = buf; *p; p++) {
if (*p == ALTSEP)
*p = SEP;
}
#endif
path = NULL;
prefix = NULL;
for (;;) {
#ifndef RISCOS
struct stat statbuf;
int rv;
rv = stat(buf, &statbuf);
if (rv == 0) {
/* it exists */
if (S_ISREG(statbuf.st_mode))
/* it's a file */
path = buf;
break;
}
#else
if (object_exists(buf)) {
/* it exists */
if (isfile(buf))
/* it's a file */
path = buf;
break;
}
#endif
/* back up one path element */
p = strrchr(buf, SEP);
if (prefix != NULL)
*prefix = SEP;
if (p == NULL)
break;
*p = '\0';
prefix = p;
}
if (path != NULL) {
PyObject *files;
files = PyDict_GetItemString(zip_directory_cache, path);
if (files == NULL) {
files = read_directory(buf);
if (files == NULL)
return -1;
if (PyDict_SetItemString(zip_directory_cache, path,
files) != 0)
return -1;
}
else
Py_INCREF(files);
self->files = files;
}
else {
PyErr_SetString(ZipImportError, "not a Zip file");
return -1;
}
if (prefix == NULL)
prefix = "";
else {
prefix++;
len = strlen(prefix);
if (prefix[len-1] != SEP) {
/* add trailing SEP */
prefix[len] = SEP;
prefix[len + 1] = '\0';
}
}
self->archive = PyString_FromString(buf);
if (self->archive == NULL)
return -1;
self->prefix = PyString_FromString(prefix);
if (self->prefix == NULL)
return -1;
return 0;
} | /* zipimporter.__init__
Split the "subdirectory" from the Zip archive path, lookup a matching
entry in sys.path_importer_cache, fetch the file directory from there
if found, or else read it from the archive. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/zipimport.c#L60-L166 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | zipimporter_traverse | static int
zipimporter_traverse(PyObject *obj, visitproc visit, void *arg)
{
ZipImporter *self = (ZipImporter *)obj;
Py_VISIT(self->files);
return 0;
} | /* GC support. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/zipimport.c#L169-L175 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | make_filename | static int
make_filename(char *prefix, char *name, char *path)
{
size_t len;
char *p;
len = strlen(prefix);
/* self.prefix + name [+ SEP + "__init__"] + ".py[co]" */
if (len + strlen(name) + 13 >= MAXPATHLEN) {
PyErr_SetString(ZipImportError, "path too long");
return -1;
}
strcpy(path, prefix);
strcpy(path + len, name);
for (p = path + len; *p; p++) {
if (*p == '.')
*p = SEP;
}
len += strlen(name);
assert(len < INT_MAX);
return (int)len;
} | /* Given a (sub)modulename, write the potential file path in the
archive (without extension) to the path buffer. Return the
length of the resulting string. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/zipimport.c#L224-L247 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_module_info | static enum zi_module_info
get_module_info(ZipImporter *self, char *fullname)
{
char *subname, path[MAXPATHLEN + 1];
int len;
struct st_zip_searchorder *zso;
subname = get_subname(fullname);
len = make_filename(PyString_AsString(self->prefix), subname, path);
if (len < 0)
return MI_ERROR;
for (zso = zip_searchorder; *zso->suffix; zso++) {
strcpy(path + len, zso->suffix);
if (PyDict_GetItemString(self->files, path) != NULL) {
if (zso->type & IS_PACKAGE)
return MI_PACKAGE;
else
return MI_MODULE;
}
}
return MI_NOT_FOUND;
} | /* Return some information about a module. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/zipimport.c#L257-L280 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_long | static long
get_long(unsigned char *buf) {
long x;
x = buf[0];
x |= (long)buf[1] << 8;
x |= (long)buf[2] << 16;
x |= (long)buf[3] << 24;
#if SIZEOF_LONG > 4
/* Sign extension for 64-bit machines */
x |= -(x & 0x80000000L);
#endif
return x;
} | /* implementation */
/* Given a buffer, return the long that is represented by the first
4 bytes, encoded as little endian. This partially reimplements
marshal.c:r_long() */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/zipimport.c#L650-L662 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | eq_mtime | static int
eq_mtime(time_t t1, time_t t2)
{
time_t d = t1 - t2;
if (d < 0)
d = -d;
/* dostime only stores even seconds, so be lenient */
return d <= 1;
} | /* Lenient date/time comparison function. The precision of the mtime
in the archive is lower than the mtime stored in a .pyc: we
must allow a difference of at most one second. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/zipimport.c#L949-L957 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | parse_dostime | static time_t
parse_dostime(int dostime, int dosdate)
{
struct tm stm;
memset((void *) &stm, '\0', sizeof(stm));
stm.tm_sec = (dostime & 0x1f) * 2;
stm.tm_min = (dostime >> 5) & 0x3f;
stm.tm_hour = (dostime >> 11) & 0x1f;
stm.tm_mday = dosdate & 0x1f;
stm.tm_mon = ((dosdate >> 5) & 0x0f) - 1;
stm.tm_year = ((dosdate >> 9) & 0x7f) + 80;
stm.tm_isdst = -1; /* wday/yday is ignored */
return mktime(&stm);
} | /* Convert the date/time values found in the Zip archive to a value
that's compatible with the time stamp stored in .pyc files. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/zipimport.c#L1064-L1080 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_mtime_of_source | static time_t
get_mtime_of_source(ZipImporter *self, char *path)
{
PyObject *toc_entry;
time_t mtime = 0;
Py_ssize_t lastchar = strlen(path) - 1;
char savechar = path[lastchar];
path[lastchar] = '\0'; /* strip 'c' or 'o' from *.py[co] */
toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL && PyTuple_Check(toc_entry) &&
PyTuple_Size(toc_entry) == 8) {
/* fetch the time stamp of the .py file for comparison
with an embedded pyc time stamp */
int time, date;
time = PyInt_AsLong(PyTuple_GetItem(toc_entry, 5));
date = PyInt_AsLong(PyTuple_GetItem(toc_entry, 6));
mtime = parse_dostime(time, date);
}
path[lastchar] = savechar;
return mtime;
} | /* Given a path to a .pyc or .pyo file in the archive, return the
modification time of the matching .py file, or 0 if no source
is available. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/zipimport.c#L1085-L1105 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | save_unconsumed_input | static int
save_unconsumed_input(compobject *self, int err)
{
if (err == Z_STREAM_END) {
/* The end of the compressed data has been reached. Store the leftover
input data in self->unused_data. */
if (self->zst.avail_in > 0) {
Py_ssize_t old_size = PyString_GET_SIZE(self->unused_data);
Py_ssize_t new_size;
PyObject *new_data;
if (self->zst.avail_in > PY_SSIZE_T_MAX - old_size) {
PyErr_NoMemory();
return -1;
}
new_size = old_size + self->zst.avail_in;
new_data = PyString_FromStringAndSize(NULL, new_size);
if (new_data == NULL)
return -1;
Py_MEMCPY(PyString_AS_STRING(new_data),
PyString_AS_STRING(self->unused_data), old_size);
Py_MEMCPY(PyString_AS_STRING(new_data) + old_size,
self->zst.next_in, self->zst.avail_in);
Py_DECREF(self->unused_data);
self->unused_data = new_data;
self->zst.avail_in = 0;
}
}
if (self->zst.avail_in > 0 || PyString_GET_SIZE(self->unconsumed_tail)) {
/* This code handles two distinct cases:
1. Output limit was reached. Save leftover input in unconsumed_tail.
2. All input data was consumed. Clear unconsumed_tail. */
PyObject *new_data = PyString_FromStringAndSize(
(char *)self->zst.next_in, self->zst.avail_in);
if (new_data == NULL)
return -1;
Py_DECREF(self->unconsumed_tail);
self->unconsumed_tail = new_data;
}
return 0;
} | /* Helper for objdecompress() and unflush(). Saves any unconsumed input data in
self->unused_data or self->unconsumed_tail, as appropriate. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/zlibmodule.c#L472-L511 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyCPointerType_SetProto | static int
PyCPointerType_SetProto(StgDictObject *stgdict, PyObject *proto)
{
if (!proto || !PyType_Check(proto)) {
PyErr_SetString(PyExc_TypeError,
"_type_ must be a type");
return -1;
}
if (!PyType_stgdict(proto)) {
PyErr_SetString(PyExc_TypeError,
"_type_ must have storage info");
return -1;
}
Py_INCREF(proto);
Py_XDECREF(stgdict->proto);
stgdict->proto = proto;
return 0;
} | /******************************************************************/
/*
The PyCPointerType_Type metaclass must ensure that the subclass of Pointer can be
created. It must check for a _type_ attribute in the class. Since are no
runtime created properties, a CField is probably *not* needed ?
class IntPointer(Pointer):
_type_ = "i"
The PyCPointer_Type provides the functionality: a contents method/property, a
size property/method, and the sequence protocol.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L892-L909 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | CharArray_set_raw | static int
CharArray_set_raw(CDataObject *self, PyObject *value)
{
char *ptr;
Py_ssize_t size;
#if (PY_VERSION_HEX >= 0x02060000)
Py_buffer view = { 0 };
#endif
if (PyBuffer_Check(value)) {
size = Py_TYPE(value)->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr);
if (size < 0)
goto fail;
} else {
#if (PY_VERSION_HEX >= 0x02060000)
if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
goto fail;
size = view.len;
ptr = view.buf;
#else
if (-1 == PyString_AsStringAndSize(value, &ptr, &size))
goto fail;
#endif
}
if (size > self->b_size) {
PyErr_SetString(PyExc_ValueError,
"string too long");
goto fail;
}
memcpy(self->b_ptr, ptr, size);
#if (PY_VERSION_HEX >= 0x02060000)
PyBuffer_Release(&view);
#endif
return 0;
fail:
#if (PY_VERSION_HEX >= 0x02060000)
PyBuffer_Release(&view);
#endif
return -1;
} | /******************************************************************/
/*
PyCArrayType_Type
*/
/*
PyCArrayType_new ensures that the new Array subclass created has a _length_
attribute, and a _type_ attribute.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L1127-L1168 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | add_getset | static int
add_getset(PyTypeObject *type, PyGetSetDef *gsp)
{
PyObject *dict = type->tp_dict;
for (; gsp->name != NULL; gsp++) {
PyObject *descr;
descr = PyDescr_NewGetSet(type, gsp);
if (descr == NULL)
return -1;
if (PyDict_SetItemString(dict, gsp->name, descr) < 0)
return -1;
Py_DECREF(descr);
}
return 0;
} | /*
The next three functions copied from Python's typeobject.c.
They are used to attach methods, members, or getsets to a type *after* it
has been created: Arrays of characters have additional getsets to treat them
as strings.
*/
/*
static int
add_methods(PyTypeObject *type, PyMethodDef *meth)
{
PyObject *dict = type->tp_dict;
for (; meth->ml_name != NULL; meth++) {
PyObject *descr;
descr = PyDescr_NewMethod(type, meth);
if (descr == NULL)
return -1;
if (PyDict_SetItemString(dict,meth->ml_name, descr) < 0)
return -1;
Py_DECREF(descr);
}
return 0;
}
static int
add_members(PyTypeObject *type, PyMemberDef *memb)
{
PyObject *dict = type->tp_dict;
for (; memb->name != NULL; memb++) {
PyObject *descr;
descr = PyDescr_NewMember(type, memb);
if (descr == NULL)
return -1;
if (PyDict_SetItemString(dict, memb->name, descr) < 0)
return -1;
Py_DECREF(descr);
}
return 0;
}
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L1337-L1351 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | KeepRef | static int
KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
{
int result;
CDataObject *ob;
PyObject *key;
/* Optimization: no need to store None */
if (keep == Py_None) {
Py_DECREF(Py_None);
return 0;
}
ob = PyCData_GetContainer(target);
if (ob->b_objects == NULL || !PyDict_CheckExact(ob->b_objects)) {
Py_XDECREF(ob->b_objects);
ob->b_objects = keep; /* refcount consumed */
return 0;
}
key = unique_key(target, index);
if (key == NULL) {
Py_DECREF(keep);
return -1;
}
result = PyDict_SetItem(ob->b_objects, key, keep);
Py_DECREF(key);
Py_DECREF(keep);
return result;
} | /*
* Keep a reference to 'keep' in the 'target', at index 'index'.
*
* If 'keep' is None, do nothing.
*
* Otherwise create a dictionary (if it does not yet exist) id the root
* objects 'b_objects' item, which will store the 'keep' object under a unique
* key.
*
* The unique_key helper travels the target's b_base pointer down to the root,
* building a string containing hex-formatted indexes found during traversal,
* separated by colons.
*
* The index tuple is used as a key into the root object's b_objects dict.
*
* Note: This function steals a refcount of the third argument, even if it
* fails!
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L2525-L2552 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyCData_traverse | static int
PyCData_traverse(CDataObject *self, visitproc visit, void *arg)
{
Py_VISIT(self->b_objects);
Py_VISIT((PyObject *)self->b_base);
return 0;
} | /******************************************************************/
/*
PyCData_Type
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L2558-L2564 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyCData_nohash | static long
PyCData_nohash(PyObject *self)
{
PyErr_SetString(PyExc_TypeError, "unhashable type");
return -1;
} | /*
* CData objects are mutable, so they cannot be hashable!
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L2661-L2666 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _ctypes_simple_instance | int _ctypes_simple_instance(PyObject *obj)
{
PyTypeObject *type = (PyTypeObject *)obj;
if (PyCSimpleTypeObject_Check(type))
return type->tp_base != &Simple_Type;
return 0;
} | /*
This function returns TRUE for c_int, c_void_p, and these kind of
classes. FALSE otherwise FALSE also for subclasses of c_int and
such.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L2866-L2873 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyCData_set | int
PyCData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
Py_ssize_t index, Py_ssize_t size, char *ptr)
{
CDataObject *mem = (CDataObject *)dst;
PyObject *result;
if (!CDataObject_Check(dst)) {
PyErr_SetString(PyExc_TypeError,
"not a ctype instance");
return -1;
}
result = _PyCData_set(mem, type, setfunc, value,
size, ptr);
if (result == NULL)
return -1;
/* KeepRef steals a refcount from it's last argument */
/* If KeepRef fails, we are stumped. The dst memory block has already
been changed */
return KeepRef(mem, index, result);
} | /*
* Set a slice in object 'dst', which has the type 'type',
* to the value 'value'.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L2994-L3016 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyCFuncPtr_set_errcheck | static int
PyCFuncPtr_set_errcheck(PyCFuncPtrObject *self, PyObject *ob)
{
if (ob && !PyCallable_Check(ob)) {
PyErr_SetString(PyExc_TypeError,
"the errcheck attribute must be callable");
return -1;
}
Py_XDECREF(self->errcheck);
Py_XINCREF(ob);
self->errcheck = ob;
return 0;
} | /*****************************************************************/
/*
PyCFuncPtr_Type
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L3054-L3066 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _check_outarg_type | static int
_check_outarg_type(PyObject *arg, Py_ssize_t index)
{
StgDictObject *dict;
if (PyCPointerTypeObject_Check(arg))
return 1;
if (PyCArrayTypeObject_Check(arg))
return 1;
dict = PyType_stgdict(arg);
if (dict
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
&& PyString_Check(dict->proto)
/* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */
&& (strchr("PzZ", PyString_AS_STRING(dict->proto)[0]))) {
return 1;
}
PyErr_Format(PyExc_TypeError,
"'out' parameter %d must be a pointer type, not %s",
Py_SAFE_DOWNCAST(index, Py_ssize_t, int),
PyType_Check(arg) ?
((PyTypeObject *)arg)->tp_name :
Py_TYPE(arg)->tp_name);
return 0;
} | /* Return 1 if usable, 0 else and exception set. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L3217-L3244 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _validate_paramflags | static int
_validate_paramflags(PyTypeObject *type, PyObject *paramflags)
{
Py_ssize_t i, len;
StgDictObject *dict;
PyObject *argtypes;
dict = PyType_stgdict((PyObject *)type);
assert(dict); /* Cannot be NULL. 'type' is a PyCFuncPtr type. */
argtypes = dict->argtypes;
if (paramflags == NULL || dict->argtypes == NULL)
return 1;
if (!PyTuple_Check(paramflags)) {
PyErr_SetString(PyExc_TypeError,
"paramflags must be a tuple or None");
return 0;
}
len = PyTuple_GET_SIZE(paramflags);
if (len != PyTuple_GET_SIZE(dict->argtypes)) {
PyErr_SetString(PyExc_ValueError,
"paramflags must have the same length as argtypes");
return 0;
}
for (i = 0; i < len; ++i) {
PyObject *item = PyTuple_GET_ITEM(paramflags, i);
int flag;
char *name;
PyObject *defval;
PyObject *typ;
if (!PyArg_ParseTuple(item, "i|zO", &flag, &name, &defval)) {
PyErr_SetString(PyExc_TypeError,
"paramflags must be a sequence of (int [,string [,value]]) tuples");
return 0;
}
typ = PyTuple_GET_ITEM(argtypes, i);
switch (flag & (PARAMFLAG_FIN | PARAMFLAG_FOUT | PARAMFLAG_FLCID)) {
case 0:
case PARAMFLAG_FIN:
case PARAMFLAG_FIN | PARAMFLAG_FLCID:
case PARAMFLAG_FIN | PARAMFLAG_FOUT:
break;
case PARAMFLAG_FOUT:
if (!_check_outarg_type(typ, i+1))
return 0;
break;
default:
PyErr_Format(PyExc_TypeError,
"paramflag value %d not supported",
flag);
return 0;
}
}
return 1;
} | /* Returns 1 on success, 0 on error */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L3247-L3304 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _init_pos_args | static int
_init_pos_args(PyObject *self, PyTypeObject *type,
PyObject *args, PyObject *kwds,
int index)
{
StgDictObject *dict;
PyObject *fields;
int i;
if (PyType_stgdict((PyObject *)type->tp_base)) {
index = _init_pos_args(self, type->tp_base,
args, kwds,
index);
if (index == -1)
return -1;
}
dict = PyType_stgdict((PyObject *)type);
fields = PyDict_GetItemString((PyObject *)dict, "_fields_");
if (fields == NULL)
return index;
for (i = 0;
i < dict->length && (i+index) < PyTuple_GET_SIZE(args);
++i) {
PyObject *pair = PySequence_GetItem(fields, i);
PyObject *name, *val;
int res;
if (!pair)
return -1;
name = PySequence_GetItem(pair, 0);
if (!name) {
Py_DECREF(pair);
return -1;
}
val = PyTuple_GET_ITEM(args, i + index);
if (kwds && PyDict_GetItem(kwds, name)) {
char *field = PyString_AsString(name);
if (field == NULL) {
PyErr_Clear();
field = "???";
}
PyErr_Format(PyExc_TypeError,
"duplicate values for field '%s'",
field);
Py_DECREF(pair);
Py_DECREF(name);
return -1;
}
res = PyObject_SetAttr(self, name, val);
Py_DECREF(pair);
Py_DECREF(name);
if (res == -1)
return -1;
}
return index + dict->length;
} | /*****************************************************************/
/*
Struct_Type
*/
/*
This function is called to initialize a Structure or Union with positional
arguments. It calls itself recursively for all Structure or Union base
classes, then retrieves the _fields_ member to associate the argument
position with the correct field name.
Returns -1 on error, or the index of next argument on success.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L4128-L4185 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | Array_init | static int
Array_init(CDataObject *self, PyObject *args, PyObject *kw)
{
Py_ssize_t i;
Py_ssize_t n;
if (!PyTuple_Check(args)) {
PyErr_SetString(PyExc_TypeError,
"args not a tuple?");
return -1;
}
n = PyTuple_GET_SIZE(args);
for (i = 0; i < n; ++i) {
PyObject *v;
v = PyTuple_GET_ITEM(args, i);
if (-1 == PySequence_SetItem((PyObject *)self, i, v))
return -1;
}
return 0;
} | /******************************************************************/
/*
PyCArray_Type
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L4310-L4329 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | Simple_set_value | static int
Simple_set_value(CDataObject *self, PyObject *value)
{
PyObject *result;
StgDictObject *dict = PyObject_stgdict((PyObject *)self);
if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
"can't delete attribute");
return -1;
}
assert(dict); /* Cannot be NULL for CDataObject instances */
assert(dict->setfunc);
result = dict->setfunc(self->b_ptr, value, dict->size);
if (!result)
return -1;
/* consumes the refcount the setfunc returns */
return KeepRef(self, 0, result);
} | /******************************************************************/
/*
Simple_Type
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes.c#L4776-L4795 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _testfunc_cbk_reg_int | EXPORT(int)
_testfunc_cbk_reg_int(int a, int b, int c, int d, int e,
int (*func)(int, int, int, int, int))
{
return func(a*a, b*b, c*c, d*d, e*e);
} | /* some functions handy for testing */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes_test.c#L28-L33 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | GetString | EXPORT(void) GetString(BSTR *pbstr)
{
*pbstr = SysAllocString(L"Goodbye!");
} | /* See Don Box (german), pp 79ff. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes_test.c#L349-L352 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | tf_bb | EXPORT(signed char) tf_bb(signed char x, signed char c) { S; return c/3; } | /*******/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/_ctypes_test.c#L480-L480 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | CThunkObject_dealloc | static void
CThunkObject_dealloc(PyObject *_self)
{
CThunkObject *self = (CThunkObject *)_self;
PyObject_GC_UnTrack(self);
Py_XDECREF(self->converters);
Py_XDECREF(self->callable);
Py_XDECREF(self->restype);
if (self->pcl_write)
ffi_closure_free(self->pcl_write);
PyObject_GC_Del(self);
} | /**************************************************************/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/callbacks.c#L17-L28 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PrintError | static void
PrintError(char *msg, ...)
{
char buf[512];
PyObject *f = PySys_GetObject("stderr");
va_list marker;
va_start(marker, msg);
vsnprintf(buf, sizeof(buf), msg, marker);
va_end(marker);
if (f)
PyFile_WriteString(buf, f);
PyErr_Print();
} | /**************************************************************/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/callbacks.c#L84-L97 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _ctypes_add_traceback | void _ctypes_add_traceback(char *funcname, char *filename, int lineno)
{
PyObject *py_globals = 0;
PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0;
py_globals = PyDict_New();
if (!py_globals) goto bad;
py_code = PyCode_NewEmpty(filename, funcname, lineno);
if (!py_code) goto bad;
py_frame = PyFrame_New(
PyThreadState_Get(), /*PyThreadState *tstate,*/
py_code, /*PyCodeObject *code,*/
py_globals, /*PyObject *globals,*/
0 /*PyObject *locals*/
);
if (!py_frame) goto bad;
py_frame->f_lineno = lineno;
PyTraceBack_Here(py_frame);
bad:
Py_XDECREF(py_globals);
Py_XDECREF(py_code);
Py_XDECREF(py_frame);
} | /* after code that pyrex generates */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/callbacks.c#L150-L173 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TryAddRef | static void
TryAddRef(StgDictObject *dict, CDataObject *obj)
{
IUnknown *punk;
if (NULL == PyDict_GetItemString((PyObject *)dict, "_needs_com_addref_"))
return;
punk = *(IUnknown **)obj->b_ptr;
if (punk)
punk->lpVtbl->AddRef(punk);
return;
} | /*
* We must call AddRef() on non-NULL COM pointers we receive as arguments
* to callback functions - these functions are COM method implementations.
* The Python instances we create have a __del__ method which calls Release().
*
* The presence of a class attribute named '_needs_com_addref_' triggers this
* behaviour. It would also be possible to call the AddRef() Python method,
* after checking for PyObject_IsTrue(), but this would probably be somewhat
* slower.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/callbacks.c#L186-L198 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | _CallPythonObject | static void _CallPythonObject(void *mem,
ffi_type *restype,
SETFUNC setfunc,
PyObject *callable,
PyObject *converters,
int flags,
void **pArgs)
{
Py_ssize_t i;
PyObject *result;
PyObject *arglist = NULL;
Py_ssize_t nArgs;
PyObject *error_object = NULL;
int *space;
#ifdef WITH_THREAD
PyGILState_STATE state = PyGILState_Ensure();
#endif
nArgs = PySequence_Length(converters);
/* Hm. What to return in case of error?
For COM, 0xFFFFFFFF seems better than 0.
*/
if (nArgs < 0) {
PrintError("BUG: PySequence_Length");
goto Done;
}
arglist = PyTuple_New(nArgs);
if (!arglist) {
PrintError("PyTuple_New()");
goto Done;
}
for (i = 0; i < nArgs; ++i) {
/* Note: new reference! */
PyObject *cnv = PySequence_GetItem(converters, i);
StgDictObject *dict;
if (cnv)
dict = PyType_stgdict(cnv);
else {
PrintError("Getting argument converter %d\n", i);
goto Done;
}
if (dict && dict->getfunc && !_ctypes_simple_instance(cnv)) {
PyObject *v = dict->getfunc(*pArgs, dict->size);
if (!v) {
PrintError("create argument %d:\n", i);
Py_DECREF(cnv);
goto Done;
}
PyTuple_SET_ITEM(arglist, i, v);
/* XXX XXX XX
We have the problem that c_byte or c_short have dict->size of
1 resp. 4, but these parameters are pushed as sizeof(int) bytes.
BTW, the same problem occurs when they are pushed as parameters
*/
} else if (dict) {
/* Hm, shouldn't we use PyCData_AtAddress() or something like that instead? */
CDataObject *obj = (CDataObject *)PyObject_CallFunctionObjArgs(cnv, NULL);
if (!obj) {
PrintError("create argument %d:\n", i);
Py_DECREF(cnv);
goto Done;
}
if (!CDataObject_Check(obj)) {
Py_DECREF(obj);
Py_DECREF(cnv);
PrintError("unexpected result of create argument %d:\n", i);
goto Done;
}
memcpy(obj->b_ptr, *pArgs, dict->size);
PyTuple_SET_ITEM(arglist, i, (PyObject *)obj);
#ifdef MS_WIN32
TryAddRef(dict, obj);
#endif
} else {
PyErr_SetString(PyExc_TypeError,
"cannot build parameter");
PrintError("Parsing argument %d\n", i);
Py_DECREF(cnv);
goto Done;
}
Py_DECREF(cnv);
/* XXX error handling! */
pArgs++;
}
#define CHECK(what, x) \
if (x == NULL) _ctypes_add_traceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print()
if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
error_object = _ctypes_get_errobj(&space);
if (error_object == NULL)
goto Done;
if (flags & FUNCFLAG_USE_ERRNO) {
int temp = space[0];
space[0] = errno;
errno = temp;
}
#ifdef MS_WIN32
if (flags & FUNCFLAG_USE_LASTERROR) {
int temp = space[1];
space[1] = GetLastError();
SetLastError(temp);
}
#endif
}
result = PyObject_CallObject(callable, arglist);
CHECK("'calling callback function'", result);
#ifdef MS_WIN32
if (flags & FUNCFLAG_USE_LASTERROR) {
int temp = space[1];
space[1] = GetLastError();
SetLastError(temp);
}
#endif
if (flags & FUNCFLAG_USE_ERRNO) {
int temp = space[0];
space[0] = errno;
errno = temp;
}
Py_XDECREF(error_object);
if ((restype != &ffi_type_void) && result) {
PyObject *keep;
assert(setfunc);
#ifdef WORDS_BIGENDIAN
/* See the corresponding code in callproc.c, around line 961 */
if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg))
mem = (char *)mem + sizeof(ffi_arg) - restype->size;
#endif
keep = setfunc(mem, result, 0);
CHECK("'converting callback result'", keep);
/* keep is an object we have to keep alive so that the result
stays valid. If there is no such object, the setfunc will
have returned Py_None.
If there is such an object, we have no choice than to keep
it alive forever - but a refcount and/or memory leak will
be the result. EXCEPT when restype is py_object - Python
itself knows how to manage the refcount of these objects.
*/
if (keep == NULL) /* Could not convert callback result. */
PyErr_WriteUnraisable(callable);
else if (keep == Py_None) /* Nothing to keep */
Py_DECREF(keep);
else if (setfunc != _ctypes_get_fielddesc("O")->setfunc) {
if (-1 == PyErr_Warn(PyExc_RuntimeWarning,
"memory leak in callback function."))
PyErr_WriteUnraisable(callable);
}
}
Py_XDECREF(result);
Done:
Py_XDECREF(arglist);
#ifdef WITH_THREAD
PyGILState_Release(state);
#endif
} | /******************************************************************************
*
* Call the python object with all arguments
*
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/callbacks.c#L206-L366 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | Call_GetClassObject | long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
PyObject *mod, *func, *result;
long retval;
static PyObject *context;
if (context == NULL)
context = PyString_InternFromString("_ctypes.DllGetClassObject");
mod = PyImport_ImportModuleNoBlock("ctypes");
if (!mod) {
PyErr_WriteUnraisable(context ? context : Py_None);
/* There has been a warning before about this already */
return E_FAIL;
}
func = PyObject_GetAttrString(mod, "DllGetClassObject");
Py_DECREF(mod);
if (!func) {
PyErr_WriteUnraisable(context ? context : Py_None);
return E_FAIL;
}
{
PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid);
PyObject *py_riid = PyLong_FromVoidPtr((void *)riid);
PyObject *py_ppv = PyLong_FromVoidPtr(ppv);
if (!py_rclsid || !py_riid || !py_ppv) {
Py_XDECREF(py_rclsid);
Py_XDECREF(py_riid);
Py_XDECREF(py_ppv);
Py_DECREF(func);
PyErr_WriteUnraisable(context ? context : Py_None);
return E_FAIL;
}
result = PyObject_CallFunctionObjArgs(func,
py_rclsid,
py_riid,
py_ppv,
NULL);
Py_DECREF(py_rclsid);
Py_DECREF(py_riid);
Py_DECREF(py_ppv);
}
Py_DECREF(func);
if (!result) {
PyErr_WriteUnraisable(context ? context : Py_None);
return E_FAIL;
}
retval = PyInt_AsLong(result);
if (PyErr_Occurred()) {
PyErr_WriteUnraisable(context ? context : Py_None);
retval = E_FAIL;
}
Py_DECREF(result);
return retval;
} | /******************************************************************/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/callbacks.c#L511-L568 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | DllCanUnloadNow | STDAPI DllCanUnloadNow(void)
{
long result;
#ifdef WITH_THREAD
PyGILState_STATE state = PyGILState_Ensure();
#endif
result = Call_CanUnloadNow();
#ifdef WITH_THREAD
PyGILState_Release(state);
#endif
return result;
} | /*
DllRegisterServer and DllUnregisterServer still missing
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/callbacks.c#L635-L646 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ConvParam | static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
{
StgDictObject *dict;
pa->keep = NULL; /* so we cannot forget it later */
dict = PyObject_stgdict(obj);
if (dict) {
PyCArgObject *carg;
assert(dict->paramfunc);
/* If it has an stgdict, it is a CDataObject */
carg = dict->paramfunc((CDataObject *)obj);
pa->ffi_type = carg->pffi_type;
memcpy(&pa->value, &carg->value, sizeof(pa->value));
pa->keep = (PyObject *)carg;
return 0;
}
if (PyCArg_CheckExact(obj)) {
PyCArgObject *carg = (PyCArgObject *)obj;
pa->ffi_type = carg->pffi_type;
Py_INCREF(obj);
pa->keep = obj;
memcpy(&pa->value, &carg->value, sizeof(pa->value));
return 0;
}
/* check for None, integer, string or unicode and use directly if successful */
if (obj == Py_None) {
pa->ffi_type = &ffi_type_pointer;
pa->value.p = NULL;
return 0;
}
if (PyInt_Check(obj)) {
pa->ffi_type = &ffi_type_sint;
pa->value.i = PyInt_AS_LONG(obj);
return 0;
}
if (PyLong_Check(obj)) {
pa->ffi_type = &ffi_type_sint;
pa->value.i = (long)PyLong_AsUnsignedLong(obj);
if (pa->value.i == -1 && PyErr_Occurred()) {
PyErr_Clear();
pa->value.i = PyLong_AsLong(obj);
if (pa->value.i == -1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_OverflowError,
"long int too long to convert");
return -1;
}
}
return 0;
}
if (PyString_Check(obj)) {
pa->ffi_type = &ffi_type_pointer;
pa->value.p = PyString_AS_STRING(obj);
Py_INCREF(obj);
pa->keep = obj;
return 0;
}
#ifdef CTYPES_UNICODE
if (PyUnicode_Check(obj)) {
#ifdef HAVE_USABLE_WCHAR_T
pa->ffi_type = &ffi_type_pointer;
pa->value.p = PyUnicode_AS_UNICODE(obj);
Py_INCREF(obj);
pa->keep = obj;
return 0;
#else
int size = PyUnicode_GET_SIZE(obj);
pa->ffi_type = &ffi_type_pointer;
size += 1; /* terminating NUL */
size *= sizeof(wchar_t);
pa->value.p = PyMem_Malloc(size);
if (!pa->value.p) {
PyErr_NoMemory();
return -1;
}
memset(pa->value.p, 0, size);
pa->keep = CAPSULE_NEW(pa->value.p, CTYPES_CAPSULE_WCHAR_T);
if (!pa->keep) {
PyMem_Free(pa->value.p);
return -1;
}
if (-1 == PyUnicode_AsWideChar((PyUnicodeObject *)obj,
pa->value.p, PyUnicode_GET_SIZE(obj)))
return -1;
return 0;
#endif
}
#endif
{
PyObject *arg;
arg = PyObject_GetAttrString(obj, "_as_parameter_");
/* Which types should we exactly allow here?
integers are required for using Python classes
as parameters (they have to expose the '_as_parameter_'
attribute)
*/
if (arg) {
int result;
result = ConvParam(arg, index, pa);
Py_DECREF(arg);
return result;
}
PyErr_Format(PyExc_TypeError,
"Don't know how to convert parameter %d",
Py_SAFE_DOWNCAST(index, Py_ssize_t, int));
return -1;
}
} | /*
* Convert a single Python object into a PyCArgObject and return it.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/callproc.c#L616-L729 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_long | static int
get_long(PyObject *v, long *p)
{
long x;
if (PyFloat_Check(v)) {
PyErr_SetString(PyExc_TypeError,
"int expected instead of float");
return -1;
}
x = PyInt_AsUnsignedLongMask(v);
if (x == -1 && PyErr_Occurred())
return -1;
*p = x;
return 0;
} | /******************************************************************/
/*
Accessor functions
*/
/* Derived from Modules/structmodule.c:
Helper routine to get a Python integer and raise the appropriate error
if it isn't one */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/cfield.c#L352-L366 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_ulong | static int
get_ulong(PyObject *v, unsigned long *p)
{
unsigned long x;
if (PyFloat_Check(v)) {
PyErr_SetString(PyExc_TypeError,
"int expected instead of float");
return -1;
}
x = PyInt_AsUnsignedLongMask(v);
if (x == (unsigned long)-1 && PyErr_Occurred())
return -1;
*p = x;
return 0;
} | /* Same, but handling unsigned long */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/cfield.c#L370-L384 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_longlong | static int
get_longlong(PyObject *v, PY_LONG_LONG *p)
{
PY_LONG_LONG x;
if (PyFloat_Check(v)) {
PyErr_SetString(PyExc_TypeError,
"int expected instead of float");
return -1;
}
x = PyInt_AsUnsignedLongLongMask(v);
if (x == -1 && PyErr_Occurred())
return -1;
*p = x;
return 0;
} | /* Same, but handling native long long. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/cfield.c#L390-L404 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_ulonglong | static int
get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
{
unsigned PY_LONG_LONG x;
if (PyFloat_Check(v)) {
PyErr_SetString(PyExc_TypeError,
"int expected instead of float");
return -1;
}
x = PyInt_AsUnsignedLongLongMask(v);
if (x == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())
return -1;
*p = x;
return 0;
} | /* Same, but handling native unsigned long long. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/cfield.c#L408-L422 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ffi_closure_free | void ffi_closure_free(void *p)
{
ITEM *item = (ITEM *)p;
item->next = free_list;
free_list = item;
} | /******************************************************************/
/* put the item back into the free list */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/malloc_closure.c#L96-L101 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyCStgDict_init | static int
PyCStgDict_init(StgDictObject *self, PyObject *args, PyObject *kwds)
{
if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0)
return -1;
self->format = NULL;
self->ndim = 0;
self->shape = NULL;
return 0;
} | /******************************************************************/
/*
StdDict - a dictionary subclass, containing additional C accessible fields
XXX blabla more
*/
/* Seems we need this, otherwise we get problems when calling
* PyDict_SetItem() (ma_lookup is NULL)
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/stgdict.c#L23-L32 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | MakeFields | static int
MakeFields(PyObject *type, CFieldObject *descr,
Py_ssize_t index, Py_ssize_t offset)
{
Py_ssize_t i;
PyObject *fields;
PyObject *fieldlist;
fields = PyObject_GetAttrString(descr->proto, "_fields_");
if (fields == NULL)
return -1;
fieldlist = PySequence_Fast(fields, "_fields_ must be a sequence");
Py_DECREF(fields);
if (fieldlist == NULL)
return -1;
for (i = 0; i < PySequence_Fast_GET_SIZE(fieldlist); ++i) {
PyObject *pair = PySequence_Fast_GET_ITEM(fieldlist, i); /* borrowed */
PyObject *fname, *ftype, *bits;
CFieldObject *fdescr;
CFieldObject *new_descr;
/* Convert to PyArg_UnpackTuple... */
if (!PyArg_ParseTuple(pair, "OO|O", &fname, &ftype, &bits)) {
Py_DECREF(fieldlist);
return -1;
}
fdescr = (CFieldObject *)PyObject_GetAttr(descr->proto, fname);
if (fdescr == NULL) {
Py_DECREF(fieldlist);
return -1;
}
if (Py_TYPE(fdescr) != &PyCField_Type) {
PyErr_SetString(PyExc_TypeError, "unexpected type");
Py_DECREF(fdescr);
Py_DECREF(fieldlist);
return -1;
}
if (fdescr->anonymous) {
int rc = MakeFields(type, fdescr,
index + fdescr->index,
offset + fdescr->offset);
Py_DECREF(fdescr);
if (rc == -1) {
Py_DECREF(fieldlist);
return -1;
}
continue;
}
new_descr = (CFieldObject *)PyObject_CallObject((PyObject *)&PyCField_Type, NULL);
if (new_descr == NULL) {
Py_DECREF(fdescr);
Py_DECREF(fieldlist);
return -1;
}
assert(Py_TYPE(new_descr) == &PyCField_Type);
new_descr->size = fdescr->size;
new_descr->offset = fdescr->offset + offset;
new_descr->index = fdescr->index + index;
new_descr->proto = fdescr->proto;
Py_XINCREF(new_descr->proto);
new_descr->getfunc = fdescr->getfunc;
new_descr->setfunc = fdescr->setfunc;
Py_DECREF(fdescr);
if (-1 == PyObject_SetAttr(type, fname, (PyObject *)new_descr)) {
Py_DECREF(fieldlist);
Py_DECREF(new_descr);
return -1;
}
Py_DECREF(new_descr);
}
Py_DECREF(fieldlist);
return 0;
} | /* descr is the descriptor for a field marked as anonymous. Get all the
_fields_ descriptors from descr->proto, create new descriptors with offset
and index adjusted, and stuff them into type.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/stgdict.c#L187-L261 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | MakeAnonFields | static int
MakeAnonFields(PyObject *type)
{
PyObject *anon;
PyObject *anon_names;
Py_ssize_t i;
anon = PyObject_GetAttrString(type, "_anonymous_");
if (anon == NULL) {
PyErr_Clear();
return 0;
}
anon_names = PySequence_Fast(anon, "_anonymous_ must be a sequence");
Py_DECREF(anon);
if (anon_names == NULL)
return -1;
for (i = 0; i < PySequence_Fast_GET_SIZE(anon_names); ++i) {
PyObject *fname = PySequence_Fast_GET_ITEM(anon_names, i); /* borrowed */
CFieldObject *descr = (CFieldObject *)PyObject_GetAttr(type, fname);
if (descr == NULL) {
Py_DECREF(anon_names);
return -1;
}
assert(Py_TYPE(descr) == &PyCField_Type);
descr->anonymous = 1;
/* descr is in the field descriptor. */
if (-1 == MakeFields(type, (CFieldObject *)descr,
((CFieldObject *)descr)->index,
((CFieldObject *)descr)->offset)) {
Py_DECREF(descr);
Py_DECREF(anon_names);
return -1;
}
Py_DECREF(descr);
}
Py_DECREF(anon_names);
return 0;
} | /* Iterate over the names in the type's _anonymous_ attribute, if present,
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/stgdict.c#L265-L305 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PyCStructUnionType_update_stgdict | int
PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
{
StgDictObject *stgdict, *basedict;
Py_ssize_t len, offset, size, align, i;
Py_ssize_t union_size, total_align;
Py_ssize_t field_size = 0;
int bitofs;
PyObject *isPacked;
int pack = 0;
Py_ssize_t ffi_ofs;
int big_endian;
/* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to
be a way to use the old, broken sematics: _fields_ are not extended
but replaced in subclasses.
XXX Remove this in ctypes 1.0!
*/
int use_broken_old_ctypes_semantics;
if (fields == NULL)
return 0;
#ifdef WORDS_BIGENDIAN
big_endian = PyObject_HasAttrString(type, "_swappedbytes_") ? 0 : 1;
#else
big_endian = PyObject_HasAttrString(type, "_swappedbytes_") ? 1 : 0;
#endif
use_broken_old_ctypes_semantics = \
PyObject_HasAttrString(type, "_use_broken_old_ctypes_structure_semantics_");
isPacked = PyObject_GetAttrString(type, "_pack_");
if (isPacked) {
pack = _PyInt_AsInt(isPacked);
if (pack < 0 || PyErr_Occurred()) {
Py_XDECREF(isPacked);
PyErr_SetString(PyExc_ValueError,
"_pack_ must be a non-negative integer");
return -1;
}
Py_DECREF(isPacked);
} else
PyErr_Clear();
len = PySequence_Length(fields);
if (len == -1) {
PyErr_SetString(PyExc_TypeError,
"'_fields_' must be a sequence of pairs");
return -1;
}
stgdict = PyType_stgdict(type);
if (!stgdict)
return -1;
/* If this structure/union is already marked final we cannot assign
_fields_ anymore. */
if (stgdict->flags & DICTFLAG_FINAL) {/* is final ? */
PyErr_SetString(PyExc_AttributeError,
"_fields_ is final");
return -1;
}
if (stgdict->format) {
PyMem_Free(stgdict->format);
stgdict->format = NULL;
}
if (stgdict->ffi_type_pointer.elements)
PyMem_Free(stgdict->ffi_type_pointer.elements);
basedict = PyType_stgdict((PyObject *)((PyTypeObject *)type)->tp_base);
if (basedict && !use_broken_old_ctypes_semantics) {
size = offset = basedict->size;
align = basedict->align;
union_size = 0;
total_align = align ? align : 1;
stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT;
stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (basedict->length + len + 1));
if (stgdict->ffi_type_pointer.elements == NULL) {
PyErr_NoMemory();
return -1;
}
memset(stgdict->ffi_type_pointer.elements, 0,
sizeof(ffi_type *) * (basedict->length + len + 1));
memcpy(stgdict->ffi_type_pointer.elements,
basedict->ffi_type_pointer.elements,
sizeof(ffi_type *) * (basedict->length));
ffi_ofs = basedict->length;
} else {
offset = 0;
size = 0;
align = 0;
union_size = 0;
total_align = 1;
stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT;
stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (len + 1));
if (stgdict->ffi_type_pointer.elements == NULL) {
PyErr_NoMemory();
return -1;
}
memset(stgdict->ffi_type_pointer.elements, 0,
sizeof(ffi_type *) * (len + 1));
ffi_ofs = 0;
}
assert(stgdict->format == NULL);
if (isStruct && !isPacked) {
stgdict->format = _ctypes_alloc_format_string(NULL, "T{");
} else {
/* PEP3118 doesn't support union, or packed structures (well,
only standard packing, but we dont support the pep for
that). Use 'B' for bytes. */
stgdict->format = _ctypes_alloc_format_string(NULL, "B");
}
#define realdict ((PyObject *)&stgdict->dict)
for (i = 0; i < len; ++i) {
PyObject *name = NULL, *desc = NULL;
PyObject *pair = PySequence_GetItem(fields, i);
PyObject *prop;
StgDictObject *dict;
int bitsize = 0;
if (!pair || !PyArg_ParseTuple(pair, "OO|i", &name, &desc, &bitsize)) {
PyErr_SetString(PyExc_AttributeError,
"'_fields_' must be a sequence of pairs");
Py_XDECREF(pair);
return -1;
}
dict = PyType_stgdict(desc);
if (dict == NULL) {
Py_DECREF(pair);
PyErr_Format(PyExc_TypeError,
#if (PY_VERSION_HEX < 0x02050000)
"second item in _fields_ tuple (index %d) must be a C type",
#else
"second item in _fields_ tuple (index %zd) must be a C type",
#endif
i);
return -1;
}
stgdict->ffi_type_pointer.elements[ffi_ofs + i] = &dict->ffi_type_pointer;
if (dict->flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER))
stgdict->flags |= TYPEFLAG_HASPOINTER;
dict->flags |= DICTFLAG_FINAL; /* mark field type final */
if (PyTuple_Size(pair) == 3) { /* bits specified */
switch(dict->ffi_type_pointer.type) {
case FFI_TYPE_UINT8:
case FFI_TYPE_UINT16:
case FFI_TYPE_UINT32:
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
break;
case FFI_TYPE_SINT8:
case FFI_TYPE_SINT16:
case FFI_TYPE_SINT32:
if (dict->getfunc != _ctypes_get_fielddesc("c")->getfunc
#ifdef CTYPES_UNICODE
&& dict->getfunc != _ctypes_get_fielddesc("u")->getfunc
#endif
)
break;
/* else fall through */
default:
PyErr_Format(PyExc_TypeError,
"bit fields not allowed for type %s",
((PyTypeObject *)desc)->tp_name);
Py_DECREF(pair);
return -1;
}
if (bitsize <= 0 || bitsize > dict->size * 8) {
PyErr_SetString(PyExc_ValueError,
"number of bits invalid for bit field");
Py_DECREF(pair);
return -1;
}
} else
bitsize = 0;
if (isStruct && !isPacked) {
char *fieldfmt = dict->format ? dict->format : "B";
char *fieldname = PyString_AsString(name);
char *ptr;
Py_ssize_t len;
char *buf;
if (fieldname == NULL)
{
PyErr_Format(PyExc_TypeError,
"structure field name must be string not %s",
name->ob_type->tp_name);
Py_DECREF(pair);
return -1;
}
len = strlen(fieldname) + strlen(fieldfmt);
buf = PyMem_Malloc(len + 2 + 1);
if (buf == NULL) {
Py_DECREF(pair);
PyErr_NoMemory();
return -1;
}
sprintf(buf, "%s:%s:", fieldfmt, fieldname);
ptr = stgdict->format;
if (dict->shape != NULL) {
stgdict->format = _ctypes_alloc_format_string_with_shape(
dict->ndim, dict->shape, stgdict->format, buf);
} else {
stgdict->format = _ctypes_alloc_format_string(stgdict->format, buf);
}
PyMem_Free(ptr);
PyMem_Free(buf);
if (stgdict->format == NULL) {
Py_DECREF(pair);
return -1;
}
}
if (isStruct) {
prop = PyCField_FromDesc(desc, i,
&field_size, bitsize, &bitofs,
&size, &offset, &align,
pack, big_endian);
} else /* union */ {
size = 0;
offset = 0;
align = 0;
prop = PyCField_FromDesc(desc, i,
&field_size, bitsize, &bitofs,
&size, &offset, &align,
pack, big_endian);
union_size = max(size, union_size);
}
total_align = max(align, total_align);
if (!prop) {
Py_DECREF(pair);
return -1;
}
if (-1 == PyObject_SetAttr(type, name, prop)) {
Py_DECREF(prop);
Py_DECREF(pair);
return -1;
}
Py_DECREF(pair);
Py_DECREF(prop);
}
#undef realdict
if (isStruct && !isPacked) {
char *ptr = stgdict->format;
stgdict->format = _ctypes_alloc_format_string(stgdict->format, "}");
PyMem_Free(ptr);
if (stgdict->format == NULL)
return -1;
}
if (!isStruct)
size = union_size;
/* Adjust the size according to the alignment requirements */
size = ((size + total_align - 1) / total_align) * total_align;
stgdict->ffi_type_pointer.alignment = Py_SAFE_DOWNCAST(total_align,
Py_ssize_t,
unsigned short);
stgdict->ffi_type_pointer.size = size;
stgdict->size = size;
stgdict->align = total_align;
stgdict->length = len; /* ADD ffi_ofs? */
/* We did check that this flag was NOT set above, it must not
have been set until now. */
if (stgdict->flags & DICTFLAG_FINAL) {
PyErr_SetString(PyExc_AttributeError,
"Structure or union cannot contain itself");
return -1;
}
stgdict->flags |= DICTFLAG_FINAL;
return MakeAnonFields(type);
} | /*
Retrive the (optional) _pack_ attribute from a type, the _fields_ attribute,
and create an StgDictObject. Used for Structure and Union subclasses.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/python/Modules/_ctypes/stgdict.c#L311-L599 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.