Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stock CompressFormat(const data[])
- {
- // This function encodes the data format in to a single cell. The format is:
- //
- // 1111111001
- //
- // Leading 1s indicate no data. The 0 immediately following the leading 1s
- // indicates the start of the format section (but is not PART of the format
- // section). The remaining bits represent either strings (1) or non-strings
- // (0). For example "(a, string:b, c)" would be:
- //
- // 1..10010
- //
- // Where "1..1" indicates full-cell padding of 1s. From this it is known that
- // the function takes three parameters: non-string, string, non-string. In
- // addition, as strings in inline functions MUST use the "string:" tag, it is
- // known that ALL strings will ALWAYS be 128 (or "YSI_MAX_STRING") cells big.
- new
- pos = 0,
- total = 1;
- for ( ; ; )
- {
- // Now matchs the compile-time code much closer.
- switch (data[pos++])
- {
- case '\0':
- {
- break;
- }
- case 's':
- {
- total <<= 1;
- }
- default:
- {
- total = (total << 1) | 1;
- }
- }
- }
- // Store the compressed format, also instantly end the string.
- return ~total;
- }
- forward @queryCallback(e_CALLBACK_FLAGS:cF, cP, cX, Alloc:cA, Alloc:a);
- public @queryCallback(e_CALLBACK_FLAGS:cF, cP, cX, Alloc:cA, Alloc:a)
- {
- new
- ret[E_CALLBACK_DATA];
- ret[E_CALLBACK_DATA_FLAGS] = cF;
- ret[E_CALLBACK_DATA_POINTER] = cP;
- ret[E_CALLBACK_DATA_FORMAT] = cX;
- ret[E_CALLBACK_DATA_ALLOC] = cA;
- Callback_Block(ret, Malloc_GetData(a, 2), Malloc_GetSlotSize(a) - 2);
- free(cA);
- free(a);
- }
- stock send_query(connectionHandle, query[], bool:cache, callback:callback, const type[], GLOBAL_TAG_TYPES:...)
- {
- new
- ret[E_CALLBACK_DATA],
- mem = CompressFormat(type);
- if (!Callback_Get(callback, ret))
- {
- return 0;
- }
- if (!(ret[E_CALLBACK_DATA_FLAGS] & e_CALLBACK_FLAGS_PUBLIC) && mem != ret[E_CALLBACK_DATA_FORMAT])
- {
- P:E("Format specifier didn't match on inline function %s: %04x%04x != %04x%04x", callback, mem >>> 16, mem & 0xFFFF, ret[E_CALLBACK_DATA_FORMAT] >>> 16, ret[E_CALLBACK_DATA_FORMAT] & 0xFFFF);
- Callback_Release(ret);
- return 0;
- }
- mem = 2;
- // Allocate enough memory to store all the parameters.
- for (new i = 0; ; ++i)
- {
- switch (type[i])
- {
- case '\0':
- {
- break;
- }
- case 's':
- {
- mem += YSI_MAX_STRING;
- }
- case 'a':
- {
- P:E("y_inline doesn't support arrays.");
- return 0;
- }
- default:
- {
- ++mem;
- }
- }
- }
- new
- Alloc:a = malloc(mem);
- if (a == NO_ALLOC)
- {
- Callback_Release(ret);
- return 0;
- }
- // Copy all the data to an array.
- //mem = 2;
- for (new i = 0, j = 4; ; ++i, ++j)
- {
- switch (type[i])
- {
- case '\0':
- {
- break;
- }
- case 's':
- {
- // Set variable argument string.
- mem -= YSI_MAX_STRING;
- Malloc_SetVAS(a, mem, j);
- //Malloc_Set(a, mem - 1, '\0');
- }
- default:
- {
- --mem;
- Malloc_Set(a, mem, getarg(j));
- }
- }
- }
- // Now call the handler.
- Malloc_Set(a, 1, _:ret[E_CALLBACK_DATA_ALLOC]);
- Malloc_Set(a, 0, mysql_function_query(connectionHandle, query, cache, "@queryCallback", "iiiii", _:ret[E_CALLBACK_DATA_FLAGS], ret[E_CALLBACK_DATA_POINTER], ret[E_CALLBACK_DATA_FORMAT], _:ret[E_CALLBACK_DATA_ALLOC], _:a));
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment